Some fix for scrolling with lasso.
[tangerine.git] / workbench / libs / muimaster / classes / penadjust.c
blob8f8002d8aa264b33397c3a58e680976a7747e239
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, (IPTR) &data->intpenspec.p_rgb);
53 set(obj, MUIA_Group_ActivePage, 2);
54 break;
56 case PST_SYS:
57 break;
61 static void UpdatePenspec(Object *obj, struct Penadjust_DATA *data)
63 IPTR val;
65 get(obj, MUIA_Group_ActivePage, &val);
67 switch(val)
69 case 0:
70 data->intpenspec.p_type = PST_MUI;
72 get(data->listobj, MUIA_List_Active, &val);
73 data->intpenspec.p_mui = (LONG)val;
74 break;
76 case 1:
77 data->intpenspec.p_type = PST_CMAP;
79 get(data->sliderobj, MUIA_Numeric_Value, &val);
80 data->intpenspec.p_cmap = (LONG)val;
81 break;
83 case 2:
84 data->intpenspec.p_type = PST_RGB;
86 get(data->coloradjobj, MUIA_Coloradjust_Red, &val);
87 data->intpenspec.p_rgb.red = (ULONG)val;
88 get(data->coloradjobj, MUIA_Coloradjust_Green, &val);
89 data->intpenspec.p_rgb.green = (ULONG)val;
90 get(data->coloradjobj, MUIA_Coloradjust_Blue, &val);
91 data->intpenspec.p_rgb.blue = (ULONG)val;
94 zune_pen_intern_to_spec(&data->intpenspec, &data->penspec);
96 D(bug(" ## penspec now %s\n", &data->penspec));
99 static IPTR MuipenDisplayFunc(struct Hook *hook, char **array, char *entry)
101 LONG line;
102 static char buf[16];
104 line = (LONG)array[-1];
105 if (line < 0 || line > 7)
106 line = 0;
107 snprintf(buf, sizeof(buf), "\33I[2:m%ld]", line);
109 *array++ = buf;
110 *array++ = "";
111 *array = entry;
113 return 0;
116 IPTR Penadjust__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
118 static const char * const register_labels[] = {"MUI", "Colormap", "RGB", NULL};
119 static const char * const lv_labels[] = {"Shine", "Halfshine", "Background", "Halfshadow", "Shadow", "Text", "Fill", "Mark", NULL};
120 static const struct Hook muipen_display_hook = { {NULL, NULL}, HookEntry, MuipenDisplayFunc, NULL };
122 struct Penadjust_DATA *data;
123 struct TagItem *tag, *tags;
124 Object *listobj, *sliderobj, *coloradjobj;
126 obj = (Object *) DoSuperNewTags
128 cl, obj, NULL,
130 MUIA_Register_Titles, (IPTR) register_labels,
131 Child, (IPTR) ListviewObject,
132 MUIA_Listview_List, (IPTR) (listobj = ListObject,
133 InputListFrame,
134 MUIA_List_SourceArray, (IPTR) lv_labels,
135 MUIA_List_Format, (IPTR) ",,",
136 MUIA_List_DisplayHook, (IPTR) &muipen_display_hook,
137 End),
138 End,
139 Child, (IPTR) (sliderobj = SliderObject,
140 MUIA_Slider_Horiz, TRUE,
141 MUIA_Numeric_Min, -128,
142 MUIA_Numeric_Max, 127,
143 End),
144 Child, (IPTR) (coloradjobj = ColoradjustObject, End),
146 TAG_MORE, (IPTR) msg->ops_AttrList
149 if (!obj) return FALSE;
151 data = INST_DATA(cl, obj);
153 data->listobj = listobj;
154 data->sliderobj = sliderobj;
155 data->coloradjobj = coloradjobj;
157 strcpy(data->penspec.ps_buf, "m5");
159 /* parse initial taglist */
160 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
162 switch (tag->ti_Tag)
164 case MUIA_Penadjust_Spec:
165 data->penspec = *(struct MUI_PenSpec *)tag->ti_Data;
166 break;
170 UpdateState(obj, data);
172 return (IPTR)obj;
175 IPTR Penadjust__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
177 struct TagItem *tags,*tag;
178 struct Penadjust_DATA *data = INST_DATA(cl, obj);
179 BOOL update = FALSE;
181 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
183 switch (tag->ti_Tag)
185 case MUIA_Penadjust_Spec:
186 data->penspec = *(struct MUI_PenSpec *)tag->ti_Data;
187 update = TRUE;
188 break;
192 if (update) UpdateState(obj, data);
194 return DoSuperMethodA(cl,obj,(Msg)msg);
197 IPTR Penadjust__OM_GET(struct IClass *cl, Object *obj, struct opGet *msg)
199 struct Penadjust_DATA *data = INST_DATA(cl, obj);
200 IPTR *store = msg->opg_Storage;
202 switch(msg->opg_AttrID)
204 case MUIA_Penadjust_Spec:
205 UpdatePenspec(obj, data);
206 *store = (IPTR)&data->penspec;
207 break;
209 default:
210 return DoSuperMethodA(cl, obj, (Msg) msg);
214 return TRUE;
217 #if ZUNE_BUILTIN_PENADJUST
218 BOOPSI_DISPATCHER(IPTR, Penadjust_Dispatcher, cl, obj, msg)
220 switch (msg->MethodID)
222 case OM_NEW: return Penadjust__OM_NEW(cl, obj, (struct opSet *)msg);
223 case OM_SET: return Penadjust__OM_SET(cl, obj, (struct opSet *)msg);
224 case OM_GET: return Penadjust__OM_GET(cl,obj,(APTR)msg);
225 default: return DoSuperMethodA(cl, obj, msg);
228 BOOPSI_DISPATCHER_END
230 const struct __MUIBuiltinClass _MUI_Penadjust_desc =
232 MUIC_Penadjust,
233 MUIC_Register,
234 sizeof(struct Penadjust_DATA),
235 (void*)Penadjust_Dispatcher
237 #endif /* ZUNE_BUILTIN_PENADJUST */