Tabs to spaces, more consistent formatting.
[AROS.git] / workbench / libs / muimaster / classes / palette.c
blob59a360fd2211e981dae6d2db51b3cf12fb2d675e
1 /*
2 Copyright © 2002-2006, The AROS Development Team. All rights reserved.
3 $Id$
4 */
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"
20 #include <string.h>
21 #include <stdio.h>
23 #include "debug.h"
25 #include "mui.h"
26 #include "imspec.h"
27 #include "muimaster_intern.h"
28 #include "support.h"
29 #include "prefs.h"
30 #include "palette.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? */
43 if (data->names)
45 /* then display user names */
46 *array = (char *)data->names[(SIPTR) array[-1]];
47 array++;
49 else
51 /* if no, show default color names */
52 sprintf(data->buf, "Color %ld", (long)(array[-1] + 1));
53 *array++ = data->buf;
55 return 0;
58 static void NotifyGun(Object * obj, struct MUI_PaletteData *data, LONG gun)
60 static Tag guntotag[3] = {
61 MUIA_Coloradjust_Red,
62 MUIA_Coloradjust_Green,
63 MUIA_Coloradjust_Blue
66 struct TagItem tags[] = {
67 {0, 0},
68 {MUIA_Coloradjust_RGB, 0},
69 {TAG_DONE}
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,
80 STACKULONG * notify)
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))
88 return 0;
89 if (mode == 1)
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);
99 data->rgb[0] = r;
100 data->rgb[1] = g;
101 data->rgb[2] = b;
102 NotifyGun((Object *) obj, data, gun);
105 else if (mode == 2)
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);
114 return 0;
117 /**************************************************************************
118 OM_NEW
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;
126 int i;
128 obj = (Object *) DoSuperNewTags(cl, obj, NULL,
129 GroupFrame,
130 MUIA_Background, MUII_ButtonBack,
131 MUIA_Group_Horiz, TRUE,
132 Child, list = ListviewObject,
133 MUIA_Listview_List, ListObject,
134 End,
135 End,
136 Child, coloradjust = ColoradjustObject,
137 End, TAG_MORE, (IPTR) msg->ops_AttrList);
139 if (obj == NULL)
140 return (IPTR) NULL;
142 data = INST_DATA(cl, obj);
144 data->list = list;
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);
156 data->entries =
157 (struct MUI_Palette_Entry *)GetTagData(MUIA_Palette_Entries, 0,
158 msg->ops_AttrList);
159 data->names =
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;
164 e = data->entries;
165 if (e)
167 data->numentries = 0;
168 while (e->mpe_ID != MUIV_Palette_Entry_End)
170 data->numentries++;
171 e++;
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,
200 data);
201 DoMethod(data->coloradjust, MUIM_Notify, MUIA_Coloradjust_Green,
202 MUIV_EveryTime, obj, 5, MUIM_CallHook, &data->setcolor_hook, 2, 1,
203 data);
204 DoMethod(data->coloradjust, MUIM_Notify, MUIA_Coloradjust_Blue,
205 MUIV_EveryTime, obj, 5, MUIM_CallHook, &data->setcolor_hook, 2, 2,
206 data);
207 return (IPTR) obj;
210 /**************************************************************************
211 OM_SET
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));)
222 switch (tag->ti_Tag)
224 case MUIA_Palette_Entries:
225 data->entries = (struct MUI_Palette_Entry *)tag->ti_Data;
226 break;
228 case MUIA_Palette_Names:
229 data->names = (const char **)tag->ti_Data;
230 break;
232 case MUIA_Palette_Groupable:
233 data->group = (ULONG) tag->ti_Data;
234 break;
237 return DoSuperMethodA(cl, obj, (Msg) msg);
240 /**************************************************************************
241 OM_GET
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;
253 return TRUE;
254 case MUIA_Palette_Names:
255 *store = (IPTR) & data->names;
256 return TRUE;
258 case MUIA_Coloradjust_Red:
259 *store = data->rgb[0];
260 return TRUE;
262 case MUIA_Coloradjust_Green:
263 *store = data->rgb[1];
264 return TRUE;
266 case MUIA_Coloradjust_Blue:
267 *store = data->rgb[2];
268 return TRUE;
270 case MUIA_Coloradjust_RGB:
271 *store = (IPTR) data->rgb;
272 return TRUE;
274 return DoSuperMethodA(cl, obj, (Msg) msg);
276 /**************************************************************************
277 OM_GET
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)
291 case OM_NEW:
292 return Palette__OM_NEW(cl, obj, (struct opSet *)msg);
293 case OM_SET:
294 return Palette__OM_SET(cl, obj, (struct opSet *)msg);
295 case OM_GET:
296 return Palette__OM_GET(cl, obj, (struct opGet *)msg);
297 case OM_DISPOSE:
298 return Palette__OM_DISPOSE(cl, obj, (struct opGet *)msg);
299 default:
300 return DoSuperMethodA(cl, obj, msg);
304 BOOPSI_DISPATCHER_END
306 * Class descriptor.
308 const struct __MUIBuiltinClass _MUI_Palette_desc =
310 MUIC_Palette,
311 MUIC_Group,
312 sizeof(struct MUI_PaletteData),
313 (void *) Palette_Dispatcher
315 #endif