revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / workbench / classes / zune / lamp / lamp.c
blobee2a7f32d7d460e10e4ef260c883cdc19fd1fc13
1 /*
2 Copyright © 2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <proto/alib.h>
9 #include <proto/muimaster.h>
10 #include <proto/intuition.h>
11 #include <proto/utility.h>
12 #include <proto/graphics.h>
14 #include "Lamp_mcc.h"
15 #include "lamp_private.h"
17 //#define DEBUG 1
18 #include <aros/debug.h>
20 // Values for lmp_PenChanged and lmp_PenChangedOld
21 #define PCH_NONE (0)
22 #define PCH_NEWPEN (1)
23 #define PCH_NEWSPEC (2)
25 // Lamp sizes from MUIV_Lamp_Type_Tiny to MUIV_Lamp_Type_Huge
26 const static ULONG lampsizes[] = {5, 6, 7, 8, 9};
28 // Lamp default colors
29 const static ULONG defaultcolors[][3] =
31 {0x00000000, 0x00000000, 0x00000000}, // MUIV_Lamp_Color_Off
32 {0x00000000, 0xffffffff, 0x00000000}, // MUIV_Lamp_Color_Ok
33 {0x80808080, 0x00000000, 0x00000000}, // MUIV_Lamp_Color_Warning
34 {0xc0c0c0c0, 0x00000000, 0x00000000}, // MUIV_Lamp_Color_Error
35 {0xffffffff, 0x00000000, 0x00000000}, // MUIV_Lamp_Color_FatalError
36 {0x00000000, 0xc0c0c0c0, 0x00000000}, // MUIV_Lamp_Color_Processing
37 {0xc0c0c0c0, 0x00000000, 0x00000000}, // MUIV_Lamp_Color_LookingUp
38 {0xffffffff, 0x00000000, 0x00000000}, // MUIV_Lamp_Color_Connecting
39 {0xffffffff, 0xffffffff, 0x00000000}, // MUIV_Lamp_Color_SendingData
40 {0x00000000, 0x00000000, 0xffffffff}, // MUIV_Lamp_Color_ReceivingData
41 {0x00000000, 0x00000000, 0xffffffff}, // MUIV_Lamp_Color_LoadingData
42 {0xffffffff, 0xffffffff, 0x00000000}, // MUIV_Lamp_Color_SavingData
46 /*** Methods ****************************************************************/
47 Object *Lamp__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
49 struct Lamp_DATA *data;
50 struct TagItem *tstate = msg->ops_AttrList;
51 struct TagItem *tag;
53 obj = (Object *)DoSuperMethodA(cl, obj, (Msg)msg);
54 if (!obj) return FALSE;
56 data = INST_DATA(cl, obj);
58 // Defaults
59 data->lmp_Type = MUIV_Lamp_Type_Medium;
60 data->lmp_ColorSpec = MUIV_Lamp_Color_Off;
61 data->lmp_Color[0] = defaultcolors[0][0];
62 data->lmp_Color[1] = defaultcolors[0][1];
63 data->lmp_Color[2] = defaultcolors[0][2];
64 data->lmp_ColorType = MUIV_Lamp_ColorType_UserDefined;
65 data->lmp_PenChanged = PCH_NEWPEN;
66 data->lmp_PenChangedOld = PCH_NONE;
67 data->lmp_PenNr = -1;
69 while ((tag = NextTagItem(&tstate)) != NULL)
71 switch (tag->ti_Tag)
73 case MUIA_Lamp_Type:
74 data->lmp_Type = tag->ti_Data;
75 break;
77 case MUIA_Lamp_Color:
78 if (tag->ti_Data < 12)
80 data->lmp_ColorSpec = tag->ti_Data;
81 data->lmp_Color[0] = defaultcolors[data->lmp_ColorSpec][0];
82 data->lmp_Color[1] = defaultcolors[data->lmp_ColorSpec][1];
83 data->lmp_Color[2] = defaultcolors[data->lmp_ColorSpec][2];
84 data->lmp_ColorType = MUIV_Lamp_ColorType_UserDefined;
86 else
88 ULONG *cols = (ULONG *)tag->ti_Data;
89 data->lmp_Color[0] = cols[0];
90 data->lmp_Color[1] = cols[1];
91 data->lmp_Color[2] = cols[2];
92 data->lmp_ColorType = MUIV_Lamp_ColorType_Color;
94 break;
96 case MUIA_Lamp_Red:
97 data->lmp_Color[0] = tag->ti_Data;
98 data->lmp_ColorType = MUIV_Lamp_ColorType_Color;
99 break;
101 case MUIA_Lamp_Green:
102 data->lmp_Color[1] = tag->ti_Data;
103 data->lmp_ColorType = MUIV_Lamp_ColorType_Color;
104 break;
106 case MUIA_Lamp_Blue:
107 data->lmp_Color[2] = tag->ti_Data;
108 data->lmp_ColorType = MUIV_Lamp_ColorType_Color;
109 break;
111 case MUIA_Lamp_PenSpec:
112 data->lmp_PenSpec = *((struct MUI_PenSpec *)tag->ti_Data);
113 data->lmp_ColorType = MUIV_Lamp_ColorType_PenSpec;
114 break;
118 return obj;
122 IPTR Lamp__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
124 struct Lamp_DATA *data = INST_DATA(cl, obj);
125 struct TagItem *tstate = msg->ops_AttrList;
126 struct TagItem *tag;
128 while ((tag = NextTagItem(&tstate)) != NULL)
130 switch (tag->ti_Tag)
132 case MUIA_Lamp_Type:
133 data->lmp_Type = tag->ti_Data;
134 MUI_Redraw(obj, MADF_DRAWUPDATE);
135 break;
137 case MUIA_Lamp_Color:
138 if (tag->ti_Data < 12)
140 data->lmp_ColorSpec = tag->ti_Data;
141 data->lmp_Color[0] = defaultcolors[data->lmp_ColorSpec][0];
142 data->lmp_Color[1] = defaultcolors[data->lmp_ColorSpec][1];
143 data->lmp_Color[2] = defaultcolors[data->lmp_ColorSpec][2];
144 data->lmp_ColorType = MUIV_Lamp_ColorType_UserDefined;
146 else
148 ULONG *cols = (ULONG *)tag->ti_Data;
149 data->lmp_Color[0] = cols[0];
150 data->lmp_Color[1] = cols[1];
151 data->lmp_Color[2] = cols[2];
152 data->lmp_ColorType = MUIV_Lamp_ColorType_Color;
154 data->lmp_PenChanged = PCH_NEWPEN;
155 MUI_Redraw(obj, MADF_DRAWUPDATE);
156 break;
158 case MUIA_Lamp_Red:
159 data->lmp_Color[0] = tag->ti_Data;
160 data->lmp_ColorType = MUIV_Lamp_ColorType_Color;
161 data->lmp_PenChanged = PCH_NEWPEN;
162 MUI_Redraw(obj, MADF_DRAWUPDATE);
163 break;
165 case MUIA_Lamp_Green:
166 data->lmp_Color[1] = tag->ti_Data;
167 data->lmp_ColorType = MUIV_Lamp_ColorType_Color;
168 data->lmp_PenChanged = PCH_NEWPEN;
169 MUI_Redraw(obj, MADF_DRAWUPDATE);
170 break;
172 case MUIA_Lamp_Blue:
173 data->lmp_Color[2] = tag->ti_Data;
174 data->lmp_ColorType = MUIV_Lamp_ColorType_Color;
175 data->lmp_PenChanged = PCH_NEWPEN;
176 MUI_Redraw(obj, MADF_DRAWUPDATE);
177 break;
179 case MUIA_Lamp_PenSpec:
180 data->lmp_PenSpec = *((struct MUI_PenSpec *)tag->ti_Data);
181 data->lmp_ColorType = MUIV_Lamp_ColorType_PenSpec;
182 data->lmp_PenChanged = PCH_NEWSPEC;
183 MUI_Redraw(obj, MADF_DRAWUPDATE);
184 break;
188 return DoSuperMethodA(cl, obj, (Msg) msg);
192 IPTR Lamp__OM_GET(struct IClass *cl, Object *obj, struct opGet *msg)
194 struct Lamp_DATA *data = INST_DATA(cl, obj);
195 IPTR *store = msg->opg_Storage;
197 switch (msg->opg_AttrID)
199 case MUIA_Lamp_Type:
200 *store = data->lmp_Type;
201 return TRUE;
203 case MUIA_Lamp_Color:
204 if (data->lmp_ColorType == MUIV_Lamp_ColorType_UserDefined)
206 *store = (IPTR)data->lmp_ColorSpec;
208 else if (data->lmp_ColorType == MUIV_Lamp_ColorType_Color)
210 *store = (IPTR)data->lmp_Color;
212 else // MUIV_Lamp_ColorType_PenSpec
214 *store = 0;
216 return TRUE;
218 case MUIA_Lamp_ColorType:
219 *store = data->lmp_ColorType;
220 return TRUE;
222 case MUIA_Lamp_Red:
223 *store = data->lmp_Color[0];
224 return TRUE;
226 case MUIA_Lamp_Green:
227 *store = data->lmp_Color[1];
228 return TRUE;
230 case MUIA_Lamp_Blue:
231 *store = data->lmp_Color[2];
232 return TRUE;
234 case MUIA_Lamp_PenSpec:
235 *store = (IPTR)&data->lmp_PenSpec;
236 return TRUE;
239 return DoSuperMethodA(cl, obj, (Msg) msg);
243 IPTR Lamp__MUIM_Cleanup(struct IClass *cl, Object *obj, Msg msg)
245 struct Lamp_DATA *data = INST_DATA(cl,obj);
247 if (data->lmp_PenChangedOld == PCH_NEWPEN)
249 if (data->lmp_PenNr != -1)
251 ReleasePen(_screen(obj)->ViewPort.ColorMap, data->lmp_PenNr);
252 data->lmp_PenNr = -1;
255 else if (data->lmp_PenChangedOld == PCH_NEWSPEC)
257 MUI_ReleasePen(muiRenderInfo(obj), data->lmp_PenNr);
260 if (data->lmp_PenChangedOld != PCH_NONE)
262 data->lmp_PenChanged = data->lmp_PenChangedOld;
263 data->lmp_PenChangedOld = PCH_NONE;
266 return DoSuperMethodA(cl, obj, msg);
270 IPTR Lamp__MUIM_Draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg)
272 struct Lamp_DATA *data = INST_DATA(cl, obj);
274 ULONG right, bottom;
276 DoSuperMethodA(cl, obj, (Msg)msg);
278 if (!(msg->flags & (MADF_DRAWOBJECT | MADF_DRAWUPDATE)))
279 return 0;
281 if (data->lmp_PenChanged)
283 if (data->lmp_PenChangedOld == PCH_NEWPEN)
285 if (data->lmp_PenNr != -1)
287 ReleasePen(_screen(obj)->ViewPort.ColorMap, data->lmp_PenNr);
288 D(bug("[Lamp/Draw] released pen %u\n", data->lmp_PenNr));
289 data->lmp_PenNr = -1;
292 else if (data->lmp_PenChangedOld == PCH_NEWSPEC)
294 MUI_ReleasePen(muiRenderInfo(obj), data->lmp_PenNr);
295 D(bug("[Lamp/Draw] released MUI pen %u\n", data->lmp_PenNr));
298 if (data->lmp_PenChanged == PCH_NEWPEN)
300 data->lmp_PenNr = ObtainBestPen
302 _screen(obj)->ViewPort.ColorMap,
303 data->lmp_Color[0],
304 data->lmp_Color[1],
305 data->lmp_Color[2],
306 OBP_Precision, PRECISION_GUI,
307 TAG_DONE
309 D(bug("[Lamp/Draw] obtained pen %u r %u g %u b %u\n", data->lmp_PenNr,
310 data->lmp_Color[0], data->lmp_Color[1], data->lmp_Color[2]));
312 if (data->lmp_PenNr != -1)
314 SetAPen(_rp(obj), data->lmp_PenNr);
317 else if (data->lmp_PenChanged == PCH_NEWSPEC)
319 data->lmp_PenNr = MUI_ObtainPen(muiRenderInfo(obj), &data->lmp_PenSpec, 0);
320 D(bug("[Lamp/Draw] obtained MUI pen %u\n", data->lmp_PenNr));
321 SetAPen(_rp(obj), MUIPEN(data->lmp_PenNr));
324 data->lmp_PenChangedOld = data->lmp_PenChanged;
325 data->lmp_PenChanged = PCH_NONE;
328 right = _mleft(obj) + lampsizes[data->lmp_Type];
329 if (right > _mright(obj))
330 right = _mright(obj);
331 bottom = _mtop(obj) + lampsizes[data->lmp_Type];
332 if (bottom > _mbottom(obj))
333 bottom = _bottom(obj);
335 D(bug("[Lamp/Draw] right %d bottom %d\n", right, bottom));
337 RectFill(_rp(obj), _mleft(obj), _mtop(obj), right, bottom);
339 return 0;
343 IPTR Lamp__MUIM_AskMinMax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg)
345 struct Lamp_DATA *data = INST_DATA(cl, obj);
347 ULONG size = lampsizes[data->lmp_Type];
349 DoSuperMethodA(cl, obj, (Msg)msg);
351 msg->MinMaxInfo->MinWidth += size;
352 msg->MinMaxInfo->DefWidth += size;
353 msg->MinMaxInfo->MaxWidth += size;
355 msg->MinMaxInfo->MinHeight += size;
356 msg->MinMaxInfo->DefHeight += size;
357 msg->MinMaxInfo->MaxHeight += size;
359 return 0;
363 IPTR Lamp__MUIM_Lamp_SetRGB(struct IClass *cl, Object *obj, struct MUIP_Lamp_SetRGB *msg)
365 ULONG rgb[3];
367 rgb[0] = msg->red;
368 rgb[1] = msg->green;
369 rgb[2] = msg->blue;
371 SET(obj, MUIA_Lamp_Color, rgb);
373 return 0;