home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 19 / AACD19.BIN / CDTools / ClassAct / Examples / FuelGauge / fuelgaugeexample.c < prev    next >
C/C++ Source or Header  |  1997-07-09  |  6KB  |  270 lines

  1. ;/* FuelGauge Example
  2. sc link fuelgaugeexample.c lib lib:classact.lib
  3. quit
  4. */
  5.  
  6. /* system includes
  7.  */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <intuition/intuition.h>
  15. #include <intuition/gadgetclass.h>
  16. #include <graphics/gfxbase.h>
  17. #include <graphics/text.h>
  18. #include <graphics/gfxmacros.h>
  19. #include <utility/tagitem.h>
  20. #include <workbench/startup.h>
  21. #include <workbench/workbench.h>
  22.  
  23. #include <proto/intuition.h>
  24. #include <proto/graphics.h>
  25. #include <proto/exec.h>
  26. #include <proto/dos.h>
  27. #include <proto/utility.h>
  28. #include <proto/wb.h>
  29. #include <proto/icon.h>
  30.  
  31. /* ClassAct includes
  32.  */
  33. #include <classact.h>
  34.  
  35.  
  36. enum
  37. {
  38.     GID_GAUGE=0,
  39.     GID_DOWN,
  40.     GID_UP,
  41.     GID_QUIT,
  42.     GID_LAST
  43. };
  44.  
  45. enum
  46. {
  47.     WID_MAIN=0,
  48.     WID_LAST
  49. };
  50.  
  51. enum
  52. {
  53.     OID_MAIN=0,
  54.     OID_LAST
  55. };
  56.  
  57. #define FMIN 0
  58. #define FMAX 100
  59.  
  60. int main(void)
  61. {
  62.     struct MsgPort *AppPort;
  63.  
  64.     struct Window *windows[WID_LAST];
  65.  
  66.     struct Gadget *gadgets[GID_LAST];
  67.  
  68.     Object *objects[OID_LAST];
  69.  
  70.     /* make sure our classes opened... */
  71.     if (!ButtonBase || !FuelGaugeBase || !WindowBase || !LayoutBase)
  72.         return(30);
  73.     else if ( AppPort = CreateMsgPort() )
  74.     {
  75.         /* Create the window object.
  76.          */
  77.         objects[OID_MAIN] = WindowObject,
  78.             WA_ScreenTitle, "ClassAct Release 2.0",
  79.             WA_Title, "ClassAct FuelGauge Example",
  80.             WA_Activate, TRUE,
  81.             WA_DepthGadget, TRUE,
  82.             WA_DragBar, TRUE,
  83.             WA_CloseGadget, TRUE,
  84.             WA_SizeGadget, TRUE,
  85.             WINDOW_IconifyGadget, TRUE,
  86.             WINDOW_IconTitle, "FuelGauge",
  87.             WINDOW_AppPort, AppPort,
  88.             WINDOW_Position, WPOS_CENTERMOUSE,
  89.             WINDOW_ParentGroup, VGroupObject,
  90.                 LAYOUT_SpaceOuter, TRUE,
  91.                 LAYOUT_DeferLayout, TRUE,
  92.  
  93.                 LAYOUT_AddChild, gadgets[GID_GAUGE] = FuelGaugeObject,
  94.                     GA_ID, GID_GAUGE,
  95.                     FUELGAUGE_Orientation, FGORIENT_HORIZ,
  96.                     FUELGAUGE_Min, FMIN,
  97.                     FUELGAUGE_Max, FMAX,
  98.                     FUELGAUGE_Level, 0,
  99.                     FUELGAUGE_Percent, TRUE,
  100.                     FUELGAUGE_TickSize, 5,
  101.                     FUELGAUGE_Ticks, 5,
  102.                     FUELGAUGE_ShortTicks, TRUE,
  103.                 FuelGaugeEnd,
  104.  
  105.                 LAYOUT_AddChild, VGroupObject,
  106.                     CLASSACT_BackFill, NULL,
  107.                     LAYOUT_SpaceOuter, TRUE,
  108.                     LAYOUT_VertAlignment, LALIGN_CENTER,
  109.                     LAYOUT_HorizAlignment, LALIGN_CENTER,
  110.                     LAYOUT_BevelStyle, BVS_FIELD,
  111.  
  112.                     LAYOUT_AddImage, LabelObject,
  113.                         LABEL_Text, "The fuelgauge supports optional tickmarks as\n",
  114.                         LABEL_Text, "well as vertical and horizontal orientation.\n",
  115.                         LABEL_Text, " \n",
  116.                         LABEL_Text, "You can set the min/max range, as well as\n",
  117.                         LABEL_Text, "options such as varargs ascii display,\n",
  118.                         LABEL_Text, "percentage display, and custom pen selection.\n",
  119.                     LabelEnd,
  120.                 LayoutEnd,
  121.  
  122.  
  123.                 LAYOUT_AddChild, HGroupObject,
  124.                     LAYOUT_SpaceOuter, FALSE,
  125.                     LAYOUT_EvenSize, TRUE,
  126.  
  127.                     LAYOUT_AddChild, ButtonObject,
  128.                         GA_ID, GID_DOWN,
  129.                         GA_RelVerify, TRUE,
  130.                         GA_Text,"_Down",
  131.                     ButtonEnd,
  132.  
  133.                     LAYOUT_AddChild, ButtonObject,
  134.                         GA_ID, GID_UP,
  135.                         GA_RelVerify, TRUE,
  136.                         GA_Text,"_Up",
  137.                     ButtonEnd,
  138.  
  139.                     LAYOUT_AddChild, ButtonObject,
  140.                         GA_ID, GID_QUIT,
  141.                         GA_RelVerify, TRUE,
  142.                         GA_Text,"_Quit",
  143.                     ButtonEnd,
  144.                 LayoutEnd,
  145.                 CHILD_WeightedHeight, 0,
  146.  
  147.             EndGroup,
  148.         EndWindow;
  149.  
  150.          /*  Object creation sucessful?
  151.           */
  152.         if (objects[OID_MAIN])
  153.         {
  154.             /*  Open the window.
  155.              */
  156.             if (windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]))
  157.             {
  158.                 ULONG wait, signal, app = (1L << AppPort->mp_SigBit);
  159.                 ULONG done = FALSE;
  160.                 ULONG result;
  161.                 UWORD code;
  162.  
  163.                  /* Obtain the window wait signal mask.
  164.                  */
  165.                 GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  166.  
  167.                 /* Input Event Loop
  168.                  */
  169.                 while (!done)
  170.                 {
  171.                     wait = Wait( signal | SIGBREAKF_CTRL_C | app );
  172.  
  173.                     if ( wait & SIGBREAKF_CTRL_C )
  174.                     {
  175.                         done = TRUE;
  176.                     }
  177.                     else
  178.                     {
  179.                         while ( (result = CA_HandleInput(objects[OID_MAIN], &code) ) != WMHI_LASTMSG )
  180.                         {
  181.                             switch (result & WMHI_CLASSMASK)
  182.                             {
  183.                                 case WMHI_CLOSEWINDOW:
  184.                                     windows[WID_MAIN] = NULL;
  185.                                     done = TRUE;
  186.                                     break;
  187.  
  188.                                 case WMHI_GADGETUP:
  189.                                     switch (result & WMHI_GADGETMASK)
  190.                                     {
  191.                                         case GID_DOWN:
  192.                                             {
  193.                                                 int i;
  194.  
  195.                                                 SetAttrs(objects[OID_MAIN], WA_BusyPointer, TRUE);
  196.  
  197.                                                 for( i = FMAX; i >= FMIN; i -= 5 )
  198.                                                 {
  199.                                                     SetGadgetAttrs(
  200.                                                         gadgets[GID_GAUGE],
  201.                                                         windows[WID_MAIN], NULL,
  202.                                                         FUELGAUGE_Level, i, TAG_DONE);
  203.                                                     Delay(3);
  204.                                                 }
  205.  
  206.                                                 SetAttrs(objects[OID_MAIN], WA_BusyPointer, FALSE);
  207. ;
  208.                                             }
  209.                                             break;
  210.  
  211.                                         case GID_UP:
  212.                                             {
  213.                                                 int i;
  214.  
  215.                                                 SetAttrs(objects[OID_MAIN], WA_BusyPointer, TRUE);
  216.  
  217.                                                 for( i = FMIN; i <= FMAX; i += 5 )
  218.                                                 {
  219.                                                     SetGadgetAttrs(
  220.                                                         gadgets[GID_GAUGE],
  221.                                                         windows[WID_MAIN], NULL,
  222.                                                         FUELGAUGE_Level, i, TAG_DONE);
  223.                                                     Delay(3);
  224.                                                 }
  225.  
  226.                                                 SetAttrs(objects[OID_MAIN], WA_BusyPointer, FALSE);
  227.                                             }
  228.                                             break;
  229.  
  230.                                         case GID_QUIT:
  231.                                             done = TRUE;
  232.                                             break;
  233.                                     }
  234.                                     break;
  235.  
  236.                                 case WMHI_ICONIFY:
  237.                                     CA_Iconify(objects[OID_MAIN]);
  238.                                     windows[WID_MAIN] = NULL;
  239.                                     break;
  240.  
  241.                                 case WMHI_UNICONIFY:
  242.                                     windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]);
  243.  
  244.                                     if (windows[WID_MAIN])
  245.                                     {
  246.                                         GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  247.                                     }
  248.                                     else
  249.                                     {
  250.                                         done = TRUE;    // error re-opening window!
  251.                                     }
  252.                                      break;
  253.                             }
  254.                         }
  255.                     }
  256.                 }
  257.             }
  258.  
  259.             /* Disposing of the window object will also close the window if it is
  260.              * already opened, and it will dispose of the layout object attached to it.
  261.              */
  262.             DisposeObject(objects[OID_MAIN]);
  263.         }
  264.  
  265.         DeleteMsgPort(AppPort);
  266.     }
  267.  
  268.     return(0);
  269. }
  270.