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
;
307 const struct TagItem
*tstate
= taglist
;
308 struct TextFont
*deffont
= NULL
;
309 struct TextAttr
*fontattr
= NULL
;
310 struct Locale
*locale
= NULL
;
311 char *pubname
= NULL
;
312 ULONG tagdata
, 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
;
404 #warning DisplayInfo.Resolution does not seem to have correct/any values yet in AROS
405 glob
->screenres
.x
= glob
->screenres
.y
= 22;
407 glob
->screenres
= displayinfo
.Resolution
;
414 glob
->maxcolval
[RED_ID
] = (1 << glob
->redbits
) - 1;
415 glob
->maxcolval
[GREEN_ID
] = (1 << glob
->greenbits
) - 1;
416 glob
->maxcolval
[BLUE_ID
] = (1 << glob
->bluebits
) - 1;
418 if (!(glob
->visinfo
= GetVisualInfoA (glob
->scr
, NULL
)) ||
419 !(glob
->drinfo
= GetScreenDrawInfo (glob
->scr
)))
427 struct ReqToolsPrefs
*prefs
;
429 prefs
= rtLockPrefs();
430 glob
->dowheel
= ( prefs
->Flags
& RTPRF_DOWHEEL
) && glob
->os30
;
431 glob
->fancywheel
= glob
->dowheel
&& ( prefs
->Flags
& RTPRF_FANCYWHEEL
);
437 if ((ColorWheelBase
= OpenLibrary ("gadgets/colorwheel.gadget", 39)))
439 GradientSliderBase
= OpenLibrary ("gadgets/gradientslider.gadget", 39);
444 SelectColor (glob
, glob
->color
);
447 if (!(glob
->reqfont
= GetReqFont (&glob
->font
, deffont
, &glob
->fontheight
,
448 &glob
->fontwidth
, glob
->os30
)))
454 if (!SetupPalWindow (glob
, title
))
458 glob
->dowheel
= FALSE
;
460 DisposeObject( glob
->wheel
);
461 DisposeObject( glob
->wheel_slider
);
463 glob
->wheel_slider
= NULL
;
464 CloseLibrary( ColorWheelBase
);
465 CloseLibrary( GradientSliderBase
);
466 ColorWheelBase
= NULL
;
467 GradientSliderBase
= NULL
;
472 if (glob
->font
.ta_YSize
> 8)
474 glob
->font
= topaz80
;
475 CloseFont (glob
->reqfont
);
484 if( glob
->fancywheel
)
486 /* Try to get a fresh undo color map (in case the wheel allocates some) */
487 RefreshVpCM( glob
->vp
, glob
->undomap
);
489 /* And make sure selected color still is correct */
490 SelectColor( glob
, glob
->color
);
494 glob
->winlock
= DoLockWindow (glob
->prwin
, glob
->lockwindow
, NULL
, TRUE
);
495 DoWaitPointer (glob
->prwin
, glob
->waitpointer
, TRUE
);
497 glob
->frontscr
= IntuitionBase
->FirstScreen
;
498 DoScreenToFront (glob
->scr
, glob
->noscreenpop
, TRUE
);
500 /* fill in RealHandlerInfo */
501 glob
->func
= (LONG (*)())PalReqHandler
;
502 glob
->rthi_WaitMask
= (1 << glob
->palwin
->UserPort
->mp_SigBit
);
504 if (reqhandler
) return (CALL_HANDLER
);
506 return ((LONG
)LoopReqHandler ((struct rtHandlerInfo
*)glob
));
509 /****************************************************************************************/
511 static LONG ASM SAVEDS
PalReqHandler (
512 REGPARAM(a1
, struct RealHandlerInfo
*, glob
),
513 REGPARAM(d0
, ULONG
, sigs
),
514 REGPARAM(a0
, struct TagItem
*, taglist
))
516 struct IntuiMessage
*palmsg
;
519 const struct TagItem
*tstate
= taglist
;
520 ULONG rgb
[3], rgbcol
;
521 ULONG tagdata
, class;
523 int i
, gadid
, shifted
, alt
;
526 /* uncomment if sigs is no longer ignored */
527 //if (glob->rthi_DoNotWait) sigs = 0;
530 while ((tag
= NextTagItem (&tstate
)))
532 tagdata
= tag
->ti_Data
;
533 if (tag
->ti_Tag
> RT_TagBase
)
537 case RTRH_EndRequest
:
538 if (tagdata
== REQ_OK
)
543 RestorePaletteFreeAll (glob
);
549 while ((palmsg
= GetWin_GT_Msg (glob
->palwin
, glob
->imsghook
, glob
->reqinfo
)))
551 class = palmsg
->Class
;
553 qual
= palmsg
->Qualifier
;
554 gad
= (struct Gadget
*)palmsg
->IAddress
;
555 Reply_GT_Msg (palmsg
);
559 case IDCMP_REFRESHWINDOW
:
560 GT_BeginRefresh (glob
->palwin
);
561 GT_EndRefresh (glob
->palwin
, TRUE
);
564 case IDCMP_CLOSEWINDOW
:
565 RestorePaletteFreeAll (glob
);
568 case IDCMP_MOUSEMOVE
:
569 case IDCMP_GADGETDOWN
:
570 if (gad
->GadgetID
<= BLUE_ID
)
572 glob
->cols
[gad
->GadgetID
] = code
;
573 SetColor (glob
, glob
->color
, glob
->cols
);
575 UpdateWheel( glob
, glob
->cols
);
582 if (class == IDCMP_RAWKEY
)
584 if (!(gadid
= CheckGadgetKey (code
, qual
, &key
, &glob
->buttoninfo
)))
586 /* key press was not for gadget, so check other cases */
587 shifted
= qual
& (IEQUALIFIER_LSHIFT
|IEQUALIFIER_RSHIFT
);
588 alt
= qual
& (IEQUALIFIER_LALT
|IEQUALIFIER_RALT
);
589 if (key
== glob
->key
[RED_ID
])
590 DoColorShortcut (glob
, RED_ID
, shifted
, alt
);
591 else if (key
== glob
->key
[GREEN_ID
])
592 DoColorShortcut (glob
, GREEN_ID
, shifted
, alt
);
593 else if (key
== glob
->key
[BLUE_ID
])
594 DoColorShortcut (glob
, BLUE_ID
, shifted
, alt
);
595 else if (key
== glob
->palettekey
)
601 if (code
>= glob
->colcount
) code
= 0;
605 if (code
<= 0) code
= glob
->colcount
;
608 myGT_SetGadgetAttrs (glob
->palgad
, glob
->palwin
, NULL
,
609 GTPA_Color
, code
, TAG_END
);
616 } /* if (class == IDCMP_RAWKEY) */
617 else gadid
= gad
->GadgetID
;
619 if (gadid
) switch (gadid
)
622 RestorePaletteFreeAll (glob
);
631 RefreshVpCM (glob
->vp
, glob
->undomap
);
635 rgbcol
= GetRGB4 (glob
->cm
, code
);
636 for (i
= 2; i
>= 0; i
--)
638 rgb
[i
] = rgbcol
& 0xf;
644 GetRGB32 (glob
->cm
, code
, 1, rgb
);
645 rgb
[0] >>= (32 - glob
->redbits
);
646 rgb
[1] >>= (32 - glob
->greenbits
);
647 rgb
[2] >>= (32 - glob
->bluebits
);
653 SetColor (glob
, glob
->color
, rgb
);
655 SetColor (glob
, code
, glob
->cols
);
658 SpreadColors (glob
, glob
->color
, code
, rgb
);
662 SelectColor (glob
, code
);
664 SetWindowTitles( glob
->palwin
, glob
->newpalwin
.Title
, NO_TITLE
);
666 UpdateWheel( glob
, glob
->cols
);
671 LoadCMap (glob
->vp
, glob
->undomap
);
672 SelectColor (glob
, glob
->color
);
674 UpdateWheel( glob
, glob
->cols
);
679 if( ( gadid
== SWAP_ID
) || ( gadid
== COPY_ID
) || ( gadid
== SPREAD_ID
) )
682 SetWindowTitles( glob
->palwin
, GetStr( glob
->catalog
, ModeTitles
[ gadid
- MODE_TITLE_OFFSET
] ), NO_TITLE
);
687 } /* if (gadid) switch (gadid) */
691 case IDCMP_IDCMPUPDATE
:
692 SetWheelColor( glob
, ( struct TagItem
* ) gad
);
697 } /* while ((palmsg = GetWin_GT_Msg (glob->palwin, glob->imsghook, glob->reqinfo))) */
699 return (CALL_HANDLER
);
702 /****************************************************************************************/
704 static void REGARGS
DoColorShortcut (GlobData
*glob
, int id
, int shifted
, int alt
)
706 int t
= glob
->cols
[id
];
710 if (alt
) t
-= 8; else t
--;
715 if (alt
) t
+= 8; else t
++;
716 if (t
>= glob
->maxcolval
[id
]) t
= glob
->maxcolval
[id
];
720 SetColor (glob
, glob
->color
, glob
->cols
);
721 SelectColor (glob
, glob
->color
);
724 /****************************************************************************************/
726 static void REGARGS
SetColor (GlobData
*glob
, int col
, ULONG
*rgb
)
730 SetRGB4( glob
->vp
, col
, rgb
[ 0 ], rgb
[ 1 ], rgb
[ 2 ] );
734 SetRGB32( glob
->vp
, col
,
735 MakeColVal( rgb
[ 0 ], glob
->redbits
),
736 MakeColVal( rgb
[ 1 ], glob
->greenbits
),
737 MakeColVal( rgb
[ 2 ], glob
->bluebits
) );
741 /****************************************************************************************/
745 /****************************************************************************************/
749 /****************************************************************************************/
752 UpdateGrad( GlobData
*glob
)
754 if( glob
->numgradpens
)
758 GetAttr( WHEEL_HSB
, (Object
*)glob
->wheel
, ( IPTR
* ) &glob
->wheel_hsb
);
760 for( i
= 0; i
< glob
->numgradpens
; ++i
)
762 glob
->wheel_hsb
.cw_Brightness
= 0xffffffff - ( ( 0xffffffff / ( glob
->numgradpens
- 1 ) ) * i
);
763 ConvertHSBToRGB( &glob
->wheel_hsb
, &glob
->wheel_rgb
);
764 SetRGB32( &glob
->scr
->ViewPort
, glob
->wheel_pens
[ i
],
765 glob
->wheel_rgb
.cw_Red
, glob
->wheel_rgb
.cw_Green
,
766 glob
->wheel_rgb
.cw_Blue
);
771 /****************************************************************************************/
775 /****************************************************************************************/
778 UpdateWheel( GlobData
*glob
, ULONG
*cols
)
782 glob
->wheel_rgb
.cw_Red
= MakeColVal( cols
[ 0 ], glob
->redbits
);
783 glob
->wheel_rgb
.cw_Green
= MakeColVal( cols
[ 1 ], glob
->greenbits
);
784 glob
->wheel_rgb
.cw_Blue
= MakeColVal( cols
[ 2 ], glob
->bluebits
);
786 SetGadgetAttrs( glob
->wheel
, glob
->palwin
, NULL
, WHEEL_RGB
, (IPTR
) &glob
->wheel_rgb
,
795 /****************************************************************************************/
798 SetWheelColor( GlobData
*glob
, struct TagItem
*tag
)
804 GetAttr( WHEEL_HSB
, (Object
*)glob
->wheel
, ( IPTR
* ) &glob
->wheel_hsb
);
805 ConvertHSBToRGB( &glob
->wheel_hsb
, &glob
->wheel_rgb
);
806 glob
->cols
[ RED_ID
] = glob
->wheel_rgb
.cw_Red
>> ( 32 - glob
->redbits
);
807 glob
->cols
[ GREEN_ID
] = glob
->wheel_rgb
.cw_Green
>> ( 32 - glob
->greenbits
);
808 glob
->cols
[ BLUE_ID
] = glob
->wheel_rgb
.cw_Blue
>> ( 32 - glob
->bluebits
);
809 SetColor( glob
, glob
->color
, glob
->cols
);
811 for( i
= 0; i
< 3; ++i
)
813 if( glob
->colgad
[ i
] )
815 myGT_SetGadgetAttrs( glob
->colgad
[ i
], glob
->palwin
, NULL
, GTSL_Level
, glob
->cols
[ i
],
826 /****************************************************************************************/
830 /****************************************************************************************/
832 static void REGARGS
SelectColor (GlobData
*glob
, int col
)
834 ULONG rgb
[3], rgbcol
= 0;
837 if (!glob
->os30
) rgbcol
= GetRGB4 (glob
->cm
, col
);
838 else GetRGB32 (glob
->cm
, col
, 1, rgb
);
840 for (i
= 2; i
>= 0; i
--)
844 glob
->cols
[i
] = rgbcol
& 0xF;
847 else glob
->cols
[i
] = rgb
[i
] >> (32 - glob
->col
.colbits
[i
]);
850 myGT_SetGadgetAttrs (glob
->colgad
[i
], glob
->palwin
, NULL
,
851 GTSL_Level
, glob
->cols
[i
], TAG_END
);
857 /****************************************************************************************/
859 static void REGARGS
RestorePaletteFreeAll (GlobData
*glob
)
861 LoadCMap (glob
->vp
, glob
->colormap
);
865 /****************************************************************************************/
867 static void REGARGS
FreeAll (GlobData
*glob
)
874 if (glob
->newpalwin
.Type
== PUBLICSCREEN
) UnlockPubScreen (NULL
, glob
->scr
);
875 DoScreenToFront (glob
->frontscr
, glob
->noscreenpop
, FALSE
);
879 DoLockWindow (glob
->prwin
, glob
->lockwindow
, glob
->winlock
, FALSE
);
880 DoWaitPointer (glob
->prwin
, glob
->waitpointer
, FALSE
);
881 DoCloseWindow (glob
->palwin
, glob
->shareidcmp
);
884 RT_CloseCatalog (glob
->catalog
);
885 my_FreeGadgets (glob
->buttoninfo
.glist
);
886 my_FreeLabelImages (&glob
->labelimages
);
889 DisposeObject (glob
->wheel
);
890 DisposeObject (glob
->wheel_slider
);
893 if( glob
->numgradpens
)
895 for( i
= 0; glob
->wheel_pens
[ i
] != (UWORD
)~0; i
++ )
897 ReleasePen( glob
->scr
->ViewPort
.ColorMap
, glob
->wheel_pens
[ i
] );
902 CloseLibrary (GradientSliderBase
);
903 CloseLibrary (ColorWheelBase
);
906 FreeVisualInfo (glob
->visinfo
);
908 if (glob
->drinfo
) FreeScreenDrawInfo (glob
->scr
, glob
->drinfo
);
909 if (glob
->reqfont
) CloseFont (glob
->reqfont
);
911 FreeVpCM (glob
->vp
, glob
->colormap
, FALSE
);
912 FreeVpCM (glob
->vp
, glob
->undomap
, FALSE
);
916 /****************************************************************************************/
918 char *colstr
[] = { MSG_RED
, MSG_GREEN
, MSG_BLUE
};
919 char *gadtxt
[] = { MSG_COPY
, MSG_SWAP
, MSG_SPREAD
, MSG_OK
, MSG_UNDO
, MSG_CANCEL
};
921 /****************************************************************************************/
923 static int REGARGS
SetupPalWindow (GlobData
*glob
, char *title
)
928 int val
, i
, top
, buttonheight
, winheight
;
929 int spacing
, scrwidth
, scrheight
, maxwidth
;
930 int winwidth
, width1
, width2
, reqpos
, levelwidth
;
932 int wheelwidth
= 0, wheelheight
= 0, wheeltopoff
;
935 int leftoff
, rightoff
;
936 ULONG gadlen
[6], gadpos
[6];
937 char *str
, *string
[6];
940 spacing
= rtGetVScreenSize (glob
->scr
, (ULONG
*)&scrwidth
, (ULONG
*)&scrheight
);
941 leftoff
= glob
->scr
->WBorLeft
+ 5;
942 rightoff
= glob
->scr
->WBorRight
+ 5;
944 top
= (glob
->scr
->WBorTop
+ glob
->scr
->Font
->ta_YSize
+ 1) + spacing
/ 2 + 1;
945 glob
->itxt
.ITextFont
= &glob
->font
;
953 for (i
= 0; i
< 6; i
++)
955 string
[i
] = GetStr (glob
->catalog
, gadtxt
[i
]);
956 val
= StrWidth_noloc (&glob
->itxt
, string
[i
]) + 16;
959 if (val
> width1
) width1
= val
;
963 if (val
> width2
) width2
= val
;
967 for (i
= 0; i
< 3; i
++) gadlen
[i
] = width1
;
968 for (i
= 3; i
< 6; i
++) gadlen
[i
] = width2
;
973 winwidth
= (leftoff
+ rightoff
) + 25 + width1
+ 2 * 8;
974 val
= (leftoff
+ rightoff
) + width2
+ 2 * 8;
975 if (val
> winwidth
) winwidth
= val
;
976 if (winwidth
< 256) winwidth
= 256;
978 val
= glob
->fontheight
* 2 + 4;
983 if (glob
->colcount
>= 64) val
*= 2;
984 if (glob
->colcount
>= 128) val
*= 2;
988 if( glob
->dowheel
&& glob
->screenres
.x
&& glob
->screenres
.y
&& ColorWheelBase
&& GradientSliderBase
)
990 LONG maxheight
= 120;
992 if( scrheight
> 600 )
996 else if( scrheight
< 300 )
1001 wheelheight
= val
+ glob
->fontheight
* 4 + 6 + 3 + spacing
* 3;
1003 if( wheelheight
> maxheight
)
1005 wheelheight
= maxheight
;
1009 #warning Changed, because gcc produced wrong code! gcc 2.95.1 compiled under UAE JIT for Linux!?
1010 wheelwidth
= glob
->screenres
.y
;
1011 wheelwidth
*= wheelheight
;
1012 wheelwidth
/= glob
->screenres
.x
;
1014 wheelwidth
= wheelheight
* glob
->screenres
.y
/ glob
->screenres
.x
;
1017 if( ( scrwidth
- winwidth
> wheelwidth
+ 8 ) &&
1018 ( scrheight
> 200 ) )
1020 wheeloff
= wheelwidth
+ 8;
1021 winwidth
+= wheeloff
;
1025 glob
->dowheel
= FALSE
;
1028 } /* if( glob->dowheel && glob->screenres.x && glob->screenres.y && ColorWheelBase && GradientSliderBase ) */
1031 glob
->dowheel
= FALSE
;
1036 rtSpread (gadpos
, gadlen
, width1
, leftoff
+ wheeloff
+ 25, winwidth
- rightoff
, 3);
1037 rtSpread (gadpos
+ 3, gadlen
+ 3, width2
, leftoff
, winwidth
- rightoff
, 3);
1040 gad
= (struct Gadget
*)CreateContext (&glob
->buttoninfo
.glist
);
1041 img
= &glob
->labelimages
;
1043 ng
.ng_VisualInfo
= glob
->visinfo
;
1044 ng
.ng_TextAttr
= &glob
->font
;
1046 str
= GetStr (glob
->catalog
, MSG_PALETTE_COLORS
);
1047 glob
->palettekey
= KeyFromStr (str
, '_');
1049 i
= leftoff
+ 25 + ( winwidth
- ( leftoff
+ rightoff
+ 25 ) -
1050 StrWidth_noloc( &glob
->itxt
, str
) ) / 2;
1059 img
= my_CreateGadgetLabelImage (img
, &ng
, str
, i
, top
, HIGHLIGHTTEXTPEN
);
1060 top
+= glob
->fontheight
+ 1 + spacing
/ 2;
1062 InitNewGadget (&ng
, leftoff
+ wheeloff
+ 25, top
, winwidth
- ( wheeloff
+ leftoff
+ rightoff
+ 25),
1063 val
, NULL
, PALETTE_ID
);
1065 gad
= glob
->palgad
= myCreateGadget (PALETTE_KIND
, gad
, &ng
,
1066 GTPA_Depth
, (IPTR
)glob
->coldepth
,
1067 GTPA_IndicatorWidth
, 38,
1068 GTPA_Color
, (IPTR
)glob
->color
, TAG_END
);
1070 if (glob
->os30
) top
+= gad
->Height
+ spacing
;
1071 else top
+= val
+ spacing
;
1073 buttonheight
= glob
->fontheight
+ 6;
1075 for (i
= 0; i
< 3; i
++)
1077 InitNewGadget (&ng
, gadpos
[i
], top
, gadlen
[i
],
1078 buttonheight
, string
[i
], COPY_ID
+ i
);
1080 gad
= my_CreateButtonGadget (gad
, '_', &ng
);
1083 top
+= buttonheight
+ spacing
;
1085 ng
.ng_Flags
|= NG_HIGHLABEL
;
1089 for (i
= 0; i
< 3; i
++)
1091 string
[i
] = GetStr (glob
->catalog
, colstr
[i
]);
1092 glob
->key
[i
] = KeyFromStr (string
[i
], '_');
1093 val
= StrWidth_noloc (&glob
->itxt
, string
[i
]);
1094 if (val
> maxwidth
) maxwidth
= val
;
1097 levelwidth
= StrWidth_noloc (&glob
->itxt
, "000 ");
1098 maxwidth
+= levelwidth
;
1101 for (i
= 0; i
< 3; i
++)
1104 val
= leftoff
+ wheeloff
+ 2 + maxwidth
+ 8;
1105 InitNewGadget (&ng
, val
, top
, winwidth
- val
- rightoff
,
1106 glob
->fontheight
+ 6, NULL
, RED_ID
+ i
);
1108 glob
->colgad
[i
] = gad
= myCreateGadget (SLIDER_KIND
, gad
, &ng
,
1109 GTSL_LevelFormat
, (IPTR
) "%3ld",
1110 GTSL_LevelPlace
, PLACETEXT_LEFT
,
1111 GTSL_MaxLevelLen
, 3, GA_RelVerify
, TRUE
, GA_Immediate
, TRUE
,
1112 GTSL_Level
, glob
->cols
[i
],
1113 GTSL_Max
, glob
->maxcolval
[i
],
1114 ((GfxBase
->LibNode
.lib_Version
>= 40) ? GTSL_Justification
: TAG_IGNORE
), GTJ_RIGHT
,
1115 GTSL_MaxPixelLen
, levelwidth
,
1118 img
= my_CreateGadgetLabelImage (img
, &ng
, string
[i
],
1119 leftoff
+ wheeloff
+ 2, top
+ 2, HIGHLIGHTTEXTPEN
);
1120 top
+= glob
->fontheight
+ 6 + spacing
/ 2;
1125 ng
.ng_Flags
&= ~NG_HIGHLABEL
;
1131 int wheeltop
= top
- ( wheelheight
+ glob
->fontheight
+ 3 + spacing
* 2 );
1133 if( wheeltop
< wheeltopoff
)
1135 top
+= wheeltopoff
- wheeltop
;
1136 wheeltop
= wheeltopoff
;
1141 if( glob
->fancywheel
)
1144 glob
->numgradpens
= LOWGRADPENS
;
1146 if( glob
->scr
->ViewPort
.ColorMap
1147 && glob
->scr
->ViewPort
.ColorMap
->PalExtra
1148 && ( glob
->scr
->ViewPort
.ColorMap
->PalExtra
->pe_NFree
> FREEFORHIGH
) )
1150 glob
->numgradpens
= HIGHGRADPENS
;
1153 /* get the RGB components of active color */
1154 glob
->wheel_rgb
.cw_Red
= glob
->cols
[ RED_ID
];
1155 glob
->wheel_rgb
.cw_Green
= glob
->cols
[ GREEN_ID
];
1156 glob
->wheel_rgb
.cw_Blue
= glob
->cols
[ BLUE_ID
];
1158 /* now convert the RGB values to HSB, and max out B component */
1159 ConvertRGBToHSB( &glob
->wheel_rgb
, &glob
->wheel_hsb
);
1160 glob
->wheel_hsb
.cw_Brightness
= 0xffffffff;
1163 /* Set up colors for gradient slider */
1164 for( i
= 0; i
< glob
->numgradpens
; i
++ )
1166 glob
->wheel_hsb
.cw_Brightness
= 0xffffffff
1167 - ( ( 0xffffffff / ( glob
->numgradpens
- 1 ) ) * ( ULONG
) i
);
1168 ConvertHSBToRGB( &glob
->wheel_hsb
, &glob
->wheel_rgb
);
1169 glob
->wheel_pens
[ i
] = ObtainPen( glob
->scr
->ViewPort
.ColorMap
,
1170 -1, glob
->wheel_rgb
.cw_Red
, glob
->wheel_rgb
.cw_Green
,
1171 glob
->wheel_rgb
.cw_Blue
, PEN_EXCLUSIVE
);
1173 if( glob
->wheel_pens
[ i
] == (UWORD
)~0 )
1180 glob
->wheel_pens
[ i
] = ( UWORD
) ~0;
1182 if( i
!= glob
->numgradpens
)
1184 for( i
= 0; glob
->wheel_pens
[ i
] != (UWORD
)~0; i
++ )
1186 ReleasePen( glob
->scr
->ViewPort
.ColorMap
, glob
->wheel_pens
[ i
] );
1189 glob
->numgradpens
= 0;
1192 } /* if( glob->fancywheel ) */
1196 struct TagItem slider_tags
[] =
1198 {GA_ID
, SLIDER_ID
},
1199 {GA_Top
, wheeltop
+ wheelheight
+ spacing
},
1200 {GA_Left
, leftoff
},
1201 {GA_Width
, wheelwidth
},
1202 {GA_Height
, glob
->fontheight
+ 3 },
1204 {glob
->numgradpens
?
1206 TAG_IGNORE
, (IPTR
)glob
->wheel_pens
},
1208 {GRAD_KnobPixels
, 8 },
1209 {PGA_Freedom
, LORIENT_HORIZ
},
1210 {ICA_TARGET
, ICTARGET_IDCMP
},
1214 glob
->wheel_slider
= (struct Gadget
*)NewObjectA(NULL
, "gradientslider.gadget", slider_tags
);
1218 if( glob
->wheel_slider
)
1220 struct TagItem wheel_tags
[] =
1222 {GA_Top
, wheeltop
},
1223 {GA_Left
, leftoff
},
1224 {GA_Width
, wheelwidth
},
1225 {GA_Height
, wheelheight
},
1226 {GA_ID
, WHEEL_ID
},
1227 {WHEEL_Screen
, (IPTR
)glob
->scr
},
1230 WHEEL_MaxPens
, 0 },
1231 {WHEEL_GradientSlider
, (IPTR
)glob
->wheel_slider
},
1233 /* Need this, because without BevelBox AROS colorwheel gadget renders through mask
1234 which because of bugs in gfx library functions (!?) does not work yet and instead
1235 causes mem trashes/crashes/etc (in AmigaOS the AROS colorwheel gadget works fine
1236 even without BevelBox, that is: with mask rendering) */
1237 {WHEEL_BevelBox
, TRUE
},
1239 {GA_Previous
, (IPTR
)glob
->wheel_slider
},
1240 {ICA_TARGET
, ICTARGET_IDCMP
},
1244 glob
->wheel
= (struct Gadget
*)NewObjectA(NULL
, "colorwheel.gadget", wheel_tags
);
1248 } /* if( glob->dowheel )*/
1252 for (i
= 3; i
< 6; i
++)
1254 InitNewGadget (&ng
, gadpos
[i
], top
, gadlen
[i
],
1255 buttonheight
, string
[i
], COPY_ID
+ i
);
1257 gad
= my_CreateButtonGadget (gad
, '_', &ng
);
1260 top
+= buttonheight
+ spacing
;
1262 winheight
= top
+ glob
->scr
->WBorBottom
;
1263 glob
->newpalwin
.Height
= winheight
;
1264 glob
->newpalwin
.Width
= winwidth
;
1265 glob
->newpalwin
.IDCMPFlags
= glob
->shareidcmp
? 0 :
1266 SLIDERIDCMP
|PALETTEIDCMP
|BUTTONIDCMP
|IDCMP_CLOSEWINDOW
|IDCMP_RAWKEY
1267 |IDCMP_REFRESHWINDOW
|IDCMP_IDCMPUPDATE
;
1268 glob
->newpalwin
.Flags
= WFLG_DEPTHGADGET
|WFLG_DRAGBAR
|WFLG_ACTIVATE
1269 |WFLG_SIMPLE_REFRESH
|WFLG_RMBTRAP
|WFLG_CLOSEGADGET
;
1270 glob
->newpalwin
.DetailPen
= glob
->drinfo
->dri_Pens
[BACKGROUNDPEN
];
1271 glob
->newpalwin
.BlockPen
= glob
->drinfo
->dri_Pens
[SHADOWPEN
];
1272 glob
->newpalwin
.Title
= title
;
1273 glob
->newpalwin
.LeftEdge
= glob
->leftedge
;
1274 glob
->newpalwin
.TopEdge
= glob
->topedge
;
1276 reqpos
= CheckReqPos (glob
->reqpos
, RTPREF_PALETTEREQ
, &glob
->newpalwin
);
1278 if (reqpos
== REQPOS_POINTER
)
1280 glob
->newpalwin
.LeftEdge
= -winwidth
/ 2;
1281 glob
->newpalwin
.TopEdge
= -winheight
/ 2;
1284 rtSetReqPosition (reqpos
, &glob
->newpalwin
, glob
->scr
, glob
->prwin
);
1286 ng
.ng_LeftEdge
= ng
.ng_TopEdge
= ng
.ng_Width
= ng
.ng_Height
= 0;
1287 ng
.ng_GadgetText
= NULL
;
1288 gad
= myCreateGadget (GENERIC_KIND
, gad
, &ng
, TAG_END
);
1292 gad
->GadgetType
|= GTYP_BOOLGADGET
;
1293 gad
->Flags
|= GFLG_GADGIMAGE
|GFLG_GADGHNONE
;
1294 gad
->GadgetRender
= ( APTR
) glob
->labelimages
.NextImage
;
1298 glob
->zoom
[ 2 ] = glob
->newpalwin
.Width
;
1299 glob
->zoom
[ 3 ] = glob
->scr
->WBorTop
+ glob
->scr
->Font
->ta_YSize
+ 1;
1301 if( ( glob
->dowheel
&& !glob
->wheel
) || !img
|| !gad
||
1302 !(glob
->palwin
= OpenWindowBF( &glob
->newpalwin
,
1303 &glob
->backfillhook
, glob
->drinfo
->dri_Pens
, NULL
, glob
->zoom
, FALSE
) ) )
1305 my_FreeGadgets( glob
->buttoninfo
.glist
);
1306 glob
->buttoninfo
.glist
= NULL
;
1307 my_FreeLabelImages( &glob
->labelimages
);
1308 glob
->labelimages
.NextImage
= NULL
;
1309 DisposeObject( glob
->wheel
);
1311 DisposeObject( glob
->wheel_slider
);
1312 glob
->wheel_slider
= NULL
;
1316 glob
->buttoninfo
.win
= glob
->palwin
;
1318 if( glob
->shareidcmp
)
1320 glob
->palwin
->UserPort
= glob
->prwin
->UserPort
;
1321 ModifyIDCMP( glob
->palwin
,
1322 SLIDERIDCMP
| PALETTEIDCMP
| BUTTONIDCMP
| IDCMP_CLOSEWINDOW
|
1323 IDCMP_RAWKEY
| IDCMP_REFRESHWINDOW
| IDCMP_IDCMPUPDATE
);
1329 AddGList( glob
->palwin
, glob
->wheel_slider
, -1, -1, NULL
);
1330 RefreshGList( glob
->wheel_slider
, glob
->palwin
, NULL
, -1 );
1334 AddGList( glob
->palwin
, glob
->buttoninfo
.glist
, -1, -1, NULL
);
1335 RefreshGList( glob
->buttoninfo
.glist
, glob
->palwin
, NULL
, -1 );
1336 GT_RefreshWindow( glob
->palwin
, NULL
);
1337 UpdateWheel( glob
, glob
->cols
);
1342 /****************************************************************************************/