2 Copyright © 2002-2018, 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 /* private msg structure passed to the hook function */
38 struct MUIP_PalNotifyMsg
40 STACKED
struct MUI_PaletteData
*palData
;
41 STACKED ULONG palMode
;
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? */
53 /* then display user names */
54 *array
= (char *)data
->names
[(SIPTR
) array
[-1]];
59 /* if no, show default color names */
60 sprintf(data
->buf
, "Color %ld", (long)(array
[-1] + 1));
66 static void NotifyGun(Object
* obj
, struct MUI_PaletteData
*data
, LONG gun
)
68 static Tag guntotag
[3] = {
70 MUIA_Coloradjust_Green
,
74 struct TagItem tags
[] = {
75 { MUIA_NoNotify
, TRUE
},
77 { MUIA_Coloradjust_RGB
, 0},
81 tags
[1].ti_Tag
= guntotag
[gun
];
82 tags
[1].ti_Data
= data
->rgb
[gun
];
83 tags
[2].ti_Data
= (IPTR
) data
->rgb
;
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
))
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
);
110 NotifyGun(data
->coloradjust
, data
, gun
);
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
);
125 /**************************************************************************
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
;
136 obj
= (Object
*) DoSuperNewTags(cl
, obj
, NULL
,
138 MUIA_Background
, MUII_ButtonBack
,
139 MUIA_Group_Horiz
, TRUE
,
140 Child
, (IPTR
)(ListviewObject
,
141 MUIA_Listview_List
, (IPTR
)(list
= ListObject
,
144 Child
, (coloradjust
= ColoradjustObject
,
146 TAG_MORE
, (IPTR
) msg
->ops_AttrList
);
151 data
= INST_DATA(cl
, obj
);
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
);
166 (struct MUI_Palette_Entry
*)GetTagData(MUIA_Palette_Entries
, 0,
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;
176 data
->numentries
= 0;
177 while (e
->mpe_ID
!= MUIV_Palette_Entry_End
)
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
,
207 DoMethod(data
->coloradjust
, MUIM_Notify
, MUIA_Coloradjust_Red
, MUIV_EveryTime
,
208 (IPTR
) obj
, 5, MUIM_CallHook
, (IPTR
) &data
->setcolor_hook
,
210 DoMethod(data
->coloradjust
, MUIM_Notify
, MUIA_Coloradjust_Green
, MUIV_EveryTime
,
211 (IPTR
) obj
, 5, MUIM_CallHook
, (IPTR
) &data
->setcolor_hook
,
213 DoMethod(data
->coloradjust
, MUIM_Notify
, MUIA_Coloradjust_Blue
, MUIV_EveryTime
,
214 (IPTR
) obj
, 5, MUIM_CallHook
, (IPTR
) &data
->setcolor_hook
,
220 /**************************************************************************
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
));)
234 case MUIA_Palette_Entries
:
235 data
->entries
= (struct MUI_Palette_Entry
*)tag
->ti_Data
;
238 case MUIA_Palette_Names
:
239 data
->names
= (const char **)tag
->ti_Data
;
242 case MUIA_Palette_Groupable
:
243 data
->group
= (ULONG
) tag
->ti_Data
;
247 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
250 /**************************************************************************
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
;
264 case MUIA_Palette_Names
:
265 *store
= (IPTR
) & data
->names
;
268 case MUIA_Coloradjust_Red
:
269 *store
= data
->rgb
[0];
272 case MUIA_Coloradjust_Green
:
273 *store
= data
->rgb
[1];
276 case MUIA_Coloradjust_Blue
:
277 *store
= data
->rgb
[2];
280 case MUIA_Coloradjust_RGB
:
281 *store
= (IPTR
) data
->rgb
;
284 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
286 /**************************************************************************
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
)
302 return Palette__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
304 return Palette__OM_SET(cl
, obj
, (struct opSet
*)msg
);
306 return Palette__OM_GET(cl
, obj
, (struct opGet
*)msg
);
308 return Palette__OM_DISPOSE(cl
, obj
, (struct opGet
*)msg
);
310 return DoSuperMethodA(cl
, obj
, msg
);
314 BOOPSI_DISPATCHER_END
318 const struct __MUIBuiltinClass _MUI_Palette_desc
=
322 sizeof(struct MUI_PaletteData
),
323 (void *) Palette_Dispatcher