revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / muimaster / classes / palette.c
blobe5ea11dda9b9038980cb683b4e4cfb1c6ef82ae2
1 /*
2 Copyright © 2002-2018, 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 /* private msg structure passed to the hook function */
38 struct MUIP_PalNotifyMsg
40 STACKED struct MUI_PaletteData *palData;
41 STACKED ULONG palMode;
42 STACKED ULONG palGun;
45 static LONG display_func(struct Hook *hook, char **array,
46 struct MUI_Palette_Entry *entry)
48 struct MUI_PaletteData *data = hook->h_Data;
50 /* do any strings exist? */
51 if (data->names)
53 /* then display user names */
54 *array = (char *)data->names[(SIPTR) array[-1]];
55 array++;
57 else
59 /* if no, show default color names */
60 sprintf(data->buf, "Color %ld", (long)(array[-1] + 1));
61 *array++ = data->buf;
63 return 0;
66 static void NotifyGun(Object * obj, struct MUI_PaletteData *data, LONG gun)
68 static Tag guntotag[3] = {
69 MUIA_Coloradjust_Red,
70 MUIA_Coloradjust_Green,
71 MUIA_Coloradjust_Blue
74 struct TagItem tags[] = {
75 { MUIA_NoNotify, TRUE},
76 { 0, 0},
77 { MUIA_Coloradjust_RGB, 0},
78 { TAG_DONE}
81 tags[1].ti_Tag = guntotag[gun];
82 tags[1].ti_Data = data->rgb[gun];
83 tags[2].ti_Data = (IPTR) data->rgb;
85 SetAttrsA(obj, tags);
88 static LONG setcolor_func(struct Hook *hook, APTR * obj, struct MUIP_PalNotifyMsg *msg)
90 struct MUI_PaletteData *data = msg->palData;
91 ULONG mode = msg->palMode;
92 ULONG gun = msg->palGun;
94 LONG entrie = XGET(data->list, MUIA_List_Active);
95 if ((entrie < 0) || (entrie >= data->numentries))
96 return 0;
97 if (mode == 1)
99 if (data->numentries > 0)
101 ULONG r = data->entries[entrie].mpe_Red;
102 ULONG g = data->entries[entrie].mpe_Green;
103 ULONG b = data->entries[entrie].mpe_Blue;
104 nnset(data->coloradjust, MUIA_Coloradjust_Red, r);
105 nnset(data->coloradjust, MUIA_Coloradjust_Green, g);
106 nnset(data->coloradjust, MUIA_Coloradjust_Blue, b);
107 data->rgb[0] = r;
108 data->rgb[1] = g;
109 data->rgb[2] = b;
110 NotifyGun(data->coloradjust, data, gun);
113 else if (mode == 2)
115 data->entries[entrie].mpe_Red =
116 XGET(data->coloradjust, MUIA_Coloradjust_Red);
117 data->entries[entrie].mpe_Green =
118 XGET(data->coloradjust, MUIA_Coloradjust_Green);
119 data->entries[entrie].mpe_Blue =
120 XGET(data->coloradjust, MUIA_Coloradjust_Blue);
122 return 0;
125 /**************************************************************************
126 OM_NEW
127 **************************************************************************/
128 IPTR Palette__OM_NEW(struct IClass * cl, Object * obj, struct opSet * msg)
130 struct MUI_PaletteData *data;
131 //struct TagItem *tag, *tags;
132 struct MUI_Palette_Entry *e;
133 Object *list, *coloradjust;
134 int i;
136 obj = (Object *) DoSuperNewTags(cl, obj, NULL,
137 GroupFrame,
138 MUIA_Background, MUII_ButtonBack,
139 MUIA_Group_Horiz, TRUE,
140 Child, (IPTR)(ListviewObject,
141 MUIA_Listview_List, (IPTR)(list = ListObject,
142 End),
143 End),
144 Child, (coloradjust = ColoradjustObject,
145 End),
146 TAG_MORE, (IPTR) msg->ops_AttrList);
148 if (obj == NULL)
149 return (IPTR) NULL;
151 data = INST_DATA(cl, obj);
153 data->list = list;
154 data->coloradjust = coloradjust;
156 data->display_hook.h_Entry = HookEntry;
157 data->display_hook.h_SubEntry = (HOOKFUNC) display_func;
158 data->display_hook.h_Data = data;
159 data->setcolor_hook.h_Entry = HookEntry;
160 data->setcolor_hook.h_SubEntry = (HOOKFUNC) setcolor_func;
161 data->setcolor_hook.h_Data = data;
163 nnset(list, MUIA_List_DisplayHook, (IPTR) & data->display_hook);
165 data->entries =
166 (struct MUI_Palette_Entry *)GetTagData(MUIA_Palette_Entries, 0,
167 msg->ops_AttrList);
168 data->names =
169 (const char **)GetTagData(MUIA_Palette_Names, 0, msg->ops_AttrList);
170 data->group = GetTagData(MUIA_Palette_Groupable, 0, msg->ops_AttrList);
172 data->numentries = 0;
173 e = data->entries;
174 if (e)
176 data->numentries = 0;
177 while (e->mpe_ID != MUIV_Palette_Entry_End)
179 data->numentries++;
180 e++;
184 if (data->numentries > 0)
186 for (i = 0; i < data->numentries; i++)
187 DoMethod(data->list, MUIM_List_InsertSingle, &data->entries[i],
188 MUIV_List_Insert_Bottom);
190 nnset(data->coloradjust, MUIA_Coloradjust_Red,
191 data->entries[0].mpe_Red);
192 nnset(data->coloradjust, MUIA_Coloradjust_Green,
193 data->entries[0].mpe_Green);
194 nnset(data->coloradjust, MUIA_Coloradjust_Blue,
195 data->entries[0].mpe_Blue);
196 nnset(data->list, MUIA_List_Active, 0);
198 data->rgb[0] = data->entries[0].mpe_Red;
199 data->rgb[1] = data->entries[0].mpe_Green;
200 data->rgb[2] = data->entries[0].mpe_Blue;
203 DoMethod(data->list, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
204 (IPTR) obj, 5, MUIM_CallHook, (IPTR) &data->setcolor_hook,
205 (IPTR) data, 1, 0);
207 DoMethod(data->coloradjust, MUIM_Notify, MUIA_Coloradjust_Red, MUIV_EveryTime,
208 (IPTR) obj, 5, MUIM_CallHook, (IPTR) &data->setcolor_hook,
209 (IPTR) data, 2, 0);
210 DoMethod(data->coloradjust, MUIM_Notify, MUIA_Coloradjust_Green, MUIV_EveryTime,
211 (IPTR) obj, 5, MUIM_CallHook, (IPTR) &data->setcolor_hook,
212 (IPTR) data, 2, 1);
213 DoMethod(data->coloradjust, MUIM_Notify, MUIA_Coloradjust_Blue, MUIV_EveryTime,
214 (IPTR) obj, 5, MUIM_CallHook, (IPTR) &data->setcolor_hook,
215 (IPTR) data, 2, 2);
217 return (IPTR) obj;
220 /**************************************************************************
221 OM_SET
222 **************************************************************************/
223 IPTR Palette__OM_SET(struct IClass * cl, Object * obj, struct opSet * msg)
225 struct MUI_PaletteData *data;
226 struct TagItem *tag, *tags;
228 data = INST_DATA(cl, obj);
230 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags));)
232 switch (tag->ti_Tag)
234 case MUIA_Palette_Entries:
235 data->entries = (struct MUI_Palette_Entry *)tag->ti_Data;
236 break;
238 case MUIA_Palette_Names:
239 data->names = (const char **)tag->ti_Data;
240 break;
242 case MUIA_Palette_Groupable:
243 data->group = (ULONG) tag->ti_Data;
244 break;
247 return DoSuperMethodA(cl, obj, (Msg) msg);
250 /**************************************************************************
251 OM_GET
252 **************************************************************************/
253 IPTR Palette__OM_GET(struct IClass * cl, Object * obj, struct opGet * msg)
255 struct MUI_PaletteData *data = INST_DATA(cl, obj);
257 IPTR *store = msg->opg_Storage;
259 switch (msg->opg_AttrID)
261 case MUIA_Palette_Entries:
262 *store = (IPTR) & data->entries;
263 return TRUE;
264 case MUIA_Palette_Names:
265 *store = (IPTR) & data->names;
266 return TRUE;
268 case MUIA_Coloradjust_Red:
269 *store = data->rgb[0];
270 return TRUE;
272 case MUIA_Coloradjust_Green:
273 *store = data->rgb[1];
274 return TRUE;
276 case MUIA_Coloradjust_Blue:
277 *store = data->rgb[2];
278 return TRUE;
280 case MUIA_Coloradjust_RGB:
281 *store = (IPTR) data->rgb;
282 return TRUE;
284 return DoSuperMethodA(cl, obj, (Msg) msg);
286 /**************************************************************************
287 OM_GET
288 **************************************************************************/
290 IPTR Palette__OM_DISPOSE(struct IClass * cl, Object * obj, Msg msg)
292 return DoSuperMethodA(cl, obj, msg);
295 #if ZUNE_BUILTIN_PALETTE
297 BOOPSI_DISPATCHER(IPTR, Palette_Dispatcher, cl, obj, msg)
299 switch (msg->MethodID)
301 case OM_NEW:
302 return Palette__OM_NEW(cl, obj, (struct opSet *)msg);
303 case OM_SET:
304 return Palette__OM_SET(cl, obj, (struct opSet *)msg);
305 case OM_GET:
306 return Palette__OM_GET(cl, obj, (struct opGet *)msg);
307 case OM_DISPOSE:
308 return Palette__OM_DISPOSE(cl, obj, (struct opGet *)msg);
309 default:
310 return DoSuperMethodA(cl, obj, msg);
314 BOOPSI_DISPATCHER_END
316 * Class descriptor.
318 const struct __MUIBuiltinClass _MUI_Palette_desc =
320 MUIC_Palette,
321 MUIC_Group,
322 sizeof(struct MUI_PaletteData),
323 (void *) Palette_Dispatcher
325 #endif