home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_07_01 / v7n1080a.txt < prev    next >
Text File  |  1987-04-27  |  20KB  |  794 lines

  1.  
  2. /*                              JustSayYes.c
  3.  
  4.    An example of Intuition use. Presenting: a generic color control window,
  5.    a very simple menu, and lots of odds and ends. 4/25/88 JMFiore dissidents.
  6.    This program is in the public domain. Use it as you see fit (with the
  7.    exception of distribution for a profit).
  8.  
  9.    compiled and linked with Manx Aztec C v3.6 under AmigaDOS 1.2
  10.  
  11.    cc +L JustSayYes.c
  12.    ln +cdb JustSayYes.o -lc32
  13.  
  14. */
  15.  
  16. #include "functions.h"
  17. #include "intuition/intuition.h"
  18.  
  19. /*---------------------------------defines---------------------------------*/
  20.  
  21.   /* MyText(*RastPort, Xposition, Yposition, char *buffer) */
  22.  
  23. #define MyText(r,x,y,b) Move((r),(x),(y)); Text((r),(b),strlen(b))
  24.  
  25. #define INTUITION_REV 33L
  26. #define GRAPHICS_REV  33L
  27. #define DEPTH         3
  28. #define MAX_COLORS    8     /* 2 raised to the DEPTH power */
  29.  
  30. /* #define COLLECT_RODENT_GYRATIONS */
  31. /* uncomment the line above if you would like a less processor intensive
  32.    color slider update, vs. responding to every single mouse move. */
  33.  
  34.  
  35. /* color requester gagdets.
  36.    These defines are used as ID numbers in order to keep track of which
  37.    color gadget is selected. CG0 - CG7 are the color select boxes, CGR, CGG
  38.    CGB are the RGB sliders, and CGSAVE, CGCANCEL are the Save/Cancel buttons. */
  39.  
  40. #define CGLOWEST      1
  41. #define CG0           2
  42. #define CG1           3
  43. #define CG2           4
  44. #define CG3           5
  45. #define CG4           6
  46. #define CG5           7
  47. #define CG6           8
  48. #define CG7           9
  49. #define CGR          10
  50. #define CGG          11
  51. #define CGB          12
  52. #define CGSAVE       13
  53. #define CGCANCEL     14
  54. #define CGHIGHEST    15
  55.  
  56. struct IntuitionBase *IntuitionBase=0L;
  57. struct GfxBase       *GfxBase=0L;
  58. struct Window        *back_wind=0L;
  59. struct Window        *color_wind=0L;
  60. struct Screen        *main_scrn=0L;
  61. struct ViewPort      *color_w_v_port=0L;
  62.  
  63.  
  64. /* use the 80 character topaz font for the screen lettering */
  65.  
  66. struct TextAttr my_font_attr={(UBYTE *)"topaz.font",TOPAZ_EIGHTY,\
  67.                               FS_NORMAL, FPF_ROMFONT};
  68.  
  69. struct NewScreen ns={0,0,640,200, DEPTH, 0,1, HIRES,\
  70.                      SCREENBEHIND | CUSTOMSCREEN, &my_font_attr, \
  71.                      (UBYTE *)"|| Color Window Example || ", NULL, NULL };
  72.  
  73. struct NewWindow b_nw={0,0,640,200, -1,-1, GADGETUP | GADGETDOWN | \
  74.                        MENUPICK , SMART_REFRESH | ACTIVATE | BACKDROP | \
  75.                        BORDERLESS, NULL, NULL, \
  76.                        (UBYTE *)" Backdrop Window ",\
  77.                        NULL, NULL, 640, 200, 640, 200, CUSTOMSCREEN};
  78.  
  79.  
  80. USHORT sys_color_table[MAX_COLORS]={0xcbb,0x530,0xf00,0xf40,0xbf0,\
  81.                                     0x84f,0xbfd,0x48b};
  82.  
  83. /* Quit requester Auto() */
  84.  
  85. struct IntuiText qr_txt[]={\
  86.  {0,1,JAM1,20,10,NULL,(UBYTE *)"Quit for sure?"},\
  87.  {0,1,JAM1,5,3,NULL,(UBYTE *)"Okay"},\
  88.  {0,1,JAM1,5,3,NULL,(UBYTE *)"Naaahh"},};
  89.  
  90.  
  91.  
  92. /* Menu set-up */
  93.  
  94. struct IntuiText itxt[]={\
  95.  {0,1,JAM1,0,0,NULL,(UBYTE *)"-Quit-"},\
  96.  {0,1,JAM1,0,0,NULL,(UBYTE *)" Color"},};
  97.  
  98.  
  99. struct MenuItem mi[]={\
  100.  {NULL,0,(0*10+1),(104+COMMSEQ),8,\
  101.   (ITEMTEXT | COMMSEQ | ITEMENABLED | HIGHBOX),\
  102.   NULL,(APTR)&itxt[0],NULL,'Q'},\
  103.  
  104.   /* Color */
  105.  
  106.  {NULL,0,(0*10+1),(52),8,\
  107.   (ITEMTEXT | ITEMENABLED | HIGHBOX),\
  108.   NULL,(APTR)&itxt[1],NULL},};
  109.  
  110.  
  111. struct Menu main_menu[]={\
  112.  {&main_menu[1],0,0,72,0,MENUENABLED,\
  113.   "Project  ",&mi[0]},\
  114.  
  115.  {NULL,280,0,56,0,MENUENABLED,\
  116.   "Color  ",&mi[1]},};
  117.  
  118.  
  119.  
  120. /* shapes for push buttons */
  121.  
  122. SHORT button50_pts[]={0,0, 50,0, 50,12, 0,12, 0,0};
  123.  
  124. SHORT button80_pts[]={0,0, 80,0, 80,12, 0,12, 0,0};
  125.  
  126.  
  127. struct Border button50= {0,0,2,0,JAM1,5,&button50_pts[0],NULL};
  128.  
  129. struct Border button80= {0,0,3,0,JAM1,5,&button80_pts[0],NULL};
  130.  
  131.  
  132. /* data chunk for color window, hi/un light, etc */
  133.  
  134. #define CGHSIZE      20 /* size of gadgets */
  135. #define CGVSIZE       7
  136. #define CGHOFF       30 /* offsets for successive gadgets */
  137. #define CGVOFF       10
  138. #define CGHPOS      170 /* initial position for starting gadget, CG0 */
  139. #define CGVPOS       20
  140.  
  141.  
  142.  
  143. SHORT color_hi_pts[]={-4,-2, CGHSIZE+2,-2, CGHSIZE+2,CGVSIZE+1,
  144.                       -4,CGVSIZE+1, -4,-2};
  145.  
  146. struct Border color_hi_light=\
  147.        {0,0,1,0,JAM1,5,&color_hi_pts[0],NULL};
  148.  
  149. struct Border color_un_light=\
  150.        {0,0,0,0,JAM1,5,&color_hi_pts[0],NULL};
  151.  
  152.  
  153.  
  154. struct IntuiText color_txt[]={\
  155.  {4,0,JAM1,15,3,NULL,(UBYTE *)"Cancel"},\
  156.  {5,0,JAM1,10,3,NULL,(UBYTE *)"Save"},\
  157.  {1,0,JAM1,-30,1,NULL,(UBYTE *)"R"},\
  158.  {1,0,JAM1,-30,1,NULL,(UBYTE *)"G"},\
  159.  {1,0,JAM1,-30,1,NULL,(UBYTE *)"B"},};
  160.  
  161.  
  162. struct Image color_box[]={\
  163.  {0,0,CGHSIZE,CGVSIZE,0,NULL,0,0,NULL},\
  164.  {0,0,CGHSIZE,CGVSIZE,0,NULL,0,1,NULL},\
  165.  {0,0,CGHSIZE,CGVSIZE,0,NULL,0,2,NULL},\
  166.  {0,0,CGHSIZE,CGVSIZE,0,NULL,0,3,NULL},\
  167.  {0,0,CGHSIZE,CGVSIZE,0,NULL,0,4,NULL},\
  168.  {0,0,CGHSIZE,CGVSIZE,0,NULL,0,5,NULL},\
  169.  {0,0,CGHSIZE,CGVSIZE,0,NULL,0,6,NULL},\
  170.  {0,0,CGHSIZE,CGVSIZE,0,NULL,0,7,NULL},};
  171.  
  172. struct Image color_img[3];
  173.  
  174. struct PropInfo color_prop[]={\
  175.  {AUTOKNOB | FREEHORIZ, 0x0, 0, 0xffff/16+1, 0},\
  176.  {AUTOKNOB | FREEHORIZ, 0x0, 0, 0xffff/16+1, 0},\
  177.  {AUTOKNOB | FREEHORIZ, 0x0, 0, 0xffff/16+1, 0},};
  178.  
  179. struct Gadget color_gadg[]={\
  180.  {&color_gadg[1],25,72,50,12,GADGHCOMP, RELVERIFY,\
  181.   BOOLGADGET, (APTR)&button50,NULL,\
  182.   &color_txt[1],NULL,NULL,CGSAVE,NULL},\
  183.  
  184.  {&color_gadg[2],40,20,110,9,GADGHCOMP,GADGIMMEDIATE |\
  185.   RELVERIFY | FOLLOWMOUSE,\
  186.   PROPGADGET ,(APTR)&color_img[0],NULL,\
  187.   &color_txt[2],NULL,(APTR)&color_prop[0],CGR,NULL},\
  188.  
  189.  {&color_gadg[3],40,32,110,9,GADGHCOMP,GADGIMMEDIATE |\
  190.   RELVERIFY | FOLLOWMOUSE,\
  191.   PROPGADGET ,(APTR)&color_img[1],NULL,\
  192.   &color_txt[3],NULL,(APTR)&color_prop[1],CGG,NULL},\
  193.  
  194.  {&color_gadg[4],40,44,110,9,GADGHCOMP,GADGIMMEDIATE |\
  195.   RELVERIFY | FOLLOWMOUSE,\
  196.   PROPGADGET ,(APTR)&color_img[2],NULL,\
  197.   &color_txt[4],NULL,(APTR)&color_prop[2],CGB,NULL},\
  198.  
  199.  {&color_gadg[5], CGHPOS, CGVPOS, CGHSIZE, CGVSIZE,\
  200.   GADGHNONE | GADGIMAGE, GADGIMMEDIATE,\
  201.   BOOLGADGET ,(APTR)&color_box[0],NULL,\
  202.   NULL,NULL,NULL,CG0,NULL},\
  203.  
  204.  {&color_gadg[6], CGHPOS, CGVPOS+CGVOFF, CGHSIZE, CGVSIZE,\
  205.   GADGHNONE | GADGIMAGE, GADGIMMEDIATE,\
  206.   BOOLGADGET ,(APTR)&color_box[1],NULL,\
  207.   NULL,NULL,NULL,CG1,NULL},\
  208.  
  209.  {&color_gadg[7], CGHPOS, CGVPOS+2*CGVOFF, CGHSIZE, CGVSIZE, \
  210.   GADGHNONE | GADGIMAGE, GADGIMMEDIATE,\
  211.   BOOLGADGET ,(APTR)&color_box[2],NULL,\
  212.   NULL,NULL,NULL,CG2,NULL},\
  213.  
  214.  {&color_gadg[8], CGHPOS, CGVPOS+3*CGVOFF, CGHSIZE, CGVSIZE, \
  215.   GADGHNONE | GADGIMAGE, GADGIMMEDIATE,\
  216.   BOOLGADGET ,(APTR)&color_box[3],NULL,\
  217.   NULL,NULL,NULL,CG3,NULL},\
  218.  
  219.  {&color_gadg[9], CGHPOS+CGHOFF, CGVPOS, CGHSIZE, CGVSIZE, \
  220.   GADGHNONE | GADGIMAGE, GADGIMMEDIATE,\
  221.   BOOLGADGET ,(APTR)&color_box[4],NULL,\
  222.   NULL,NULL,NULL,CG4,NULL},\
  223.  
  224.  {&color_gadg[10], CGHPOS+CGHOFF, CGVPOS+CGVOFF, CGHSIZE, CGVSIZE, \
  225.   GADGHNONE | GADGIMAGE, GADGIMMEDIATE,\
  226.   BOOLGADGET ,(APTR)&color_box[5],NULL,\
  227.   NULL,NULL,NULL,CG5,NULL},\
  228.  
  229.  {&color_gadg[11], CGHPOS+CGHOFF, CGVPOS+2*CGVOFF, CGHSIZE, CGVSIZE, \
  230.   GADGHNONE | GADGIMAGE, GADGIMMEDIATE,\
  231.   BOOLGADGET ,(APTR)&color_box[6],NULL,\
  232.   NULL,NULL,NULL,CG6,NULL},\
  233.  
  234.  {&color_gadg[12], CGHPOS+CGHOFF, CGVPOS+3*CGVOFF, CGHSIZE, CGVSIZE, \
  235.   GADGHNONE | GADGIMAGE, GADGIMMEDIATE,\
  236.   BOOLGADGET ,(APTR)&color_box[7],NULL,\
  237.   NULL,NULL,NULL,CG7,NULL},\
  238.  
  239.  {NULL,170,72,80,12,GADGHCOMP, RELVERIFY,\
  240.   BOOLGADGET ,(APTR)&button80,NULL,\
  241.   &color_txt[0],NULL,NULL,CGCANCEL,NULL},};
  242.  
  243.  
  244. struct NewWindow c_nw={100,20,270,100, -1,-1, GADGETDOWN | GADGETUP | \
  245.                      MOUSEMOVE, SMART_REFRESH | ACTIVATE | WINDOWDRAG |\
  246.                      WINDOWDEPTH | REPORTMOUSE, &color_gadg[0], NULL, \
  247.                      (UBYTE *) " -Color Control- ", NULL, NULL,\
  248.                      0,0,0,0, CUSTOMSCREEN};
  249.  
  250. /* color_box_ptr will indicate which pen color (image) needs to be
  251.    highlighted. Initialized to color 3 (pen #2) */
  252.  
  253. struct Gadget        *color_box_ptr = &color_gadg[6];
  254.  
  255.  
  256. VOID open_all(), damp_mop(), handle_main_messages(), handle_color_messages(),\
  257.      handle_main_menu(), setup_color(), handle_color_gadg(), hi_color(), \
  258.      update_color_pots();
  259.  
  260.  
  261.  
  262.  
  263. /*------------------------------start of main()----------------------------*/
  264.  
  265. main()
  266.  
  267. {
  268.  LONG main_wait_bit, color_wait_bit, wait_mask;
  269.  
  270.  
  271. /*-------------------------open Intuition and graphics--------------------*/
  272.  
  273.  open_all();
  274.  
  275.  
  276.  if ((main_scrn=(struct Screen *)OpenScreen(&ns))\
  277.     ==NULL) damp_mop();
  278.  
  279.  b_nw.Screen=main_scrn;
  280.  
  281.  if ((back_wind=(struct Window *)OpenWindow(&b_nw))\
  282.     ==NULL) damp_mop();
  283.  
  284.  color_w_v_port=ViewPortAddress(back_wind);
  285.   /* ^ only 1 viewport into screen! */
  286.  
  287.  LoadRGB4(color_w_v_port, sys_color_table, MAX_COLORS);
  288.  
  289.  SetMenuStrip(back_wind,&main_menu[0]);
  290.  
  291.  ScreenToFront(main_scrn);
  292.  
  293. /*-------------------------set up IDCMP read loop-------------------------*/
  294.  
  295.  FOREVER
  296.    {
  297.     main_wait_bit= 1<<back_wind->UserPort->mp_SigBit;
  298.  
  299.     if (color_wind)
  300.      color_wait_bit= 1<<color_wind->UserPort->mp_SigBit;
  301.  
  302.     wait_mask=Wait(main_wait_bit | color_wait_bit);
  303.  
  304.     if (wait_mask & main_wait_bit)
  305.      handle_main_messages();
  306.  
  307.     if (color_wind && (wait_mask & color_wait_bit))
  308.      handle_color_messages();
  309.  
  310.    }
  311.  
  312. }          /* end of main() */
  313.  
  314.  
  315.  
  316.  
  317.  
  318. /*--------------------opens Intuition and graphics-------------------------*/
  319.  
  320. VOID open_all()
  321.  
  322. {
  323.  
  324.  IntuitionBase=(struct IntuitionBase *)OpenLibrary\
  325.     ("intuition.library", INTUITION_REV);
  326.  
  327.  if (IntuitionBase==NULL) {damp_mop();}
  328.  
  329.  
  330.  GfxBase=(struct GfxBase *)OpenLibrary("graphics.library", GRAPHICS_REV);
  331.  
  332.  if (GfxBase==NULL) { damp_mop(); }
  333.  
  334. }
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341. /*---------------closes windows, screen, graphics, Intuition---------------*/
  342.  
  343. VOID damp_mop()
  344.  
  345. {
  346.  struct IntuiMessage *mes;
  347.  
  348.  if (color_wind)
  349.   {                /* drain the IDCMP
  350.     actually this isn't really required as this memory will be reclaimed,
  351.     but I sleep better if I do it */
  352.  
  353.    while( mes=(struct IntuiMessage *)\
  354.           GetMsg(back_wind->UserPort))
  355.      ReplyMsg(mes);
  356.    CloseWindow(color_wind);
  357.   }
  358.  
  359.  if (back_wind)
  360.   {                /* drain the IDCMP, ditto above */
  361.    while( mes=(struct IntuiMessage *)\
  362.           GetMsg(back_wind->UserPort))
  363.      ReplyMsg(mes);
  364.    if (&main_menu[0])     ClearMenuStrip(back_wind);
  365.    CloseWindow(back_wind);
  366.   }
  367.  
  368.  if (main_scrn)     CloseScreen(main_scrn);
  369.  if (GfxBase)       CloseLibrary(GfxBase);
  370.  if (IntuitionBase) CloseLibrary(IntuitionBase);
  371.  exit(FALSE);
  372.  
  373. }
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380. VOID handle_main_menu(number)
  381.  
  382. USHORT number;
  383.  
  384. {
  385.   while (number!=MENUNULL)
  386.    {
  387.      switch(MENUNUM(number))
  388.        {
  389.          case 0:      /* Project */
  390.            switch(ITEMNUM(number))
  391.              {
  392.                case 0:
  393.                  if( AutoRequest(back_wind,&qr_txt[0],\
  394.                   &qr_txt[1],&qr_txt[2],NULL,NULL,200,60) )
  395.                   damp_mop();
  396.                  break;
  397.  
  398.              } /* end of switch(ITEMNUM(number)) */
  399.            break;
  400.  
  401.          case 1:            /* Color */
  402.            setup_color();
  403.            break;
  404.  
  405.          default:
  406.            break;
  407.  
  408.        } /* end of switch(MENUNUM(number)) */
  409.  
  410.      number=ItemAddress(&main_menu[0],number)->NextSelect;
  411.  
  412.    }  /* end of while(number!=MENUNULL) */
  413.  
  414. }
  415.  
  416.  
  417.  
  418. /* color control functions starting */
  419.  
  420.  
  421.  
  422.  
  423.  
  424. VOID handle_color_gadg(gadg_ptr) /* checks gadget id to see which gadget was
  425.                                    activated, then performs the appropriate
  426.                                    action (detailed within) */
  427. struct Gadget *gadg_ptr;
  428. {
  429.  
  430.   SHORT           id=gadg_ptr->GadgetID;
  431.   char            text_buf[5];
  432.   static USHORT   red, green, blue, entry, old_entry;
  433.   SHORT           c_count;
  434.   struct RastPort *rast=color_wind->RPort;
  435.  
  436.   SetAPen(rast,1);
  437.   SetBPen(rast,0);
  438.  
  439.   if(id==CGSAVE)    /* colors are good, just clean up */
  440.     {
  441.      CloseWindow(color_wind);
  442.      color_wind = NULL;
  443.      return;
  444.     }
  445.  
  446.   if(id==CGCANCEL)  /* dump the present colors and use the ones that
  447.                        existed when this window first opened */
  448.     {
  449.      LoadRGB4(color_w_v_port, sys_color_table, MAX_COLORS);
  450.      CloseWindow(color_wind);
  451.      color_wind = NULL;
  452.      return;
  453.     }
  454.  
  455.  
  456.   if((id>=CG0) && (id<=CG7)) /* hilight box and update slider positioning */
  457.     {
  458.      color_box_ptr = gadg_ptr;
  459.      entry = id-(CGLOWEST+1);
  460.      /* ^ find absolute color map entry */
  461.  
  462.      hi_color(entry, old_entry, rast);
  463.  
  464.      old_entry = entry;
  465.      update_color_pots(entry, &red, &green, &blue);
  466.  
  467.      return;
  468.     }
  469.  
  470.  
  471.   if(id==CGR)  /* read Red slider, set, and print value next to it */
  472.     {
  473.      red=(((struct PropInfo *)(color_gadg[1].SpecialInfo))->\
  474.       HorizPot)/(0xffff/15);
  475.      SetRGB4(color_w_v_port, entry, red, green, blue);
  476.  
  477.      sprintf(text_buf, "%2d", red);
  478.      MyText(rast,20,27,text_buf);
  479.      return;
  480.     }
  481.  
  482.   if(id==CGG)   /* read Green slider, set, and print value next to it */
  483.     {
  484.      green=(((struct PropInfo *)(color_gadg[2].SpecialInfo))->\
  485.       HorizPot)/(0xffff/15);
  486.      SetRGB4(color_w_v_port, entry, red, green, blue);
  487.  
  488.      sprintf(text_buf, "%2d", green);
  489.      MyText(rast,20,39,text_buf);
  490.      return;
  491.     }
  492.  
  493.   if(id==CGB)   /* read Blue slider, set, and print value next to it */
  494.     {
  495.      blue=(((struct PropInfo *)(color_gadg[3].SpecialInfo))->\
  496.       HorizPot)/(0xffff/15);
  497.      SetRGB4(color_w_v_port, entry, red, green, blue);
  498.  
  499.      sprintf(text_buf, "%2d", blue);
  500.      MyText(rast,20,51,text_buf);
  501.      return;
  502.     }
  503.  
  504.   /* Note: a case statement can be used in place of the ifs. We use ifs
  505.      at dissidents because it's a little easier for us to optimize the
  506.      assembly code. */
  507.  
  508. }       /* end of handle_color_gadg() */
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516. VOID setup_color()  /* open the color window, copy present color_table */
  517. {
  518.  /* Did the user select the color menu item, even though the color
  519.     window already exists? If so, call him a ninny (flash screen), and
  520.     return. If we don't, we're going to have two windows and only one
  521.     pointer (BIG problems!). The color_wind pointer will be NULL unless
  522.     the color window exists. Note that color_wind is NULLed in the
  523.     handle_color_gadg routine if SAVE or CANCEL are selected. */
  524.  
  525.  if(color_wind) {DisplayBeep(main_scrn); return;}
  526.    
  527.  /* The color window doesn't exist now, so open it ! */
  528.  
  529.  c_nw.Screen=main_scrn;
  530.  
  531.  if ((color_wind=(struct Window *)OpenWindow(&c_nw))\
  532.     ==NULL) {DisplayBeep(main_scrn); return;}
  533.  
  534.  
  535.  /* Get the present color table and copy to sys_color. This table will be
  536.     copied back in if the user decides to cancel his color changes. */
  537.  {
  538.   SHORT count;
  539.   for(count=0;count<MAX_COLORS;++count)
  540.     sys_color_table[count]=\
  541.                   GetRGB4( (color_w_v_port->ColorMap), count );
  542.  }
  543.  
  544.  handle_color_gadg(color_box_ptr); /* can only be 1 of 8 boxes */
  545.                     /* since ptr is set in (if (id >= CG0...)) */
  546. }
  547.  
  548.  
  549.  
  550.  
  551.  
  552. VOID update_color_pots(entry,r,g,b)  /* figures out the present RGB values
  553.                                        for a given entry, moves the sliders
  554.                                        for correct display, and prints the
  555.                                        RGB values next to the sliders */
  556. SHORT  entry, *r, *g, *b;
  557. {
  558.   char            text_buf[5];
  559.   struct RastPort *rast= color_wind->RPort;
  560.  
  561.      /*bits0-3blue,4-7green,8-11red*/
  562.  
  563.   *b=(0x000f &  GetRGB4( color_w_v_port->ColorMap, entry) );
  564.   *g=(0x000f & (GetRGB4( color_w_v_port->ColorMap, entry) >> 4) );
  565.   *r=(0x000f & (GetRGB4( color_w_v_port->ColorMap, entry) >> 8) );
  566.  
  567.   /* color_gadg[1]=red, [2]=green, [3]=blue */
  568.  
  569.   ((struct PropInfo *)(color_gadg[1].SpecialInfo))->HorizPot=*r*(0xffff/15);
  570.   ((struct PropInfo *)(color_gadg[2].SpecialInfo))->HorizPot=*g*(0xffff/15);
  571.   ((struct PropInfo *)(color_gadg[3].SpecialInfo))->HorizPot=*b*(0xffff/15);
  572.  
  573.   sprintf(text_buf, "%2d", *r);
  574.   MyText(rast, 20, 27, text_buf);
  575.  
  576.   sprintf(text_buf, "%2d", *g);
  577.   MyText(rast, 20, 39, text_buf);
  578.  
  579.   sprintf(text_buf, "%2d", *b);
  580.   MyText(rast, 20, 51, text_buf);
  581.  
  582.   RefreshGList(&color_gadg[1],color_wind,NULL,3);
  583. }
  584.  
  585.  
  586.  
  587.  
  588.  
  589. VOID hi_color(id,old,rp)  /* highlights and un-highlights the color boxes */
  590.  
  591. USHORT id, old;
  592. struct RastPort *rp;
  593. {
  594.   /* change id and old from absolute to relative gadget id's */
  595.  
  596.  id  = id+CGLOWEST+1;
  597.  old = old+CGLOWEST+1;
  598.  
  599.  /* kill old highlight by drawing over it in the background color */
  600.  switch (old)
  601.   {
  602.     case CG0:
  603.       DrawBorder(rp,&color_un_light,CGHPOS,CGVPOS);
  604.       break;
  605.  
  606.     case CG1:
  607.       DrawBorder(rp,&color_un_light,CGHPOS,CGVPOS+CGVOFF);
  608.       break;
  609.  
  610.     case CG2:
  611.       DrawBorder(rp,&color_un_light,CGHPOS,CGVPOS+2*CGVOFF);
  612.       break;
  613.  
  614.     case CG3:
  615.       DrawBorder(rp,&color_un_light,CGHPOS,CGVPOS+3*CGVOFF);
  616.       break;
  617.  
  618.     case CG4:
  619.       DrawBorder(rp,&color_un_light,CGHPOS+CGHOFF,CGVPOS);
  620.       break;
  621.  
  622.     case CG5:
  623.       DrawBorder(rp,&color_un_light,CGHPOS+CGHOFF,CGVPOS+CGVOFF);
  624.       break;
  625.  
  626.     case CG6:
  627.       DrawBorder(rp,&color_un_light,CGHPOS+CGHOFF,CGVPOS+2*CGVOFF);
  628.       break;
  629.  
  630.     case CG7:
  631.       DrawBorder(rp,&color_un_light,CGHPOS+CGHOFF,CGVPOS+3*CGVOFF);
  632.       break;
  633.  
  634.   }
  635.  
  636.  /* highlight the new guy */
  637.  switch (id)
  638.   {
  639.     case CG0:
  640.       DrawBorder(rp,&color_hi_light,CGHPOS,CGVPOS);
  641.       break;
  642.  
  643.     case CG1:
  644.       DrawBorder(rp,&color_hi_light,CGHPOS,CGVPOS+CGVOFF);
  645.       break;
  646.  
  647.     case CG2:
  648.       DrawBorder(rp,&color_hi_light,CGHPOS,CGVPOS+2*CGVOFF);
  649.       break;
  650.  
  651.     case CG3:
  652.       DrawBorder(rp,&color_hi_light,CGHPOS,CGVPOS+3*CGVOFF);
  653.       break;
  654.  
  655.     case CG4:
  656.       DrawBorder(rp,&color_hi_light,CGHPOS+CGHOFF,CGVPOS);
  657.       break;
  658.  
  659.     case CG5:
  660.       DrawBorder(rp,&color_hi_light,CGHPOS+CGHOFF,CGVPOS+CGVOFF);
  661.       break;
  662.  
  663.     case CG6:
  664.       DrawBorder(rp,&color_hi_light,CGHPOS+CGHOFF,CGVPOS+2*CGVOFF);
  665.       break;
  666.  
  667.     case CG7:
  668.       DrawBorder(rp,&color_hi_light,CGHPOS+CGHOFF,CGVPOS+3*CGVOFF);
  669.       break;
  670.  
  671.   }
  672. }
  673.  
  674. /* end of color control functions */
  675.  
  676.  
  677.  
  678.  
  679. /*--------------------------- IDCMP routines -----------------------------*/
  680.  
  681. VOID handle_main_messages()  /* A bare bones IDCMP routine for the background
  682.                                 window. Looks for menu stuff only. */
  683. {
  684.   struct IntuiMessage *message;
  685.  
  686.  
  687.   while (message=(struct IntuiMessage *)\
  688.         GetMsg(back_wind->UserPort))
  689.    {
  690.      ULONG  class=message->Class;
  691.      USHORT code=message->Code;
  692.  
  693.      ReplyMsg(message);
  694.  
  695.      switch(class)
  696.        {
  697.          case MENUPICK:
  698.            handle_main_menu(code);
  699.            break;
  700.  
  701.        }
  702.    }         /* end of while(message..) */
  703.  
  704.  
  705. } /* end of handle_main_messages() */
  706.  
  707.  
  708.  
  709.  
  710.  
  711. VOID handle_color_messages()
  712. {
  713.   struct IntuiMessage  *message;
  714.   static SHORT         color_slider_ok;
  715.   static APTR          slider_ptr;
  716.   static USHORT        g_id;
  717.  
  718. #ifdef COLLECT_RODENT_GYRATIONS
  719.  
  720.   static SHORT         mouse_moved;
  721. #endif
  722.  
  723.   if (color_wind == NULL) return;
  724.  
  725. #ifdef COLLECT_RODENT_GYRATIONS
  726.  
  727.   mouse_moved = FALSE;
  728. #endif
  729.  
  730.   while (message=(struct IntuiMessage *)\
  731.         GetMsg(color_wind->UserPort))
  732.    {
  733.      ULONG  class=message->Class;
  734.      USHORT code=message->Code;
  735.      APTR   address=message->IAddress;
  736.  
  737.      ReplyMsg(message);
  738.      switch(class)
  739.        {
  740.          case MOUSEMOVE:
  741.  
  742. #ifdef COLLECT_RODENT_GYRATIONS
  743.  
  744.            mouse_moved = TRUE;
  745. #else
  746.            if (color_slider_ok)
  747.             handle_color_gadg((struct Gadget *)slider_ptr);
  748. #endif
  749.            break;
  750.  
  751.          case GADGETDOWN:
  752.            g_id = ((struct Gadget *)address)->GadgetID;
  753.            color_slider_ok = FALSE;
  754.  
  755.            if(g_id>CGLOWEST && g_id<CGHIGHEST)
  756.             {
  757.              slider_ptr = address;
  758.              if ( (g_id==CGR) || (g_id==CGG) || (g_id==CGB) )
  759.                color_slider_ok = TRUE;
  760.              handle_color_gadg((struct Gadget *)address);
  761.              break;
  762.             }
  763.            break;
  764.  
  765.          case GADGETUP:
  766.            g_id = ((struct Gadget *)address)->GadgetID;
  767.            color_slider_ok = FALSE;
  768.  
  769.            if(g_id>CGLOWEST && g_id<CGHIGHEST)
  770.             {
  771.              handle_color_gadg((struct Gadget *)address);
  772.              break;
  773.             }
  774.  
  775.            break;
  776.  
  777.        }
  778.  
  779.     if (color_wind == NULL) return; /* a rather ugly (but effective)
  780.                       break when this window is killed by CGSAVE, CGCANCEL */
  781.    }         /* end of while(message..) */
  782.  
  783. #ifdef COLLECT_RODENT_GYRATIONS
  784.  
  785.     if (mouse_moved && color_slider_ok)
  786.       handle_color_gadg((struct Gadget *)slider_ptr);
  787.  
  788. #endif
  789.  
  790. } /* end of handle_color_messages() */
  791.  
  792.  
  793. /********************** Dat's all folks.... ******************************/
  794.