home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Programming / MR_Classes / Dev / Examples / TCPalette / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-04  |  7.4 KB  |  239 lines

  1. #include <clib/alib_protos.h>
  2. #include <clib/extras_protos.h>
  3.  
  4. #include <stdio.h>
  5. #include <tagitemmacros.h>
  6.  
  7. #include <classes/supermodel.h>
  8. #include <proto/classes/supermodel.h>
  9.  
  10. #include <proto/classes/gadgets/tcpalette.h>
  11. #include <classes/gadgets/tcpalette.h>
  12.  
  13. #include <proto/exec.h>
  14. #include <proto/dos.h>
  15. #include <proto/intuition.h>
  16. #include <proto/window.h>
  17. #include <proto/label.h>
  18. #include <proto/slider.h>
  19. #include <proto/layout.h>
  20. #include <proto/button.h>
  21.  
  22. #include <intuition/classes.h>
  23.  
  24. #include <classes/window.h>
  25.  
  26. #include <gadgets/layout.h>
  27. #include <gadgets/button.h>
  28. #include <gadgets/slider.h>
  29.  
  30. #include <images/label.h>
  31.  
  32. #include <reaction/reaction.h>
  33. #include <reaction/reaction_macros.h>
  34.  
  35.  
  36. #define APP_Test (TAG_USER + 1)
  37. #define APP_Red (TAG_USER + 2)
  38. #define APP_Green (TAG_USER + 3)
  39. #define APP_Blue (TAG_USER + 4)
  40.  
  41. #define ID_BUTTON       1
  42. #define ID_FOREGROUND      2
  43. #define ID_BACKGROUND    3
  44.  
  45. struct Library  *WindowBase,
  46.                 *LayoutBase,
  47.                 *LabelBase,
  48.                 *ButtonBase,
  49.                 *BevelBase,
  50.                 *SliderBase,
  51.                 *TCPaletteBase,
  52.                 *SuperModelBase;
  53.                 
  54. struct LocaleBase *LocaleBase;
  55.  
  56. struct Catalog *Catalog;
  57.  
  58. struct Libs MyLibs[]=
  59. {
  60.   (APTR *)&WindowBase,    "window.class",               44,     0,
  61.   (APTR *)&LayoutBase,    "gadgets/layout.gadget",      44,     0,
  62.   (APTR *)&ButtonBase,    "gadgets/button.gadget",      44,     0,
  63.   (APTR *)&LabelBase,     "images/label.image",         44,     0,
  64.   (APTR *)&BevelBase,     "images/bevel.image",         44,     0,
  65.   (APTR *)&SliderBase,    "gadgets/slider.gadget",      44,     0,
  66.   (APTR *)&TCPaletteBase, "gadgets/tcpalette.gadget",   44,     0,
  67.   (APTR *)&SuperModelBase,"supermodel.class",           44,     0,
  68.   0, 0, 0, 0
  69. };
  70.  
  71.  
  72. int main( int argc, char *argv[] )
  73. {
  74.     struct Window *window;
  75.     Object *Win_Object, *Pal1, *Red, *Green, *Blue;
  76.   ULONG palette[]={0xff0000, 0x00ff00, 0x0000ff, 0xffffff, 0x000000, 0x888888},l,lrgb;
  77.   struct TCPaletteRGB p[6],rgb;
  78.  
  79.     if(ex_OpenLibs(argc, "TCPaletteTest", 0,0,0, MyLibs))
  80.   {
  81.     Win_Object = (Object *)WindowObject,
  82.               WA_ScreenTitle, "TCPalette",
  83.               WA_Title,       "TCPalette",
  84.               WA_SizeGadget,  TRUE,
  85.               WA_DepthGadget, TRUE,
  86.               WA_DragBar,     TRUE,
  87.               WA_CloseGadget, TRUE,
  88.               WA_Activate,    TRUE,
  89.               WA_SmartRefresh,      TRUE,
  90.                WINDOW_ParentGroup,   VLayoutObject,
  91.                   LAYOUT_DeferLayout, TRUE,
  92.           LAYOUT_AddChild,    Button("Test",0), 
  93.             CHILD_WeightedHeight,0,
  94.           LAYOUT_AddChild,    Pal1=TCPaletteObject,
  95.                                 TCPALETTE_NumColors,    6,
  96.                                 TCPALETTE_LRGBPalette,  palette, 
  97.                                 TCPALETTE_Precision,    8,
  98.                                 End,          
  99.             Label("_Palette"),
  100.           
  101.           LAYOUT_AddChild,    Red=SliderObject,
  102.                                 SLIDER_Max, 0xff,
  103.                                 SLIDER_Min, 0,
  104.                                 SLIDER_Orientation,FREEHORIZ,
  105.                                 End,          
  106.             CHILD_WeightedHeight,0,
  107.           
  108.           LAYOUT_AddChild,    Green=SliderObject,
  109.                                 SLIDER_Max, 0xff,
  110.                                 SLIDER_Min, 0,
  111.                                 SLIDER_Orientation,FREEHORIZ,
  112.                                 End,
  113.             CHILD_WeightedHeight,0,
  114.             
  115.           LAYOUT_AddChild,    Blue=SliderObject,
  116.                                 SLIDER_Max, 0xff,
  117.                                 SLIDER_Min, 0,
  118.                                 SLIDER_Orientation,FREEHORIZ,
  119.                                 End,                    
  120.             CHILD_WeightedHeight,0,
  121.                EndMember,
  122.           EndWindow;
  123.   
  124.           /*  Object creation sucessful?
  125.            */
  126.     if( Win_Object )
  127.       {
  128.       Object *model;
  129.       model=SM_NewSuperModel(
  130.                   SMA_AddMember,  SM_SICMAP( Pal1,
  131.                                     TCPALETTE_SelectedRGB,         APP_Test,
  132.                                     TCPALETTE_SelectedRed,         APP_Red,
  133.                                     TCPALETTE_SelectedGreen,       APP_Green,
  134.                                     TCPALETTE_SelectedBlue,        APP_Blue,
  135.                                     TAG_DONE),
  136.                   SMA_AddMember,  SM_SICMAP( Red,
  137.                                     SLIDER_Level,                   APP_Red,
  138.                                     TAG_DONE),
  139.                   SMA_AddMember,  SM_SICMAP( Green,
  140.                                     SLIDER_Level,                   APP_Green,
  141.                                     TAG_DONE),
  142.                   SMA_AddMember,  SM_SICMAP( Blue,
  143.                                     SLIDER_Level,                   APP_Blue,
  144.                                     TAG_DONE),                              
  145.                   TAG_DONE);
  146.         
  147.               /*  Open the window. */
  148.        
  149.       if( window = (struct Window *) RA_OpenWindow(Win_Object) )
  150.       {
  151.             ULONG wait, signal, result, done = FALSE;
  152.               WORD Code;
  153.                   
  154.               /* Obtain the window wait signal mask. */
  155.             GetAttr( WINDOW_SigMask, Win_Object, &signal );
  156.   
  157.               /* Input Event Loop */
  158.               while( !done )
  159.               {
  160.                 wait = Wait(signal|SIGBREAKF_CTRL_C);
  161.                      if (wait & SIGBREAKF_CTRL_C) 
  162.             done = TRUE;
  163.                      else
  164.           {
  165.                       while ((result = RA_HandleInput(Win_Object,&Code)) != WMHI_LASTMSG)
  166.                       {
  167.                           switch (result & WMHI_CLASSMASK)
  168.                           {
  169.                               case WMHI_CLOSEWINDOW:
  170.                                   done = TRUE;
  171.                                   break;
  172.   
  173.                               case WMHI_GADGETUP:
  174.                                   switch(result & WMHI_GADGETMASK)
  175.                                   {
  176.                                       case ID_BUTTON:
  177.                                           break;
  178.                                   }
  179.                                   break;
  180.                           }
  181.                       }
  182.                   }
  183.               }
  184.   
  185.               /* Disposing of the window object will
  186.                * also close the window if it is
  187.                * already opened and it will dispose of
  188.                * all objects attached to it.
  189.                */
  190.         GetAttr(TCPALETTE_RGBPalette, Pal1, p);
  191.         
  192.         for(l=0;l<6;l++)
  193.         {
  194.           printf("TCPALETTE_RGBPalette %d R:%08x G:%08x B:%08x\n",l,p[l].R,p[l].G,p[l].B);
  195.         }
  196.          
  197.         GetAttr(TCPALETTE_LRGBPalette, Pal1, palette);
  198.         for(l=0;l<6;l++)
  199.         {
  200.           printf("TCPALETTE_LRGBPalette %d 0x%06x\n",l,palette[l]);
  201.         }
  202.         
  203.         GetAttr(TCPALETTE_SelectedColor, Pal1, &l);
  204.         printf("TCPALETTE_SelectedColor %d\n",l);
  205.         
  206.         GetAttr(TCPALETTE_SelectedRGB, Pal1, &rgb);
  207.         printf("TCPALETTE_PaletteRGB R:0%08x G:0%08x B:0%08x\n",rgb.R,rgb.G,rgb.B);
  208.         
  209.         GetAttr(TCPALETTE_SelectedLRGB, Pal1, &lrgb);
  210.         printf("TCPALETTE_SelectedLRGB 0x%06x\n",lrgb);
  211.         printf("Note: TCPALETTE_SelectedRed, Green & Blue use the folowing precision\n");
  212.         
  213.         GetAttr(TCPALETTE_Precision, Pal1, &l);
  214.         printf("TCPALETTE_Precision   0x%08x\n",l);
  215.         
  216.         GetAttr(TCPALETTE_SelectedRed, Pal1, &l);
  217.         printf("TCPALETTE_SelectedRed   0x%08x\n",l);
  218.         
  219.         GetAttr(TCPALETTE_SelectedGreen, Pal1, &l);
  220.         printf("TCPALETTE_SelectedGreen 0x%08x\n",l);
  221.         
  222.         GetAttr(TCPALETTE_SelectedBlue, Pal1, &l);
  223.         printf("TCPALETTE_SelectedBlue  0x%08x\n",l);
  224.         
  225.         GetAttr(TCPALETTE_ShowSelected, Pal1, &l);
  226.         printf("TCPALETTE_ShowSelected  %d\n",l);
  227.         
  228.         GetAttr(TCPALETTE_NumColors, Pal1, &l);
  229.         printf("TCPALETTE_NumColors  %d\n",l);
  230.            
  231.         DisposeObject(model);
  232.               DisposeObject( Win_Object );
  233.           }
  234.     }
  235.     ex_CloseLibs(MyLibs);
  236.   }
  237. }
  238.  
  239.