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] =
50 MUIA_Coloradjust_Green
,
54 struct TagItem tags
[] =
57 {MUIA_Coloradjust_RGB
, 0},
61 tags
[0].ti_Tag
= guntotag
[gun
];
62 tags
[0].ti_Data
= data
->rgb
[gun
];
63 tags
[1].ti_Data
= (IPTR
)data
->rgb
;
65 CoerceMethod(data
->notifyclass
, obj
, OM_SET
, (IPTR
)tags
, NULL
);
68 static void NotifyAll(Object
*obj
, struct Coloradjust_DATA
*data
)
70 struct TagItem tags
[] =
72 {MUIA_Coloradjust_Red
, 0 },
73 {MUIA_Coloradjust_Green
, 0 },
74 {MUIA_Coloradjust_Blue
, 0 },
75 {MUIA_Coloradjust_RGB
, 0 },
78 tags
[0].ti_Data
= data
->rgb
[0];
79 tags
[1].ti_Data
= data
->rgb
[1];
80 tags
[2].ti_Data
= data
->rgb
[2];
81 tags
[3].ti_Data
= (IPTR
)data
->rgb
;
82 CoerceMethod(data
->notifyclass
, obj
, OM_SET
, (IPTR
)tags
, NULL
);
85 static void SliderFunc(struct Hook
*hook
, Object
*obj
, APTR msg
)
87 struct ColorWheelRGB cw
;
88 struct Coloradjust_DATA
*data
= *(struct Coloradjust_DATA
**)msg
;
89 IPTR gun
= ((IPTR
*)msg
)[1];
91 ULONG red
= XGET(data
->rslider
,MUIA_Numeric_Value
);
92 ULONG green
= XGET(data
->gslider
,MUIA_Numeric_Value
);
93 ULONG blue
= XGET(data
->bslider
,MUIA_Numeric_Value
);
95 cw
.cw_Red
= (red
<<24)|(red
<<16)|(red
<<8)|red
;
96 cw
.cw_Green
= (green
<<24)|(green
<<16)|(green
<<8)|green
;
97 cw
.cw_Blue
= (blue
<<24)|(blue
<<16)|(blue
<<8)|blue
;
99 data
->rgb
[0] = cw
.cw_Red
;
100 data
->rgb
[1] = cw
.cw_Green
;
101 data
->rgb
[2] = cw
.cw_Blue
;
103 nnset(data
->colfield
, MUIA_Colorfield_RGB
, (IPTR
)data
->rgb
);
107 struct ColorWheelHSB hsb
;
109 ConvertRGBToHSB(&cw
, &hsb
);
110 nnset(data
->wheel
, WHEEL_HSB
, (IPTR
)&hsb
);
111 nnset(data
->grad
, GRAD_CurVal
, 0xFFFF - (hsb
.cw_Brightness
>> 16));
113 if (data
->gradpen
!= -1)
115 hsb
.cw_Brightness
= 0xFFFFFFFF;
116 ConvertHSBToRGB(&hsb
, &cw
);
118 SetRGB32(&_screen(obj
)->ViewPort
, data
->gradpen
, cw
.cw_Red
, cw
.cw_Green
, cw
.cw_Blue
);
119 if (data
->truecolor
) MUI_Redraw(data
->grad
, MADF_DRAWUPDATE
);
123 NotifyGun(obj
, data
, gun
);
126 static void WheelFunc(struct Hook
*hook
, Object
*obj
, APTR msg
)
128 struct Coloradjust_DATA
*data
= *(struct Coloradjust_DATA
**)msg
;
129 struct ColorWheelHSB hsb
;
130 struct ColorWheelRGB cw
;
132 hsb
.cw_Hue
= XGET(data
->wheel
, WHEEL_Hue
);
133 hsb
.cw_Saturation
= XGET(data
->wheel
, WHEEL_Saturation
);
134 hsb
.cw_Brightness
= 0xFFFF - XGET(data
->grad
, GRAD_CurVal
);
135 hsb
.cw_Brightness
|= (hsb
.cw_Brightness
<< 16) ;
137 ConvertHSBToRGB(&hsb
, &cw
);
139 data
->rgb
[0] = cw
.cw_Red
;
140 data
->rgb
[1] = cw
.cw_Green
;
141 data
->rgb
[2] = cw
.cw_Blue
;
143 nnset(data
->rslider
, MUIA_Numeric_Value
, data
->rgb
[0] >> 24);
144 nnset(data
->gslider
, MUIA_Numeric_Value
, data
->rgb
[1] >> 24);
145 nnset(data
->bslider
, MUIA_Numeric_Value
, data
->rgb
[2] >> 24);
147 nnset(data
->colfield
, MUIA_Colorfield_RGB
, (IPTR
)data
->rgb
);
149 if (data
->gradpen
!= -1)
151 hsb
.cw_Brightness
= 0xFFFFFFFF;
152 ConvertHSBToRGB(&hsb
, &cw
);
154 SetRGB32(&_screen(obj
)->ViewPort
, data
->gradpen
, cw
.cw_Red
, cw
.cw_Green
, cw
.cw_Blue
);
155 if (data
->truecolor
) MUI_Redraw(data
->grad
, MADF_DRAWUPDATE
);
158 NotifyAll(obj
, data
);
161 static void GradFunc(struct Hook
*hook
, Object
*obj
, APTR msg
)
163 struct Coloradjust_DATA
*data
= *(struct Coloradjust_DATA
**)msg
;
164 struct ColorWheelHSB hsb
;
165 struct ColorWheelRGB cw
;
167 ULONG bright
= XGET(data
->grad
, GRAD_CurVal
);
169 bright
= 0xFFFF - bright
;
170 bright
|= (bright
<< 16);
172 hsb
.cw_Hue
= XGET(data
->wheel
, WHEEL_Hue
);
173 hsb
.cw_Saturation
= XGET(data
->wheel
, WHEEL_Saturation
);
174 hsb
.cw_Brightness
= bright
;
176 ConvertHSBToRGB(&hsb
, &cw
);
178 data
->rgb
[0] = cw
.cw_Red
;
179 data
->rgb
[1] = cw
.cw_Green
;
180 data
->rgb
[2] = cw
.cw_Blue
;
182 nnset(data
->rslider
, MUIA_Numeric_Value
, data
->rgb
[0] >> 24);
183 nnset(data
->gslider
, MUIA_Numeric_Value
, data
->rgb
[1] >> 24);
184 nnset(data
->bslider
, MUIA_Numeric_Value
, data
->rgb
[2] >> 24);
186 nnset(data
->colfield
, MUIA_Colorfield_RGB
, (IPTR
)data
->rgb
);
188 NotifyAll(obj
, data
);
192 IPTR
Coloradjust__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
194 struct Coloradjust_DATA
*data
;
195 struct TagItem
*tag
, *tags
;
196 struct Library
*colorwheelbase
, *gradientsliderbase
;
197 Object
*rslider
, *gslider
, *bslider
;
198 Object
*colfield
, *wheel
= NULL
, *grad
= NULL
;
201 colorwheelbase
= OpenLibrary("gadgets/colorwheel.gadget", 0);
202 gradientsliderbase
= OpenLibrary("gadgets/gradientslider.gadget", 0);
204 obj
= (Object
*) DoSuperNewTags
208 MUIA_Group_Columns
, 2,
209 MUIA_Group_VertSpacing
, 1,
211 Child
, (IPTR
) Label1("Red:"),
212 Child
, (IPTR
) (rslider
= SliderObject
, MUIA_Group_Horiz
, TRUE
, MUIA_Numeric_Min
, 0, MUIA_Numeric_Max
, 255, End
),
213 Child
, (IPTR
) Label1("Green:"),
214 Child
, (IPTR
) (gslider
= SliderObject
, MUIA_Group_Horiz
, TRUE
, MUIA_Numeric_Min
, 0, MUIA_Numeric_Max
, 255, End
),
215 Child
, (IPTR
) Label1("Blue:"),
216 Child
, (IPTR
) (bslider
= SliderObject
, MUIA_Group_Horiz
, TRUE
, MUIA_Numeric_Min
, 0, MUIA_Numeric_Max
, 255, End
),
217 Child
, (IPTR
) VSpace(1),
218 Child
, (IPTR
) VSpace(1),
219 Child
, (IPTR
) (colfield
= ColorfieldObject
, TextFrame
, MUIA_Weight
, 0, End
),
220 Child
, (!colorwheelbase
|| !gradientsliderbase
) ? (IPTR
) HVSpace
: (IPTR
) HGroup
,
221 /* FIXME: this looks severely broken if the HVSpace path is taken... */
222 MUIA_Group_HorizSpacing
, 2,
223 Child
, (IPTR
) (wheel
= BoopsiObject
,
224 MUIA_Boopsi_ClassID
, (IPTR
) "colorwheel.gadget",
225 MUIA_Boopsi_MinWidth
, 16,
226 MUIA_Boopsi_MinHeight
, 16,
227 MUIA_Boopsi_Remember
, WHEEL_Saturation
,
228 MUIA_Boopsi_Remember
, WHEEL_Hue
,
229 MUIA_Boopsi_TagScreen
, WHEEL_Screen
,
230 WHEEL_Screen
, (IPTR
)NULL
,
235 ICA_TARGET
, ICTARGET_IDCMP
,
238 Child
, (IPTR
) (grad
= BoopsiObject
,
239 MUIA_Boopsi_ClassID
, (IPTR
) "gradientslider.gadget",
240 MUIA_Boopsi_MinWidth
, 16,
241 MUIA_Boopsi_MinHeight
, 16,
242 MUIA_Boopsi_MaxWidth
, 16,
243 MUIA_Boopsi_Remember
, GRAD_CurVal
,
244 MUIA_Boopsi_Remember
, GRAD_PenArray
,
245 MUIA_Boopsi_Remember
, GRAD_KnobPixels
,
251 PGA_Freedom
, LORIENT_VERT
,
252 ICA_TARGET
, ICTARGET_IDCMP
,
257 TAG_MORE
, (IPTR
) msg
->ops_AttrList
262 CloseLibrary(gradientsliderbase
);
263 CloseLibrary(colorwheelbase
);
267 data
= INST_DATA(cl
, obj
);
269 data
->colorwheelbase
= colorwheelbase
;
270 data
->gradientsliderbase
= gradientsliderbase
;
271 if (!EXEC_INTERFACE_GET_MAIN(data
->icolorwheel
,data
->colorwheelbase
))
273 CoerceMethod(cl
,obj
,OM_DISPOSE
);
276 data
->notifyclass
= cl
->cl_Super
->cl_Super
;
278 data
->sliderhook
.h_Entry
= HookEntry
;
279 data
->sliderhook
.h_SubEntry
= (HOOKFUNC
)SliderFunc
;
281 data
->wheelhook
.h_Entry
= HookEntry
;
282 data
->wheelhook
.h_SubEntry
= (HOOKFUNC
)WheelFunc
;
284 data
->gradhook
.h_Entry
= HookEntry
;
285 data
->gradhook
.h_SubEntry
= (HOOKFUNC
)GradFunc
;
287 data
->rslider
= rslider
;
288 data
->gslider
= gslider
;
289 data
->bslider
= bslider
;
290 data
->colfield
= colfield
;
294 data
->rgb
[0] = data
->rgb
[1] = data
->rgb
[2] = 0xFFFFFFFF;
296 /* parse initial taglist */
297 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
)); )
301 case MUIA_Coloradjust_Red
:
302 data
->rgb
[0] = (ULONG
)tag
->ti_Data
;
305 case MUIA_Coloradjust_Green
:
306 data
->rgb
[1] = (ULONG
)tag
->ti_Data
;
309 case MUIA_Coloradjust_Blue
:
310 data
->rgb
[2] = (ULONG
)tag
->ti_Data
;
313 case MUIA_Coloradjust_RGB
:
314 rgb
= (ULONG
*)tag
->ti_Data
;
315 data
->rgb
[0] = *rgb
++;
316 data
->rgb
[1] = *rgb
++;
317 data
->rgb
[2] = *rgb
++;
323 nnset(colfield
, MUIA_Colorfield_RGB
, (IPTR
)data
->rgb
);
324 nnset(rslider
, MUIA_Numeric_Value
, data
->rgb
[0] >> 24);
325 nnset(gslider
, MUIA_Numeric_Value
, data
->rgb
[1] >> 24);
326 nnset(bslider
, MUIA_Numeric_Value
, data
->rgb
[2] >> 24);
330 struct ColorWheelRGB cw
;
331 struct ColorWheelHSB hsb
;
333 cw
.cw_Red
= data
->rgb
[0];
334 cw
.cw_Green
= data
->rgb
[1];
335 cw
.cw_Blue
= data
->rgb
[2];
337 ConvertRGBToHSB(&cw
, &hsb
);
339 nnset(wheel
, WHEEL_HSB
, (IPTR
)&hsb
);
340 /* just to be sure - colorwheel seems to have some problems */
341 nnset(wheel
, WHEEL_Saturation
, hsb
.cw_Saturation
);
342 nnset(wheel
, WHEEL_Hue
, hsb
.cw_Hue
);
343 nnset(data
->grad
, GRAD_CurVal
, 0xFFFF - (hsb
.cw_Brightness
>> 16));
344 nnset(data
->grad
, GRAD_PenArray
, (IPTR
)data
->gradpenarray
);
347 DoMethod(rslider
, MUIM_Notify
, MUIA_Numeric_Value
, MUIV_EveryTime
, (IPTR
)obj
, 4, MUIM_CallHook
, (IPTR
)&data
->sliderhook
, (IPTR
)data
, 0);
348 DoMethod(gslider
, MUIM_Notify
, MUIA_Numeric_Value
, MUIV_EveryTime
, (IPTR
)obj
, 4, MUIM_CallHook
, (IPTR
)&data
->sliderhook
, (IPTR
)data
, 1);
349 DoMethod(bslider
, MUIM_Notify
, MUIA_Numeric_Value
, MUIV_EveryTime
, (IPTR
)obj
, 4, MUIM_CallHook
, (IPTR
)&data
->sliderhook
, (IPTR
)data
, 2);
353 DoMethod(wheel
, MUIM_Notify
, WHEEL_Hue
, MUIV_EveryTime
, (IPTR
)obj
, 3, MUIM_CallHook
, (IPTR
)&data
->wheelhook
, (IPTR
)data
);
354 DoMethod(wheel
, MUIM_Notify
, WHEEL_Saturation
, MUIV_EveryTime
, (IPTR
)obj
, 3, MUIM_CallHook
, (IPTR
)&data
->wheelhook
, (IPTR
)data
);
355 DoMethod(grad
, MUIM_Notify
, GRAD_CurVal
, MUIV_EveryTime
, (IPTR
)obj
, 3, MUIM_CallHook
, (IPTR
)&data
->gradhook
, (IPTR
)data
);
361 IPTR
Coloradjust__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
363 struct Coloradjust_DATA
*data
;
364 struct Library
*colorwheelbase
;
365 struct Library
*gradientsliderbase
;
368 data
= INST_DATA(cl
, obj
);
370 EXEC_INTERFACE_DROP(data
->icolorwheel
);
371 colorwheelbase
= data
->colorwheelbase
;
372 gradientsliderbase
= data
->gradientsliderbase
;
374 retval
= DoSuperMethodA(cl
, obj
, msg
);
376 if (colorwheelbase
) CloseLibrary(colorwheelbase
);
377 if (gradientsliderbase
) CloseLibrary(gradientsliderbase
);
382 IPTR
Coloradjust__OM_SET(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
384 struct Coloradjust_DATA
*data
;
385 struct TagItem
*tag
, *tags
;
389 data
= INST_DATA(cl
, obj
);
391 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
)); )
395 case MUIA_Coloradjust_Red
:
396 data
->rgb
[0] = (ULONG
)tag
->ti_Data
;
400 case MUIA_Coloradjust_Green
:
401 data
->rgb
[1] = (ULONG
)tag
->ti_Data
;
405 case MUIA_Coloradjust_Blue
:
406 data
->rgb
[2] = (ULONG
)tag
->ti_Data
;
410 case MUIA_Coloradjust_RGB
:
411 rgb
= (ULONG
*)tag
->ti_Data
;
412 data
->rgb
[0] = *rgb
++;
413 data
->rgb
[1] = *rgb
++;
414 data
->rgb
[2] = *rgb
++;
423 nnset(data
->rslider
, MUIA_Numeric_Value
, data
->rgb
[0] >> 24);
424 nnset(data
->gslider
, MUIA_Numeric_Value
, data
->rgb
[1] >> 24);
425 nnset(data
->bslider
, MUIA_Numeric_Value
, data
->rgb
[2] >> 24);
426 D(bug("coloradjust: sliders set to %ld, %ld, %ld\n", data
->rgb
[0] >> 24,
427 data
->rgb
[1] >> 24, data
->rgb
[2] >> 24));
429 nnset(data
->colfield
, MUIA_Colorfield_RGB
, (IPTR
)data
->rgb
);
433 struct ColorWheelRGB cw
;
434 struct ColorWheelHSB hsb
;
436 cw
.cw_Red
= data
->rgb
[0];
437 cw
.cw_Green
= data
->rgb
[1];
438 cw
.cw_Blue
= data
->rgb
[2];
440 ConvertRGBToHSB(&cw
, &hsb
);
441 nnset(data
->wheel
, WHEEL_HSB
, (IPTR
)&hsb
);
442 nnset(data
->wheel
, WHEEL_Saturation
, hsb
.cw_Saturation
);
443 nnset(data
->wheel
, WHEEL_Hue
, hsb
.cw_Hue
);
444 nnset(data
->grad
, GRAD_CurVal
, 0xFFFF - (hsb
.cw_Brightness
>> 16));
446 if ((_flags(obj
) & MADF_SETUP
) && (data
->gradpen
!= -1))
448 hsb
.cw_Brightness
= 0xFFFFFFFF;
449 ConvertHSBToRGB(&hsb
, &cw
);
451 SetRGB32(&_screen(obj
)->ViewPort
, data
->gradpen
, cw
.cw_Red
, cw
.cw_Green
, cw
.cw_Blue
);
454 MUI_Redraw(data
->grad
, MADF_DRAWOBJECT
);
461 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
464 IPTR
Coloradjust__OM_GET(struct IClass
*cl
, Object
* obj
, struct opGet
*msg
)
466 struct Coloradjust_DATA
*data
= INST_DATA(cl
, obj
);
467 IPTR
*store
= msg
->opg_Storage
;
469 switch (msg
->opg_AttrID
)
471 case MUIA_Coloradjust_Red
:
472 *store
= data
->rgb
[0];
475 case MUIA_Coloradjust_Green
:
476 *store
= data
->rgb
[1];
479 case MUIA_Coloradjust_Blue
:
480 *store
= data
->rgb
[2];
483 case MUIA_Coloradjust_RGB
:
484 *(IPTR
**)store
= data
->rgb
;
488 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
491 IPTR
Coloradjust__MUIM_Setup(struct IClass
*cl
, Object
*obj
, struct MUIP_Setup
*msg
)
493 struct Coloradjust_DATA
*data
= INST_DATA(cl
,obj
);
495 if (!(DoSuperMethodA(cl
, obj
, (Msg
)msg
))) return 0;
499 struct ColorWheelHSB hsb
;
500 struct ColorWheelRGB rgb
;
502 rgb
.cw_Red
= data
->rgb
[0];
503 rgb
.cw_Green
= data
->rgb
[1];
504 rgb
.cw_Blue
= data
->rgb
[2];
506 data
->gradpenarray
[0] = _pens(obj
)[MPEN_SHINE
];
507 data
->gradpenarray
[1] = _pens(obj
)[MPEN_SHADOW
];
508 data
->gradpenarray
[2] = (UWORD
)~0;
510 data
->gradpen
= ObtainPen(_screen(obj
)->ViewPort
.ColorMap
,
517 if (data
->gradpen
!= -1)
519 data
->gradpenarray
[0] = data
->gradpen
;
522 ConvertRGBToHSB(&rgb
, &hsb
);
523 /* setting this will force wheel to properly set its display */
524 nnset(data
->wheel
, WHEEL_Saturation
, hsb
.cw_Saturation
);
525 nnset(data
->wheel
, WHEEL_Hue
, hsb
.cw_Hue
);
527 hsb
.cw_Brightness
= 0xFFFFFFFF;
528 ConvertHSBToRGB(&hsb
, &rgb
);
530 if (data
->gradpen
!= -1)
532 SetRGB32(&_screen(obj
)->ViewPort
, data
->gradpen
, rgb
.cw_Red
, rgb
.cw_Green
, rgb
.cw_Blue
);
535 data
->truecolor
= GetBitMapAttr(_screen(obj
)->RastPort
.BitMap
, BMA_DEPTH
) >= 15;
541 IPTR
Coloradjust__MUIM_Cleanup(struct IClass
*cl
, Object
*obj
, struct MUIP_Cleanup
*msg
)
543 struct Coloradjust_DATA
*data
= INST_DATA(cl
,obj
);
545 if (data
->gradpen
!= -1)
547 ReleasePen(_screen(obj
)->ViewPort
.ColorMap
, data
->gradpen
);
551 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
554 #if ZUNE_BUILTIN_COLORADJUST
555 BOOPSI_DISPATCHER(IPTR
, Coloradjust_Dispatcher
, cl
, obj
, msg
)
557 switch (msg
->MethodID
)
559 case OM_NEW
: return Coloradjust__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
560 case OM_DISPOSE
: return Coloradjust__OM_DISPOSE(cl
, obj
, msg
);
561 case OM_SET
: return Coloradjust__OM_SET(cl
, obj
, (struct opSet
*)msg
);
562 case OM_GET
: return Coloradjust__OM_GET(cl
, obj
, (struct opGet
*)msg
);
563 case MUIM_Setup
: return Coloradjust__MUIM_Setup(cl
, obj
, (struct MUIP_Setup
*)msg
);
564 case MUIM_Cleanup
: return Coloradjust__MUIM_Cleanup(cl
, obj
, (struct MUIP_Cleanup
*)msg
);
565 default: return DoSuperMethodA(cl
, obj
, msg
);
568 BOOPSI_DISPATCHER_END
570 const struct __MUIBuiltinClass _MUI_Coloradjust_desc
=
574 sizeof(struct Coloradjust_DATA
),
575 (void*)Coloradjust_Dispatcher
577 #endif /* ZUNE_BUILTIN_COLORADJUST */