4 #include <exec/types.h>
5 #include <exec/memory.h>
6 #include <libraries/dos.h>
7 #include <libraries/dosextens.h>
8 #include <libraries/gadtools.h>
9 #include <intuition/icclass.h>
10 #include <intuition/intuition.h>
11 #include <intuition/gadgetclass.h>
12 #include <intuition/intuitionbase.h>
13 #include <intuition/gadgetclass.h>
14 #include <gadgets/colorwheel.h>
15 #include <gadgets/gradientslider.h>
16 #include <graphics/gfxbase.h>
17 #include <proto/graphics.h>
18 #include <proto/exec.h>
19 #include <proto/intuition.h>
20 #include <proto/dos.h>
21 #include <proto/gadtools.h>
22 #include <proto/utility.h>
23 #include <proto/alib.h>
24 #include <proto/colorwheel.h>
25 #include <clib/macros.h>
28 #include <libraries/reqtools.h>
29 #include <proto/reqtools.h>
33 #include "boopsigads.h"
37 /****************************************************************************************/
39 extern struct ReqToolsBase
*ReqToolsBase
;
41 /****************************************************************************************/
46 /****************************************************************************************/
48 extern ULONG ASM
LoopReqHandler (ASM_REGPARAM(a1
, struct rtHandlerInfo
*,));
49 extern ULONG ASM
myGetDisplayInfoData (
50 OPT_REGPARAM(a1
, UBYTE
*,),
51 OPT_REGPARAM(d0
, unsigned long,),
52 OPT_REGPARAM(d1
, unsigned long,),
53 OPT_REGPARAM(d2
, unsigned long,));
55 /****************************************************************************************/
57 #define RED_ID 0 /* DO NOT CHANGE !!! */
58 #define GREEN_ID 1 /* DO NOT CHANGE !!! */
59 #define BLUE_ID 2 /* DO NOT CHANGE !!! */
71 /****************************************************************************************/
80 /****************************************************************************************/
82 #define MODE_TITLE_OFFSET COPY_ID
86 #define HIGHGRADPENS 8
87 #define FREEFORHIGH 32
89 #define NO_TITLE ( ( STRPTR ) ~0 )
91 /****************************************************************************************/
93 extern struct Library
*GadToolsBase
;
94 extern struct IntuitionBase
*IntuitionBase
;
95 extern struct GfxBase
*GfxBase
;
97 extern struct TextAttr topaz80
;
99 /****************************************************************************************/
101 typedef struct RealHandlerInfo GlobData
;
103 struct RealHandlerInfo
105 LONG (*func
)(); /* private */
107 ULONG rthi_DoNotWait
;
110 ULONG cols
[3]; /* DO NOT MOVE, see cols offset in misc.asm */
111 struct ViewPort
*vp
; /* DO NOT MOVE, see vp offset in misc.asm */
113 { /* DO NOT MOVE, see offsets in misc.asm */
116 ULONG red
, green
, blue
;
120 struct NewWindow newpalwin
;
121 struct KeyButtonInfo buttoninfo
;
122 struct Screen
*scr
, *frontscr
;
123 struct Gadget
*colgad
[3], *palgad
;
124 struct Window
*palwin
, *win
, *prwin
;
126 struct TextAttr font
;
127 struct TextFont
*reqfont
;
128 struct DrawInfo
*drinfo
;
129 struct Image labelimages
;
130 struct rtReqInfo
*reqinfo
;
131 struct Hook
*imsghook
, backfillhook
;
132 struct Catalog
*catalog
;
133 struct IntuiText itxt
;
134 long color
, coldepth
, colcount
, reqpos
, leftedge
, topedge
;
135 int waitpointer
, lockwindow
, shareidcmp
, noscreenpop
;
136 int fontwidth
, fontheight
, mode
, os30
, maxcolval
[3];
137 char key
[3], palettekey
;
138 APTR colormap
, undomap
;
139 APTR visinfo
, winlock
;
144 struct Library
*ColorWheelBase
;
145 struct Library
*GradientSliderBase
;
146 struct ColorWheelRGB wheel_rgb
;
147 struct ColorWheelHSB wheel_hsb
;
148 struct Gadget
*wheel
;
149 struct Gadget
*wheel_slider
;
150 ULONG wheel_colortable
[3];
153 UWORD wheel_pens
[ HIGHGRADPENS
+ 1 ];
156 WORD dowheel
, fancywheel
;
161 /****************************************************************************************/
163 #define redbits col.bits.red
164 #define greenbits col.bits.green
165 #define bluebits col.bits.blue
167 #define ThisProcess() ( ( struct Process * ) FindTask( NULL ) )
169 /****************************************************************************************/
171 extern ULONG ASM
MakeColVal (ASM_REGPARAM(d0
, ULONG
,), ASM_REGPARAM(d4
, ULONG
,));
172 extern void REGARGS
SpreadColors (GlobData
*, int, int, ULONG
*);
174 static int REGARGS
SetupPalWindow (GlobData
*, char *);
175 static void REGARGS
SelectColor (GlobData
*, int);
176 static void REGARGS
FreeAll (GlobData
*);
177 static void REGARGS
SetColor (GlobData
*, int, ULONG
*);
178 static void REGARGS
SetWheelColor (GlobData
*, struct TagItem
* );
179 static void REGARGS
UpdateWheel( GlobData
*, ULONG
* );
180 static void REGARGS
RestorePaletteFreeAll (GlobData
*);
181 static void REGARGS
DoColorShortcut (GlobData
*, int, int, int);
182 static LONG ASM SAVEDS
PalReqHandler (
183 REGPARAM(a1
, struct RealHandlerInfo
*,),
184 REGPARAM(d0
, ULONG
,),
185 REGPARAM(a0
, struct TagItem
*,));
187 /****************************************************************************************/
190 #define ColorWheelBase glob->ColorWheelBase
191 #define GradientSliderBase glob->GradientSliderBase
195 /****************************************************************************************/
199 /****************************************************************************************/
201 ULONG
MakeColVal(ULONG val
, ULONG bits
)
205 val2
= val
<< (32 - bits
);
216 /****************************************************************************************/
218 void REGARGS
SpreadColors (GlobData
*glob
, int from
, int to
, ULONG
*rgb2
)
223 WORD actcol
, steps
, gun
;
236 for(gun
= 0; gun
< 3; gun
++)
238 LONG diff
= rgb2
[gun
] - glob
->cols
[gun
];
239 step
[gun
] = (diff
<< 16L) / steps
;
240 rgb
[gun
] = glob
->cols
[gun
] << 16;
247 actcol
+= colstep
, rgb
[0] += step
[0], rgb
[1] += step
[1], rgb
[2] += step
[2])
249 ULONG red
= (((ULONG
)rgb
[0]) + 0x8000) >> 16;
250 ULONG green
= (((ULONG
)rgb
[1]) + 0x8000) >> 16;
251 ULONG blue
= (((ULONG
)rgb
[2]) + 0x8000) >> 16;
253 if (GfxBase
->LibNode
.lib_Version
>= 39)
255 SetRGB32(glob
->vp
, actcol
, MakeColVal(red
, glob
->col
.colbits
[0]),
256 MakeColVal(green
, glob
->col
.colbits
[1]),
257 MakeColVal(blue
, glob
->col
.colbits
[2]));
261 SetRGB4(glob
->vp
, actcol
, red
, green
, blue
);
268 /****************************************************************************************/
270 #endif /* !USE_ASM_FUNCS */
272 /****************************************************************************************/
285 for( i
= 1, j
= 4; i
<= 8; ++i
, j
<<= 1 )
297 /****************************************************************************************/
299 LONG ASM SAVEDS
PaletteRequestA (
300 REGPARAM(a2
, char *, title
),
301 REGPARAM(a3
, struct rtReqInfo
*, reqinfo
),
302 REGPARAM(a0
, struct TagItem
*, taglist
))
305 struct DisplayInfo displayinfo
;
306 struct TagItem
*tag
, *tstate
= taglist
;
307 struct TextFont
*deffont
= NULL
;
308 struct TextAttr
*fontattr
= NULL
;
309 struct Locale
*locale
= NULL
;
310 char *pubname
= NULL
;
312 BOOL reqhandler
= FALSE
;
314 if (!(glob
= AllocVec (sizeof(GlobData
), MEMF_PUBLIC
|MEMF_CLEAR
)))
317 glob
->os30
= (GfxBase
->LibNode
.lib_Version
>= 39);
319 glob
->reqpos
= REQPOS_DEFAULT
;
321 if ((glob
->reqinfo
= reqinfo
))
323 glob
->reqpos
= reqinfo
->ReqPos
;
324 glob
->leftedge
= reqinfo
->LeftOffset
;
325 glob
->topedge
= reqinfo
->TopOffset
;
326 deffont
= reqinfo
->DefaultFont
;
327 glob
->waitpointer
= reqinfo
->WaitPointer
;
328 glob
->lockwindow
= reqinfo
->LockWindow
;
329 glob
->shareidcmp
= reqinfo
->ShareIDCMP
;
330 glob
->imsghook
= reqinfo
->IntuiMsgFunc
;
334 while ((tag
= NextTagItem (&tstate
)))
336 tagdata
= tag
->ti_Data
;
337 if (tag
->ti_Tag
> RT_TagBase
)
341 case RT_Window
: glob
->prwin
= (struct Window
*)tagdata
; break;
342 case RT_ReqPos
: glob
->reqpos
= tagdata
; break;
343 case RT_LeftOffset
: glob
->leftedge
= tagdata
; break;
344 case RT_TopOffset
: glob
->topedge
= tagdata
; break;
345 case RT_PubScrName
: pubname
= (char *)tagdata
; break;
346 case RT_Screen
: glob
->scr
= (struct Screen
*)tagdata
; break;
347 case RT_ReqHandler
: *(APTR
*)tagdata
= glob
;
350 case RT_DefaultFont
: deffont
= (struct TextFont
*)tagdata
; break;
351 case RT_WaitPointer
: glob
->waitpointer
= tagdata
; break;
352 case RT_ShareIDCMP
: glob
->shareidcmp
= tagdata
; break;
353 case RT_LockWindow
: glob
->lockwindow
= tagdata
; break;
354 case RT_ScreenToFront
: glob
->noscreenpop
= !tagdata
; break;
355 case RT_TextAttr
: fontattr
= (struct TextAttr
*)tagdata
; break;
356 case RT_IntuiMsgFunc
: glob
->imsghook
= (struct Hook
*)tagdata
; break;
357 case RT_Locale
: locale
= (struct Locale
*)tagdata
; break;
358 case RTPA_Color
: glob
->color
= tagdata
; break;
363 glob
->catalog
= RT_OpenCatalog (locale
);
365 if (!glob
->prwin
|| !glob
->prwin
->UserPort
||
366 (glob
->prwin
->UserPort
->mp_SigTask
!= ThisProcess()))
367 glob
->shareidcmp
= FALSE
;
369 if (!(glob
->scr
= GetReqScreen (&glob
->newpalwin
, &glob
->prwin
, glob
->scr
, pubname
)))
374 glob
->vp
= &glob
->scr
->ViewPort
;
375 glob
->cm
= glob
->vp
->ColorMap
;
377 if (!(glob
->coldepth
= GetVpCM (glob
->vp
, &glob
->colormap
)) ||
378 !GetVpCM (glob
->vp
, &glob
->undomap
))
384 glob
->colcount
= (1 << glob
->coldepth
);
385 glob
->newpalwin
.Screen
= glob
->scr
;
388 glob
->font
= *fontattr
;
390 glob
->font
= *glob
->scr
->Font
;
392 glob
->redbits
= glob
->greenbits
= glob
->bluebits
= 4;
395 if (myGetDisplayInfoData ((UBYTE
*)&displayinfo
, sizeof (struct DisplayInfo
),
396 DTAG_DISP
, GetVPModeID (glob
->vp
)) > 0)
398 glob
->redbits
= displayinfo
.RedBits
;
399 glob
->greenbits
= displayinfo
.GreenBits
;
400 glob
->bluebits
= displayinfo
.BlueBits
;
403 glob
->screenres
= displayinfo
.Resolution
;
409 glob
->maxcolval
[RED_ID
] = (1 << glob
->redbits
) - 1;
410 glob
->maxcolval
[GREEN_ID
] = (1 << glob
->greenbits
) - 1;
411 glob
->maxcolval
[BLUE_ID
] = (1 << glob
->bluebits
) - 1;
413 if (!(glob
->visinfo
= GetVisualInfoA (glob
->scr
, NULL
)) ||
414 !(glob
->drinfo
= GetScreenDrawInfo (glob
->scr
)))
422 struct ReqToolsPrefs
*prefs
;
424 prefs
= rtLockPrefs();
425 glob
->dowheel
= ( prefs
->Flags
& RTPRF_DOWHEEL
) && glob
->os30
;
426 glob
->fancywheel
= glob
->dowheel
&& ( prefs
->Flags
& RTPRF_FANCYWHEEL
);
432 if ((ColorWheelBase
= OpenLibrary ("gadgets/colorwheel.gadget", 39)))
434 GradientSliderBase
= OpenLibrary ("gadgets/gradientslider.gadget", 39);
439 SelectColor (glob
, glob
->color
);
442 if (!(glob
->reqfont
= GetReqFont (&glob
->font
, deffont
, &glob
->fontheight
,
443 &glob
->fontwidth
, glob
->os30
)))
449 if (!SetupPalWindow (glob
, title
))
453 glob
->dowheel
= FALSE
;
455 DisposeObject( glob
->wheel
);
456 DisposeObject( glob
->wheel_slider
);
458 glob
->wheel_slider
= NULL
;
459 CloseLibrary( ColorWheelBase
);
460 CloseLibrary( GradientSliderBase
);
461 ColorWheelBase
= NULL
;
462 GradientSliderBase
= NULL
;
467 if (glob
->font
.ta_YSize
> 8)
469 glob
->font
= topaz80
;
470 CloseFont (glob
->reqfont
);
479 if( glob
->fancywheel
)
481 /* Try to get a fresh undo color map (in case the wheel allocates some) */
482 RefreshVpCM( glob
->vp
, glob
->undomap
);
484 /* And make sure selected color still is correct */
485 SelectColor( glob
, glob
->color
);
489 glob
->winlock
= DoLockWindow (glob
->prwin
, glob
->lockwindow
, NULL
, TRUE
);
490 DoWaitPointer (glob
->prwin
, glob
->waitpointer
, TRUE
);
492 glob
->frontscr
= IntuitionBase
->FirstScreen
;
493 DoScreenToFront (glob
->scr
, glob
->noscreenpop
, TRUE
);
495 /* fill in RealHandlerInfo */
496 glob
->func
= (LONG (*)())PalReqHandler
;
497 glob
->rthi_WaitMask
= (1 << glob
->palwin
->UserPort
->mp_SigBit
);
499 if (reqhandler
) return (CALL_HANDLER
);
501 return ((LONG
)LoopReqHandler ((struct rtHandlerInfo
*)glob
));
504 /****************************************************************************************/
506 static LONG ASM SAVEDS
PalReqHandler (
507 REGPARAM(a1
, struct RealHandlerInfo
*, glob
),
508 REGPARAM(d0
, ULONG
, sigs
),
509 REGPARAM(a0
, struct TagItem
*, taglist
))
511 struct IntuiMessage
*palmsg
;
514 struct TagItem
*tstate
= taglist
;
515 ULONG rgb
[3], rgbcol
;
516 ULONG tagdata
, class;
518 int i
, gadid
, shifted
, alt
;
521 /* uncomment if sigs is no longer ignored */
522 //if (glob->rthi_DoNotWait) sigs = 0;
525 while ((tag
= NextTagItem (&tstate
)))
527 tagdata
= tag
->ti_Data
;
528 if (tag
->ti_Tag
> RT_TagBase
)
532 case RTRH_EndRequest
:
533 if (tagdata
== REQ_OK
)
538 RestorePaletteFreeAll (glob
);
544 while ((palmsg
= GetWin_GT_Msg (glob
->palwin
, glob
->imsghook
, glob
->reqinfo
)))
546 class = palmsg
->Class
;
548 qual
= palmsg
->Qualifier
;
549 gad
= (struct Gadget
*)palmsg
->IAddress
;
550 Reply_GT_Msg (palmsg
);
554 case IDCMP_REFRESHWINDOW
:
555 GT_BeginRefresh (glob
->palwin
);
556 GT_EndRefresh (glob
->palwin
, TRUE
);
559 case IDCMP_CLOSEWINDOW
:
560 RestorePaletteFreeAll (glob
);
563 case IDCMP_MOUSEMOVE
:
564 case IDCMP_GADGETDOWN
:
565 if (gad
->GadgetID
<= BLUE_ID
)
567 glob
->cols
[gad
->GadgetID
] = code
;
568 SetColor (glob
, glob
->color
, glob
->cols
);
570 UpdateWheel( glob
, glob
->cols
);
577 if (class == IDCMP_RAWKEY
)
579 if (!(gadid
= CheckGadgetKey (code
, qual
, &key
, &glob
->buttoninfo
)))
581 /* key press was not for gadget, so check other cases */
582 shifted
= qual
& (IEQUALIFIER_LSHIFT
|IEQUALIFIER_RSHIFT
);
583 alt
= qual
& (IEQUALIFIER_LALT
|IEQUALIFIER_RALT
);
584 if (key
== glob
->key
[RED_ID
])
585 DoColorShortcut (glob
, RED_ID
, shifted
, alt
);
586 else if (key
== glob
->key
[GREEN_ID
])
587 DoColorShortcut (glob
, GREEN_ID
, shifted
, alt
);
588 else if (key
== glob
->key
[BLUE_ID
])
589 DoColorShortcut (glob
, BLUE_ID
, shifted
, alt
);
590 else if (key
== glob
->palettekey
)
596 if (code
>= glob
->colcount
) code
= 0;
600 if (code
<= 0) code
= glob
->colcount
;
603 myGT_SetGadgetAttrs (glob
->palgad
, glob
->palwin
, NULL
,
604 GTPA_Color
, code
, TAG_END
);
611 } /* if (class == IDCMP_RAWKEY) */
612 else gadid
= gad
->GadgetID
;
614 if (gadid
) switch (gadid
)
617 RestorePaletteFreeAll (glob
);
626 RefreshVpCM (glob
->vp
, glob
->undomap
);
630 rgbcol
= GetRGB4 (glob
->cm
, code
);
631 for (i
= 2; i
>= 0; i
--)
633 rgb
[i
] = rgbcol
& 0xf;
639 GetRGB32 (glob
->cm
, code
, 1, rgb
);
640 rgb
[0] >>= (32 - glob
->redbits
);
641 rgb
[1] >>= (32 - glob
->greenbits
);
642 rgb
[2] >>= (32 - glob
->bluebits
);
648 SetColor (glob
, glob
->color
, rgb
);
650 SetColor (glob
, code
, glob
->cols
);
653 SpreadColors (glob
, glob
->color
, code
, rgb
);
657 SelectColor (glob
, code
);
659 SetWindowTitles( glob
->palwin
, glob
->newpalwin
.Title
, NO_TITLE
);
661 UpdateWheel( glob
, glob
->cols
);
666 LoadCMap (glob
->vp
, glob
->undomap
);
667 SelectColor (glob
, glob
->color
);
669 UpdateWheel( glob
, glob
->cols
);
674 if( ( gadid
== SWAP_ID
) || ( gadid
== COPY_ID
) || ( gadid
== SPREAD_ID
) )
677 SetWindowTitles( glob
->palwin
, GetStr( glob
->catalog
, ModeTitles
[ gadid
- MODE_TITLE_OFFSET
] ), NO_TITLE
);
682 } /* if (gadid) switch (gadid) */
686 case IDCMP_IDCMPUPDATE
:
687 SetWheelColor( glob
, ( struct TagItem
* ) gad
);
692 } /* while ((palmsg = GetWin_GT_Msg (glob->palwin, glob->imsghook, glob->reqinfo))) */
694 return (CALL_HANDLER
);
697 /****************************************************************************************/
699 static void REGARGS
DoColorShortcut (GlobData
*glob
, int id
, int shifted
, int alt
)
701 int t
= glob
->cols
[id
];
705 if (alt
) t
-= 8; else t
--;
710 if (alt
) t
+= 8; else t
++;
711 if (t
>= glob
->maxcolval
[id
]) t
= glob
->maxcolval
[id
];
715 SetColor (glob
, glob
->color
, glob
->cols
);
716 SelectColor (glob
, glob
->color
);
719 /****************************************************************************************/
721 static void REGARGS
SetColor (GlobData
*glob
, int col
, ULONG
*rgb
)
725 SetRGB4( glob
->vp
, col
, rgb
[ 0 ], rgb
[ 1 ], rgb
[ 2 ] );
729 SetRGB32( glob
->vp
, col
,
730 MakeColVal( rgb
[ 0 ], glob
->redbits
),
731 MakeColVal( rgb
[ 1 ], glob
->greenbits
),
732 MakeColVal( rgb
[ 2 ], glob
->bluebits
) );
736 /****************************************************************************************/
740 /****************************************************************************************/
744 /****************************************************************************************/
747 UpdateGrad( GlobData
*glob
)
749 if( glob
->numgradpens
)
753 GetAttr( WHEEL_HSB
, (Object
*)glob
->wheel
, ( IPTR
* ) &glob
->wheel_hsb
);
755 for( i
= 0; i
< glob
->numgradpens
; ++i
)
757 glob
->wheel_hsb
.cw_Brightness
= 0xffffffff - ( ( 0xffffffff / ( glob
->numgradpens
- 1 ) ) * i
);
758 ConvertHSBToRGB( &glob
->wheel_hsb
, &glob
->wheel_rgb
);
759 SetRGB32( &glob
->scr
->ViewPort
, glob
->wheel_pens
[ i
],
760 glob
->wheel_rgb
.cw_Red
, glob
->wheel_rgb
.cw_Green
,
761 glob
->wheel_rgb
.cw_Blue
);
766 /****************************************************************************************/
770 /****************************************************************************************/
773 UpdateWheel( GlobData
*glob
, ULONG
*cols
)
777 glob
->wheel_rgb
.cw_Red
= MakeColVal( cols
[ 0 ], glob
->redbits
);
778 glob
->wheel_rgb
.cw_Green
= MakeColVal( cols
[ 1 ], glob
->greenbits
);
779 glob
->wheel_rgb
.cw_Blue
= MakeColVal( cols
[ 2 ], glob
->bluebits
);
781 SetGadgetAttrs( glob
->wheel
, glob
->palwin
, NULL
, WHEEL_RGB
, (IPTR
) &glob
->wheel_rgb
,
790 /****************************************************************************************/
793 SetWheelColor( GlobData
*glob
, struct TagItem
*tag
)
799 GetAttr( WHEEL_HSB
, (Object
*)glob
->wheel
, ( IPTR
* ) &glob
->wheel_hsb
);
800 ConvertHSBToRGB( &glob
->wheel_hsb
, &glob
->wheel_rgb
);
801 glob
->cols
[ RED_ID
] = glob
->wheel_rgb
.cw_Red
>> ( 32 - glob
->redbits
);
802 glob
->cols
[ GREEN_ID
] = glob
->wheel_rgb
.cw_Green
>> ( 32 - glob
->greenbits
);
803 glob
->cols
[ BLUE_ID
] = glob
->wheel_rgb
.cw_Blue
>> ( 32 - glob
->bluebits
);
804 SetColor( glob
, glob
->color
, glob
->cols
);
806 for( i
= 0; i
< 3; ++i
)
808 if( glob
->colgad
[ i
] )
810 myGT_SetGadgetAttrs( glob
->colgad
[ i
], glob
->palwin
, NULL
, GTSL_Level
, glob
->cols
[ i
],
821 /****************************************************************************************/
825 /****************************************************************************************/
827 static void REGARGS
SelectColor (GlobData
*glob
, int col
)
829 ULONG rgb
[3], rgbcol
= 0;
832 if (!glob
->os30
) rgbcol
= GetRGB4 (glob
->cm
, col
);
833 else GetRGB32 (glob
->cm
, col
, 1, rgb
);
835 for (i
= 2; i
>= 0; i
--)
839 glob
->cols
[i
] = rgbcol
& 0xF;
842 else glob
->cols
[i
] = rgb
[i
] >> (32 - glob
->col
.colbits
[i
]);
845 myGT_SetGadgetAttrs (glob
->colgad
[i
], glob
->palwin
, NULL
,
846 GTSL_Level
, glob
->cols
[i
], TAG_END
);
852 /****************************************************************************************/
854 static void REGARGS
RestorePaletteFreeAll (GlobData
*glob
)
856 LoadCMap (glob
->vp
, glob
->colormap
);
860 /****************************************************************************************/
862 static void REGARGS
FreeAll (GlobData
*glob
)
869 if (glob
->newpalwin
.Type
== PUBLICSCREEN
) UnlockPubScreen (NULL
, glob
->scr
);
870 DoScreenToFront (glob
->frontscr
, glob
->noscreenpop
, FALSE
);
874 DoLockWindow (glob
->prwin
, glob
->lockwindow
, glob
->winlock
, FALSE
);
875 DoWaitPointer (glob
->prwin
, glob
->waitpointer
, FALSE
);
876 DoCloseWindow (glob
->palwin
, glob
->shareidcmp
);
879 RT_CloseCatalog (glob
->catalog
);
880 my_FreeGadgets (glob
->buttoninfo
.glist
);
881 my_FreeLabelImages (&glob
->labelimages
);
884 DisposeObject (glob
->wheel
);
885 DisposeObject (glob
->wheel_slider
);
888 if( glob
->numgradpens
)
890 for( i
= 0; glob
->wheel_pens
[ i
] != (UWORD
)~0; i
++ )
892 ReleasePen( glob
->scr
->ViewPort
.ColorMap
, glob
->wheel_pens
[ i
] );
897 CloseLibrary (GradientSliderBase
);
898 CloseLibrary (ColorWheelBase
);
901 FreeVisualInfo (glob
->visinfo
);
903 if (glob
->drinfo
) FreeScreenDrawInfo (glob
->scr
, glob
->drinfo
);
904 if (glob
->reqfont
) CloseFont (glob
->reqfont
);
906 FreeVpCM (glob
->vp
, glob
->colormap
, FALSE
);
907 FreeVpCM (glob
->vp
, glob
->undomap
, FALSE
);
911 /****************************************************************************************/
913 char *colstr
[] = { MSG_RED
, MSG_GREEN
, MSG_BLUE
};
914 char *gadtxt
[] = { MSG_COPY
, MSG_SWAP
, MSG_SPREAD
, MSG_OK
, MSG_UNDO
, MSG_CANCEL
};
916 /****************************************************************************************/
918 static int REGARGS
SetupPalWindow (GlobData
*glob
, char *title
)
923 int val
, i
, top
, buttonheight
, winheight
;
924 int spacing
, scrwidth
, scrheight
, maxwidth
;
925 int winwidth
, width1
, width2
, reqpos
, levelwidth
;
927 int wheelwidth
= 0, wheelheight
= 0, wheeltopoff
;
930 int leftoff
, rightoff
;
931 ULONG gadlen
[6], gadpos
[6];
932 char *str
, *string
[6];
935 spacing
= rtGetVScreenSize (glob
->scr
, (ULONG
*)&scrwidth
, (ULONG
*)&scrheight
);
936 leftoff
= glob
->scr
->WBorLeft
+ 5;
937 rightoff
= glob
->scr
->WBorRight
+ 5;
939 top
= (glob
->scr
->WBorTop
+ glob
->scr
->Font
->ta_YSize
+ 1) + spacing
/ 2 + 1;
940 glob
->itxt
.ITextFont
= &glob
->font
;
948 for (i
= 0; i
< 6; i
++)
950 string
[i
] = GetStr (glob
->catalog
, gadtxt
[i
]);
951 val
= StrWidth_noloc (&glob
->itxt
, string
[i
]) + 16;
954 if (val
> width1
) width1
= val
;
958 if (val
> width2
) width2
= val
;
962 for (i
= 0; i
< 3; i
++) gadlen
[i
] = width1
;
963 for (i
= 3; i
< 6; i
++) gadlen
[i
] = width2
;
968 winwidth
= (leftoff
+ rightoff
) + 25 + width1
+ 2 * 8;
969 val
= (leftoff
+ rightoff
) + width2
+ 2 * 8;
970 if (val
> winwidth
) winwidth
= val
;
971 if (winwidth
< 256) winwidth
= 256;
973 val
= glob
->fontheight
* 2 + 4;
978 if (glob
->colcount
>= 64) val
*= 2;
979 if (glob
->colcount
>= 128) val
*= 2;
983 if( glob
->dowheel
&& glob
->screenres
.x
&& glob
->screenres
.y
&& ColorWheelBase
&& GradientSliderBase
)
985 LONG maxheight
= 120;
987 if( scrheight
> 600 )
991 else if( scrheight
< 300 )
996 wheelheight
= val
+ glob
->fontheight
* 4 + 6 + 3 + spacing
* 3;
998 if( wheelheight
> maxheight
)
1000 wheelheight
= maxheight
;
1004 #warning Changed, because gcc produced wrong code! gcc 2.95.1 compiled under UAE JIT for Linux!?
1005 wheelwidth
= glob
->screenres
.y
;
1006 wheelwidth
*= wheelheight
;
1007 wheelwidth
/= glob
->screenres
.x
;
1009 wheelwidth
= wheelheight
* glob
->screenres
.y
/ glob
->screenres
.x
;
1012 if( ( scrwidth
- winwidth
> wheelwidth
+ 8 ) &&
1013 ( scrheight
> 200 ) )
1015 wheeloff
= wheelwidth
+ 8;
1016 winwidth
+= wheeloff
;
1020 glob
->dowheel
= FALSE
;
1023 } /* if( glob->dowheel && glob->screenres.x && glob->screenres.y && ColorWheelBase && GradientSliderBase ) */
1026 glob
->dowheel
= FALSE
;
1031 rtSpread (gadpos
, gadlen
, width1
, leftoff
+ wheeloff
+ 25, winwidth
- rightoff
, 3);
1032 rtSpread (gadpos
+ 3, gadlen
+ 3, width2
, leftoff
, winwidth
- rightoff
, 3);
1035 gad
= (struct Gadget
*)CreateContext (&glob
->buttoninfo
.glist
);
1036 img
= &glob
->labelimages
;
1038 ng
.ng_VisualInfo
= glob
->visinfo
;
1039 ng
.ng_TextAttr
= &glob
->font
;
1041 str
= GetStr (glob
->catalog
, MSG_PALETTE_COLORS
);
1042 glob
->palettekey
= KeyFromStr (str
, '_');
1044 i
= leftoff
+ 25 + ( winwidth
- ( leftoff
+ rightoff
+ 25 ) -
1045 StrWidth_noloc( &glob
->itxt
, str
) ) / 2;
1054 img
= my_CreateGadgetLabelImage (img
, &ng
, str
, i
, top
, HIGHLIGHTTEXTPEN
);
1055 top
+= glob
->fontheight
+ 1 + spacing
/ 2;
1057 InitNewGadget (&ng
, leftoff
+ wheeloff
+ 25, top
, winwidth
- ( wheeloff
+ leftoff
+ rightoff
+ 25),
1058 val
, NULL
, PALETTE_ID
);
1060 gad
= glob
->palgad
= myCreateGadget (PALETTE_KIND
, gad
, &ng
,
1061 GTPA_Depth
, (IPTR
)glob
->coldepth
,
1062 GTPA_IndicatorWidth
, 38,
1063 GTPA_Color
, (IPTR
)glob
->color
, TAG_END
);
1065 if (glob
->os30
) top
+= gad
->Height
+ spacing
;
1066 else top
+= val
+ spacing
;
1068 buttonheight
= glob
->fontheight
+ 6;
1070 for (i
= 0; i
< 3; i
++)
1072 InitNewGadget (&ng
, gadpos
[i
], top
, gadlen
[i
],
1073 buttonheight
, string
[i
], COPY_ID
+ i
);
1075 gad
= my_CreateButtonGadget (gad
, '_', &ng
);
1078 top
+= buttonheight
+ spacing
;
1080 ng
.ng_Flags
|= NG_HIGHLABEL
;
1084 for (i
= 0; i
< 3; i
++)
1086 string
[i
] = GetStr (glob
->catalog
, colstr
[i
]);
1087 glob
->key
[i
] = KeyFromStr (string
[i
], '_');
1088 val
= StrWidth_noloc (&glob
->itxt
, string
[i
]);
1089 if (val
> maxwidth
) maxwidth
= val
;
1092 levelwidth
= StrWidth_noloc (&glob
->itxt
, "000 ");
1093 maxwidth
+= levelwidth
;
1096 for (i
= 0; i
< 3; i
++)
1099 val
= leftoff
+ wheeloff
+ 2 + maxwidth
+ 8;
1100 InitNewGadget (&ng
, val
, top
, winwidth
- val
- rightoff
,
1101 glob
->fontheight
+ 6, NULL
, RED_ID
+ i
);
1103 glob
->colgad
[i
] = gad
= myCreateGadget (SLIDER_KIND
, gad
, &ng
,
1104 GTSL_LevelFormat
, (IPTR
) "%3ld",
1105 GTSL_LevelPlace
, PLACETEXT_LEFT
,
1106 GTSL_MaxLevelLen
, 3, GA_RelVerify
, TRUE
, GA_Immediate
, TRUE
,
1107 GTSL_Level
, glob
->cols
[i
],
1108 GTSL_Max
, glob
->maxcolval
[i
],
1109 ((GfxBase
->LibNode
.lib_Version
>= 40) ? GTSL_Justification
: TAG_IGNORE
), GTJ_RIGHT
,
1110 GTSL_MaxPixelLen
, levelwidth
,
1113 img
= my_CreateGadgetLabelImage (img
, &ng
, string
[i
],
1114 leftoff
+ wheeloff
+ 2, top
+ 2, HIGHLIGHTTEXTPEN
);
1115 top
+= glob
->fontheight
+ 6 + spacing
/ 2;
1120 ng
.ng_Flags
&= ~NG_HIGHLABEL
;
1126 int wheeltop
= top
- ( wheelheight
+ glob
->fontheight
+ 3 + spacing
* 2 );
1128 if( wheeltop
< wheeltopoff
)
1130 top
+= wheeltopoff
- wheeltop
;
1131 wheeltop
= wheeltopoff
;
1136 if( glob
->fancywheel
)
1139 glob
->numgradpens
= LOWGRADPENS
;
1141 if( glob
->scr
->ViewPort
.ColorMap
1142 && glob
->scr
->ViewPort
.ColorMap
->PalExtra
1143 && ( glob
->scr
->ViewPort
.ColorMap
->PalExtra
->pe_NFree
> FREEFORHIGH
) )
1145 glob
->numgradpens
= HIGHGRADPENS
;
1148 /* get the RGB components of active color */
1149 glob
->wheel_rgb
.cw_Red
= glob
->cols
[ RED_ID
];
1150 glob
->wheel_rgb
.cw_Green
= glob
->cols
[ GREEN_ID
];
1151 glob
->wheel_rgb
.cw_Blue
= glob
->cols
[ BLUE_ID
];
1153 /* now convert the RGB values to HSB, and max out B component */
1154 ConvertRGBToHSB( &glob
->wheel_rgb
, &glob
->wheel_hsb
);
1155 glob
->wheel_hsb
.cw_Brightness
= 0xffffffff;
1158 /* Set up colors for gradient slider */
1159 for( i
= 0; i
< glob
->numgradpens
; i
++ )
1161 glob
->wheel_hsb
.cw_Brightness
= 0xffffffff
1162 - ( ( 0xffffffff / ( glob
->numgradpens
- 1 ) ) * ( ULONG
) i
);
1163 ConvertHSBToRGB( &glob
->wheel_hsb
, &glob
->wheel_rgb
);
1164 glob
->wheel_pens
[ i
] = ObtainPen( glob
->scr
->ViewPort
.ColorMap
,
1165 -1, glob
->wheel_rgb
.cw_Red
, glob
->wheel_rgb
.cw_Green
,
1166 glob
->wheel_rgb
.cw_Blue
, PEN_EXCLUSIVE
);
1168 if( glob
->wheel_pens
[ i
] == (UWORD
)~0 )
1175 glob
->wheel_pens
[ i
] = ( UWORD
) ~0;
1177 if( i
!= glob
->numgradpens
)
1179 for( i
= 0; glob
->wheel_pens
[ i
] != (UWORD
)~0; i
++ )
1181 ReleasePen( glob
->scr
->ViewPort
.ColorMap
, glob
->wheel_pens
[ i
] );
1184 glob
->numgradpens
= 0;
1187 } /* if( glob->fancywheel ) */
1191 struct TagItem slider_tags
[] =
1193 {GA_ID
, SLIDER_ID
},
1194 {GA_Top
, wheeltop
+ wheelheight
+ spacing
},
1195 {GA_Left
, leftoff
},
1196 {GA_Width
, wheelwidth
},
1197 {GA_Height
, glob
->fontheight
+ 3 },
1199 {glob
->numgradpens
?
1201 TAG_IGNORE
, (IPTR
)glob
->wheel_pens
},
1203 {GRAD_KnobPixels
, 8 },
1204 {PGA_Freedom
, LORIENT_HORIZ
},
1205 {ICA_TARGET
, ICTARGET_IDCMP
},
1209 glob
->wheel_slider
= (struct Gadget
*)NewObjectA(NULL
, "gradientslider.gadget", slider_tags
);
1213 if( glob
->wheel_slider
)
1215 struct TagItem wheel_tags
[] =
1217 {GA_Top
, wheeltop
},
1218 {GA_Left
, leftoff
},
1219 {GA_Width
, wheelwidth
},
1220 {GA_Height
, wheelheight
},
1221 {GA_ID
, WHEEL_ID
},
1222 {WHEEL_Screen
, (IPTR
)glob
->scr
},
1225 WHEEL_MaxPens
, 0 },
1226 {WHEEL_GradientSlider
, (IPTR
)glob
->wheel_slider
},
1228 /* Need this, because without BevelBox AROS colorwheel gadget renders through mask
1229 which because of bugs in gfx library functions (!?) does not work yet and instead
1230 causes mem trashes/crashes/etc (in AmigaOS the AROS colorwheel gadget works fine
1231 even without BevelBox, that is: with mask rendering) */
1232 {WHEEL_BevelBox
, TRUE
},
1234 {GA_Previous
, (IPTR
)glob
->wheel_slider
},
1235 {ICA_TARGET
, ICTARGET_IDCMP
},
1239 glob
->wheel
= (struct Gadget
*)NewObjectA(NULL
, "colorwheel.gadget", wheel_tags
);
1243 } /* if( glob->dowheel )*/
1247 for (i
= 3; i
< 6; i
++)
1249 InitNewGadget (&ng
, gadpos
[i
], top
, gadlen
[i
],
1250 buttonheight
, string
[i
], COPY_ID
+ i
);
1252 gad
= my_CreateButtonGadget (gad
, '_', &ng
);
1255 top
+= buttonheight
+ spacing
;
1257 winheight
= top
+ glob
->scr
->WBorBottom
;
1258 glob
->newpalwin
.Height
= winheight
;
1259 glob
->newpalwin
.Width
= winwidth
;
1260 glob
->newpalwin
.IDCMPFlags
= glob
->shareidcmp
? 0 :
1261 SLIDERIDCMP
|PALETTEIDCMP
|BUTTONIDCMP
|IDCMP_CLOSEWINDOW
|IDCMP_RAWKEY
1262 |IDCMP_REFRESHWINDOW
|IDCMP_IDCMPUPDATE
;
1263 glob
->newpalwin
.Flags
= WFLG_DEPTHGADGET
|WFLG_DRAGBAR
|WFLG_ACTIVATE
1264 |WFLG_SIMPLE_REFRESH
|WFLG_RMBTRAP
|WFLG_CLOSEGADGET
;
1265 glob
->newpalwin
.DetailPen
= glob
->drinfo
->dri_Pens
[BACKGROUNDPEN
];
1266 glob
->newpalwin
.BlockPen
= glob
->drinfo
->dri_Pens
[SHADOWPEN
];
1267 glob
->newpalwin
.Title
= title
;
1268 glob
->newpalwin
.LeftEdge
= glob
->leftedge
;
1269 glob
->newpalwin
.TopEdge
= glob
->topedge
;
1271 reqpos
= CheckReqPos (glob
->reqpos
, RTPREF_PALETTEREQ
, &glob
->newpalwin
);
1273 if (reqpos
== REQPOS_POINTER
)
1275 glob
->newpalwin
.LeftEdge
= -winwidth
/ 2;
1276 glob
->newpalwin
.TopEdge
= -winheight
/ 2;
1279 rtSetReqPosition (reqpos
, &glob
->newpalwin
, glob
->scr
, glob
->prwin
);
1281 ng
.ng_LeftEdge
= ng
.ng_TopEdge
= ng
.ng_Width
= ng
.ng_Height
= 0;
1282 ng
.ng_GadgetText
= NULL
;
1283 gad
= myCreateGadget (GENERIC_KIND
, gad
, &ng
, TAG_END
);
1287 gad
->GadgetType
|= GTYP_BOOLGADGET
;
1288 gad
->Flags
|= GFLG_GADGIMAGE
|GFLG_GADGHNONE
;
1289 gad
->GadgetRender
= ( APTR
) glob
->labelimages
.NextImage
;
1293 glob
->zoom
[ 2 ] = glob
->newpalwin
.Width
;
1294 glob
->zoom
[ 3 ] = glob
->scr
->WBorTop
+ glob
->scr
->Font
->ta_YSize
+ 1;
1296 if( ( glob
->dowheel
&& !glob
->wheel
) || !img
|| !gad
||
1297 !(glob
->palwin
= OpenWindowBF( &glob
->newpalwin
,
1298 &glob
->backfillhook
, glob
->drinfo
->dri_Pens
, NULL
, glob
->zoom
, FALSE
) ) )
1300 my_FreeGadgets( glob
->buttoninfo
.glist
);
1301 glob
->buttoninfo
.glist
= NULL
;
1302 my_FreeLabelImages( &glob
->labelimages
);
1303 glob
->labelimages
.NextImage
= NULL
;
1304 DisposeObject( glob
->wheel
);
1306 DisposeObject( glob
->wheel_slider
);
1307 glob
->wheel_slider
= NULL
;
1311 glob
->buttoninfo
.win
= glob
->palwin
;
1313 if( glob
->shareidcmp
)
1315 glob
->palwin
->UserPort
= glob
->prwin
->UserPort
;
1316 ModifyIDCMP( glob
->palwin
,
1317 SLIDERIDCMP
| PALETTEIDCMP
| BUTTONIDCMP
| IDCMP_CLOSEWINDOW
|
1318 IDCMP_RAWKEY
| IDCMP_REFRESHWINDOW
| IDCMP_IDCMPUPDATE
);
1324 AddGList( glob
->palwin
, glob
->wheel_slider
, -1, -1, NULL
);
1325 RefreshGList( glob
->wheel_slider
, glob
->palwin
, NULL
, -1 );
1329 AddGList( glob
->palwin
, glob
->buttoninfo
.glist
, -1, -1, NULL
);
1330 RefreshGList( glob
->buttoninfo
.glist
, glob
->palwin
, NULL
, -1 );
1331 GT_RefreshWindow( glob
->palwin
, NULL
);
1332 UpdateWheel( glob
, glob
->cols
);
1337 /****************************************************************************************/