Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / muimaster / classes / colorfield.c
blob864f3292b8aa2d4a553ed1f29981772521f8e13c
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 const struct TagItem *tags;
43 struct TagItem *tag;
44 ULONG *rgb;
46 obj = (Object *)DoSuperMethodA(cl, obj, (Msg)msg);
47 if (!obj) return FALSE;
49 data = INST_DATA(cl, obj);
51 /* parse initial taglist */
52 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
54 switch (tag->ti_Tag)
56 case MUIA_Colorfield_Red:
57 data->rgb[0] = (ULONG)tag->ti_Data;
58 break;
60 case MUIA_Colorfield_Green:
61 data->rgb[1] = (ULONG)tag->ti_Data;
62 break;
64 case MUIA_Colorfield_Blue:
65 data->rgb[2] = (ULONG)tag->ti_Data;
66 break;
68 case MUIA_Colorfield_RGB:
69 rgb = (ULONG *)tag->ti_Data;
70 data->rgb[0] = *rgb++;
71 data->rgb[1] = *rgb++;
72 data->rgb[2] = *rgb++;
73 break;
75 case MUIA_Colorfield_Pen:
76 data->pen = (UBYTE)tag->ti_Data;
77 data->pen = FLAG_FIXED_PEN;
78 break;
83 return (IPTR)obj;
86 IPTR Colorfield__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
88 struct Colorfield_DATA *data;
89 const struct TagItem *tags;
90 struct TagItem *tag;
91 ULONG *rgb;
92 BOOL newcol = FALSE;
93 IPTR retval;
95 data = INST_DATA(cl, obj);
97 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
99 switch (tag->ti_Tag)
101 case MUIA_Colorfield_Red:
102 data->rgb[0] = (ULONG)tag->ti_Data;
103 newcol = TRUE;
104 break;
106 case MUIA_Colorfield_Green:
107 data->rgb[1] = (ULONG)tag->ti_Data;
108 newcol = TRUE;
109 break;
111 case MUIA_Colorfield_Blue:
112 data->rgb[2] = (ULONG)tag->ti_Data;
113 newcol = TRUE;
114 break;
116 case MUIA_Colorfield_RGB:
117 rgb = (ULONG *)tag->ti_Data;
118 data->rgb[0] = *rgb++;
119 data->rgb[1] = *rgb++;
120 data->rgb[2] = *rgb++;
121 newcol = TRUE;
122 break;
124 case MUIA_Colorfield_Pen:
125 if (data->flags & FLAG_PEN_ALLOCATED)
127 ReleasePen(_screen(obj)->ViewPort.ColorMap, data->pen);
128 data->flags &= ~(FLAG_PEN_ALLOCATED | FLAG_NO_PEN);
130 data->pen = (UBYTE)data->pen;
131 data->flags |= FLAG_FIXED_PEN;
132 break;
137 retval = DoSuperMethodA(cl, obj, (Msg)msg);
139 if (newcol && (_flags(obj) & MADF_SETUP) && !(data->flags & FLAG_NO_PEN))
141 SetRGB32(&_screen(obj)->ViewPort, data->pen, data->rgb[0], data->rgb[1], data->rgb[2]);
143 if (GetBitMapAttr(_rp(obj)->BitMap, BMA_DEPTH) > 8)
145 MUI_Redraw(obj, MADF_DRAWUPDATE);
149 return retval;
152 IPTR Colorfield__OM_GET(struct IClass *cl, Object * obj, struct opGet *msg)
154 struct Colorfield_DATA *data = INST_DATA(cl, obj);
155 IPTR *store = msg->opg_Storage;
157 switch (msg->opg_AttrID)
159 case MUIA_Colorfield_Red:
160 *store = data->rgb[0];
161 break;
163 case MUIA_Colorfield_Green:
164 *store = data->rgb[1];
165 break;
167 case MUIA_Colorfield_Blue:
168 *store = data->rgb[2];
169 break;
171 case MUIA_Colorfield_RGB:
172 *(ULONG **)store = data->rgb;
173 break;
175 case MUIA_Colorfield_Pen:
176 *store = data->pen;
177 break;
179 default:
180 return DoSuperMethodA(cl, obj, (Msg)msg);
183 return TRUE;
186 IPTR Colorfield__MUIM_Setup(struct IClass *cl, Object *obj, struct MUIP_Setup *msg)
188 struct Colorfield_DATA *data = INST_DATA(cl,obj);
190 if (!(DoSuperMethodA(cl, obj, (Msg)msg))) return 0;
192 if (data->flags & FLAG_FIXED_PEN)
194 SetRGB32(&_screen(obj)->ViewPort,
195 data->pen,
196 data->rgb[0],
197 data->rgb[1],
198 data->rgb[2]);
200 else
202 LONG pen;
204 pen = ObtainPen(_screen(obj)->ViewPort.ColorMap,
205 (ULONG)-1,
206 data->rgb[0],
207 data->rgb[1],
208 data->rgb[2],
209 PENF_EXCLUSIVE);
211 if (pen == -1)
213 data->flags |= FLAG_NO_PEN;
214 data->pen = 0;
216 else
218 data->pen = (UBYTE)pen;
219 data->flags |= FLAG_PEN_ALLOCATED;
223 return 1;
226 IPTR Colorfield__MUIM_Cleanup(struct IClass *cl, Object *obj, struct MUIP_Cleanup *msg)
228 struct Colorfield_DATA *data = INST_DATA(cl,obj);
230 if (data->flags & FLAG_PEN_ALLOCATED)
232 ReleasePen(_screen(obj)->ViewPort.ColorMap, data->pen);
233 data->flags &= ~FLAG_PEN_ALLOCATED;
234 data->pen = 0;
236 data->flags &= ~FLAG_NO_PEN;
238 return DoSuperMethodA(cl, obj, (Msg)msg);
241 IPTR Colorfield__MUIM_AskMinMax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg)
243 DoSuperMethodA(cl,obj,(Msg)msg);
245 msg->MinMaxInfo->MinWidth += 1;
246 msg->MinMaxInfo->MinHeight += 1;
247 msg->MinMaxInfo->DefWidth += 16;
248 msg->MinMaxInfo->DefHeight += 16;
249 msg->MinMaxInfo->MaxWidth = MUI_MAXMAX;
250 msg->MinMaxInfo->MaxHeight = MUI_MAXMAX;
252 return 0;
255 IPTR Colorfield__MUIM_Draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg)
257 struct Colorfield_DATA *data = INST_DATA(cl,obj);
259 DoSuperMethodA(cl,obj,(Msg)msg);
261 if (!(msg->flags & (MADF_DRAWOBJECT | MADF_DRAWUPDATE)))
262 return FALSE;
264 if (data->flags & FLAG_NO_PEN)
266 static UWORD pat[] = {0x1111,0x2222,0x4444,0x8888};
268 SetAfPt(_rp(obj), pat, 2);
269 SetABPenDrMd(_rp(obj), _pens(obj)[MPEN_SHADOW], _pens(obj)[MPEN_BACKGROUND],JAM2);
272 else
274 SetABPenDrMd(_rp(obj), data->pen, 0,JAM1);
277 RectFill(_rp(obj), _mleft(obj), _mtop(obj), _mright(obj), _mbottom(obj));
279 SetAfPt(_rp(obj), NULL, 0);
281 return 0;
284 #if ZUNE_BUILTIN_COLORFIELD
285 BOOPSI_DISPATCHER(IPTR, Colorfield_Dispatcher, cl, obj, msg)
287 switch (msg->MethodID)
289 case OM_NEW: return Colorfield__OM_NEW(cl, obj, (struct opSet *)msg);
290 case OM_SET: return Colorfield__OM_SET(cl, obj, (struct opSet *)msg);
291 case OM_GET: return Colorfield__OM_GET(cl, obj, (struct opGet *)msg);
292 case MUIM_Setup: return Colorfield__MUIM_Setup(cl, obj, (struct MUIP_Setup *)msg);
293 case MUIM_Cleanup: return Colorfield__MUIM_Cleanup(cl, obj, (struct MUIP_Cleanup *)msg);
294 case MUIM_AskMinMax: return Colorfield__MUIM_AskMinMax(cl, obj, (struct MUIP_AskMinMax*)msg);
295 case MUIM_Draw: return Colorfield__MUIM_Draw(cl, obj, (struct MUIP_Draw*)msg);
296 default: return DoSuperMethodA(cl, obj, msg);
299 BOOPSI_DISPATCHER_END
301 const struct __MUIBuiltinClass _MUI_Colorfield_desc =
303 MUIC_Colorfield,
304 MUIC_Area,
305 sizeof(struct Colorfield_DATA),
306 (void*)Colorfield_Dispatcher
308 #endif /* ZUNE_BUILTIN_COLORFIELD */