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
, struct MUI_Palette_Entry
*entry
)
39 struct MUI_PaletteData
*data
= hook
->h_Data
;
41 if (data
->names
) { /* does any strings exist */
42 *array
= (char *)data
->names
[(int) array
[-1]]; /*then display user names */
45 sprintf(data
->buf
,"Color %ld",(long)(array
[-1]+1)); /* if nos show default color names */
51 static void NotifyGun(Object
*obj
, struct MUI_PaletteData
*data
, LONG gun
)
53 static Tag guntotag
[3] =
56 MUIA_Coloradjust_Green
,
60 struct TagItem tags
[] =
63 {MUIA_Coloradjust_RGB
, 0},
67 tags
[0].ti_Tag
= guntotag
[gun
];
68 tags
[0].ti_Data
= data
->rgb
[gun
];
69 tags
[1].ti_Data
= (IPTR
)data
->rgb
;
71 CoerceMethod(data
->notifyclass
, obj
, OM_SET
, (IPTR
)tags
, NULL
);
74 static LONG
setcolor_func(struct Hook
*hook
, APTR
*obj
, STACKULONG
*notify
)
77 ULONG mode
= *notify
++;
78 ULONG gun
= *notify
++;
79 struct MUI_PaletteData
*data
= (struct MUI_PaletteData
*) *notify
++;
81 LONG entrie
= XGET(data
->list
, MUIA_List_Active
);
82 if ((entrie
< 0) || (entrie
>= data
->numentries
)) return 0;
84 if (data
->numentries
> 0) {
85 val
= XGET(data
->list
, MUIA_List_Active
);
86 ULONG r
= data
->entries
[entrie
].mpe_Red
;
87 ULONG g
= data
->entries
[entrie
].mpe_Green
;
88 ULONG b
= data
->entries
[entrie
].mpe_Blue
;
89 nnset(data
->coloradjust
, MUIA_Coloradjust_Red
, r
);
90 nnset(data
->coloradjust
, MUIA_Coloradjust_Green
, g
);
91 nnset(data
->coloradjust
, MUIA_Coloradjust_Blue
, b
);
95 NotifyGun((Object
*)obj
, data
, gun
);
97 } else if (mode
== 2) {
98 data
->entries
[entrie
].mpe_Red
= XGET(data
->coloradjust
, MUIA_Coloradjust_Red
);
99 data
->entries
[entrie
].mpe_Green
= XGET(data
->coloradjust
, MUIA_Coloradjust_Green
);
100 data
->entries
[entrie
].mpe_Blue
= XGET(data
->coloradjust
, MUIA_Coloradjust_Blue
);
105 /**************************************************************************
107 **************************************************************************/
108 IPTR
Palette__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
110 struct MUI_PaletteData
*data
;
111 //struct TagItem *tag, *tags;
112 struct MUI_Palette_Entry
*e
;
113 Object
*list
, *coloradjust
;
116 obj
= (Object
*) DoSuperNewTags(cl
, obj
, NULL
,
118 MUIA_Background
, MUII_ButtonBack
,
119 MUIA_Group_Horiz
, TRUE
,
120 Child
, list
= ListviewObject
,
121 MUIA_Listview_List
, ListObject
,
124 Child
, coloradjust
= ColoradjustObject
,
126 TAG_MORE
, (IPTR
) msg
->ops_AttrList
);
128 if (obj
== NULL
) return (IPTR
)NULL
;
130 data
= INST_DATA(cl
, obj
);
133 data
->coloradjust
= coloradjust
;
135 data
->display_hook
.h_Entry
= HookEntry
;
136 data
->display_hook
.h_SubEntry
= (HOOKFUNC
)display_func
;
137 data
->display_hook
.h_Data
= data
;
138 data
->setcolor_hook
.h_Entry
= HookEntry
;
139 data
->setcolor_hook
.h_SubEntry
= (HOOKFUNC
)setcolor_func
;
140 data
->setcolor_hook
.h_Data
= data
;
142 nnset(list
, MUIA_List_DisplayHook
, (IPTR
)&data
->display_hook
);
144 data
->entries
= (struct MUI_Palette_Entry
*)GetTagData(MUIA_Palette_Entries
, 0, msg
->ops_AttrList
);
145 data
->names
= (const char**)GetTagData(MUIA_Palette_Names
, 0, msg
->ops_AttrList
);
146 data
->group
= GetTagData(MUIA_Palette_Groupable
, 0, msg
->ops_AttrList
);
148 data
->numentries
= 0;
151 data
->numentries
= 0;
152 while(e
->mpe_ID
!= MUIV_Palette_Entry_End
) {
158 data
->notifyclass
= cl
->cl_Super
->cl_Super
;
160 if (data
->numentries
> 0) {
161 for (i
= 0; i
< data
->numentries
; i
++) DoMethod(data
->list
,MUIM_List_InsertSingle
,&data
->entries
[i
],MUIV_List_Insert_Bottom
);
163 nnset(data
->coloradjust
, MUIA_Coloradjust_Red
, data
->entries
[0].mpe_Red
);
164 nnset(data
->coloradjust
, MUIA_Coloradjust_Green
, data
->entries
[0].mpe_Green
);
165 nnset(data
->coloradjust
, MUIA_Coloradjust_Blue
, data
->entries
[0].mpe_Blue
);
166 nnset(data
->list
, MUIA_List_Active
, 0);
168 data
->rgb
[0] = data
->entries
[0].mpe_Red
;
169 data
->rgb
[1] = data
->entries
[0].mpe_Green
;
170 data
->rgb
[2] = data
->entries
[0].mpe_Blue
;
172 DoMethod(data
->list
, MUIM_Notify
, MUIA_List_Active
, MUIV_EveryTime
, obj
, 5, MUIM_CallHook
, &data
->setcolor_hook
, 1, 0, data
);
173 DoMethod(data
->coloradjust
, MUIM_Notify
, MUIA_Coloradjust_Red
, MUIV_EveryTime
, obj
, 5, MUIM_CallHook
, &data
->setcolor_hook
, 2, 0, data
);
174 DoMethod(data
->coloradjust
, MUIM_Notify
, MUIA_Coloradjust_Green
, MUIV_EveryTime
, obj
, 5, MUIM_CallHook
, &data
->setcolor_hook
, 2, 1, data
);
175 DoMethod(data
->coloradjust
, MUIM_Notify
, MUIA_Coloradjust_Blue
, MUIV_EveryTime
, obj
, 5, MUIM_CallHook
, &data
->setcolor_hook
, 2, 2, data
);
179 /**************************************************************************
181 **************************************************************************/
182 IPTR
Palette__OM_SET(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
184 struct MUI_PaletteData
*data
;
185 struct TagItem
*tag
, *tags
;
187 data
= INST_DATA(cl
, obj
);
189 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem((const struct TagItem
**)&tags
)); )
193 case MUIA_Palette_Entries
:
194 data
->entries
= (struct MUI_Palette_Entry
*) tag
->ti_Data
;
197 case MUIA_Palette_Names
:
198 data
->names
= (const char **) tag
->ti_Data
;
201 case MUIA_Palette_Groupable
:
202 data
->group
= (ULONG
) tag
->ti_Data
;
206 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
209 /**************************************************************************
211 **************************************************************************/
212 IPTR
Palette__OM_GET(struct IClass
*cl
, Object
*obj
, struct opGet
*msg
)
214 struct MUI_PaletteData
*data
= INST_DATA(cl
, obj
);
216 IPTR
*store
= msg
->opg_Storage
;
218 switch(msg
->opg_AttrID
)
220 case MUIA_Palette_Entries
:
221 *store
= (IPTR
)&data
->entries
;
223 case MUIA_Palette_Names
:
224 *store
= (IPTR
)&data
->names
;
227 case MUIA_Coloradjust_Red
:
228 *store
= data
->rgb
[0];
231 case MUIA_Coloradjust_Green
:
232 *store
= data
->rgb
[1];
235 case MUIA_Coloradjust_Blue
:
236 *store
= data
->rgb
[2];
239 case MUIA_Coloradjust_RGB
:
240 *store
= (IPTR
)data
->rgb
;
243 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
245 /**************************************************************************
247 **************************************************************************/
249 IPTR
Palette__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
251 struct MUI_PaletteData
*data
;
253 data
= INST_DATA(cl
, obj
);
255 return DoSuperMethodA(cl
, obj
, msg
);
258 #if ZUNE_BUILTIN_PALETTE
260 BOOPSI_DISPATCHER(IPTR
, Palette_Dispatcher
, cl
, obj
, msg
)
262 switch (msg
->MethodID
)
264 case OM_NEW
: return Palette__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
265 case OM_SET
: return Palette__OM_SET(cl
, obj
, (struct opSet
*)msg
);
266 case OM_GET
: return Palette__OM_GET(cl
, obj
, (struct opGet
*)msg
);
267 case OM_DISPOSE
: return Palette__OM_DISPOSE(cl
, obj
, (struct opGet
*)msg
);
268 default: return DoSuperMethodA(cl
, obj
, msg
);
271 BOOPSI_DISPATCHER_END
276 const struct __MUIBuiltinClass _MUI_Palette_desc
= {
279 sizeof(struct MUI_PaletteData
),
280 (void*)Palette_Dispatcher