home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------
- You can now change the colors on any screen and use the AGA's 24 bit
- palette. The only major change over the last palette requester I wrote is
- that it now uses the actual 3.0 functions LoadRGB32(), and GetRGB32() rather
- than my own home brewed versions. You will also notice the additions of
- Keyboard equivalents, and "R", "G", and "B" by the sliders, and the addition
- of a "Selected Color" box on the left side of the Palette gadget.
-
- By the way, I am not rich, but I am not doing this for money
- either. All I ask is if you use or modify this program let me know.
- I am really interested in seeing how far this program gets.
- Do what you want with it.
-
- But if it makes you fell better, I will take cash :-))
- You can guesse the legal matters, "I am not responsible..."
-
- Psychotic Psoftware
- Anthony J. Moringello
- 2209 E. Park Pl. #4
- Miwlaukee, WI 53211
- ----------------------------------------------------------------------*/
- /*
- * Source machine generated by GadToolsBox V2.0
- * which is (c) Copyright 1991-1993 Jaba Development
- *
- * GUI Designed by : Anthony J. Moringello - anthonym@csd4.csd.uwm.edu
- */
-
- #include <exec/types.h>
- #include <Exec/Memory.h>
- #include <intuition/intuition.h>
- #include <Intuition/IntuitionBase.h>
- #include <intuition/classes.h>
- #include <intuition/classusr.h>
- #include <intuition/imageclass.h>
- #include <intuition/gadgetclass.h>
- #include <libraries/gadtools.h>
- #include <graphics/displayinfo.h>
- #include <graphics/gfxbase.h>
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/gadtools_protos.h>
- #include <clib/graphics_protos.h>
- #include <clib/utility_protos.h>
- #include <CLib/AGA_Protos.h>
- #include <string.h>
-
- extern struct ExecBase **SysBase;
- extern struct IntuitionBase *IntuitionBase;
- extern struct GfxBase *GfxBase;
- extern struct GadToolsBase *GadToolsBase;
-
- #include <pragmas/exec_pragmas.h>
- #include <pragmas/intuition_pragmas.h>
- #include <pragmas/gadtools_pragmas.h>
- #include <pragmas/graphics_pragmas.h>
- #include <pragmas/utility_pragmas.h>
- #include <Pragmas/AGA_Pragmas.h>
-
- #include "Palette.h"
-
- struct Screen *Scr = NULL;
- struct Window *PReqWnd = NULL;
- struct Gadget *PReqGList = NULL;
- struct IntuiMessage PReqMsg;
- struct Gadget *PReqGadgets[7];
- APTR VisualInfo = NULL;
- UWORD PReqWidth = 300;
- UWORD PReqHeight = 189;
- UBYTE *PReqWdt = (UBYTE *)"24 Bit Palette Requester";
-
- ULONG red, green, blue;
- ULONG index, ncolors;
- ULONG table[2+3];
- ULONG *originalpalette; // Allocate later for depth of screen
- int ResetPalette(void);
- int SetTable(void);
-
- struct TextAttr topaz8 = {
- ( STRPTR )"topaz.font", 8, 0x00, 0x01 };
-
- UWORD PReqGTypes[] = {
- SLIDER_KIND,
- SLIDER_KIND,
- SLIDER_KIND,
- BUTTON_KIND,
- BUTTON_KIND,
- BUTTON_KIND,
- PALETTE_KIND
- };
-
- struct NewGadget PReqNGad[] = {
- 24, 169, 243, 14, (UBYTE *)"_B", NULL, GD_BlueSliderG, PLACETEXT_LEFT, NULL, (APTR)BlueSliderGClicked,
- 24, 152, 243, 14, (UBYTE *)"_G", NULL, GD_GreenSliderG, PLACETEXT_LEFT, NULL, (APTR)GreenSliderGClicked,
- 24, 135, 243, 14, (UBYTE *)"_R", NULL, GD_RedSliderG, PLACETEXT_LEFT, NULL, (APTR)RedSliderGClicked,
- 2, 97, 86, 32, (UBYTE *)"_Use", NULL, GD_UseG, PLACETEXT_IN, NULL, (APTR)UseGClicked,
- 104, 97, 86, 32, (UBYTE *)"r_Eset", NULL, GD_ResetG, PLACETEXT_IN, NULL, (APTR)ResetGClicked,
- 203, 97, 86, 32, (UBYTE *)"_Cancel", NULL, GD_CancelG, PLACETEXT_IN, NULL, (APTR)CancelGClicked,
- 51, 3, 238, 90, NULL, NULL, GD_PaletteG, 0, NULL, (APTR)PaletteGClicked
- };
-
- ULONG PReqGTags[] = {
- (GTSL_Max), 255, (GTSL_MaxLevelLen), 3, (GTSL_LevelFormat), (ULONG)"%2lX", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
- (GTSL_Max), 255, (GTSL_MaxLevelLen), 3, (GTSL_LevelFormat), (ULONG)"%2lX", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
- (GTSL_Max), 255, (GTSL_MaxLevelLen), 3, (GTSL_LevelFormat), (ULONG)"%2lX", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
- (GT_Underscore), '_', (TAG_DONE),
- (GT_Underscore), '_', (TAG_DONE),
- (GT_Underscore), '_', (TAG_DONE),
- (GTPA_Depth), 8, (TAG_DONE)
- };
-
- void PReqRender( void )
- {
- UWORD offx, offy;
-
- offx = PReqWnd->BorderLeft;
- offy = PReqWnd->BorderTop;
-
-
- DrawBevelBox( PReqWnd->RPort, offx + 3, offy + 26, 45, 39, GT_VisualInfo, VisualInfo, TAG_DONE );
- DrawBevelBox( PReqWnd->RPort, offx + 7, offy + 28, 37, 35, GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
- }
-
- int HandlePReqIDCMP( void )
- {
- struct IntuiMessage *m;
- int (*func)(struct IntuiMessage *);
- BOOL running = TRUE;
-
- while( m = GT_GetIMsg( PReqWnd->UserPort )) {
-
- CopyMem(( char * )m, ( char * )&PReqMsg, (long)sizeof( struct IntuiMessage ));
-
- GT_ReplyIMsg( m );
-
- switch ( PReqMsg.Class ) {
-
- case IDCMP_REFRESHWINDOW:
- GT_BeginRefresh( PReqWnd );
- PReqRender();
- GT_EndRefresh( PReqWnd, TRUE );
- break;
-
- case IDCMP_CLOSEWINDOW:
- running = PReqCloseWindow();
- break;
-
- case IDCMP_VANILLAKEY:
- switch(PReqMsg.Code)
- {
- case 'u':
- case 'U':
- running = FALSE;
- break;
- case 'e':
- case 'E':
- ResetPalette();
- running = TRUE;
- break;
- case 'c':
- case 'C':
- ResetPalette();
- running = FALSE;
- break;
- case 'r':
- red = (++red)&0xFF;
- GT_SetGadgetAttrs(PReqGadgets[2], PReqWnd, NULL, GTSL_Level, red, TAG_END);
- SetTable();
- break;
- case 'R':
- red = (--red)&0xFF;
- GT_SetGadgetAttrs(PReqGadgets[2], PReqWnd, NULL, GTSL_Level, red, TAG_END);
- SetTable();
- break;
- case 'g':
- green = (++green)&0xFF;
- GT_SetGadgetAttrs(PReqGadgets[1], PReqWnd, NULL, GTSL_Level, green, TAG_END);
- SetTable();
- break;
- case 'G':
- green = (--green)&0xFF;
- GT_SetGadgetAttrs(PReqGadgets[1], PReqWnd, NULL, GTSL_Level, green, TAG_END);
- SetTable();
- break;
- case 'b':
- blue = (++blue)&0xFF;
- GT_SetGadgetAttrs(PReqGadgets[0], PReqWnd, NULL, GTSL_Level, blue, TAG_END);
- SetTable();
- break;
- case 'B':
- blue = (--blue)&0xFF;
- GT_SetGadgetAttrs(PReqGadgets[0], PReqWnd, NULL, GTSL_Level, blue, TAG_END);
- SetTable();
- break;
-
- default:
- break;
- }
- break;
-
- case IDCMP_MOUSEMOVE:
- case IDCMP_GADGETUP:
- case IDCMP_GADGETDOWN:
- func = ( void * )(( struct Gadget * )PReqMsg.IAddress )->UserData;
- running = func(&PReqMsg);
- break;
- }
- }
- return( running );
- }
-
- int OpenPReqWindow( void )
- {
- struct NewGadget ng;
- struct Gadget *g;
- UWORD lc, tc;
- UWORD offx = Scr->WBorLeft, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
-
- if ( ! ( g = CreateContext( &PReqGList )))
- return( 1L );
-
- for( lc = 0, tc = 0; lc < PReq_CNT; lc++ ) {
-
- CopyMem((char * )&PReqNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
-
- ng.ng_VisualInfo = VisualInfo;
- ng.ng_TextAttr = &topaz8;
- ng.ng_LeftEdge += offx;
- ng.ng_TopEdge += offy;
-
- PReqGadgets[ lc ] = g = CreateGadgetA((ULONG)PReqGTypes[ lc ], g, &ng, ( struct TagItem * )&PReqGTags[ tc ] );
-
- while( PReqGTags[ tc ] ) tc += 2;
- tc++;
-
- if ( NOT g )
- return( 2L );
- }
-
- if ( ! ( PReqWnd = OpenWindowTags( NULL,
- WA_Left, 0,
- WA_Top, 0,
- WA_Width, PReqWidth,
- WA_Height, PReqHeight + offy,
- WA_IDCMP, SLIDERIDCMP|BUTTONIDCMP|PALETTEIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_MOUSEMOVE|IDCMP_VANILLAKEY,
- WA_Flags, WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
- WA_Gadgets, PReqGList,
- WA_Title, PReqWdt,
- WA_ScreenTitle, "24 Bit Palette Requester © Anthony J. Moringello",
- WA_PubScreen, Scr,
- TAG_DONE )))
- return( 4L );
-
- GT_RefreshWindow( PReqWnd, NULL );
-
- PReqRender();
-
- return( 0L );
- }
-
- void ClosePReqWindow( void )
- {
- if ( PReqWnd ) {
- CloseWindow( PReqWnd );
- PReqWnd = NULL;
- }
-
- if ( PReqGList ) {
- FreeGadgets( PReqGList );
- PReqGList = NULL;
- }
- }
-
- /*------------- Now actually do stuff when events come in. ----------------*/
- #include "Palette_Temp.c"
-
- VOID
- main()
- {
- BOOL running = TRUE;
- // struct EasyStruct es;
-
-
- IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37);
- if( IntuitionBase )
- {
- GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39);
- if( GfxBase )
- {
- GadToolsBase = (struct GadToolsBase *)OpenLibrary("gadtools.library", 37);
- if( GadToolsBase )
- {
- Scr = IntuitionBase->FirstScreen;
- if( (VisualInfo = GetVisualInfo( Scr, TAG_DONE)) )
- {
- ncolors = 1<< Scr->BitMap.Depth;
- PReqGTags[61] = Scr->BitMap.Depth;
- OpenPReqWindow();
- if( PReqWnd )
- {
- originalpalette = AllocVec(8+ 12*ncolors, MEMF_ANY|MEMF_CLEAR);
- if( originalpalette )
- {
- GetRGB32(Scr->ViewPort.ColorMap, 0, ncolors, &originalpalette[1]);
- originalpalette[0] = ncolors<<16 + 0;
- ResetPalette();
- while( running )
- {
- Wait(1L<<PReqWnd->UserPort->mp_SigBit);
- running = HandlePReqIDCMP();
- }
- }
- FreeVec(originalpalette);
- ClosePReqWindow();
- }
- FreeVisualInfo( VisualInfo );
- VisualInfo = NULL;
- }
- CloseLibrary((struct Library *)GadToolsBase);
- }
- CloseLibrary((struct Library *)GfxBase);
- }
- /*----------------------------------------------------------------------------
- else
- {
- if( GfxBase->LibNode.dl_lib.Version < 39 )
- {
- es.es_StructSize = sizeof(struct EasyStruct)
- es.es_Flags = NULL;
- es.es_Title = "Palette Req Error!";
- es.es_TextFormat = "You need version 39 of Gfx Library.";
- es.es_GadgetFormat = "OK";
-
- EasyRequest( etc....
- ------------------------------------------------------------------------------*/
- CloseLibrary((struct Library *)IntuitionBase);
- }
- }
-
- int
- ResetPalette(void)
- {
- LoadRGB32(&Scr->ViewPort, originalpalette);
- GetRGB32(Scr->ViewPort.ColorMap, index, 1, &table[1]);
- red = table[1]>>24;
- green = table[2]>>24;
- blue = table[3]>>24;
- SetAPen(PReqWnd->RPort, index);
- RectFill(PReqWnd->RPort, PReqWnd->BorderLeft+9, PReqWnd->BorderTop+29,
- PReqWnd->BorderLeft+41, PReqWnd->BorderTop+61);
- GT_SetGadgetAttrs(PReqGadgets[2], PReqWnd, NULL,
- GTSL_Level, red, TAG_END);
- GT_SetGadgetAttrs(PReqGadgets[1], PReqWnd, NULL,
- GTSL_Level, green, TAG_END);
- GT_SetGadgetAttrs(PReqGadgets[0], PReqWnd, NULL,
- GTSL_Level, blue, TAG_END);
- return(0);
- }
-