use dmb/dsb from asm/cpu.h file.
[AROS.git] / workbench / libs / muimaster / classes / colorfield.c
blob385cfb83bba626dee8433758fdd50aa086dd3ad0
1 /*
2 Copyright © 2002-2015, 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 /****** Colorfield.mui/MUIA_Colorfield_Pen ***********************************
41 * NAME
42 * MUIA_Colorfield_Pen -- (V4) [ISG], ULONG
44 * FUNCTION
45 * The used pen. If not set explicitly, a new one is obtained
46 * automatically.
48 * This attribute was incorrectly documented as gettable-only in the MUI
49 * documentation.
51 ******************************************************************************
55 /****** Colorfield.mui/MUIA_Colorfield_Red ***********************************
57 * NAME
58 * MUIA_Colorfield_Red -- (V4) [ISG], ULONG
60 * FUNCTION
61 * The red component of the color field as an unsigned 32-bit value
62 * (0 to 0xFFFFFFFF).
64 * SEE ALSO
65 * MUIA_Colorfield_RGB, MUIA_Colorfield_Green, MUIA_Colorfield_Blue
67 ******************************************************************************
71 /****** Colorfield.mui/MUIA_Colorfield_Green *********************************
73 * NAME
74 * MUIA_Colorfield_Green -- (V4) [ISG], ULONG
76 * FUNCTION
77 * The green component of the color field as an unsigned 32-bit value
78 * (0 to 0xFFFFFFFF).
80 * SEE ALSO
81 * MUIA_Colorfield_RGB, MUIA_Colorfield_Red, MUIA_Colorfield_Blue
83 ******************************************************************************
87 /****** Colorfield.mui/MUIA_Colorfield_Blue **********************************
89 * NAME
90 * MUIA_Colorfield_Blue -- (V4) [ISG], ULONG
92 * FUNCTION
93 * The blue component of the color field as an unsigned 32-bit value
94 * (0 to 0xFFFFFFFF).
96 * SEE ALSO
97 * MUIA_Colorfield_RGB, MUIA_Colorfield_Red, MUIA_Colorfield_Green
99 ******************************************************************************
103 /****** Colorfield.mui/MUIA_Colorfield_RGB ***********************************
105 * NAME
106 * MUIA_Colorfield_RGB -- (V4) [ISG], ULONG *
108 * FUNCTION
109 * The red, green and blue components of the color field as an array of
110 * unsigned 32-bit values (0 to 0xFFFFFFFF).
112 * SEE ALSO
113 * MUIA_Colorfield_Red, MUIA_Colorfield_Green, MUIA_Colorfield_Blue
115 ******************************************************************************
119 IPTR Colorfield__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
121 struct Colorfield_DATA *data;
122 struct TagItem *tags;
123 struct TagItem *tag;
124 ULONG *rgb;
126 obj = (Object *) DoSuperMethodA(cl, obj, (Msg) msg);
127 if (!obj)
128 return FALSE;
130 data = INST_DATA(cl, obj);
132 /* parse initial taglist */
133 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags));)
135 switch (tag->ti_Tag)
137 case MUIA_Colorfield_Red:
138 data->rgb[0] = (ULONG) tag->ti_Data;
139 break;
141 case MUIA_Colorfield_Green:
142 data->rgb[1] = (ULONG) tag->ti_Data;
143 break;
145 case MUIA_Colorfield_Blue:
146 data->rgb[2] = (ULONG) tag->ti_Data;
147 break;
149 case MUIA_Colorfield_RGB:
150 rgb = (ULONG *) tag->ti_Data;
151 data->rgb[0] = *rgb++;
152 data->rgb[1] = *rgb++;
153 data->rgb[2] = *rgb++;
154 break;
156 case MUIA_Colorfield_Pen:
157 data->pen = (UBYTE) tag->ti_Data;
158 data->flags |= FLAG_FIXED_PEN;
159 break;
164 return (IPTR) obj;
167 IPTR Colorfield__OM_SET(struct IClass *cl, Object *obj,
168 struct opSet *msg)
170 struct Colorfield_DATA *data;
171 struct opSet supMsg;
172 struct TagItem *tags;
173 struct TagItem *tag;
174 ULONG *rgb;
175 BOOL newcol = FALSE;
176 IPTR retval;
177 struct TagItem extra_tags[] = {{TAG_IGNORE, 0}, {TAG_IGNORE, 0},
178 {TAG_IGNORE, 0}, {TAG_IGNORE, 0},
179 {TAG_MORE, (IPTR)msg->ops_AttrList}};
181 data = INST_DATA(cl, obj);
183 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags));)
185 switch (tag->ti_Tag)
187 case MUIA_Colorfield_Red:
188 data->rgb[0] = (ULONG) tag->ti_Data;
189 newcol = TRUE;
190 extra_tags[3].ti_Tag = MUIA_Colorfield_RGB;
191 break;
193 case MUIA_Colorfield_Green:
194 data->rgb[1] = (ULONG) tag->ti_Data;
195 newcol = TRUE;
196 extra_tags[3].ti_Tag = MUIA_Colorfield_RGB;
197 break;
199 case MUIA_Colorfield_Blue:
200 data->rgb[2] = (ULONG) tag->ti_Data;
201 newcol = TRUE;
202 extra_tags[3].ti_Tag = MUIA_Colorfield_RGB;
203 break;
205 case MUIA_Colorfield_RGB:
206 rgb = (ULONG *) tag->ti_Data;
207 data->rgb[0] = *rgb++;
208 data->rgb[1] = *rgb++;
209 data->rgb[2] = *rgb++;
210 newcol = TRUE;
211 extra_tags[0].ti_Tag = MUIA_Colorfield_Red;
212 extra_tags[1].ti_Tag = MUIA_Colorfield_Green;
213 extra_tags[2].ti_Tag = MUIA_Colorfield_Blue;
214 break;
216 case MUIA_Colorfield_Pen:
217 if (data->flags & FLAG_PEN_ALLOCATED)
219 ReleasePen(_screen(obj)->ViewPort.ColorMap, data->pen);
220 data->flags &= ~(FLAG_PEN_ALLOCATED | FLAG_NO_PEN);
222 data->pen = (UBYTE) tag->ti_Data;
223 data->flags |= FLAG_FIXED_PEN;
224 newcol = TRUE;
225 break;
230 /* Prepare notification values for inter-dependent attributes */
231 extra_tags[0].ti_Data = data->rgb[0];
232 extra_tags[1].ti_Data = data->rgb[1];
233 extra_tags[2].ti_Data = data->rgb[2];
234 extra_tags[3].ti_Data = (IPTR) data->rgb;
235 supMsg.MethodID = msg->MethodID;
236 supMsg.ops_AttrList = extra_tags;
237 supMsg.ops_GInfo = msg->ops_GInfo;
239 retval = DoSuperMethodA(cl, obj, (Msg) &supMsg);
241 if (newcol && (_flags(obj) & MADF_SETUP)
242 && !(data->flags & FLAG_NO_PEN))
244 SetRGB32(&_screen(obj)->ViewPort, data->pen, data->rgb[0],
245 data->rgb[1], data->rgb[2]);
247 if (GetBitMapAttr(_rp(obj)->BitMap, BMA_DEPTH) > 8)
249 MUI_Redraw(obj, MADF_DRAWUPDATE);
253 return retval;
256 IPTR Colorfield__OM_GET(struct IClass *cl, Object *obj,
257 struct opGet *msg)
259 struct Colorfield_DATA *data = INST_DATA(cl, obj);
260 IPTR *store = msg->opg_Storage;
262 switch (msg->opg_AttrID)
264 case MUIA_Colorfield_Red:
265 *store = data->rgb[0];
266 break;
268 case MUIA_Colorfield_Green:
269 *store = data->rgb[1];
270 break;
272 case MUIA_Colorfield_Blue:
273 *store = data->rgb[2];
274 break;
276 case MUIA_Colorfield_RGB:
277 *(ULONG **) store = data->rgb;
278 break;
280 case MUIA_Colorfield_Pen:
281 *store = data->pen;
282 break;
284 default:
285 return DoSuperMethodA(cl, obj, (Msg) msg);
288 return TRUE;
291 IPTR Colorfield__MUIM_Setup(struct IClass *cl, Object *obj,
292 struct MUIP_Setup *msg)
294 struct Colorfield_DATA *data = INST_DATA(cl, obj);
296 if (!(DoSuperMethodA(cl, obj, (Msg) msg)))
297 return 0;
299 if (data->flags & FLAG_FIXED_PEN)
301 SetRGB32(&_screen(obj)->ViewPort,
302 data->pen, data->rgb[0], data->rgb[1], data->rgb[2]);
304 else
306 LONG pen;
308 pen = ObtainPen(_screen(obj)->ViewPort.ColorMap,
309 (ULONG) -1,
310 data->rgb[0], data->rgb[1], data->rgb[2], PENF_EXCLUSIVE);
312 if (pen == -1)
314 data->flags |= FLAG_NO_PEN;
315 data->pen = 0;
317 else
319 data->pen = (UBYTE) pen;
320 data->flags |= FLAG_PEN_ALLOCATED;
324 return 1;
327 IPTR Colorfield__MUIM_Cleanup(struct IClass *cl, Object *obj,
328 struct MUIP_Cleanup *msg)
330 struct Colorfield_DATA *data = INST_DATA(cl, obj);
332 if (data->flags & FLAG_PEN_ALLOCATED)
334 ReleasePen(_screen(obj)->ViewPort.ColorMap, data->pen);
335 data->flags &= ~FLAG_PEN_ALLOCATED;
336 data->pen = 0;
338 data->flags &= ~FLAG_NO_PEN;
340 return DoSuperMethodA(cl, obj, (Msg) msg);
343 IPTR Colorfield__MUIM_AskMinMax(struct IClass *cl, Object *obj,
344 struct MUIP_AskMinMax *msg)
346 DoSuperMethodA(cl, obj, (Msg) msg);
348 msg->MinMaxInfo->MinWidth += 1;
349 msg->MinMaxInfo->MinHeight += 1;
350 msg->MinMaxInfo->DefWidth += 16;
351 msg->MinMaxInfo->DefHeight += 16;
352 msg->MinMaxInfo->MaxWidth = MUI_MAXMAX;
353 msg->MinMaxInfo->MaxHeight = MUI_MAXMAX;
355 return 0;
358 IPTR Colorfield__MUIM_Draw(struct IClass *cl, Object *obj,
359 struct MUIP_Draw *msg)
361 struct Colorfield_DATA *data = INST_DATA(cl, obj);
363 DoSuperMethodA(cl, obj, (Msg) msg);
365 if (!(msg->flags & (MADF_DRAWOBJECT | MADF_DRAWUPDATE)))
366 return FALSE;
368 if (data->flags & FLAG_NO_PEN)
370 static UWORD pat[] = { 0x1111, 0x2222, 0x4444, 0x8888 };
372 SetAfPt(_rp(obj), pat, 2);
373 SetABPenDrMd(_rp(obj), _pens(obj)[MPEN_SHADOW],
374 _pens(obj)[MPEN_BACKGROUND], JAM2);
377 else
379 SetABPenDrMd(_rp(obj), data->pen, 0, JAM1);
382 RectFill(_rp(obj), _mleft(obj), _mtop(obj), _mright(obj),
383 _mbottom(obj));
385 SetAfPt(_rp(obj), NULL, 0);
387 return 0;
390 #if ZUNE_BUILTIN_COLORFIELD
391 BOOPSI_DISPATCHER(IPTR, Colorfield_Dispatcher, cl, obj, msg)
393 switch (msg->MethodID)
395 case OM_NEW:
396 return Colorfield__OM_NEW(cl, obj, (struct opSet *)msg);
397 case OM_SET:
398 return Colorfield__OM_SET(cl, obj, (struct opSet *)msg);
399 case OM_GET:
400 return Colorfield__OM_GET(cl, obj, (struct opGet *)msg);
401 case MUIM_Setup:
402 return Colorfield__MUIM_Setup(cl, obj, (struct MUIP_Setup *)msg);
403 case MUIM_Cleanup:
404 return Colorfield__MUIM_Cleanup(cl, obj,
405 (struct MUIP_Cleanup *)msg);
406 case MUIM_AskMinMax:
407 return Colorfield__MUIM_AskMinMax(cl, obj,
408 (struct MUIP_AskMinMax *)msg);
409 case MUIM_Draw:
410 return Colorfield__MUIM_Draw(cl, obj, (struct MUIP_Draw *)msg);
411 default:
412 return DoSuperMethodA(cl, obj, msg);
415 BOOPSI_DISPATCHER_END
417 const struct __MUIBuiltinClass _MUI_Colorfield_desc =
419 MUIC_Colorfield,
420 MUIC_Area,
421 sizeof(struct Colorfield_DATA),
422 (void *) Colorfield_Dispatcher
424 #endif /* ZUNE_BUILTIN_COLORFIELD */