Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / muimaster / mui_redraw.c
blobe85b98007e60e7ac5aca04a5ba3058b826b32eb5
1 /*
2 Copyright © 2003-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <string.h>
7 #include <clib/alib_protos.h>
8 #include <intuition/classusr.h>
9 #include <graphics/gfxmacros.h>
10 #include <cybergraphx/cybergraphics.h>
11 #include <proto/graphics.h>
12 #include <proto/intuition.h>
13 #include <proto/muimaster.h>
14 #include <proto/cybergraphics.h>
16 #include "muimaster_intern.h"
17 #include "mui.h"
18 #include "support.h"
20 #include "debug.h"
22 /*****************************************************************************
24 NAME */
25 AROS_LH2(VOID, MUI_Redraw,
27 /* SYNOPSIS */
28 AROS_LHA(Object *, obj, A0),
29 AROS_LHA(ULONG, flags, D0),
31 /* LOCATION */
32 struct Library *, MUIMasterBase, 17, MUIMaster)
34 /* FUNCTION
36 INPUTS
38 RESULT
40 NOTES
42 EXAMPLE
44 BUGS
46 SEE ALSO
48 INTERNALS
50 HISTORY
52 *****************************************************************************/
54 AROS_LIBFUNC_INIT
56 APTR clip = (APTR)-1;
57 IPTR disabled;
59 if (!(_flags(obj) & MADF_CANDRAW)) return;
61 if (_flags(obj) & MADF_INVIRTUALGROUP)
63 Object *wnd;
64 Object *parent;
65 struct Region *region = NULL;
67 get(obj,MUIA_WindowObject,&wnd);
68 parent = obj;
70 while (get(parent,MUIA_Parent,&parent))
72 if (!parent) break;
73 if (parent == wnd) break;
75 if (_flags(parent) & MADF_ISVIRTUALGROUP)
77 struct Rectangle rect;
79 rect.MinX = _mleft(parent);
80 rect.MinY = _mtop(parent);
81 rect.MaxX = _mright(parent);
82 rect.MaxY = _mbottom(parent);
84 if (!region)
86 if ((region = NewRegion()))
88 OrRectRegion(region, &rect);
90 } else
92 AndRectRegion(region, &rect);
97 if (region)
99 clip = MUI_AddClipRegion(muiRenderInfo(obj),region);
102 } /* if object is in a virtual group */
104 if (1)
106 struct Region *region;
107 struct Rectangle *clip_rect;
108 struct Layer *l;
110 clip_rect = &muiRenderInfo(obj)->mri_ClipRect;
112 if (muiRenderInfo(obj)->mri_Window)
114 l = muiRenderInfo(obj)->mri_Window->WLayer;
116 else
118 l = muiRenderInfo(obj)->mri_RastPort->Layer;
121 if (l && (region = l->ClipRegion))
123 /* Maybe this should went to MUI_AddClipRegion() */
124 clip_rect->MinX = MAX(_left(obj),region->bounds.MinX);
125 clip_rect->MinY = MAX(_top(obj),region->bounds.MinY);
126 clip_rect->MaxX = MIN(_right(obj),region->bounds.MaxX);
127 clip_rect->MaxY = MIN(_bottom(obj),region->bounds.MaxY);
129 } else
131 clip_rect->MinX = _left(obj);
132 clip_rect->MinY = _top(obj);
133 clip_rect->MaxX = _right(obj);
134 clip_rect->MaxY = _bottom(obj);
138 _flags(obj) = (_flags(obj) & ~MADF_DRAWFLAGS) | (flags & MADF_DRAWFLAGS);
140 DoMethod(obj, MUIM_Draw, 0);
142 if (get(obj, MUIA_Disabled, &disabled))
144 #if 0
146 Commented out, because group childs were drawn wrongly
147 when they have been disabled while window is open.
149 if (_parent(obj))
151 IPTR parentDisabled;
152 if (get(_parent(obj), MUIA_Disabled, &parentDisabled))
154 /* Let the parent draw the pattern... */
155 if (parentDisabled) disabled = FALSE;
158 #endif
160 if (disabled)
162 #ifdef __AROS__
163 #if 0
165 This aproach might be faster *provided* that the buffer is
166 allocated and filled *once* at startup of muimaster.library.
168 In reality, the WritePixelArray() call has quite a big
169 overhead, so you should only use this buffer if the gadget
170 completely fits inside, and fall back to allocating a new
171 buffer if the gadget is too big.
173 Perhaps a future optimization...
175 LONG width = 200;
176 LONG height = 100;
177 LONG *buffer = AllocVec(width * height * sizeof(LONG), MEMF_ANY);
178 LONG x, y;
180 memset(buffer, 0xAA, width * height * sizeof(LONG));
182 for (y = 0; y < _height(obj); y += height)
184 for (x = 0; x < _width(obj); x += width)
186 WritePixelArrayAlpha
188 buffer, 0, 0, width * sizeof(LONG),
189 _rp(obj), _left(obj) + x, _top(obj) + y,
190 x + width > _width(obj) ? _width(obj) - x : width,
191 y + height > _height(obj) ? _height(obj) - y : height,
192 0xffffffff
196 #else
197 LONG width = _width(obj);
198 LONG height = _height(obj);
199 LONG *buffer = NULL;
201 if (GetBitMapAttr(_rp(obj)->BitMap, BMA_DEPTH) >= 15)
203 buffer = AllocVec(width * sizeof(LONG), MEMF_ANY);
206 if (buffer != NULL)
208 memset(buffer, 0xAA, width * sizeof(LONG));
210 WritePixelArrayAlpha
212 buffer, 0, 0, 0,
213 _rp(obj), _left(obj), _top(obj), width, height,
214 0xffffffff
216 FreeVec(buffer);
217 } else
218 #endif
219 #endif
221 /* fallback */
222 const static UWORD pattern[] = { 0x8888, 0x2222, };
223 LONG fg = muiRenderInfo(obj)->mri_Pens[MPEN_SHADOW];
225 SetDrMd(_rp(obj), JAM1);
226 SetAPen(_rp(obj), fg);
227 SetAfPt(_rp(obj), pattern, 1);
228 RectFill(_rp(obj), _left(obj), _top(obj), _right(obj), _bottom(obj));
229 SetAfPt(_rp(obj), NULL, 0);
232 } /* if (object is disabled) */
234 /* copy buffer to window */
235 if (muiRenderInfo(obj)->mri_BufferBM)
237 ClipBlit(&muiRenderInfo(obj)->mri_BufferRP, _left(obj), _top(obj),
238 muiRenderInfo(obj)->mri_Window->RPort, _left(obj), _top(obj),
239 _width(obj), _height(obj), 0xc0);
242 if (clip != (APTR)-1)
244 /* This call actually also frees the region */
245 MUI_RemoveClipRegion(muiRenderInfo(obj), clip);
248 AROS_LIBFUNC_EXIT
250 } /* MUIA_Redraw */