Removed the unnecessary inner group: the list and scrollbar are now
[AROS.git] / workbench / libs / muimaster / classes / penadjust.c
blob9da4ea17d5838aae7c6cb612e8db11342c9d0ab8
1 /*
2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <stdio.h>
9 #include <stdlib.h>
11 #include <graphics/gfx.h>
12 #include <graphics/view.h>
13 #include <clib/alib_protos.h>
15 #include <proto/dos.h>
16 #include <proto/exec.h>
17 #include <proto/graphics.h>
18 #include <proto/utility.h>
19 #include <proto/intuition.h>
20 #include <proto/muimaster.h>
22 #include <string.h>
24 #define MYDEBUG 1
25 #include "debug.h"
26 #include "mui.h"
27 #include "muimaster_intern.h"
28 #include "support.h"
29 #include "support_classes.h"
30 #include "penspec.h"
31 #include "penadjust_private.h"
33 extern struct Library *MUIMasterBase;
35 static void UpdateState(Object *obj, struct Penadjust_DATA *data)
37 zune_pen_spec_to_intern(&data->penspec, &data->intpenspec);
39 switch (data->intpenspec.p_type)
41 case PST_MUI:
42 set(data->listobj, MUIA_List_Active, data->intpenspec.p_mui);
43 set(obj, MUIA_Group_ActivePage, 0);
44 break;
46 case PST_CMAP:
47 set(data->sliderobj, MUIA_Numeric_Value, data->intpenspec.p_cmap);
48 set(obj, MUIA_Group_ActivePage, 1);
49 break;
51 case PST_RGB:
52 set(data->coloradjobj, MUIA_Coloradjust_RGB,
53 (IPTR) & data->intpenspec.p_rgb);
54 set(obj, MUIA_Group_ActivePage, 2);
55 break;
57 case PST_SYS:
58 break;
62 static void UpdatePenspec(Object *obj, struct Penadjust_DATA *data)
64 IPTR val;
66 val = 0;
67 get(obj, MUIA_Group_ActivePage, &val);
69 switch (val)
71 case 0:
72 data->intpenspec.p_type = PST_MUI;
74 val = 0;
75 get(data->listobj, MUIA_List_Active, &val);
76 data->intpenspec.p_mui = (LONG) val;
77 break;
79 case 1:
80 data->intpenspec.p_type = PST_CMAP;
82 val = 0;
83 get(data->sliderobj, MUIA_Numeric_Value, &val);
84 data->intpenspec.p_cmap = (LONG) val;
85 break;
87 case 2:
88 data->intpenspec.p_type = PST_RGB;
90 val = 0;
91 get(data->coloradjobj, MUIA_Coloradjust_Red, &val);
92 data->intpenspec.p_rgb.red = (ULONG) val;
93 val = 0;
94 get(data->coloradjobj, MUIA_Coloradjust_Green, &val);
95 data->intpenspec.p_rgb.green = (ULONG) val;
96 val = 0;
97 get(data->coloradjobj, MUIA_Coloradjust_Blue, &val);
98 data->intpenspec.p_rgb.blue = (ULONG) val;
101 zune_pen_intern_to_spec(&data->intpenspec, &data->penspec);
103 D(bug(" ## penspec now %s\n", &data->penspec));
106 static IPTR MuipenDisplayFunc(struct Hook *hook, char **array, char *entry)
108 LONG line;
109 static char buf[16];
111 line = (SIPTR) array[-1];
112 if (line < 0 || line > 7)
113 line = 0;
114 snprintf(buf, sizeof(buf), "\033I[2:m%d]", (int)line);
116 *array++ = buf;
117 *array++ = "";
118 *array = entry;
120 return 0;
123 IPTR Penadjust__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
125 static const char *const register_labels[] =
126 { "MUI", "Colormap", "RGB", NULL };
127 static const char *const lv_labels[] =
128 { "Shine", "Halfshine", "Background", "Halfshadow", "Shadow",
129 "Text", "Fill", "Mark", NULL };
130 static const struct Hook muipen_display_hook =
131 { {NULL, NULL}, HookEntry, MuipenDisplayFunc, NULL };
133 struct Penadjust_DATA *data;
134 struct TagItem *tags;
135 struct TagItem *tag;
136 Object *listobj, *sliderobj, *coloradjobj;
138 obj = (Object *) DoSuperNewTags
140 cl, obj, NULL,
142 MUIA_Register_Titles, (IPTR) register_labels,
143 Child, (IPTR) ListviewObject,
144 MUIA_Listview_List, (IPTR) (listobj = (Object *)ListObject,
145 InputListFrame,
146 MUIA_List_SourceArray, (IPTR) lv_labels,
147 MUIA_List_Format, (IPTR) ",,",
148 MUIA_List_DisplayHook, (IPTR) &muipen_display_hook,
149 End),
150 End,
151 Child, (IPTR) (sliderobj = (Object *)SliderObject,
152 MUIA_Slider_Horiz, TRUE,
153 MUIA_Numeric_Min, -128,
154 MUIA_Numeric_Max, 127,
155 End),
156 Child, (IPTR) (coloradjobj = (Object *)ColoradjustObject, End),
158 TAG_MORE, (IPTR) msg->ops_AttrList
161 if (!obj)
162 return FALSE;
164 data = INST_DATA(cl, obj);
166 data->listobj = listobj;
167 data->sliderobj = sliderobj;
168 data->coloradjobj = coloradjobj;
170 strcpy(data->penspec.ps_buf, "m5");
172 /* parse initial taglist */
173 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags));)
175 switch (tag->ti_Tag)
177 case MUIA_Penadjust_Spec:
178 data->penspec = *(struct MUI_PenSpec *)tag->ti_Data;
179 break;
183 UpdateState(obj, data);
185 return (IPTR) obj;
188 IPTR Penadjust__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
190 struct TagItem *tags;
191 struct TagItem *tag;
192 struct Penadjust_DATA *data = INST_DATA(cl, obj);
193 BOOL update = FALSE;
195 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags));)
197 switch (tag->ti_Tag)
199 case MUIA_Penadjust_Spec:
200 data->penspec = *(struct MUI_PenSpec *)tag->ti_Data;
201 update = TRUE;
202 break;
206 if (update)
207 UpdateState(obj, data);
209 return DoSuperMethodA(cl, obj, (Msg) msg);
212 IPTR Penadjust__OM_GET(struct IClass *cl, Object *obj, struct opGet *msg)
214 struct Penadjust_DATA *data = INST_DATA(cl, obj);
215 IPTR *store = msg->opg_Storage;
217 switch (msg->opg_AttrID)
219 case MUIA_Penadjust_Spec:
220 UpdatePenspec(obj, data);
221 *store = (IPTR) & data->penspec;
222 break;
224 default:
225 return DoSuperMethodA(cl, obj, (Msg) msg);
229 return TRUE;
232 #if ZUNE_BUILTIN_PENADJUST
233 BOOPSI_DISPATCHER(IPTR, Penadjust_Dispatcher, cl, obj, msg)
235 switch (msg->MethodID)
237 case OM_NEW:
238 return Penadjust__OM_NEW(cl, obj, (struct opSet *)msg);
239 case OM_SET:
240 return Penadjust__OM_SET(cl, obj, (struct opSet *)msg);
241 case OM_GET:
242 return Penadjust__OM_GET(cl, obj, (APTR) msg);
243 default:
244 return DoSuperMethodA(cl, obj, msg);
247 BOOPSI_DISPATCHER_END
249 const struct __MUIBuiltinClass _MUI_Penadjust_desc =
251 MUIC_Penadjust,
252 MUIC_Register,
253 sizeof(struct Penadjust_DATA),
254 (void *) Penadjust_Dispatcher
256 #endif /* ZUNE_BUILTIN_PENADJUST */