2 Copyright © 2002-2018, 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 /* private msg structure's passed to the hook functions */
46 struct MUIP_CANotifyMsg
48 STACKED
struct Coloradjust_DATA
*caData
;
51 struct MUIP_CASliderNotifyMsg
53 STACKED
struct Coloradjust_DATA
*caData
;
57 static void NotifyGun(Object
*obj
, struct Coloradjust_DATA
*data
, ULONG gun
)
59 static Tag guntotag
[3] = {
61 MUIA_Coloradjust_Green
,
65 struct TagItem tags
[] = {
67 {MUIA_Coloradjust_RGB
, 0},
71 tags
[0].ti_Tag
= guntotag
[gun
];
72 tags
[0].ti_Data
= data
->rgb
[gun
];
73 tags
[1].ti_Data
= (IPTR
) data
->rgb
;
75 CoerceMethod(OCLASS(obj
), obj
, OM_SET
, (IPTR
) tags
, TAG_DONE
);
78 static void NotifyAll(Object
*obj
, struct Coloradjust_DATA
*data
)
80 struct TagItem tags
[] = {
81 {MUIA_Coloradjust_Red
, 0},
82 {MUIA_Coloradjust_Green
, 0},
83 {MUIA_Coloradjust_Blue
, 0},
84 {MUIA_Coloradjust_RGB
, 0},
87 tags
[0].ti_Data
= data
->rgb
[0];
88 tags
[1].ti_Data
= data
->rgb
[1];
89 tags
[2].ti_Data
= data
->rgb
[2];
90 tags
[3].ti_Data
= (IPTR
) data
->rgb
;
92 CoerceMethod(OCLASS(obj
), obj
, OM_SET
, (IPTR
) tags
, TAG_DONE
);
95 static void SliderFunc(struct Hook
*hook
, Object
*obj
, struct MUIP_CASliderNotifyMsg
*msg
)
97 struct Coloradjust_DATA
*data
= msg
->caData
;
98 ULONG gun
= msg
->caGun
;
99 struct ColorWheelRGB cw
;
101 ULONG red
= XGET(data
->rslider
, MUIA_Numeric_Value
);
102 ULONG green
= XGET(data
->gslider
, MUIA_Numeric_Value
);
103 ULONG blue
= XGET(data
->bslider
, MUIA_Numeric_Value
);
105 cw
.cw_Red
= (red
<< 24) | (red
<< 16) | (red
<< 8) | red
;
106 cw
.cw_Green
= (green
<< 24) | (green
<< 16) | (green
<< 8) | green
;
107 cw
.cw_Blue
= (blue
<< 24) | (blue
<< 16) | (blue
<< 8) | blue
;
109 data
->rgb
[0] = cw
.cw_Red
;
110 data
->rgb
[1] = cw
.cw_Green
;
111 data
->rgb
[2] = cw
.cw_Blue
;
113 nnset(data
->colfield
, MUIA_Colorfield_RGB
, (IPTR
) data
->rgb
);
117 struct ColorWheelHSB hsb
;
119 ConvertRGBToHSB(&cw
, &hsb
);
120 nnset(data
->wheel
, WHEEL_HSB
, (IPTR
) & hsb
);
122 nnset(data
->grad
, GRAD_CurVal
, 0xFFFF - (hsb
.cw_Brightness
>> 16));
124 if (data
->gradpen
!= -1)
126 hsb
.cw_Brightness
= 0xFFFFFFFF;
127 ConvertHSBToRGB(&hsb
, &cw
);
129 SetRGB32(&_screen(obj
)->ViewPort
, data
->gradpen
, cw
.cw_Red
,
130 cw
.cw_Green
, cw
.cw_Blue
);
131 if ((data
->truecolor
) && (data
->grad
))
132 MUI_Redraw(data
->grad
, MADF_DRAWUPDATE
);
136 NotifyGun(obj
, data
, gun
);
139 static void WheelFunc(struct Hook
*hook
, Object
*obj
, struct MUIP_CANotifyMsg
*msg
)
141 struct Coloradjust_DATA
*data
= msg
->caData
;
142 struct ColorWheelHSB hsb
;
143 struct ColorWheelRGB cw
;
145 hsb
.cw_Hue
= XGET(data
->wheel
, WHEEL_Hue
);
146 hsb
.cw_Saturation
= XGET(data
->wheel
, WHEEL_Saturation
);
149 hsb
.cw_Brightness
= 0xFFFF - XGET(data
->grad
, GRAD_CurVal
);
150 hsb
.cw_Brightness
|= (hsb
.cw_Brightness
<< 16);
152 ConvertHSBToRGB(&hsb
, &cw
);
154 data
->rgb
[0] = cw
.cw_Red
;
155 data
->rgb
[1] = cw
.cw_Green
;
156 data
->rgb
[2] = cw
.cw_Blue
;
158 nnset(data
->rslider
, MUIA_Numeric_Value
, data
->rgb
[0] >> 24);
159 nnset(data
->gslider
, MUIA_Numeric_Value
, data
->rgb
[1] >> 24);
160 nnset(data
->bslider
, MUIA_Numeric_Value
, data
->rgb
[2] >> 24);
162 nnset(data
->colfield
, MUIA_Colorfield_RGB
, (IPTR
) data
->rgb
);
164 if (data
->gradpen
!= -1)
166 hsb
.cw_Brightness
= 0xFFFFFFFF;
167 ConvertHSBToRGB(&hsb
, &cw
);
169 SetRGB32(&_screen(obj
)->ViewPort
, data
->gradpen
, cw
.cw_Red
,
170 cw
.cw_Green
, cw
.cw_Blue
);
171 if ((data
->truecolor
) && (data
->grad
))
172 MUI_Redraw(data
->grad
, MADF_DRAWUPDATE
);
175 NotifyAll(obj
, data
);
178 static void GradFunc(struct Hook
*hook
, Object
*obj
, struct MUIP_CANotifyMsg
*msg
)
180 struct Coloradjust_DATA
*data
= msg
->caData
;
181 struct ColorWheelHSB hsb
;
182 struct ColorWheelRGB cw
;
186 bright
= XGET(data
->grad
, GRAD_CurVal
);
188 bright
= 0xFFFF - bright
;
189 bright
|= (bright
<< 16);
191 hsb
.cw_Hue
= XGET(data
->wheel
, WHEEL_Hue
);
192 hsb
.cw_Saturation
= XGET(data
->wheel
, WHEEL_Saturation
);
193 hsb
.cw_Brightness
= bright
;
195 ConvertHSBToRGB(&hsb
, &cw
);
197 data
->rgb
[0] = cw
.cw_Red
;
198 data
->rgb
[1] = cw
.cw_Green
;
199 data
->rgb
[2] = cw
.cw_Blue
;
201 nnset(data
->rslider
, MUIA_Numeric_Value
, data
->rgb
[0] >> 24);
202 nnset(data
->gslider
, MUIA_Numeric_Value
, data
->rgb
[1] >> 24);
203 nnset(data
->bslider
, MUIA_Numeric_Value
, data
->rgb
[2] >> 24);
205 nnset(data
->colfield
, MUIA_Colorfield_RGB
, (IPTR
) data
->rgb
);
207 NotifyAll(obj
, data
);
210 IPTR
Coloradjust__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
212 struct Coloradjust_DATA
*data
;
213 struct TagItem
*tags
;
215 struct Library
*colorwheelbase
, *gradientsliderbase
;
216 Object
*rslider
, *gslider
, *bslider
;
217 Object
*colfield
, *wheel
= NULL
, *grad
= NULL
;
220 colorwheelbase
= OpenLibrary("gadgets/colorwheel.gadget", 0);
221 gradientsliderbase
= OpenLibrary("gadgets/gradientslider.gadget", 0);
223 obj
= (Object
*) DoSuperNewTags
225 MUIA_Group_Columns
, 2,
226 MUIA_Group_VertSpacing
, 1,
227 Child
, (IPTR
) Label1("Red:"),
228 Child
, (IPTR
) (rslider
= (Object
*)SliderObject
,
229 MUIA_Group_Horiz
, TRUE
,
231 MUIA_Numeric_Max
, 255,
233 Child
, (IPTR
) Label1("Green:"),
234 Child
, (IPTR
) (gslider
= (Object
*)SliderObject
,
235 MUIA_Group_Horiz
, TRUE
,
237 MUIA_Numeric_Max
, 255,
239 Child
, (IPTR
) Label1("Blue:"),
240 Child
, (IPTR
) (bslider
= (Object
*)SliderObject
,
241 MUIA_Group_Horiz
, TRUE
,
243 MUIA_Numeric_Max
, 255,
245 Child
, (IPTR
) VSpace(1),
246 Child
, (IPTR
) VSpace(1),
247 Child
, (IPTR
) (colfield
= (Object
*) ColorfieldObject
,
251 Child
, (IPTR
) (HGroup
,
252 MUIA_Group_HorizSpacing
, 2,
253 (!colorwheelbase
) ? TAG_IGNORE
: Child
,
254 (IPTR
) (wheel
= (Object
*) BoopsiObject
,
255 MUIA_Boopsi_ClassID
, (IPTR
) "colorwheel.gadget",
256 MUIA_Boopsi_MinWidth
, 16,
257 MUIA_Boopsi_MinHeight
, 16,
258 MUIA_Boopsi_Remember
, WHEEL_Saturation
,
259 MUIA_Boopsi_Remember
, WHEEL_Hue
,
260 MUIA_Boopsi_TagScreen
, WHEEL_Screen
,
261 WHEEL_Screen
, (IPTR
) NULL
,
266 ICA_TARGET
, ICTARGET_IDCMP
,
269 (!gradientsliderbase
) ? TAG_IGNORE
: Child
,
270 (IPTR
) (grad
= (Object
*) BoopsiObject
,
271 MUIA_Boopsi_ClassID
, (IPTR
) "gradientslider.gadget",
272 MUIA_Boopsi_MinWidth
, 16,
273 MUIA_Boopsi_MinHeight
, 16,
274 MUIA_Boopsi_MaxWidth
, 16,
275 MUIA_Boopsi_Remember
, GRAD_CurVal
,
276 MUIA_Boopsi_Remember
, GRAD_PenArray
,
277 MUIA_Boopsi_Remember
, GRAD_KnobPixels
,
283 PGA_Freedom
, LORIENT_VERT
,
284 ICA_TARGET
, ICTARGET_IDCMP
,
287 (!colorwheelbase
&& !gradientsliderbase
) ? Child
: TAG_IGNORE
,
290 TAG_MORE
, (IPTR
) msg
->ops_AttrList
);
294 if (gradientsliderbase
)
295 CloseLibrary(gradientsliderbase
);
297 CloseLibrary(colorwheelbase
);
301 data
= INST_DATA(cl
, obj
);
303 data
->colorwheelbase
= colorwheelbase
;
304 data
->gradientsliderbase
= gradientsliderbase
;
305 if (!EXEC_INTERFACE_GET_MAIN(data
->icolorwheel
, data
->colorwheelbase
))
307 CoerceMethod(cl
, obj
, OM_DISPOSE
);
311 data
->sliderhook
.h_Entry
= HookEntry
;
312 data
->sliderhook
.h_SubEntry
= (HOOKFUNC
) SliderFunc
;
314 data
->wheelhook
.h_Entry
= HookEntry
;
315 data
->wheelhook
.h_SubEntry
= (HOOKFUNC
) WheelFunc
;
317 data
->gradhook
.h_Entry
= HookEntry
;
318 data
->gradhook
.h_SubEntry
= (HOOKFUNC
) GradFunc
;
320 data
->rslider
= rslider
;
321 data
->gslider
= gslider
;
322 data
->bslider
= bslider
;
323 data
->colfield
= colfield
;
327 data
->rgb
[0] = data
->rgb
[1] = data
->rgb
[2] = 0xFFFFFFFF;
329 /* parse initial taglist */
330 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
334 case MUIA_Coloradjust_Red
:
335 data
->rgb
[0] = (ULONG
) tag
->ti_Data
;
338 case MUIA_Coloradjust_Green
:
339 data
->rgb
[1] = (ULONG
) tag
->ti_Data
;
342 case MUIA_Coloradjust_Blue
:
343 data
->rgb
[2] = (ULONG
) tag
->ti_Data
;
346 case MUIA_Coloradjust_RGB
:
347 rgb
= (ULONG
*) tag
->ti_Data
;
348 data
->rgb
[0] = *rgb
++;
349 data
->rgb
[1] = *rgb
++;
350 data
->rgb
[2] = *rgb
++;
356 nnset(colfield
, MUIA_Colorfield_RGB
, (IPTR
) data
->rgb
);
357 nnset(rslider
, MUIA_Numeric_Value
, data
->rgb
[0] >> 24);
358 nnset(gslider
, MUIA_Numeric_Value
, data
->rgb
[1] >> 24);
359 nnset(bslider
, MUIA_Numeric_Value
, data
->rgb
[2] >> 24);
363 struct ColorWheelRGB cw
;
364 struct ColorWheelHSB hsb
;
366 cw
.cw_Red
= data
->rgb
[0];
367 cw
.cw_Green
= data
->rgb
[1];
368 cw
.cw_Blue
= data
->rgb
[2];
370 ConvertRGBToHSB(&cw
, &hsb
);
372 nnset(data
->wheel
, WHEEL_HSB
, (IPTR
) & hsb
);
373 /* just to be sure - colorwheel seems to have some problems */
374 nnset(data
->wheel
, WHEEL_Saturation
, hsb
.cw_Saturation
);
375 nnset(data
->wheel
, WHEEL_Hue
, hsb
.cw_Hue
);
378 nnset(data
->grad
, GRAD_CurVal
, 0xFFFF - (hsb
.cw_Brightness
>> 16));
379 nnset(data
->grad
, GRAD_PenArray
, (IPTR
) data
->gradpenarray
);
383 DoMethod(rslider
, MUIM_Notify
, MUIA_Numeric_Value
, MUIV_EveryTime
,
384 (IPTR
) obj
, 4, MUIM_CallHook
, (IPTR
) & data
->sliderhook
,
386 DoMethod(gslider
, MUIM_Notify
, MUIA_Numeric_Value
, MUIV_EveryTime
,
387 (IPTR
) obj
, 4, MUIM_CallHook
, (IPTR
) & data
->sliderhook
,
389 DoMethod(bslider
, MUIM_Notify
, MUIA_Numeric_Value
, MUIV_EveryTime
,
390 (IPTR
) obj
, 4, MUIM_CallHook
, (IPTR
) & data
->sliderhook
,
395 DoMethod(data
->wheel
, MUIM_Notify
, WHEEL_Hue
, MUIV_EveryTime
,
396 (IPTR
) obj
, 3, MUIM_CallHook
, (IPTR
) & data
->wheelhook
,
398 DoMethod(data
->wheel
, MUIM_Notify
, WHEEL_Saturation
, MUIV_EveryTime
,
399 (IPTR
) obj
, 3, MUIM_CallHook
, (IPTR
) & data
->wheelhook
,
404 DoMethod(data
->grad
, MUIM_Notify
, GRAD_CurVal
, MUIV_EveryTime
,
405 (IPTR
) obj
, 3, MUIM_CallHook
, (IPTR
) & data
->gradhook
,
411 IPTR
Coloradjust__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
413 struct Coloradjust_DATA
*data
;
414 struct Library
*colorwheelbase
;
415 struct Library
*gradientsliderbase
;
418 data
= INST_DATA(cl
, obj
);
420 EXEC_INTERFACE_DROP(data
->icolorwheel
);
421 colorwheelbase
= data
->colorwheelbase
;
422 gradientsliderbase
= data
->gradientsliderbase
;
424 retval
= DoSuperMethodA(cl
, obj
, msg
);
427 CloseLibrary(colorwheelbase
);
428 if (gradientsliderbase
)
429 CloseLibrary(gradientsliderbase
);
434 IPTR
Coloradjust__OM_SET(struct IClass
*cl
, Object
*obj
,
437 struct Coloradjust_DATA
*data
;
438 struct TagItem
*tags
;
443 data
= INST_DATA(cl
, obj
);
445 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
449 case MUIA_Coloradjust_Red
:
450 data
->rgb
[0] = (ULONG
) tag
->ti_Data
;
454 case MUIA_Coloradjust_Green
:
455 data
->rgb
[1] = (ULONG
) tag
->ti_Data
;
459 case MUIA_Coloradjust_Blue
:
460 data
->rgb
[2] = (ULONG
) tag
->ti_Data
;
464 case MUIA_Coloradjust_RGB
:
465 rgb
= (ULONG
*) tag
->ti_Data
;
466 data
->rgb
[0] = *rgb
++;
467 data
->rgb
[1] = *rgb
++;
468 data
->rgb
[2] = *rgb
++;
477 nnset(data
->rslider
, MUIA_Numeric_Value
, data
->rgb
[0] >> 24);
478 nnset(data
->gslider
, MUIA_Numeric_Value
, data
->rgb
[1] >> 24);
479 nnset(data
->bslider
, MUIA_Numeric_Value
, data
->rgb
[2] >> 24);
480 D(bug("coloradjust: sliders set to %ld, %ld, %ld\n",
481 data
->rgb
[0] >> 24, data
->rgb
[1] >> 24,
482 data
->rgb
[2] >> 24));
484 nnset(data
->colfield
, MUIA_Colorfield_RGB
, (IPTR
) data
->rgb
);
488 struct ColorWheelRGB cw
;
489 struct ColorWheelHSB hsb
;
491 cw
.cw_Red
= data
->rgb
[0];
492 cw
.cw_Green
= data
->rgb
[1];
493 cw
.cw_Blue
= data
->rgb
[2];
495 ConvertRGBToHSB(&cw
, &hsb
);
496 nnset(data
->wheel
, WHEEL_HSB
, (IPTR
) & hsb
);
497 nnset(data
->wheel
, WHEEL_Saturation
, hsb
.cw_Saturation
);
498 nnset(data
->wheel
, WHEEL_Hue
, hsb
.cw_Hue
);
500 nnset(data
->grad
, GRAD_CurVal
,
501 0xFFFF - (hsb
.cw_Brightness
>> 16));
503 if ((_flags(obj
) & MADF_SETUP
) && (data
->gradpen
!= -1))
505 hsb
.cw_Brightness
= 0xFFFFFFFF;
506 ConvertHSBToRGB(&hsb
, &cw
);
508 SetRGB32(&_screen(obj
)->ViewPort
, data
->gradpen
, cw
.cw_Red
,
509 cw
.cw_Green
, cw
.cw_Blue
);
510 if ((data
->truecolor
) && (data
->grad
))
512 MUI_Redraw(data
->grad
, MADF_DRAWOBJECT
);
518 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
521 IPTR
Coloradjust__OM_GET(struct IClass
*cl
, Object
*obj
,
524 struct Coloradjust_DATA
*data
= INST_DATA(cl
, obj
);
525 IPTR
*store
= msg
->opg_Storage
;
527 switch (msg
->opg_AttrID
)
529 case MUIA_Coloradjust_Red
:
530 *store
= data
->rgb
[0];
533 case MUIA_Coloradjust_Green
:
534 *store
= data
->rgb
[1];
537 case MUIA_Coloradjust_Blue
:
538 *store
= data
->rgb
[2];
541 case MUIA_Coloradjust_RGB
:
542 *(IPTR
*) store
= (IPTR
) & data
->rgb
[0];
546 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
549 IPTR
Coloradjust__MUIM_Setup(struct IClass
*cl
, Object
*obj
,
550 struct MUIP_Setup
*msg
)
552 struct Coloradjust_DATA
*data
= INST_DATA(cl
, obj
);
554 if (!(DoSuperMethodA(cl
, obj
, (Msg
) msg
)))
559 struct ColorWheelHSB hsb
;
560 struct ColorWheelRGB rgb
;
562 rgb
.cw_Red
= data
->rgb
[0];
563 rgb
.cw_Green
= data
->rgb
[1];
564 rgb
.cw_Blue
= data
->rgb
[2];
566 data
->gradpenarray
[0] = _pens(obj
)[MPEN_SHINE
];
567 data
->gradpenarray
[1] = _pens(obj
)[MPEN_SHADOW
];
568 data
->gradpenarray
[2] = (UWORD
) ~ 0;
570 data
->gradpen
= ObtainPen(_screen(obj
)->ViewPort
.ColorMap
,
572 rgb
.cw_Red
, rgb
.cw_Green
, rgb
.cw_Blue
, PENF_EXCLUSIVE
);
574 if (data
->gradpen
!= -1)
576 data
->gradpenarray
[0] = data
->gradpen
;
579 ConvertRGBToHSB(&rgb
, &hsb
);
580 /* setting this will force wheel to properly set its display */
581 nnset(data
->wheel
, WHEEL_Saturation
, hsb
.cw_Saturation
);
582 nnset(data
->wheel
, WHEEL_Hue
, hsb
.cw_Hue
);
584 hsb
.cw_Brightness
= 0xFFFFFFFF;
585 ConvertHSBToRGB(&hsb
, &rgb
);
587 if (data
->gradpen
!= -1)
589 SetRGB32(&_screen(obj
)->ViewPort
, data
->gradpen
, rgb
.cw_Red
,
590 rgb
.cw_Green
, rgb
.cw_Blue
);
594 GetBitMapAttr(_screen(obj
)->RastPort
.BitMap
, BMA_DEPTH
) >= 15;
600 IPTR
Coloradjust__MUIM_Cleanup(struct IClass
*cl
, Object
*obj
,
601 struct MUIP_Cleanup
*msg
)
603 struct Coloradjust_DATA
*data
= INST_DATA(cl
, obj
);
605 if (data
->gradpen
!= -1)
607 ReleasePen(_screen(obj
)->ViewPort
.ColorMap
, data
->gradpen
);
611 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
614 #if ZUNE_BUILTIN_COLORADJUST
615 BOOPSI_DISPATCHER(IPTR
, Coloradjust_Dispatcher
, cl
, obj
, msg
)
617 switch (msg
->MethodID
)
620 return Coloradjust__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
622 return Coloradjust__OM_DISPOSE(cl
, obj
, msg
);
624 return Coloradjust__OM_SET(cl
, obj
, (struct opSet
*)msg
);
626 return Coloradjust__OM_GET(cl
, obj
, (struct opGet
*)msg
);
628 return Coloradjust__MUIM_Setup(cl
, obj
, (struct MUIP_Setup
*)msg
);
630 return Coloradjust__MUIM_Cleanup(cl
, obj
,
631 (struct MUIP_Cleanup
*)msg
);
633 return DoSuperMethodA(cl
, obj
, msg
);
636 BOOPSI_DISPATCHER_END
638 const struct __MUIBuiltinClass _MUI_Coloradjust_desc
=
642 sizeof(struct Coloradjust_DATA
),
643 (void *) Coloradjust_Dispatcher
645 #endif /* ZUNE_BUILTIN_COLORADJUST */