home *** CD-ROM | disk | FTP | other *** search
- /*=========================================================================
- Star10.c -- This module builds and submits a requester in response to
- the user's choice of 'change screen colors' from the OPTIONS menu
- of the Star Chart program. The requester lets the user modify the
- default color Palette for the starchart program.
- This is really a general purpose Palette requester.
-
-
- Credits for Star Chart:
- Robert L. Hill of the Orange County, CA. Amiga Friends User Group
- wrote the original version of StarChart in AmigaBasic
- The star data and many of the main functions of this
- version are derived from that program.
-
- Ray R. Larson wrote the c version 1.0 of StarChart, 'intuitionizing'
- and enhancing the speed and functions of the original.
-
- Copyright (c) 1986 by Ray R. Larson
-
- This program may be freely distributed and copied, but may not be sold
- without the permission of the author. If you modify or enhance it,
- please include the above credits (and please send me a copy!).
-
- Ray R. Larson
- 6425 Central Ave. #304
- El Cerrito, CA 94530
-
- BitNet LARSON@UCBCMSA
- =========================================================================*/
- /*------------Header file for all of the standard stuff----*/
- /*-------------plus definitions of global structures-------*/
- #include "star.h"
-
-
- /* Definitions for Gadget ID numbers */
- #define PALETTEG 1
- #define CANPALGAD 2
- #define OKPALGAD 3
- #define RESTRGAD 4
- #define BLUECTLG 8
- #define GREENCTLG 9
- #define REDCTLG 10
-
- /**********************************************************************
- * Text attribute structures used in rendering IntuiTexts
- **********************************************************************/
- extern struct TextAttr TxtAt_Plain,TxtAt_BIU,TxtAt_BU,TxtAt_BI,TxtAt_B,
- TxtAt_IU,TxtAt_I,TxtAt_U;
-
-
- /* Text for the proportional gadgets */
- struct IntuiText red_label = {2,1,JAM2,-7,2,NULL,(UBYTE *)"R",NULL};
- struct IntuiText green_label = {2,1,JAM2,-7,2,NULL,(UBYTE *)"G",NULL};
- struct IntuiText blue_label = {2,1,JAM2,-7,2,NULL,(UBYTE *)"B",NULL};
- struct IntuiText brushtxt = {1,0,COMPLEMENT,60,38,NULL,
- (UBYTE *)"Selected Color",NULL};
-
-
- SHORT brushpairs[]=
- { -1,-1, 161,-1, 161,15, -1,15, -1,-1};
-
-
- /**********************************************************************
- * Border Definitions for PaletteReq requester
- **********************************************************************/
-
- SHORT PaletteReq_Pairs_1[] = {
- 0, 0,
- 257, 0,
- 257, 140,
- 0, 140,
- 0, 0
- };
- struct Border PaletteReq_bord_1 = {
- 1, 1, /* LeftEdge, TopEdge */
- 7, 1, JAM2, /* FrontPen, BackPen, DrawMode*/
- 5, /* Count of XY pairs */
- (SHORT *)&PaletteReq_Pairs_1, /* XY pairs */
- NULL /* Next Border */
- };
-
- SHORT PaletteReq_Pairs_2[] = {
- 0, 0,
- 251, 0,
- 251, 137,
- 0, 137,
- 0, 0
- };
- struct Border PaletteReq_bord_2 = {
- 3, 3, /* LeftEdge, TopEdge */
- 1, 7, JAM2, /* FrontPen, BackPen, DrawMode*/
- 5, /* Count of XY pairs */
- (SHORT *)&PaletteReq_Pairs_2, /* XY pairs */
- &PaletteReq_bord_1 /* Next Border */
- };
-
-
- /* border for the selected color box */
- struct Border boxborder =
- {50,35,1,0,JAM1,5,&brushpairs[0],NULL};
-
-
- SHORT PalGadPairs[] = {
- 0, 0,
- 160, 0,
- 160, 20,
- 0, 20,
- 0, 0
- };
- struct Border PalGadBord = {
- -1, -1,
- 1, 3, JAM2,
- 5,
- (SHORT *)&PalGadPairs,
- NULL
- };
-
- struct Gadget paletteGadg = {
- NULL, 50, 10, 160, 20,
- GADGHNONE,
- RELVERIFY | GADGIMMEDIATE,
- BOOLGADGET,
- (APTR)&PalGadBord,
- NULL,
- NULL,/* intuitext */
- 0x0,
- NULL,
- PALETTEG,
- NULL
- };
-
-
- /* Images for the color proportional gadgets - filled in later */
- struct Image r_shape, g_shape, b_shape;
-
- /* Proportional info for the color prop gadgets */
- struct PropInfo r_prop, g_prop, b_prop;
-
- /* global flags and body size for modifyprops */
- LONG propflags, propHbody;
-
- /* The color prop gadgets themselves */
-
- struct Gadget blue_control =
- { &paletteGadg, /* next in the line */
- 50, 85, /* Left and Top Edges */
- 160, 11, /* Width, Height */
- GADGHCOMP, /* Flags (complement) */
- GADGIMMEDIATE |
- RELVERIFY, /* activation */
- PROPGADGET, /* GadgetType */
- (APTR)&b_shape, /* GadgetRender image */
- NULL, /* no SelectRender */
- &blue_label, /* GadgetText */
- NULL, /* no MutualExclude */
- (APTR)&b_prop, /* SpecialInfo */
- BLUECTLG, /* GadgetID */
- NULL, /* No UserData */
- };
-
- struct Gadget green_control =
- { &blue_control, /* next in the line */
- 50, 70, /* Left and Top Edges */
- 160, 11, /* Width, Height */
- GADGHCOMP, /* Flags (complement) */
- GADGIMMEDIATE |
- RELVERIFY, /* activation */
- PROPGADGET, /* GadgetType */
- (APTR)&g_shape, /* GadgetRender image */
- NULL, /* no SelectRender */
- &green_label, /* GadgetText */
- NULL, /* no MutualExclude */
- (APTR)&g_prop, /* SpecialInfo */
- GREENCTLG, /* GadgetID */
- NULL, /* No UserData */
- };
-
- struct Gadget red_control =
- { &green_control, /* next in the line */
- 50, 55, /* Left and Top Edges */
- 160, 11, /* Width, Height */
- GADGHCOMP, /* Flags (complement) */
- GADGIMMEDIATE |
- RELVERIFY, /* activation */
- PROPGADGET, /* GadgetType */
- (APTR)&r_shape, /* GadgetRender image */
- NULL, /* no SelectRender */
- &red_label, /* GadgetText */
- NULL, /* no MutualExclude */
- (APTR)&r_prop, /* SpecialInfo */
- REDCTLG, /* GadgetID */
- NULL, /* No UserData */
- };
-
-
- /**********************************************************************
- * Border Definitions for okPal gadget
- **********************************************************************/
-
- SHORT okPal_Pairs_2[] = {
- 0, 0,
- 88, 0,
- 88, 17,
- 0, 17,
- 0, 0
- };
- struct Border okPal_bord_2 = {
- -1, -1, /* LeftEdge, TopEdge */
- 1, 7, JAM2, /* FrontPen, BackPen, DrawMode*/
- 5, /* Count of XY pairs */
- (SHORT *)&okPal_Pairs_2, /* XY pairs */
- NULL /* Next Border */
- };
-
-
- /**********************************************************************
- * IntuiTexts for the okPal gadget.
- **********************************************************************/
-
- struct IntuiText okPal_Text_0 = {
- 15, 0, /* FrontPen, BackPen */
- JAM2, /* DrawMode */
- 12, 4, /* LeftEdge, TopEdge */
- &TxtAt_B, /* ITextFont Pointer */
- /* The IText */
- (UBYTE *)" OK ",
- NULL
- };
-
-
-
- /**********************************************************************
- * Gadget Structure definition for the okPal gadget.
- **********************************************************************/
-
- struct Gadget okPal = {
- &red_control, /* NextGadget pointer */
- 150, 120, /* LeftEdge, TopEdge */
- 88, 17, /* Width, Height */
- /* Gadget Flags */
- GADGHCOMP,
- /* Activation Flags */
- RELVERIFY | GADGIMMEDIATE,
- /* GadgetType */
- BOOLGADGET | REQGADGET,
- (APTR)&okPal_bord_2, /* GadgetRender */
- NULL, /* SelectRender */
- &okPal_Text_0, /* GadgetText */
- 0x0, /* MutualExclude */
- NULL, /* SpecialInfo */
- OKPALGAD, /* GadgetID */
- 0x1 /* UserData Pointer */
- };
-
-
- /**********************************************************************
- * Border Definitions for canPal gadget
- **********************************************************************/
-
- SHORT canPal_Pairs_3[] = {
- 0, 0,
- 88, 0,
- 88, 17,
- 0, 17,
- 0, 0
- };
- struct Border canPal_bord_3 = {
- -1, -1, /* LeftEdge, TopEdge */
- 1, 7, JAM2, /* FrontPen, BackPen, DrawMode*/
- 5, /* Count of XY pairs */
- (SHORT *)&canPal_Pairs_3, /* XY pairs */
- NULL /* Next Border */
- };
-
-
- /**********************************************************************
- * IntuiTexts for the canPal gadget.
- **********************************************************************/
-
- struct IntuiText canPal_Text_0 = {
- 15, 0, /* FrontPen, BackPen */
- JAM2, /* DrawMode */
- 10, 4, /* LeftEdge, TopEdge */
- &TxtAt_B, /* ITextFont Pointer */
- /* The IText */
- (UBYTE *)" CANCEL ",
- NULL
- };
-
-
-
- /**********************************************************************
- * Gadget Structure definition for the canPal gadget.
- **********************************************************************/
-
- struct Gadget canPal = {
- &okPal, /* NextGadget pointer */
- 20, 120, /* LeftEdge, TopEdge */
- 88, 17, /* Width, Height */
- /* Gadget Flags */
- GADGHCOMP,
- /* Activation Flags */
- RELVERIFY | GADGIMMEDIATE | ENDGADGET,
- /* GadgetType */
- BOOLGADGET | REQGADGET,
- (APTR)&canPal_bord_3, /* GadgetRender */
- NULL, /* SelectRender */
- &canPal_Text_0, /* GadgetText */
- 0x0, /* MutualExclude */
- NULL, /* SpecialInfo */
- CANPALGAD, /* GadgetID */
- 0x1 /* UserData Pointer */
- };
-
- /**********************************************************************
- * Border Definitions for restore gadget
- **********************************************************************/
-
- SHORT restPal_Pairs_3[] = {
- 0, 0,
- 88, 0,
- 88, 17,
- 0, 17,
- 0, 0
- };
- struct Border restPal_bord_3 = {
- -1, -1, /* LeftEdge, TopEdge */
- 1, 7, JAM2, /* FrontPen, BackPen, DrawMode*/
- 5, /* Count of XY pairs */
- (SHORT *)&restPal_Pairs_3, /* XY pairs */
- NULL /* Next Border */
- };
-
-
- /**********************************************************************
- * IntuiTexts for the restPal gadget.
- **********************************************************************/
-
- struct IntuiText restPal_Text_0 = {
- 15, 0, /* FrontPen, BackPen */
- JAM2, /* DrawMode */
- 7, 4, /* LeftEdge, TopEdge */
- &TxtAt_B, /* ITextFont Pointer */
- /* The IText */
- (UBYTE *)" RESTORE ",
- NULL
- };
-
-
-
- /**********************************************************************
- * Gadget Structure definition for the restPal gadget.
- **********************************************************************/
-
- struct Gadget restPal = {
- &canPal, /* NextGadget pointer */
- 84, 100, /* LeftEdge, TopEdge */
- 88, 17, /* Width, Height */
- /* Gadget Flags */
- GADGHCOMP,
- /* Activation Flags */
- RELVERIFY | GADGIMMEDIATE,
- /* GadgetType */
- BOOLGADGET | REQGADGET,
- (APTR)&restPal_bord_3, /* GadgetRender */
- NULL, /* SelectRender */
- &restPal_Text_0, /* GadgetText */
- 0x0, /* MutualExclude */
- NULL, /* SpecialInfo */
- RESTRGAD, /* GadgetID */
- 0x1 /* UserData Pointer */
- };
-
-
- /****************************************************************************
- * Global Structures
- ***************************************************************************/
-
- /* the newwindow structure used in starchart*/
- extern struct NewWindow nw;
- extern struct Window *w;
- extern FLOAT MaxPlus, MaxWhite;
- /*------------------- color table definitions ------------------*/
-
- extern UWORD defaultCT[32], CTable[32], *ctabptr;
- extern struct ColorMap *cmap;
- extern struct ViewPort *vport;
-
- /****************************************************************************
- * External function definitions
- ***************************************************************************/
- extern struct IntuiMessage *GetMsg();
-
- /****************************************************************************
- * Requester structure and global pointer to it's gadget list.
- ***************************************************************************/
- struct Requester PaletteRequester;
-
- /****************************************************************************
- * The Code part of the SetColors module.
- ***************************************************************************/
- SetColors()
- {
- BOOL cancelchosen;
- LONG iflags;
- struct RastPort *reqrp;
- UWORD tempCTable[32];
- short i;
-
- /* store the current colortable in case the user cancels */
- for(i=0;i<32;i++) tempCTable[i] = CTable[i];
-
- /* fix the IDCMP flags to report requester set and clear */
- iflags = nw.IDCMPFlags;
- iflags |= REQCLEAR;
- ModifyIDCMP(w,iflags);
-
- /* set the flags and body sizes for the proportional gadgets */
-
- propflags = r_prop.Flags = g_prop.Flags = b_prop.Flags = FREEHORIZ | AUTOKNOB;
- propHbody = r_prop.HorizBody = g_prop.HorizBody = b_prop.HorizBody = 0x1000;
-
- /* initialize the Palettetude requester */
- InitPalReq();
-
- /* Put up the requester */
- Request(&PaletteRequester,w);
-
- reqrp = PaletteRequester.ReqLayer->rp;
-
- /* initialize the palette */
- initpalette(reqrp,4);
-
- /* add the brush color box */
- DrawBorder(reqrp, &boxborder,0L,0L);
-
- SetAPen(reqrp,0L);
- RectFill(reqrp,50L,35L,210L,49L); /* fill in brush color box */
- PrintIText(reqrp,&brushtxt,1L,1L);
-
- /* zap the prop gadgets to reflect the current color value */
- ModifyProp(&red_control,w,&PaletteRequester,propflags,
- (LONG)((CTable[0] & 0xf00) << 4),0L,propHbody,0L);
- ModifyProp(&green_control,w,&PaletteRequester,propflags,
- (LONG)((CTable[0] & 0x0f0) << 8),0L,propHbody,0L);
- ModifyProp(&blue_control,w,&PaletteRequester,propflags,
- (LONG)(CTable[0] << 12),0L,propHbody,0L);
- RefreshGadgets(&red_control,w,&PaletteRequester);
-
- /* let the user fill in the parameters and wait for a cancel or ok. */
- cancelchosen = WaitPaletteReq(reqrp);
-
- /* if the user cancelled, reset to the Palette that was saved */
- if (cancelchosen)
- { LoadRGB4(vport,&tempCTable[0],32L);
- for(i=0;i<32;i++) CTable[i] = tempCTable[i];
- }
-
- } /* SetColors */
-
- /*
- * Init the Palette requester
- */
- InitPalReq()
- {
- struct RastPort *reqrp;
-
- InitRequester(&PaletteRequester);
- PaletteRequester.LeftEdge = 110;
- PaletteRequester.TopEdge = 12;
- PaletteRequester.Width = 260;
- PaletteRequester.Height = 145;
- PaletteRequester.ReqGadget = &restPal;
- PaletteRequester.ReqText = NULL;
- PaletteRequester.BackFill = 2;
- PaletteRequester.Flags = 0;
- PaletteRequester.ReqBorder = &PaletteReq_bord_2;
-
- }
-
- /* initialize palette - this will set up a pallette for any depth of */
- /* screen. */
- initpalette(rp,depth)
- struct RastPort *rp;
- SHORT depth;
- {
- SHORT i, j, c_rows, n_colors, c_per_row;
- LONG x, y, bx, by, boxw, boxh, pen;
-
- n_colors = 1 << depth;
- if (n_colors > 8) c_rows = 2;
- else c_rows = 1;
-
- c_per_row = n_colors / c_rows;
-
- boxw = (LONG)paletteGadg.Width/c_per_row;
- boxh = (LONG)paletteGadg.Height/c_rows;
- pen = 0L;
- for (j = 0; j < c_rows; j++)
- {
- for (i=0; i < c_per_row; i++, pen++)
- {
- SetAPen(rp,pen);
- x = ((LONG)i * boxw) + (LONG)paletteGadg.LeftEdge ;
- y = ((LONG)j * boxh) + (LONG)paletteGadg.TopEdge ;
- bx = x + boxw -1L;
- by = y + boxh -1L;
- RectFill(rp,x,y,bx,by); /* fill in color box */
- }
- }
-
- }
-
-
-
-
- /****************************************************************************
- * WaitPaletteReq - permit user to change the values in the requester gadgets
- * and check the values they install until either the
- * CANCEL gadget is clicked or the OK gadget is clicked AND
- * there are no outstanding input errors
- ***************************************************************************/
- BOOL WaitPaletteReq(reqrp)
- struct RastPort *reqrp;
- {
- ULONG class = GADGETDOWN;
- struct IntuiMessage *message;
- struct Gadget *gadget;
- BOOL cancelflag = FALSE;
- LONG errorflag = 0L, checkPal();
- LONG curpen, color;
- SHORT mousex, mousey;
- BOOL prophit = FALSE;
-
- curpen = 0L;
- while (class != REQCLEAR)
- {
- if ((message=(struct IntuiMessage *) GetMsg(w->UserPort)) == 0L)
- {
- Wait(1L<<w->UserPort->mp_SigBit);
- continue;
- }
-
- class = message->Class;
- mousex = message->MouseX;
- mousey = message->MouseY;
- gadget = (struct Gadget *) message->IAddress;
- ReplyMsg(message);
- switch (class)
- {
- case GADGETDOWN:
- switch (gadget->GadgetID)
- {
- case BLUECTLG:
- case GREENCTLG:
- case REDCTLG:
- prophit = TRUE;
- break;
-
- }
- break;
-
- case GADGETUP:
- switch (gadget->GadgetID)
- {
- case PALETTEG:
- /* ignore if the mouse is over the same color*/
- mousex = mousex - (LONG)PaletteRequester.LeftEdge;
- mousey = mousey - (LONG)PaletteRequester.TopEdge;
- if(( color = (LONG)
- ReadPixel(reqrp,(LONG)mousex,(LONG)mousey))
- == curpen) break;
-
- SetAPen(reqrp,color);
- curpen = color;
- /* fill in brush color box */
- RectFill(reqrp,50L,35L,210L,49L);
- PrintIText(reqrp,&brushtxt,1L,1L);
- /* zap the prop gadgets to show the current color value */
- ModifyProp(&red_control,w,&PaletteRequester,propflags,
- (LONG)((CTable[curpen] & 0xf00) << 4),0L,propHbody,0L);
- ModifyProp(&green_control,w,&PaletteRequester,propflags,
- (LONG)((CTable[curpen] & 0x0f0) << 8),0L,propHbody,0L);
- ModifyProp(&blue_control,w,&PaletteRequester,propflags,
- (LONG)(CTable[curpen] << 12),0L,propHbody,0L);
- RefreshGadgets(&red_control,w,&PaletteRequester);
- break;
-
- case BLUECTLG:
- case GREENCTLG:
- case REDCTLG:
- /*Set the colors*/
- SetRGB4(vport,curpen,
- (LONG)(r_prop.HorizPot >> 12),
- (LONG)(g_prop.HorizPot >> 12),
- (LONG)(b_prop.HorizPot >> 12));
- /* save color in CTable - can be output */
- /* if the user wants a custom color table*/
- CTable[curpen] =
- ((r_prop.HorizPot >> 4) & 0xf00) +
- ((g_prop.HorizPot >> 8) & 0xf0) +
- (b_prop.HorizPot >> 12);
- prophit = FALSE;
- break;
-
-
- case RESTRGAD: /* restore default colors */
- CTable[0] = 0x05A; /* register 0 is dark blue */
- CTable[1] = 0xFFF; /* register 1 is white */
- CTable[2] = 0x002; /* register 2 is Black (almost)*/
- CTable[3] = 0xFFF; /* register 4 is white */
- CTable[4] = 0xEEE; /* register 5 is darker */
- CTable[5] = 0xDDD; /* register 6 is darker */
- CTable[6] = 0xCCC; /* register 7 is darrker */
- CTable[7] = 0xBBB; /* register 8 is darker */
- CTable[8] = 0xAAA; /* register 9 is darker */
- CTable[9] = 0x999; /* register 10 is darker */
- CTable[10] = 0x888;/* register 11 is medium gray */
- CTable[11] = 0xF11;/* reqister 3 is bright red - */
- CTable[12] = 0x00B;/* register 12 is dark blue */
- CTable[13] = 0xF0F;/* register 13 is magenta */
- CTable[14] = 0xFFF;/* register 14 is also white */
- CTable[15] = 0xF80;/* register 15 is Orange */
-
- /* change the registers to the new colors */
- LoadRGB4(vport,&CTable,32L);
-
- /* zap the prop gadgets to show the current color value */
- ModifyProp(&red_control,w,&PaletteRequester,propflags,
- (LONG)((CTable[curpen] & 0xf00) << 4),0L,propHbody,0L);
- ModifyProp(&green_control,w,&PaletteRequester,propflags,
- (LONG)((CTable[curpen] & 0x0f0) << 8),0L,propHbody,0L);
- ModifyProp(&blue_control,w,&PaletteRequester,propflags,
- (LONG)(CTable[curpen] << 12),0L,propHbody,0L);
- RefreshGadgets(&red_control,w,&PaletteRequester);
-
- break;
-
- case CANPALGAD :
- cancelflag = TRUE;
- break;
-
- case OKPALGAD :
- if (errorflag == 0)
- EndRequest(&PaletteRequester,w);
- else DisplayBeep(w->WScreen);
- break;
-
- } /* end of GADGETUP switch */
-
- case MOUSEMOVE:
- if (prophit == FALSE) break;
- else
- /*Set the colors*/
- SetRGB4(vport,curpen,
- (LONG)(r_prop.HorizPot >> 12),
- (LONG)(g_prop.HorizPot >> 12),
- (LONG)(b_prop.HorizPot >> 12));
- break;
-
-
- } /* end of CLASS switch */
- }/* end of while loop */
-
-
- return(cancelflag);
-
- } /* WaitPaletteReq */
-
-