2 Copyright © 2002-2006, The AROS Development Team. All rights reserved.
6 #include <graphics/gfx.h>
7 #include <graphics/view.h>
8 #include <clib/alib_protos.h>
9 #include <proto/exec.h>
10 #include <proto/graphics.h>
11 #include <proto/utility.h>
12 #include <proto/intuition.h>
13 #include <proto/muimaster.h>
14 #include <proto/colorwheel.h>
15 #include <utility/hooks.h>
16 #include "gadgets/colorwheel.h"
17 #include <gadgets/gradientslider.h>
18 #include "intuition/icclass.h"
19 #include "intuition/gadgetclass.h"
27 #include "muimaster_intern.h"
31 #include "palette_private.h"
33 #define ColorWheelBase data->colorwheelbase
35 extern struct Library
*MUIMasterBase
;
37 static LONG
display_func(struct Hook
*hook
, char **array
,
38 struct MUI_Palette_Entry
*entry
)
40 struct MUI_PaletteData
*data
= hook
->h_Data
;
42 /* do any strings exist? */
45 /* then display user names */
46 *array
= (char *)data
->names
[(SIPTR
) array
[-1]];
51 /* if no, show default color names */
52 sprintf(data
->buf
, "Color %ld", (long)(array
[-1] + 1));
58 static void NotifyGun(Object
* obj
, struct MUI_PaletteData
*data
, LONG gun
)
60 static Tag guntotag
[3] = {
62 MUIA_Coloradjust_Green
,
66 struct TagItem tags
[] = {
68 {MUIA_Coloradjust_RGB
, 0},
72 tags
[0].ti_Tag
= guntotag
[gun
];
73 tags
[0].ti_Data
= data
->rgb
[gun
];
74 tags
[1].ti_Data
= (IPTR
) data
->rgb
;
76 CoerceMethod(data
->notifyclass
, obj
, OM_SET
, (IPTR
) tags
, NULL
);
79 static LONG
setcolor_func(struct Hook
*hook
, APTR
* obj
,
82 ULONG mode
= *notify
++;
83 ULONG gun
= *notify
++;
84 struct MUI_PaletteData
*data
= (struct MUI_PaletteData
*)*notify
++;
86 LONG entrie
= XGET(data
->list
, MUIA_List_Active
);
87 if ((entrie
< 0) || (entrie
>= data
->numentries
))
91 if (data
->numentries
> 0)
93 ULONG r
= data
->entries
[entrie
].mpe_Red
;
94 ULONG g
= data
->entries
[entrie
].mpe_Green
;
95 ULONG b
= data
->entries
[entrie
].mpe_Blue
;
96 nnset(data
->coloradjust
, MUIA_Coloradjust_Red
, r
);
97 nnset(data
->coloradjust
, MUIA_Coloradjust_Green
, g
);
98 nnset(data
->coloradjust
, MUIA_Coloradjust_Blue
, b
);
102 NotifyGun((Object
*) obj
, data
, gun
);
107 data
->entries
[entrie
].mpe_Red
=
108 XGET(data
->coloradjust
, MUIA_Coloradjust_Red
);
109 data
->entries
[entrie
].mpe_Green
=
110 XGET(data
->coloradjust
, MUIA_Coloradjust_Green
);
111 data
->entries
[entrie
].mpe_Blue
=
112 XGET(data
->coloradjust
, MUIA_Coloradjust_Blue
);
117 /**************************************************************************
119 **************************************************************************/
120 IPTR
Palette__OM_NEW(struct IClass
* cl
, Object
* obj
, struct opSet
* msg
)
122 struct MUI_PaletteData
*data
;
123 //struct TagItem *tag, *tags;
124 struct MUI_Palette_Entry
*e
;
125 Object
*list
, *coloradjust
;
128 obj
= (Object
*) DoSuperNewTags(cl
, obj
, NULL
,
130 MUIA_Background
, MUII_ButtonBack
,
131 MUIA_Group_Horiz
, TRUE
,
132 Child
, list
= ListviewObject
,
133 MUIA_Listview_List
, ListObject
,
136 Child
, coloradjust
= ColoradjustObject
,
137 End
, TAG_MORE
, (IPTR
) msg
->ops_AttrList
);
142 data
= INST_DATA(cl
, obj
);
145 data
->coloradjust
= coloradjust
;
147 data
->display_hook
.h_Entry
= HookEntry
;
148 data
->display_hook
.h_SubEntry
= (HOOKFUNC
) display_func
;
149 data
->display_hook
.h_Data
= data
;
150 data
->setcolor_hook
.h_Entry
= HookEntry
;
151 data
->setcolor_hook
.h_SubEntry
= (HOOKFUNC
) setcolor_func
;
152 data
->setcolor_hook
.h_Data
= data
;
154 nnset(list
, MUIA_List_DisplayHook
, (IPTR
) & data
->display_hook
);
157 (struct MUI_Palette_Entry
*)GetTagData(MUIA_Palette_Entries
, 0,
160 (const char **)GetTagData(MUIA_Palette_Names
, 0, msg
->ops_AttrList
);
161 data
->group
= GetTagData(MUIA_Palette_Groupable
, 0, msg
->ops_AttrList
);
163 data
->numentries
= 0;
167 data
->numentries
= 0;
168 while (e
->mpe_ID
!= MUIV_Palette_Entry_End
)
175 data
->notifyclass
= cl
->cl_Super
->cl_Super
;
177 if (data
->numentries
> 0)
179 for (i
= 0; i
< data
->numentries
; i
++)
180 DoMethod(data
->list
, MUIM_List_InsertSingle
, &data
->entries
[i
],
181 MUIV_List_Insert_Bottom
);
183 nnset(data
->coloradjust
, MUIA_Coloradjust_Red
,
184 data
->entries
[0].mpe_Red
);
185 nnset(data
->coloradjust
, MUIA_Coloradjust_Green
,
186 data
->entries
[0].mpe_Green
);
187 nnset(data
->coloradjust
, MUIA_Coloradjust_Blue
,
188 data
->entries
[0].mpe_Blue
);
189 nnset(data
->list
, MUIA_List_Active
, 0);
191 data
->rgb
[0] = data
->entries
[0].mpe_Red
;
192 data
->rgb
[1] = data
->entries
[0].mpe_Green
;
193 data
->rgb
[2] = data
->entries
[0].mpe_Blue
;
196 DoMethod(data
->list
, MUIM_Notify
, MUIA_List_Active
, MUIV_EveryTime
, obj
,
197 5, MUIM_CallHook
, &data
->setcolor_hook
, 1, 0, data
);
198 DoMethod(data
->coloradjust
, MUIM_Notify
, MUIA_Coloradjust_Red
,
199 MUIV_EveryTime
, obj
, 5, MUIM_CallHook
, &data
->setcolor_hook
, 2, 0,
201 DoMethod(data
->coloradjust
, MUIM_Notify
, MUIA_Coloradjust_Green
,
202 MUIV_EveryTime
, obj
, 5, MUIM_CallHook
, &data
->setcolor_hook
, 2, 1,
204 DoMethod(data
->coloradjust
, MUIM_Notify
, MUIA_Coloradjust_Blue
,
205 MUIV_EveryTime
, obj
, 5, MUIM_CallHook
, &data
->setcolor_hook
, 2, 2,
210 /**************************************************************************
212 **************************************************************************/
213 IPTR
Palette__OM_SET(struct IClass
* cl
, Object
* obj
, struct opSet
* msg
)
215 struct MUI_PaletteData
*data
;
216 struct TagItem
*tag
, *tags
;
218 data
= INST_DATA(cl
, obj
);
220 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
224 case MUIA_Palette_Entries
:
225 data
->entries
= (struct MUI_Palette_Entry
*)tag
->ti_Data
;
228 case MUIA_Palette_Names
:
229 data
->names
= (const char **)tag
->ti_Data
;
232 case MUIA_Palette_Groupable
:
233 data
->group
= (ULONG
) tag
->ti_Data
;
237 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
240 /**************************************************************************
242 **************************************************************************/
243 IPTR
Palette__OM_GET(struct IClass
* cl
, Object
* obj
, struct opGet
* msg
)
245 struct MUI_PaletteData
*data
= INST_DATA(cl
, obj
);
247 IPTR
*store
= msg
->opg_Storage
;
249 switch (msg
->opg_AttrID
)
251 case MUIA_Palette_Entries
:
252 *store
= (IPTR
) & data
->entries
;
254 case MUIA_Palette_Names
:
255 *store
= (IPTR
) & data
->names
;
258 case MUIA_Coloradjust_Red
:
259 *store
= data
->rgb
[0];
262 case MUIA_Coloradjust_Green
:
263 *store
= data
->rgb
[1];
266 case MUIA_Coloradjust_Blue
:
267 *store
= data
->rgb
[2];
270 case MUIA_Coloradjust_RGB
:
271 *store
= (IPTR
) data
->rgb
;
274 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
276 /**************************************************************************
278 **************************************************************************/
280 IPTR
Palette__OM_DISPOSE(struct IClass
* cl
, Object
* obj
, Msg msg
)
282 return DoSuperMethodA(cl
, obj
, msg
);
285 #if ZUNE_BUILTIN_PALETTE
287 BOOPSI_DISPATCHER(IPTR
, Palette_Dispatcher
, cl
, obj
, msg
)
289 switch (msg
->MethodID
)
292 return Palette__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
294 return Palette__OM_SET(cl
, obj
, (struct opSet
*)msg
);
296 return Palette__OM_GET(cl
, obj
, (struct opGet
*)msg
);
298 return Palette__OM_DISPOSE(cl
, obj
, (struct opGet
*)msg
);
300 return DoSuperMethodA(cl
, obj
, msg
);
304 BOOPSI_DISPATCHER_END
308 const struct __MUIBuiltinClass _MUI_Palette_desc
=
312 sizeof(struct MUI_PaletteData
),
313 (void *) Palette_Dispatcher