Some code using SetRGB32() missed code checking wether the
[tangerine.git] / workbench / libs / muimaster / classes / colorfield.c
blobe4ca2e4182a98c37ddc29a00157de169c9bd00b4
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>
10 #include <graphics/gfx.h>
11 #include <graphics/view.h>
12 #include <graphics/gfxmacros.h>
13 #include <clib/alib_protos.h>
14 #include <proto/exec.h>
15 #include <proto/graphics.h>
16 #include <proto/utility.h>
17 #include <proto/intuition.h>
18 #include <proto/muimaster.h>
20 #include <string.h>
22 #include "mui.h"
23 #include "muimaster_intern.h"
24 #include "textengine.h"
25 #include "support.h"
26 #include "support_classes.h"
27 #include "colorfield_private.h"
29 /* #define MYDEBUG 1 */
30 #include "debug.h"
32 extern struct Library *MUIMasterBase;
34 #define FLAG_FIXED_PEN 1
35 #define FLAG_PEN_ALLOCATED 2
36 #define FLAG_NO_PEN 4
39 IPTR Colorfield__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
41 struct Colorfield_DATA *data;
42 struct TagItem *tag, *tags;
43 ULONG *rgb;
45 obj = (Object *)DoSuperMethodA(cl, obj, (Msg)msg);
46 if (!obj) return FALSE;
48 data = INST_DATA(cl, obj);
50 /* parse initial taglist */
51 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
53 switch (tag->ti_Tag)
55 case MUIA_Colorfield_Red:
56 data->rgb[0] = (ULONG)tag->ti_Data;
57 break;
59 case MUIA_Colorfield_Green:
60 data->rgb[1] = (ULONG)tag->ti_Data;
61 break;
63 case MUIA_Colorfield_Blue:
64 data->rgb[2] = (ULONG)tag->ti_Data;
65 break;
67 case MUIA_Colorfield_RGB:
68 rgb = (ULONG *)tag->ti_Data;
69 data->rgb[0] = *rgb++;
70 data->rgb[1] = *rgb++;
71 data->rgb[2] = *rgb++;
72 break;
74 case MUIA_Colorfield_Pen:
75 data->pen = (UBYTE)tag->ti_Data;
76 data->pen = FLAG_FIXED_PEN;
77 break;
82 return (IPTR)obj;
85 IPTR Colorfield__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
87 struct Colorfield_DATA *data;
88 struct TagItem *tag, *tags;
89 ULONG *rgb;
90 BOOL newcol = FALSE;
91 IPTR retval;
93 data = INST_DATA(cl, obj);
95 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
97 switch (tag->ti_Tag)
99 case MUIA_Colorfield_Red:
100 data->rgb[0] = (ULONG)tag->ti_Data;
101 newcol = TRUE;
102 break;
104 case MUIA_Colorfield_Green:
105 data->rgb[1] = (ULONG)tag->ti_Data;
106 newcol = TRUE;
107 break;
109 case MUIA_Colorfield_Blue:
110 data->rgb[2] = (ULONG)tag->ti_Data;
111 newcol = TRUE;
112 break;
114 case MUIA_Colorfield_RGB:
115 rgb = (ULONG *)tag->ti_Data;
116 data->rgb[0] = *rgb++;
117 data->rgb[1] = *rgb++;
118 data->rgb[2] = *rgb++;
119 newcol = TRUE;
120 break;
122 case MUIA_Colorfield_Pen:
123 if (data->flags & FLAG_PEN_ALLOCATED)
125 ReleasePen(_screen(obj)->ViewPort.ColorMap, data->pen);
126 data->flags &= ~(FLAG_PEN_ALLOCATED | FLAG_NO_PEN);
128 data->pen = (UBYTE)data->pen;
129 data->flags |= FLAG_FIXED_PEN;
130 break;
135 retval = DoSuperMethodA(cl, obj, (Msg)msg);
137 if (newcol && (_flags(obj) & MADF_SETUP) && !(data->flags & FLAG_NO_PEN))
139 SetRGB32(&_screen(obj)->ViewPort, data->pen, data->rgb[0], data->rgb[1], data->rgb[2]);
141 if (GetBitMapAttr(_rp(obj)->BitMap, BMA_DEPTH) > 8)
143 MUI_Redraw(obj, MADF_DRAWUPDATE);
147 return retval;
150 IPTR Colorfield__OM_GET(struct IClass *cl, Object * obj, struct opGet *msg)
152 struct Colorfield_DATA *data = INST_DATA(cl, obj);
153 IPTR *store = msg->opg_Storage;
155 switch (msg->opg_AttrID)
157 case MUIA_Colorfield_Red:
158 *store = data->rgb[0];
159 break;
161 case MUIA_Colorfield_Green:
162 *store = data->rgb[1];
163 break;
165 case MUIA_Colorfield_Blue:
166 *store = data->rgb[2];
167 break;
169 case MUIA_Colorfield_RGB:
170 *(ULONG **)store = data->rgb;
171 break;
173 case MUIA_Colorfield_Pen:
174 *store = data->pen;
175 break;
177 default:
178 return DoSuperMethodA(cl, obj, (Msg)msg);
181 return TRUE;
184 IPTR Colorfield__MUIM_Setup(struct IClass *cl, Object *obj, struct MUIP_Setup *msg)
186 struct Colorfield_DATA *data = INST_DATA(cl,obj);
188 if (!(DoSuperMethodA(cl, obj, (Msg)msg))) return 0;
190 if (data->flags & FLAG_FIXED_PEN)
192 SetRGB32(&_screen(obj)->ViewPort,
193 data->pen,
194 data->rgb[0],
195 data->rgb[1],
196 data->rgb[2]);
198 else
200 LONG pen;
202 pen = ObtainPen(_screen(obj)->ViewPort.ColorMap,
203 (ULONG)-1,
204 data->rgb[0],
205 data->rgb[1],
206 data->rgb[2],
207 PENF_EXCLUSIVE);
209 if (pen == -1)
211 data->flags |= FLAG_NO_PEN;
212 data->pen = 0;
214 else
216 data->pen = (UBYTE)pen;
217 data->flags |= FLAG_PEN_ALLOCATED;
221 return 1;
224 IPTR Colorfield__MUIM_Cleanup(struct IClass *cl, Object *obj, struct MUIP_Cleanup *msg)
226 struct Colorfield_DATA *data = INST_DATA(cl,obj);
228 if (data->flags & FLAG_PEN_ALLOCATED)
230 ReleasePen(_screen(obj)->ViewPort.ColorMap, data->pen);
231 data->flags &= ~FLAG_PEN_ALLOCATED;
232 data->pen = 0;
234 data->flags &= ~FLAG_NO_PEN;
236 return DoSuperMethodA(cl, obj, (Msg)msg);
239 IPTR Colorfield__MUIM_AskMinMax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg)
241 DoSuperMethodA(cl,obj,(Msg)msg);
243 msg->MinMaxInfo->MinWidth += 1;
244 msg->MinMaxInfo->MinHeight += 1;
245 msg->MinMaxInfo->DefWidth += 16;
246 msg->MinMaxInfo->DefHeight += 16;
247 msg->MinMaxInfo->MaxWidth = MUI_MAXMAX;
248 msg->MinMaxInfo->MaxHeight = MUI_MAXMAX;
250 return 0;
253 IPTR Colorfield__MUIM_Draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg)
255 struct Colorfield_DATA *data = INST_DATA(cl,obj);
257 DoSuperMethodA(cl,obj,(Msg)msg);
259 if (!(msg->flags & (MADF_DRAWOBJECT | MADF_DRAWUPDATE)))
260 return FALSE;
262 if (data->flags & FLAG_NO_PEN)
264 static UWORD pat[] = {0x1111,0x2222,0x4444,0x8888};
266 SetAfPt(_rp(obj), pat, 2);
267 SetABPenDrMd(_rp(obj), _pens(obj)[MPEN_SHADOW], _pens(obj)[MPEN_BACKGROUND],JAM2);
270 else
272 SetABPenDrMd(_rp(obj), data->pen, 0,JAM1);
275 RectFill(_rp(obj), _mleft(obj), _mtop(obj), _mright(obj), _mbottom(obj));
277 SetAfPt(_rp(obj), NULL, 0);
279 return 0;
282 #if ZUNE_BUILTIN_COLORFIELD
283 BOOPSI_DISPATCHER(IPTR, Colorfield_Dispatcher, cl, obj, msg)
285 switch (msg->MethodID)
287 case OM_NEW: return Colorfield__OM_NEW(cl, obj, (struct opSet *)msg);
288 case OM_SET: return Colorfield__OM_SET(cl, obj, (struct opSet *)msg);
289 case OM_GET: return Colorfield__OM_GET(cl, obj, (struct opGet *)msg);
290 case MUIM_Setup: return Colorfield__MUIM_Setup(cl, obj, (struct MUIP_Setup *)msg);
291 case MUIM_Cleanup: return Colorfield__MUIM_Cleanup(cl, obj, (struct MUIP_Cleanup *)msg);
292 case MUIM_AskMinMax: return Colorfield__MUIM_AskMinMax(cl, obj, (struct MUIP_AskMinMax*)msg);
293 case MUIM_Draw: return Colorfield__MUIM_Draw(cl, obj, (struct MUIP_Draw*)msg);
294 default: return DoSuperMethodA(cl, obj, msg);
297 BOOPSI_DISPATCHER_END
299 const struct __MUIBuiltinClass _MUI_Colorfield_desc =
301 MUIC_Colorfield,
302 MUIC_Area,
303 sizeof(struct Colorfield_DATA),
304 (void*)Colorfield_Dispatcher
306 #endif /* ZUNE_BUILTIN_COLORFIELD */