/*********************************************************************** * palette.c * This program is useful for designing color palettes. * It may be used stand-alone (I would be setting the 'default map', * if preferences had a complete color map...), or you can use it * as a subroutine with minor modifications. * One of the unique features of this program is that it prints * the hex value of the selected color, so you use it to generate * numeric values for use in programs. * (c) 1985 by Charlie Heath of Microsmiths, this program is in * the public domain. Not to be used commercially without permission * from MicroSmiths. ***********************************************************************/ #include #include #include #include #include #include #include #define I_REV 29 #define G_REV 29 struct IntuitionBase *IntuitionBase; struct GfxBase { int b; } *GfxBase; #define FAST register /* Register type variable */ #define DPTH 5 /* Raster dimensions */ #define WDTH 320 #define HGHT 200 #define NL 0 #define BCOL 1 /* Background color for menus, etc */ #define CTSIZ 32 /* In spite of myself, color table size */ /* Font Descriptor */ struct TextAttr MyFont = {"topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT }; /* Used to open a Screen */ struct NewScreen NewScreen = { 0,0,WDTH,HGHT,DPTH, /* Left,Top,Width,Height,Depth */ 1,2,NL, /* DetailPen, BlockPen, ViewModes */ CUSTOMSCREEN,&MyFont, /* Type, Font */ (UBYTE *)"MicroSmiths Palette Tool", /* Title */ NL,NL }; /* Gadgets, BitMap */ /* Used to open a Window */ struct NewWindow NewWindow = { 0,0,WDTH,HGHT, /* LeftEdge,TopEdge,Width,Height */ 8,BCOL, /* DetailPen,BlockPen */ MOUSEBUTTONS | MOUSEMOVE | MENUVERIFY | MENUPICK | GADGETUP | GADGETDOWN | CLOSEWINDOW | ACTIVEWINDOW, SMART_REFRESH | REPORTMOUSE | ACTIVATE | BACKDROP | BORDERLESS, /*Flags*/ NL,NL,NL, /* FirstGadget, CheckMark, Title */ NL, /* MUST SET SCREEN AFTER OPENSCREEN!!! */ NL, /* BitMap */ 100,60,32767,32767, /* MinW, MinH, MaxW, MaxH */ CUSTOMSCREEN }; /* Type */ /**** Variables Initialized by init_program() **********/ struct Screen *p_S; struct Window *p_W; struct ViewPort *p_Vp; struct ColorMap *p_Co; USHORT *p_ct; /* Color table as words */ USHORT default_color[CTSIZ]; /* Save a copy of the defaults */ /**************************************************************** * init_program() * * Opens screen and full-sized window for program. * * Initializes handles p_S,p_W * * See also: clear_program() */ init_program() { FAST int i; if ( ! (IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",I_REV)) || ! (GfxBase =(struct GfxBase *)OpenLibrary("graphics.library",G_REV)) ) exit(20); if ( ! (p_S =(struct Screen *)OpenScreen(&NewScreen)) ) { printf("Can't Open Screen! Get More Mem!\n"); exit(21); } NewWindow.Screen = p_S; /* NEED TO SET SCREEN!!! */ if ( ! (p_W =(struct Window *)OpenWindow(&NewWindow)) ) { CloseScreen(p_S); printf("This is not good.\n"); exit(22); } p_Vp = (struct ViewPort *)ViewPortAddress(p_W); p_Co = (struct ColorMap *)GetColorMap(CTSIZ); p_ct = (USHORT *)p_Co->ColorTable; for ( i=0; i= 0; cursel--) backup[cursel] = p_ct[cursel]; r_prop.Flags = g_prop.Flags = b_prop.Flags = FREEHORIZ | AUTOKNOB; r_prop.HorizBody = g_prop.HorizBody = b_prop.HorizBody = 0x1000; /* Get screen from calling window */ NewCmod.Screen = calling_window->WScreen; /* NEED TO SET SCREEN!!! */ if ( ! (cW = (struct Window *)OpenWindow(&NewCmod)) ) { return(FALSE); /* Oops... */ } PrintIText(cW->RPort,&mstxt,7,71); cW->UserPort = calling_window->UserPort; ModifyIDCMP(cW, GADGETUP | GADGETDOWN | MENUVERIFY ); for ( munge = keepon = TRUE; keepon; ) { if ( munge ) { SetAPen(cW->RPort,cursel); RectFill(cW->RPort,133,3,PLX-5,66); /* RJ will proably cringe if he see's this, but it is proably */ /* safe to modify the HorizPot values this way, UNLESS the */ /* gadgets were being fiddled with when you do it. Here that */ /* is quite unlikely, since another gadget was just activated */ /* to cause the munge flag to be set... */ r_prop.HorizPot = (p_ct[cursel] & 0xf00) << 4; g_prop.HorizPot = (p_ct[cursel] & 0x0f0) << 8; b_prop.HorizPot = p_ct[cursel] << 12; RefreshGadgets(&red_gad,cW,NL); munge = FALSE; hxtxt.FrontPen = cursel ^ 15; hxtxt.BackPen = cursel; } while ( ! (imsg=(struct IntuiMessage *)GetMsg(cW->UserPort)) ) { class = p_ct[cursel] = ((r_prop.HorizPot >> 4) & 0xf00) + ((g_prop.HorizPot >> 8) & 0xf0) + (b_prop.HorizPot >>12); set_cmap(); frog[0] = hxtab[class >> 8]; frog[1] = hxtab[ (class >> 4) & 0x0f]; frog[2] = hxtab[class & 0x0f]; PrintIText(cW->RPort,&hxtxt,0,0); /* Proably, should do a WaitPort(cW->UserPort); */ /* I didn't, so the color updates faster. */ /* In a multitasking environment, the system is */ /* being gronked... */ } igad =(struct Gadget *) imsg->IAddress; if ( (class = imsg->Class) == MENUVERIFY ) { imsg->Code = MENUCANCEL; /* Don't Let Em Out! */ DisplayBeep(NL); } ReplyMsg(imsg); switch ( class ) { case GADGETUP: case GADGETDOWN: if ((igad->GadgetID >= PGAD)&&(igad->GadgetID < PGAD+CTSIZ)) { cursel = igad->GadgetID - PGAD; munge = TRUE; } else switch ( igad->GadgetID ) { case PGHI+1: /* Cancel */ for ( class =0 ; classUserPort = NL; CloseWindow(cW); return(TRUE); } /*************************************************************/ main() { init_program(); palette(p_W); clear_program(); } /*** End of MicroSmith's Palette Tool ***/