home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- Palette Requester 4th August 87
- ************************************************************************/
- #include <exec/types.h>
- #include <intuition/intuition.h>
-
- #include "shm_defines"
-
- extern struct ViewPort *WVP;
- extern struct TextAttr Fnt;
- extern USHORT col1[16],col2[16];
-
- /************************************************************************
- Palette Definitions
- ************************************************************************/
-
- #define PLX 134 /* Palette Window Size */
- #define PLY 159
-
- /************* Not really a gadget - current colour box ****************/
-
- struct Image curbox_img = {0, 0, 47, 31, 1, NL, 0, 1, NL};
-
- char curbox_str[4];
- struct IntuiText curbox_txt = {1, 0, JAM1, 12, 12, &Fnt, NL, NL};
-
- struct Gadget curbox_gad =
- {NL,
- 80, 124, 47, 31,
- GADGHNONE | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET,
- (APTR)&curbox_img,
- NL, &curbox_txt, NL, NL,
- 22, NL
- };
-
- /*************************** Palette Sliders ***************************/
-
- struct IntuiText rtxt = {2,2,JAM1,-11,2,&Fnt,(UBYTE *)"R",NL};
- struct IntuiText gtxt = {2,2,JAM1,-11,2,&Fnt,(UBYTE *)"G",NL};
- struct IntuiText btxt = {2,2,JAM1,-11,2,&Fnt,(UBYTE *)"B",NL};
-
- struct Image r_img, g_img, b_img;
- struct PropInfo r_prop,g_prop,b_prop;
-
- struct Gadget blue_gad = {
- &curbox_gad, 17,109, 113,11, GADGHCOMP, GADGIMMEDIATE | RELVERIFY,
- PROPGADGET | REQGADGET,(APTR)&b_img, NL,
- &btxt, NL,(APTR)&b_prop, 16, NL };
-
- struct Gadget green_gad = {
- &blue_gad, 17,94, 113,11, GADGHCOMP, GADGIMMEDIATE | RELVERIFY,
- PROPGADGET | REQGADGET,(APTR)&g_img, NL,
- >xt, NL,(APTR)&g_prop, 17, NL };
-
- struct Gadget red_gad = {
- &green_gad, 17,79, 113,11, GADGHCOMP, GADGIMMEDIATE | RELVERIFY,
- PROPGADGET | REQGADGET,(APTR)&r_img, NL,
- &rtxt, NL,(APTR)&r_prop, 18, NL };
-
- /*************************** Palette Switches **************************/
-
- struct IntuiText pal_cancel_txt = {3,0,JAM1,13,1,&Fnt,
- (UBYTE *)"Cancel",NL};
- struct IntuiText pal_def_txt = {3,0,JAM1,8,1,&Fnt,(UBYTE *)"Default",NL};
- struct IntuiText pal_ok_txt = {3,0,JAM1,26,1,&Fnt,(UBYTE *)"OK",NL};
-
- struct Image pal_gad_img = {0,0, 70,9, 1, NL, 0, 2, NL};
-
- struct Gadget pal_def_gad = {
- &red_gad, 5,135, 70,9, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&pal_gad_img, NL,
- &pal_def_txt, NL,NL, 19, NL };
- struct Gadget pal_cancel_gad = {
- &pal_def_gad, 5,124, 70,9, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&pal_gad_img, NL,
- &pal_cancel_txt, NL,NL, 20, NL };
- struct Gadget pal_ok_gad = {
- &pal_cancel_gad, 5,146, 70,9, GADGHBOX | GADGIMAGE,
- RELVERIFY | ENDGADGET, BOOLGADGET | REQGADGET, (APTR)&pal_gad_img, NL,
- &pal_ok_txt, NL,NL, 21, NL };
-
- /************************ Palette Colour Select ************************/
-
- struct Image m3C[16] = {
- {0,0,30,14,1, NL ,0,0,NL },
- {0,0,30,14,1, NL ,0,1,NL },
- {0,0,30,14,1, NL ,0,2,NL },
- {0,0,30,14,1, NL ,0,3,NL },
- {0,0,30,14,1, NL ,0,4,NL },
- {0,0,30,14,1, NL ,0,5,NL },
- {0,0,30,14,1, NL ,0,6,NL },
- {0,0,30,14,1, NL ,0,7,NL },
- {0,0,30,14,1, NL ,0,8,NL },
- {0,0,30,14,1, NL ,0,9,NL },
- {0,0,30,14,1, NL ,0,10,NL },
- {0,0,30,14,1, NL ,0,11,NL },
- {0,0,30,14,1, NL ,0,12,NL },
- {0,0,30,14,1, NL ,0,13,NL },
- {0,0,30,14,1, NL ,0,14,NL },
- {0,0,30,14,1, NL ,0,15,NL } };
-
- struct Gadget palg[16] = {
- { &palg[1], 4, 15, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[0], NL,NL,NL,NL, 0, NL},
- { &palg[2], 36,15, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[1], NL,NL,NL,NL, 1, NL},
- { &palg[3], 68,15, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[2], NL,NL,NL,NL, 2, NL},
- { &palg[4], 100,15, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[3], NL,NL,NL,NL, 3, NL},
- { &palg[5], 4,30, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[4], NL,NL,NL,NL, 4, NL},
- { &palg[6], 36,30, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[5], NL,NL,NL,NL, 5, NL},
- { &palg[7], 68,30, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[6], NL,NL,NL,NL, 6, NL},
- { &palg[8],100,30, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[7], NL,NL,NL,NL, 7, NL},
- { &palg[9], 4,45, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[8], NL,NL,NL,NL, 8, NL},
- { &palg[10],36,45, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[9], NL,NL,NL,NL, 9, NL},
- { &palg[11],68,45, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[10], NL,NL,NL,NL, 10, NL},
- { &palg[12],100,45, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[11], NL,NL,NL,NL, 11, NL},
- { &palg[13],4,60, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[12], NL,NL,NL,NL, 12, NL},
- { &palg[14],36,60, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[13], NL,NL,NL,NL, 13, NL},
- { &palg[15],68,60, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[14], NL,NL,NL,NL, 14, NL},
- { &pal_ok_gad, 100,60, 30,14, GADGHBOX | GADGIMAGE, RELVERIFY,
- BOOLGADGET | REQGADGET, (APTR)&m3C[15], NL,NL,NL,NL, 15, NL} };
-
- struct IntuiText mstxt={2,2,JAM1,10,3,&Fnt,(UBYTE *)"Palette Control",NL};
-
- struct Requester palette_req;
-
- SHORT pal_border_coords[] = {0,0, PLX-1,0, PLX-1,PLY-1, 0,PLY-1, 0,0};
-
- struct Border pal_border =
- {
- 0,0,
- 1,0,JAM1,
- 5,&pal_border_coords[0],
- NL
- };
-
- /************************************************************************
- Palette Function
- ************************************************************************/
- palette(cW)
- struct Window *cW;
- {
-
- FAST struct IntuiMessage *message;
-
- FAST int class,cursel,i,item;
- BOOL loop,change;
- USHORT backup[16],temp_col;
-
- for (i=0; i<16; i++) backup[i]=col1[i];
-
- r_prop.Flags = g_prop.Flags = b_prop.Flags = FREEHORIZ | AUTOKNOB;
- r_prop.HorizBody = g_prop.HorizBody = b_prop.HorizBody = 0x1000;
-
- ModifyIDCMP(cW, GADGETUP | GADGETDOWN | REQCLEAR | MOUSEMOVE );
-
- InitRequester(&palette_req);
- palette_req.LeftEdge = 250;
- palette_req.TopEdge = 25;
- palette_req.Width = PLX;
- palette_req.Height = PLY;
- palette_req.ReqGadget = &palg[0];
- palette_req.ReqText = &mstxt;
- palette_req.BackFill = 0;
- palette_req.ReqBorder = &pal_border;
- Request(&palette_req,cW);
-
- cursel = 1;
-
- r_prop.HorizPot = (col1[cursel] & 0xf00) << 4;
- g_prop.HorizPot = (col1[cursel] & 0x0f0) << 8;
- b_prop.HorizPot = col1[cursel] << 12;
- curbox_img.PlaneOnOff = (UBYTE) cursel;
- RefreshGList(&red_gad,cW,&palette_req,4);
-
- loop = TRUE;
- change = FALSE;
-
- while (loop)
- {
- Wait(1 << cW->UserPort->mp_SigBit); /* Be good and go to sleep till
- Intuition sends a message */
-
- while (message = (struct IntuiMessage *) GetMsg(cW->UserPort))
- {
- class = message->Class; /* Process all outstanding Messages */
- ReplyMsg(message);
-
- if (class == REQCLEAR) loop = FALSE; /* OK selected */
-
- if ((class == GADGETDOWN) || (class == GADGETUP))
- item = ((struct Gadget *) message->IAddress)->GadgetID;
- }
-
- /* MOUSEMOVE events are not acknowledged specifically, but by
- generating a message cause the following code to update the
- sliders */
-
- /********* item is the GadgetID of the gadget selected ***********/
-
- if ((item >= 0) && (item < 16) && (item != cursel)) change = TRUE;
- switch (item)
- {
- case 16 : /* The sliders have been changed. Update curbox */
- case 17 : /* and the current palette member selected */
- case 18 : temp_col = ((r_prop.HorizPot >> 4) & 0xf00)
- + ((g_prop.HorizPot >> 8) & 0xf0)
- + (b_prop.HorizPot >>12);
- if (col1[cursel] != temp_col)
- {
- col1[cursel] = temp_col;
- LoadRGB4(WVP,&col1,16);
- RefreshGList(&curbox_gad,cW,&palette_req,1);
- RefreshGList(&palg[cursel],cW,&palette_req,1);
- }
- break;
- case 19 : /* Reset to the default palette */
- for (i = 0; i < 16; i++) col1[i] = col2[i];
- LoadRGB4(WVP,&col1,16);
- r_prop.HorizPot = (col1[cursel] & 0xf00) << 4;
- g_prop.HorizPot = (col1[cursel] & 0x0f0) << 8;
- b_prop.HorizPot = col1[cursel] << 12;
- RefreshGList(&red_gad,cW,&palette_req,3);
- item = 99;
- break;
- case 20 : /* Reset to the backup palette */
- for (i = 0; i < 16; i++) col1[i] = backup[i];
- LoadRGB4(WVP,&col1,16);
- r_prop.HorizPot = (col1[cursel] & 0xf00) << 4;
- g_prop.HorizPot = (col1[cursel] & 0x0f0) << 8;
- b_prop.HorizPot = col1[cursel] << 12;
- RefreshGList(&red_gad,cW,&palette_req,3);
- item = 99;
- break;
- case 22 : sprintf(curbox_str,"%03X\0",col1[cursel]);
- curbox_txt.IText = (UBYTE *)curbox_str;
- if (cursel != 0) curbox_txt.FrontPen = 0;
- else curbox_txt.FrontPen =1;
- RefreshGList(&curbox_gad,cW,&palette_req,1);
- curbox_txt.IText = NL;
- item = 99;
- }
- if (change)
- { /* A new colour has been selected */
- cursel = item; /* Reset sliders and curbox gadget */
- curbox_img.PlaneOnOff = (UBYTE) cursel;
- r_prop.HorizPot = (col1[cursel] & 0xf00) << 4;
- g_prop.HorizPot = (col1[cursel] & 0x0f0) << 8;
- b_prop.HorizPot = col1[cursel] << 12;
- RefreshGList(&red_gad,cW,&palette_req,4);
- change = FALSE;
- }
- }
- ModifyIDCMP(cW,MENUPICK | REQCLEAR | INTUITICKS);
- return(TRUE);
- }
-