home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0922.lha / DesignerDemo / KeyDemo / KeyDemo.c < prev    next >
C/C++ Source or Header  |  1993-10-07  |  7KB  |  239 lines

  1. /* Simple demo using a Designer created file */
  2. /* Only run from CLI */
  3.  
  4. #include <keydemowin.c>
  5.  
  6. ULONG MyTags[]=
  7.     {
  8.     0,0,
  9.     TAG_DONE
  10.     };
  11.  
  12. void main(void)
  13. {
  14. int done=0;
  15. ULONG class;
  16. UWORD code;
  17. struct Gadget *pgsel;
  18. struct IntuiMessage *imsg;
  19. int GadNumber;
  20. int CycleGadPos=0;
  21. int SliderPos=0;
  22. int ScrollerPos=0;
  23. int PalettePos=0;
  24. if (OpenLibs()==0)
  25.     {
  26.     if (OpenWindowMainWindow()==0)
  27.         {
  28.         printf("Key Demo Begins...\n");
  29.         while (done==0)
  30.             {
  31.             Wait(1L << MainWindow->UserPort->mp_SigBit);
  32.             imsg=GT_GetIMsg(MainWindow->UserPort);
  33.             while (imsg != NULL )
  34.                 {
  35.                 class=imsg->Class;
  36.                 code=imsg->Code;
  37.                 pgsel=(struct Gadget *)imsg->IAddress; /* Only reference if it is a gadget message */
  38.                 GT_ReplyIMsg(imsg);
  39.                 GadNumber = 99;
  40.                 switch (class)
  41.                     {
  42.                     case IDCMP_CLOSEWINDOW :
  43.                         done=1;
  44.                         break;
  45.                     case IDCMP_GADGETDOWN :
  46.                         GadNumber = pgsel->GadgetID;
  47.                         break;
  48.                     case IDCMP_GADGETUP :
  49.                         GadNumber = pgsel->GadgetID;
  50.                         break;
  51.                     case IDCMP_VANILLAKEY :
  52.                         
  53.                         /* For these gadgets case matters  */
  54.                         
  55.                         switch (code)
  56.                             {
  57.                             case 'p' :
  58.                                 PalettePos += 1;
  59.                                 if (PalettePos>(1L << MainWindowDepth)-1)
  60.                                   PalettePos=0;
  61.                                 printf("Palette = %ld\n",PalettePos);
  62.                                 MyTags[0] = GTPA_Color;
  63.                                 MyTags[1] = PalettePos;
  64.                                 GT_SetGadgetAttrsA(MainWindowGadgets[PaletteGadget], MainWindow, NULL, MyTags);
  65.                                 break;
  66.                             case 'P' :
  67.                                 PalettePos -= 1;
  68.                                 if (PalettePos<0)
  69.                                   PalettePos = (1L << MainWindowDepth)-1;
  70.                                 printf("Palette = %ld\n",PalettePos);
  71.                                 MyTags[0] = GTPA_Color;
  72.                                 MyTags[1] = PalettePos;
  73.                                 GT_SetGadgetAttrsA(MainWindowGadgets[PaletteGadget], MainWindow, NULL, MyTags);
  74.                                 break;
  75.                             case 'y' :
  76.                                 CycleGadPos += 1;
  77.                                 if (CycleGadPos>3)
  78.                                   CycleGadPos=0;
  79.                                 printf("Cycle = %ld\n",CycleGadPos);
  80.                                 MyTags[0] = GTCY_Active;
  81.                                 MyTags[1] = CycleGadPos;
  82.                                 GT_SetGadgetAttrsA(MainWindowGadgets[CycleGadget], MainWindow, NULL, MyTags);
  83.                                 break;
  84.                             case 'Y' :
  85.                                 CycleGadPos -= 1;
  86.                                 if (CycleGadPos<0)
  87.                                   CycleGadPos=3;
  88.                                 printf("Cycle = %ld\n",CycleGadPos);
  89.                                 MyTags[0] = GTCY_Active;
  90.                                 MyTags[1] = CycleGadPos;
  91.                                 GT_SetGadgetAttrsA(MainWindowGadgets[CycleGadget], MainWindow, NULL, MyTags);
  92.                                 break;
  93.                             case 'r' :
  94.                                 if (ScrollerPos<8)
  95.                                   ScrollerPos += 1;
  96.                                 printf("Scroller =  %ld\n",ScrollerPos);
  97.                                 MyTags[0] = GTSC_Top;
  98.                                 MyTags[1] = ScrollerPos;
  99.                                 GT_SetGadgetAttrsA(MainWindowGadgets[ScrollerGadget], MainWindow, NULL, MyTags);
  100.                                 break;
  101.                             case 'R' :
  102.                                 if (ScrollerPos>0)
  103.                                   ScrollerPos -= 1;
  104.                                 printf("Scroller =  %ld\n",ScrollerPos);
  105.                                 MyTags[0] = GTSC_Top;
  106.                                 MyTags[1] = ScrollerPos;
  107.                                 GT_SetGadgetAttrsA(MainWindowGadgets[ScrollerGadget], MainWindow, NULL, MyTags);
  108.                                 break;
  109.                             case 'l' :
  110.                                 if (SliderPos<15)
  111.                                   SliderPos += 1;
  112.                                 printf("Slider = %ld\n",SliderPos);
  113.                                 MyTags[0] = GTSL_Level;
  114.                                 MyTags[1] = SliderPos;
  115.                                 GT_SetGadgetAttrsA(MainWindowGadgets[SliderGadget], MainWindow, NULL, MyTags);
  116.                                 break;
  117.                             case 'L' :
  118.                                 if (SliderPos>0)
  119.                                   SliderPos -= 1;
  120.                                 printf("Slider = %ld\n",SliderPos);
  121.                                 MyTags[0] = GTSL_Level;
  122.                                 MyTags[1] = SliderPos;
  123.                                 GT_SetGadgetAttrsA(MainWindowGadgets[SliderGadget], MainWindow, NULL, MyTags);
  124.                                 break;
  125.                             }
  126.                         
  127.                         /* Downcase key code */
  128.                         
  129.                         if ( (64<code) && (code<91) )
  130.                             code +=32;
  131.                         
  132.                         /* For these gadgets case does not matter */
  133.                         
  134.                         switch (code)
  135.                             {
  136.                             case 's' :
  137.                                 printf("Activating String Gadget\n");
  138.                                 ActivateGadget(MainWindowGadgets[StringGadget], MainWindow, NULL);
  139.                                 break;
  140.                             case 'i' :
  141.                                 printf("Activating Integer Gadget\n");
  142.                                 ActivateGadget(MainWindowGadgets[IntegerGadget], MainWindow, NULL);
  143.                                 break;
  144.                             case 'q' :
  145.                                 GadNumber = QuitButton;
  146.                                 break;
  147.                             case 'b' :
  148.                                 GadNumber = ButtonGadget;
  149.                                 break;
  150.                             case '0' :
  151.                                 printf("MX = 0\n");
  152.                                 MyTags[0] = GTMX_Active;
  153.                                 MyTags[1] = 0;
  154.                                 GT_SetGadgetAttrsA(MainWindowGadgets[MXGadget], MainWindow, NULL, MyTags);
  155.                                 break;
  156.                             case '1' :
  157.                                 printf("MX = 1\n");
  158.                                 MyTags[0] = GTMX_Active;
  159.                                 MyTags[1] = 1;
  160.                                 GT_SetGadgetAttrsA(MainWindowGadgets[MXGadget], MainWindow, NULL, MyTags);
  161.                                 break;
  162.                             case '2' :
  163.                                 printf("MX = 2\n");
  164.                                 MyTags[0] = GTMX_Active;
  165.                                 MyTags[1] = 2;
  166.                                 GT_SetGadgetAttrsA(MainWindowGadgets[MXGadget], MainWindow, NULL, MyTags);
  167.                                 break;
  168.                             case '3' :
  169.                                 printf("MX = 3\n");
  170.                                 MyTags[0] = GTMX_Active;
  171.                                 MyTags[1] = 3;
  172.                                 GT_SetGadgetAttrsA(MainWindowGadgets[MXGadget], MainWindow, NULL, MyTags);
  173.                                 break;
  174.                             case 'c' :
  175.                                 printf("CheckBox Toggled\n");
  176.                                 MyTags[0] = GTCB_Checked;
  177.                                 if ((MainWindowGadgets[CheckBoxGadget]->Flags & GFLG_SELECTED)==0)
  178.                                     {
  179.                                     MyTags[1] = TRUE;
  180.                                     }
  181.                                 else
  182.                                     {
  183.                                     MyTags[1] = FALSE;
  184.                                     };
  185.                                 GT_SetGadgetAttrsA(MainWindowGadgets[CheckBoxGadget], MainWindow, NULL, MyTags);
  186.                                 break;
  187.                             }
  188.                         break;
  189.                     };
  190.                 switch (GadNumber)
  191.                     {
  192.                     case CheckBoxGadget :
  193.                         printf("CheckBox Toggled\n");
  194.                         break;
  195.                     case PaletteGadget :
  196.                         PalettePos = code;
  197.                         printf("Palette = %ld\n",code);
  198.                         break;
  199.                     case ButtonGadget :
  200.                         printf("Button Pressed\n");
  201.                         break;
  202.                     case IntegerGadget :
  203.                         printf("Integer Gadget = %ld\n",((struct StringInfo *)MainWindowGadgets[IntegerGadget]->SpecialInfo)->LongInt);
  204.                         break;
  205.                     case StringGadget :
  206.                         printf("String Gadget = %s\n",((struct StringInfo *)MainWindowGadgets[StringGadget]->SpecialInfo)->Buffer);
  207.                         break;
  208.                     case QuitButton :
  209.                         done = 1;
  210.                         break;
  211.                     case MXGadget :
  212.                         printf("MX = %ld\n",code);
  213.                         break;
  214.                     case CycleGadget :
  215.                         CycleGadPos = code;
  216.                         printf("Cycle = %ld\n",code);
  217.                         break;
  218.                     case SliderGadget :
  219.                         SliderPos = code;
  220.                         printf("Slider = %ld\n",code);
  221.                         break;
  222.                     case ScrollerGadget :
  223.                         ScrollerPos = code;
  224.                         printf("Scroller = %ld\n",code);
  225.                         break;
  226.                     };
  227.                 imsg=GT_GetIMsg(MainWindow->UserPort);
  228.                 }
  229.             }
  230.         printf("Bye...\n");
  231.         CloseWindowMainWindow();
  232.         }
  233.     else
  234.         printf("Cannot open window.\n");
  235.     }
  236. else
  237.     printf("Cannot open libraries.\n");
  238. }
  239.