2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
10 #include <graphics/gfx.h>
11 #include <graphics/view.h>
12 #include <graphics/gfxmacros.h>
13 #include <intuition/gadgetclass.h>
14 #include <gadgets/colorwheel.h>
15 #include <gadgets/gradientslider.h>
16 #include <intuition/icclass.h>
17 #include <clib/alib_protos.h>
18 #include <proto/exec.h>
19 #include <proto/graphics.h>
20 #include <proto/utility.h>
21 #include <proto/intuition.h>
22 #include <proto/colorwheel.h>
23 #include <proto/muimaster.h>
28 #include "muimaster_intern.h"
30 #include "support_classes.h"
31 #include "coloradjust_private.h"
33 /* #define MYDEBUG 1 */
36 extern struct Library
*MUIMasterBase
;
38 #define FLAG_FIXED_PEN 1
39 #define FLAG_PEN_ALLOCATED 2
42 #define ColorWheelBase data->colorwheelbase
43 #define IColorWheel data->icolorwheel
45 static void NotifyGun(Object
*obj
, struct Coloradjust_DATA
*data
, LONG gun
)
47 static Tag guntotag
[3] = {
49 MUIA_Coloradjust_Green
,
53 struct TagItem tags
[] = {
55 {MUIA_Coloradjust_RGB
, 0},
59 tags
[0].ti_Tag
= guntotag
[gun
];
60 tags
[0].ti_Data
= data
->rgb
[gun
];
61 tags
[1].ti_Data
= (IPTR
) data
->rgb
;
63 CoerceMethod(data
->notifyclass
, obj
, OM_SET
, (IPTR
) tags
, NULL
);
66 static void NotifyAll(Object
*obj
, struct Coloradjust_DATA
*data
)
68 struct TagItem tags
[] = {
69 {MUIA_Coloradjust_Red
, 0},
70 {MUIA_Coloradjust_Green
, 0},
71 {MUIA_Coloradjust_Blue
, 0},
72 {MUIA_Coloradjust_RGB
, 0},
75 tags
[0].ti_Data
= data
->rgb
[0];
76 tags
[1].ti_Data
= data
->rgb
[1];
77 tags
[2].ti_Data
= data
->rgb
[2];
78 tags
[3].ti_Data
= (IPTR
) data
->rgb
;
79 CoerceMethod(data
->notifyclass
, obj
, OM_SET
, (IPTR
) tags
, NULL
);
82 static void SliderFunc(struct Hook
*hook
, Object
*obj
, APTR msg
)
84 struct ColorWheelRGB cw
;
85 struct Coloradjust_DATA
*data
= *(struct Coloradjust_DATA
**)msg
;
86 IPTR gun
= ((IPTR
*) msg
)[1];
88 ULONG red
= XGET(data
->rslider
, MUIA_Numeric_Value
);
89 ULONG green
= XGET(data
->gslider
, MUIA_Numeric_Value
);
90 ULONG blue
= XGET(data
->bslider
, MUIA_Numeric_Value
);
92 cw
.cw_Red
= (red
<< 24) | (red
<< 16) | (red
<< 8) | red
;
93 cw
.cw_Green
= (green
<< 24) | (green
<< 16) | (green
<< 8) | green
;
94 cw
.cw_Blue
= (blue
<< 24) | (blue
<< 16) | (blue
<< 8) | blue
;
96 data
->rgb
[0] = cw
.cw_Red
;
97 data
->rgb
[1] = cw
.cw_Green
;
98 data
->rgb
[2] = cw
.cw_Blue
;
100 nnset(data
->colfield
, MUIA_Colorfield_RGB
, (IPTR
) data
->rgb
);
104 struct ColorWheelHSB hsb
;
106 ConvertRGBToHSB(&cw
, &hsb
);
107 nnset(data
->wheel
, WHEEL_HSB
, (IPTR
) & hsb
);
108 nnset(data
->grad
, GRAD_CurVal
, 0xFFFF - (hsb
.cw_Brightness
>> 16));
110 if (data
->gradpen
!= -1)
112 hsb
.cw_Brightness
= 0xFFFFFFFF;
113 ConvertHSBToRGB(&hsb
, &cw
);
115 SetRGB32(&_screen(obj
)->ViewPort
, data
->gradpen
, cw
.cw_Red
,
116 cw
.cw_Green
, cw
.cw_Blue
);
118 MUI_Redraw(data
->grad
, MADF_DRAWUPDATE
);
122 NotifyGun(obj
, data
, gun
);
125 static void WheelFunc(struct Hook
*hook
, Object
*obj
, APTR msg
)
127 struct Coloradjust_DATA
*data
= *(struct Coloradjust_DATA
**)msg
;
128 struct ColorWheelHSB hsb
;
129 struct ColorWheelRGB cw
;
131 hsb
.cw_Hue
= XGET(data
->wheel
, WHEEL_Hue
);
132 hsb
.cw_Saturation
= XGET(data
->wheel
, WHEEL_Saturation
);
133 hsb
.cw_Brightness
= 0xFFFF - XGET(data
->grad
, GRAD_CurVal
);
134 hsb
.cw_Brightness
|= (hsb
.cw_Brightness
<< 16);
136 ConvertHSBToRGB(&hsb
, &cw
);
138 data
->rgb
[0] = cw
.cw_Red
;
139 data
->rgb
[1] = cw
.cw_Green
;
140 data
->rgb
[2] = cw
.cw_Blue
;
142 nnset(data
->rslider
, MUIA_Numeric_Value
, data
->rgb
[0] >> 24);
143 nnset(data
->gslider
, MUIA_Numeric_Value
, data
->rgb
[1] >> 24);
144 nnset(data
->bslider
, MUIA_Numeric_Value
, data
->rgb
[2] >> 24);
146 nnset(data
->colfield
, MUIA_Colorfield_RGB
, (IPTR
) data
->rgb
);
148 if (data
->gradpen
!= -1)
150 hsb
.cw_Brightness
= 0xFFFFFFFF;
151 ConvertHSBToRGB(&hsb
, &cw
);
153 SetRGB32(&_screen(obj
)->ViewPort
, data
->gradpen
, cw
.cw_Red
,
154 cw
.cw_Green
, cw
.cw_Blue
);
156 MUI_Redraw(data
->grad
, MADF_DRAWUPDATE
);
159 NotifyAll(obj
, data
);
162 static void GradFunc(struct Hook
*hook
, Object
*obj
, APTR msg
)
164 struct Coloradjust_DATA
*data
= *(struct Coloradjust_DATA
**)msg
;
165 struct ColorWheelHSB hsb
;
166 struct ColorWheelRGB cw
;
168 ULONG bright
= XGET(data
->grad
, GRAD_CurVal
);
170 bright
= 0xFFFF - bright
;
171 bright
|= (bright
<< 16);
173 hsb
.cw_Hue
= XGET(data
->wheel
, WHEEL_Hue
);
174 hsb
.cw_Saturation
= XGET(data
->wheel
, WHEEL_Saturation
);
175 hsb
.cw_Brightness
= bright
;
177 ConvertHSBToRGB(&hsb
, &cw
);
179 data
->rgb
[0] = cw
.cw_Red
;
180 data
->rgb
[1] = cw
.cw_Green
;
181 data
->rgb
[2] = cw
.cw_Blue
;
183 nnset(data
->rslider
, MUIA_Numeric_Value
, data
->rgb
[0] >> 24);
184 nnset(data
->gslider
, MUIA_Numeric_Value
, data
->rgb
[1] >> 24);
185 nnset(data
->bslider
, MUIA_Numeric_Value
, data
->rgb
[2] >> 24);
187 nnset(data
->colfield
, MUIA_Colorfield_RGB
, (IPTR
) data
->rgb
);
189 NotifyAll(obj
, data
);
193 IPTR
Coloradjust__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
195 struct Coloradjust_DATA
*data
;
196 struct TagItem
*tags
;
198 struct Library
*colorwheelbase
, *gradientsliderbase
;
199 Object
*rslider
, *gslider
, *bslider
;
200 Object
*colfield
, *wheel
= NULL
, *grad
= NULL
;
203 colorwheelbase
= OpenLibrary("gadgets/colorwheel.gadget", 0);
204 gradientsliderbase
= OpenLibrary("gadgets/gradientslider.gadget", 0);
206 obj
= (Object
*) DoSuperNewTags
208 MUIA_Group_Columns
, 2,
209 MUIA_Group_VertSpacing
, 1,
210 Child
, (IPTR
) Label1("Red:"),
211 Child
, (IPTR
) (rslider
=
212 (Object
*) (SliderObject
, MUIA_Group_Horiz
, TRUE
,
213 MUIA_Numeric_Min
, 0, MUIA_Numeric_Max
, 255, End
)), Child
,
214 (IPTR
) Label1("Green:"), Child
, (IPTR
) (gslider
=
215 (Object
*) (SliderObject
, MUIA_Group_Horiz
, TRUE
,
216 MUIA_Numeric_Min
, 0, MUIA_Numeric_Max
, 255, End
)), Child
,
217 (IPTR
) Label1("Blue:"), Child
, (IPTR
) (bslider
=
218 (Object
*) (SliderObject
, MUIA_Group_Horiz
, TRUE
,
219 MUIA_Numeric_Min
, 0, MUIA_Numeric_Max
, 255, End
)), Child
,
220 (IPTR
) VSpace(1), Child
, (IPTR
) VSpace(1), Child
, (IPTR
) (colfield
=
221 (Object
*) (ColorfieldObject
, TextFrame
, MUIA_Weight
, 0, End
)),
222 Child
, (!colorwheelbase
223 || !gradientsliderbase
) ? (IPTR
) HVSpace
: (IPTR
) HGroup
,
224 /* FIXME: this looks severely broken if the HVSpace path is taken... */
225 MUIA_Group_HorizSpacing
, 2,
226 Child
, (IPTR
) (wheel
= (Object
*) BoopsiObject
,
227 MUIA_Boopsi_ClassID
, (IPTR
) "colorwheel.gadget",
228 MUIA_Boopsi_MinWidth
, 16,
229 MUIA_Boopsi_MinHeight
, 16,
230 MUIA_Boopsi_Remember
, WHEEL_Saturation
,
231 MUIA_Boopsi_Remember
, WHEEL_Hue
,
232 MUIA_Boopsi_TagScreen
, WHEEL_Screen
,
233 WHEEL_Screen
, (IPTR
) NULL
,
238 ICA_TARGET
, ICTARGET_IDCMP
,
241 Child
, (IPTR
) (grad
= (Object
*) BoopsiObject
,
242 MUIA_Boopsi_ClassID
, (IPTR
) "gradientslider.gadget",
243 MUIA_Boopsi_MinWidth
, 16,
244 MUIA_Boopsi_MinHeight
, 16,
245 MUIA_Boopsi_MaxWidth
, 16,
246 MUIA_Boopsi_Remember
, GRAD_CurVal
,
247 MUIA_Boopsi_Remember
, GRAD_PenArray
,
248 MUIA_Boopsi_Remember
, GRAD_KnobPixels
,
254 PGA_Freedom
, LORIENT_VERT
,
255 ICA_TARGET
, ICTARGET_IDCMP
,
257 End
), End
, TAG_MORE
, (IPTR
) msg
->ops_AttrList
);
261 CloseLibrary(gradientsliderbase
);
262 CloseLibrary(colorwheelbase
);
266 data
= INST_DATA(cl
, obj
);
268 data
->colorwheelbase
= colorwheelbase
;
269 data
->gradientsliderbase
= gradientsliderbase
;
270 if (!EXEC_INTERFACE_GET_MAIN(data
->icolorwheel
, data
->colorwheelbase
))
272 CoerceMethod(cl
, obj
, OM_DISPOSE
);
275 data
->notifyclass
= cl
->cl_Super
->cl_Super
;
277 data
->sliderhook
.h_Entry
= HookEntry
;
278 data
->sliderhook
.h_SubEntry
= (HOOKFUNC
) SliderFunc
;
280 data
->wheelhook
.h_Entry
= HookEntry
;
281 data
->wheelhook
.h_SubEntry
= (HOOKFUNC
) WheelFunc
;
283 data
->gradhook
.h_Entry
= HookEntry
;
284 data
->gradhook
.h_SubEntry
= (HOOKFUNC
) GradFunc
;
286 data
->rslider
= rslider
;
287 data
->gslider
= gslider
;
288 data
->bslider
= bslider
;
289 data
->colfield
= colfield
;
293 data
->rgb
[0] = data
->rgb
[1] = data
->rgb
[2] = 0xFFFFFFFF;
295 /* parse initial taglist */
296 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
300 case MUIA_Coloradjust_Red
:
301 data
->rgb
[0] = (ULONG
) tag
->ti_Data
;
304 case MUIA_Coloradjust_Green
:
305 data
->rgb
[1] = (ULONG
) tag
->ti_Data
;
308 case MUIA_Coloradjust_Blue
:
309 data
->rgb
[2] = (ULONG
) tag
->ti_Data
;
312 case MUIA_Coloradjust_RGB
:
313 rgb
= (ULONG
*) tag
->ti_Data
;
314 data
->rgb
[0] = *rgb
++;
315 data
->rgb
[1] = *rgb
++;
316 data
->rgb
[2] = *rgb
++;
322 nnset(colfield
, MUIA_Colorfield_RGB
, (IPTR
) data
->rgb
);
323 nnset(rslider
, MUIA_Numeric_Value
, data
->rgb
[0] >> 24);
324 nnset(gslider
, MUIA_Numeric_Value
, data
->rgb
[1] >> 24);
325 nnset(bslider
, MUIA_Numeric_Value
, data
->rgb
[2] >> 24);
329 struct ColorWheelRGB cw
;
330 struct ColorWheelHSB hsb
;
332 cw
.cw_Red
= data
->rgb
[0];
333 cw
.cw_Green
= data
->rgb
[1];
334 cw
.cw_Blue
= data
->rgb
[2];
336 ConvertRGBToHSB(&cw
, &hsb
);
338 nnset(wheel
, WHEEL_HSB
, (IPTR
) & hsb
);
339 /* just to be sure - colorwheel seems to have some problems */
340 nnset(wheel
, WHEEL_Saturation
, hsb
.cw_Saturation
);
341 nnset(wheel
, WHEEL_Hue
, hsb
.cw_Hue
);
342 nnset(data
->grad
, GRAD_CurVal
, 0xFFFF - (hsb
.cw_Brightness
>> 16));
343 nnset(data
->grad
, GRAD_PenArray
, (IPTR
) data
->gradpenarray
);
346 DoMethod(rslider
, MUIM_Notify
, MUIA_Numeric_Value
, MUIV_EveryTime
,
347 (IPTR
) obj
, 4, MUIM_CallHook
, (IPTR
) & data
->sliderhook
,
349 DoMethod(gslider
, MUIM_Notify
, MUIA_Numeric_Value
, MUIV_EveryTime
,
350 (IPTR
) obj
, 4, MUIM_CallHook
, (IPTR
) & data
->sliderhook
,
352 DoMethod(bslider
, MUIM_Notify
, MUIA_Numeric_Value
, MUIV_EveryTime
,
353 (IPTR
) obj
, 4, MUIM_CallHook
, (IPTR
) & data
->sliderhook
,
358 DoMethod(wheel
, MUIM_Notify
, WHEEL_Hue
, MUIV_EveryTime
, (IPTR
) obj
,
359 3, MUIM_CallHook
, (IPTR
) & data
->wheelhook
, (IPTR
) data
);
360 DoMethod(wheel
, MUIM_Notify
, WHEEL_Saturation
, MUIV_EveryTime
,
361 (IPTR
) obj
, 3, MUIM_CallHook
, (IPTR
) & data
->wheelhook
,
363 DoMethod(grad
, MUIM_Notify
, GRAD_CurVal
, MUIV_EveryTime
, (IPTR
) obj
,
364 3, MUIM_CallHook
, (IPTR
) & data
->gradhook
, (IPTR
) data
);
370 IPTR
Coloradjust__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
372 struct Coloradjust_DATA
*data
;
373 struct Library
*colorwheelbase
;
374 struct Library
*gradientsliderbase
;
377 data
= INST_DATA(cl
, obj
);
379 EXEC_INTERFACE_DROP(data
->icolorwheel
);
380 colorwheelbase
= data
->colorwheelbase
;
381 gradientsliderbase
= data
->gradientsliderbase
;
383 retval
= DoSuperMethodA(cl
, obj
, msg
);
386 CloseLibrary(colorwheelbase
);
387 if (gradientsliderbase
)
388 CloseLibrary(gradientsliderbase
);
393 IPTR
Coloradjust__OM_SET(struct IClass
*cl
, Object
*obj
,
396 struct Coloradjust_DATA
*data
;
397 struct TagItem
*tags
;
402 data
= INST_DATA(cl
, obj
);
404 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
408 case MUIA_Coloradjust_Red
:
409 data
->rgb
[0] = (ULONG
) tag
->ti_Data
;
413 case MUIA_Coloradjust_Green
:
414 data
->rgb
[1] = (ULONG
) tag
->ti_Data
;
418 case MUIA_Coloradjust_Blue
:
419 data
->rgb
[2] = (ULONG
) tag
->ti_Data
;
423 case MUIA_Coloradjust_RGB
:
424 rgb
= (ULONG
*) tag
->ti_Data
;
425 data
->rgb
[0] = *rgb
++;
426 data
->rgb
[1] = *rgb
++;
427 data
->rgb
[2] = *rgb
++;
436 nnset(data
->rslider
, MUIA_Numeric_Value
, data
->rgb
[0] >> 24);
437 nnset(data
->gslider
, MUIA_Numeric_Value
, data
->rgb
[1] >> 24);
438 nnset(data
->bslider
, MUIA_Numeric_Value
, data
->rgb
[2] >> 24);
439 D(bug("coloradjust: sliders set to %ld, %ld, %ld\n",
440 data
->rgb
[0] >> 24, data
->rgb
[1] >> 24,
441 data
->rgb
[2] >> 24));
443 nnset(data
->colfield
, MUIA_Colorfield_RGB
, (IPTR
) data
->rgb
);
447 struct ColorWheelRGB cw
;
448 struct ColorWheelHSB hsb
;
450 cw
.cw_Red
= data
->rgb
[0];
451 cw
.cw_Green
= data
->rgb
[1];
452 cw
.cw_Blue
= data
->rgb
[2];
454 ConvertRGBToHSB(&cw
, &hsb
);
455 nnset(data
->wheel
, WHEEL_HSB
, (IPTR
) & hsb
);
456 nnset(data
->wheel
, WHEEL_Saturation
, hsb
.cw_Saturation
);
457 nnset(data
->wheel
, WHEEL_Hue
, hsb
.cw_Hue
);
458 nnset(data
->grad
, GRAD_CurVal
,
459 0xFFFF - (hsb
.cw_Brightness
>> 16));
461 if ((_flags(obj
) & MADF_SETUP
) && (data
->gradpen
!= -1))
463 hsb
.cw_Brightness
= 0xFFFFFFFF;
464 ConvertHSBToRGB(&hsb
, &cw
);
466 SetRGB32(&_screen(obj
)->ViewPort
, data
->gradpen
, cw
.cw_Red
,
467 cw
.cw_Green
, cw
.cw_Blue
);
470 MUI_Redraw(data
->grad
, MADF_DRAWOBJECT
);
477 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
480 IPTR
Coloradjust__OM_GET(struct IClass
*cl
, Object
*obj
,
483 struct Coloradjust_DATA
*data
= INST_DATA(cl
, obj
);
484 IPTR
*store
= msg
->opg_Storage
;
486 switch (msg
->opg_AttrID
)
488 case MUIA_Coloradjust_Red
:
489 *store
= data
->rgb
[0];
492 case MUIA_Coloradjust_Green
:
493 *store
= data
->rgb
[1];
496 case MUIA_Coloradjust_Blue
:
497 *store
= data
->rgb
[2];
500 case MUIA_Coloradjust_RGB
:
501 *(IPTR
*) store
= (IPTR
) & data
->rgb
[0];
505 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
508 IPTR
Coloradjust__MUIM_Setup(struct IClass
*cl
, Object
*obj
,
509 struct MUIP_Setup
*msg
)
511 struct Coloradjust_DATA
*data
= INST_DATA(cl
, obj
);
513 if (!(DoSuperMethodA(cl
, obj
, (Msg
) msg
)))
518 struct ColorWheelHSB hsb
;
519 struct ColorWheelRGB rgb
;
521 rgb
.cw_Red
= data
->rgb
[0];
522 rgb
.cw_Green
= data
->rgb
[1];
523 rgb
.cw_Blue
= data
->rgb
[2];
525 data
->gradpenarray
[0] = _pens(obj
)[MPEN_SHINE
];
526 data
->gradpenarray
[1] = _pens(obj
)[MPEN_SHADOW
];
527 data
->gradpenarray
[2] = (UWORD
) ~ 0;
529 data
->gradpen
= ObtainPen(_screen(obj
)->ViewPort
.ColorMap
,
531 rgb
.cw_Red
, rgb
.cw_Green
, rgb
.cw_Blue
, PENF_EXCLUSIVE
);
533 if (data
->gradpen
!= -1)
535 data
->gradpenarray
[0] = data
->gradpen
;
538 ConvertRGBToHSB(&rgb
, &hsb
);
539 /* setting this will force wheel to properly set its display */
540 nnset(data
->wheel
, WHEEL_Saturation
, hsb
.cw_Saturation
);
541 nnset(data
->wheel
, WHEEL_Hue
, hsb
.cw_Hue
);
543 hsb
.cw_Brightness
= 0xFFFFFFFF;
544 ConvertHSBToRGB(&hsb
, &rgb
);
546 if (data
->gradpen
!= -1)
548 SetRGB32(&_screen(obj
)->ViewPort
, data
->gradpen
, rgb
.cw_Red
,
549 rgb
.cw_Green
, rgb
.cw_Blue
);
553 GetBitMapAttr(_screen(obj
)->RastPort
.BitMap
, BMA_DEPTH
) >= 15;
559 IPTR
Coloradjust__MUIM_Cleanup(struct IClass
*cl
, Object
*obj
,
560 struct MUIP_Cleanup
*msg
)
562 struct Coloradjust_DATA
*data
= INST_DATA(cl
, obj
);
564 if (data
->gradpen
!= -1)
566 ReleasePen(_screen(obj
)->ViewPort
.ColorMap
, data
->gradpen
);
570 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
573 #if ZUNE_BUILTIN_COLORADJUST
574 BOOPSI_DISPATCHER(IPTR
, Coloradjust_Dispatcher
, cl
, obj
, msg
)
576 switch (msg
->MethodID
)
579 return Coloradjust__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
581 return Coloradjust__OM_DISPOSE(cl
, obj
, msg
);
583 return Coloradjust__OM_SET(cl
, obj
, (struct opSet
*)msg
);
585 return Coloradjust__OM_GET(cl
, obj
, (struct opGet
*)msg
);
587 return Coloradjust__MUIM_Setup(cl
, obj
, (struct MUIP_Setup
*)msg
);
589 return Coloradjust__MUIM_Cleanup(cl
, obj
,
590 (struct MUIP_Cleanup
*)msg
);
592 return DoSuperMethodA(cl
, obj
, msg
);
595 BOOPSI_DISPATCHER_END
597 const struct __MUIBuiltinClass _MUI_Coloradjust_desc
=
601 sizeof(struct Coloradjust_DATA
),
602 (void *) Coloradjust_Dispatcher
604 #endif /* ZUNE_BUILTIN_COLORADJUST */