2 Copyright © 2011, The AROS Development Team. All rights reserved.
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>
15 #include "lamp_private.h"
18 #include <aros/debug.h>
20 // Values for lmp_PenChanged and lmp_PenChangedOld
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
;
53 obj
= (Object
*)DoSuperMethodA(cl
, obj
, (Msg
)msg
);
54 if (!obj
) return FALSE
;
56 data
= INST_DATA(cl
, obj
);
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
;
69 while ((tag
= NextTagItem(&tstate
)) != NULL
)
74 data
->lmp_Type
= tag
->ti_Data
;
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
;
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
;
97 data
->lmp_Color
[0] = tag
->ti_Data
;
98 data
->lmp_ColorType
= MUIV_Lamp_ColorType_Color
;
101 case MUIA_Lamp_Green
:
102 data
->lmp_Color
[1] = tag
->ti_Data
;
103 data
->lmp_ColorType
= MUIV_Lamp_ColorType_Color
;
107 data
->lmp_Color
[2] = tag
->ti_Data
;
108 data
->lmp_ColorType
= MUIV_Lamp_ColorType_Color
;
111 case MUIA_Lamp_PenSpec
:
112 data
->lmp_PenSpec
= *((struct MUI_PenSpec
*)tag
->ti_Data
);
113 data
->lmp_ColorType
= MUIV_Lamp_ColorType_PenSpec
;
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
;
128 while ((tag
= NextTagItem(&tstate
)) != NULL
)
133 data
->lmp_Type
= tag
->ti_Data
;
134 MUI_Redraw(obj
, MADF_DRAWUPDATE
);
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
;
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
);
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
);
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
);
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
);
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
);
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
)
200 *store
= data
->lmp_Type
;
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
218 case MUIA_Lamp_ColorType
:
219 *store
= data
->lmp_ColorType
;
223 *store
= data
->lmp_Color
[0];
226 case MUIA_Lamp_Green
:
227 *store
= data
->lmp_Color
[1];
231 *store
= data
->lmp_Color
[2];
234 case MUIA_Lamp_PenSpec
:
235 *store
= (IPTR
)&data
->lmp_PenSpec
;
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
);
276 DoSuperMethodA(cl
, obj
, (Msg
)msg
);
278 if (!(msg
->flags
& (MADF_DRAWOBJECT
| MADF_DRAWUPDATE
)))
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
,
306 OBP_Precision
, PRECISION_GUI
,
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
);
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
;
363 IPTR
Lamp__MUIM_Lamp_SetRGB(struct IClass
*cl
, Object
*obj
, struct MUIP_Lamp_SetRGB
*msg
)
371 SET(obj
, MUIA_Lamp_Color
, rgb
);