added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / libs / muimaster / mui_redraw.c
blobae49af3e3fddbe30db570728a6cd09e87e65f505
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
45 The function itself is a bug ;-) Remove it!
47 SEE ALSO
49 INTERNALS
51 HISTORY
53 *****************************************************************************/
55 AROS_LIBFUNC_INIT
57 APTR clip = (APTR)-1;
58 ULONG disabled;
60 if (!(_flags(obj) & MADF_CANDRAW)) return;
62 if (_flags(obj) & MADF_INVIRTUALGROUP)
64 Object *wnd;
65 Object *parent;
66 struct Region *region = NULL;
68 get(obj,MUIA_WindowObject,&wnd);
69 parent = obj;
71 while (get(parent,MUIA_Parent,&parent))
73 if (!parent) break;
74 if (parent == wnd) break;
76 if (_flags(parent) & MADF_ISVIRTUALGROUP)
78 struct Rectangle rect;
80 rect.MinX = _mleft(parent);
81 rect.MinY = _mtop(parent);
82 rect.MaxX = _mright(parent);
83 rect.MaxY = _mbottom(parent);
85 if (!region)
87 if ((region = NewRegion()))
89 OrRectRegion(region, &rect);
91 } else
93 AndRectRegion(region, &rect);
98 if (region)
100 clip = MUI_AddClipRegion(muiRenderInfo(obj),region);
103 } /* if object is in a virtual group */
105 if (1)
107 struct Region *region;
108 struct Rectangle *clip_rect;
109 struct Layer *l;
111 clip_rect = &muiRenderInfo(obj)->mri_ClipRect;
113 if (muiRenderInfo(obj)->mri_Window)
115 l = muiRenderInfo(obj)->mri_Window->WLayer;
117 else
119 l = muiRenderInfo(obj)->mri_RastPort->Layer;
122 if (l && (region = l->ClipRegion))
124 /* Maybe this should went to MUI_AddClipRegion() */
125 clip_rect->MinX = MAX(_left(obj),region->bounds.MinX);
126 clip_rect->MinY = MAX(_top(obj),region->bounds.MinY);
127 clip_rect->MaxX = MIN(_right(obj),region->bounds.MaxX);
128 clip_rect->MaxY = MIN(_bottom(obj),region->bounds.MaxY);
130 } else
132 clip_rect->MinX = _left(obj);
133 clip_rect->MinY = _top(obj);
134 clip_rect->MaxX = _right(obj);
135 clip_rect->MaxY = _bottom(obj);
139 _flags(obj) = (_flags(obj) & ~MADF_DRAWFLAGS) | (flags & MADF_DRAWFLAGS);
141 DoMethod(obj, MUIM_Draw, 0);
143 if (get(obj, MUIA_Disabled, &disabled))
145 if (_parent(obj))
147 ULONG parentDisabled;
148 if (get(_parent(obj), MUIA_Disabled, &parentDisabled))
150 /* Let the parent draw the pattern... */
151 if (parentDisabled) disabled = FALSE;
155 if (disabled)
157 #ifdef __AROS__
158 #if 0
160 This aproach might be faster *provided* that the buffer is
161 allocated and filled *once* at startup of muimaster.library.
163 In reality, the WritePixelArray() call has quite a big
164 overhead, so you should only use this buffer if the gadget
165 completely fits inside, and fall back to allocating a new
166 buffer if the gadget is too big.
168 Perhaps a future optimization...
170 LONG width = 200;
171 LONG height = 100;
172 LONG *buffer = AllocVec(width * height * sizeof(LONG), MEMF_ANY);
173 LONG x, y;
175 memset(buffer, 0xAA, width * height * sizeof(LONG));
177 for (y = 0; y < _height(obj); y += height)
179 for (x = 0; x < _width(obj); x += width)
181 WritePixelArrayAlpha
183 buffer, 0, 0, width * sizeof(LONG),
184 _rp(obj), _left(obj) + x, _top(obj) + y,
185 x + width > _width(obj) ? _width(obj) - x : width,
186 y + height > _height(obj) ? _height(obj) - y : height,
187 0xffffffff
191 #else
192 LONG width = _width(obj);
193 LONG height = _height(obj);
194 LONG *buffer = NULL;
196 if (GetBitMapAttr(_rp(obj)->BitMap, BMA_DEPTH) >= 15)
198 buffer = AllocVec(width * sizeof(LONG), MEMF_ANY);
201 if (buffer != NULL)
203 memset(buffer, 0xAA, width * sizeof(LONG));
205 WritePixelArrayAlpha
207 buffer, 0, 0, 0,
208 _rp(obj), _left(obj), _top(obj), width, height,
209 0xffffffff
211 FreeVec(buffer);
212 } else
213 #endif
214 #endif
216 /* fallback */
217 const static UWORD pattern[] = { 0x8888, 0x2222, };
218 LONG fg = muiRenderInfo(obj)->mri_Pens[MPEN_SHADOW];
220 SetDrMd(_rp(obj), JAM1);
221 SetAPen(_rp(obj), fg);
222 SetAfPt(_rp(obj), pattern, 1);
223 RectFill(_rp(obj), _left(obj), _top(obj), _right(obj), _bottom(obj));
224 SetAfPt(_rp(obj), NULL, 0);
227 } /* if (object is disabled) */
229 /* copy buffer to window */
230 if (muiRenderInfo(obj)->mri_BufferBM)
232 ClipBlit(&muiRenderInfo(obj)->mri_BufferRP, _left(obj), _top(obj),
233 muiRenderInfo(obj)->mri_Window->RPort, _left(obj), _top(obj),
234 _width(obj), _height(obj), 0xc0);
237 if (clip != (APTR)-1)
239 /* This call actually also frees the region */
240 MUI_RemoveClipRegion(muiRenderInfo(obj), clip);
243 AROS_LIBFUNC_EXIT
245 } /* MUIA_Redraw */