revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / muimaster / classes / rectangle.c
blobeed05ce11cb82da49e9e437a1f3324a546c94b4e
1 /*
2 Copyright © 1999, David Le Corfec.
3 Copyright © 2002-2006, The AROS Development Team.
4 All rights reserved.
6 $Id$
7 */
9 #include <string.h>
11 #include <exec/types.h>
13 #include <clib/alib_protos.h>
14 #include <proto/intuition.h>
15 #include <proto/graphics.h>
16 #include <proto/utility.h>
17 #include <proto/exec.h>
18 #include <proto/muimaster.h>
20 #include "mui.h"
21 #include "muimaster_intern.h"
22 #include "support.h"
23 #include "textengine.h"
24 #include "prefs.h"
26 /* #define MYDEBUG 1 */
27 #include "debug.h"
29 extern struct Library *MUIMasterBase;
31 static const int __version = 1;
32 static const int __revision = 1;
34 struct Rectangle_DATA
36 STRPTR BarTitle;
37 ULONG Type;
38 ZText *ztext;
41 #define RECTANGLE_TYPE_NORMAL 0
42 #define RECTANGLE_TYPE_HBAR 1
43 #define RECTANGLE_TYPE_VBAR 2
45 static void draw_line(struct RastPort *rp, int xa, int ya, int xb, int yb)
47 Move(rp, xa, ya);
48 Draw(rp, xb, yb);
52 IPTR Rectangle__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
54 struct Rectangle_DATA *data;
55 struct TagItem *tags, *tag;
57 obj = (Object *) DoSuperNewTags(cl, obj, NULL,
58 MUIA_Font, MUIV_Font_Title, TAG_MORE, (IPTR) msg->ops_AttrList);
60 if (!obj)
61 return 0;
63 /* Initial local instance data */
64 data = INST_DATA(cl, obj);
66 data->Type = RECTANGLE_TYPE_NORMAL;
68 /* parse initial taglist */
70 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags));)
72 switch (tag->ti_Tag)
74 case MUIA_Rectangle_BarTitle:
75 data->BarTitle = StrDup((STRPTR) tag->ti_Data);
76 break;
77 case MUIA_Rectangle_HBar:
78 data->Type = RECTANGLE_TYPE_HBAR;
79 break;
80 case MUIA_Rectangle_VBar:
81 data->Type = RECTANGLE_TYPE_VBAR;
82 break;
86 D(bug("muimaster.library/rectangle.c: New Rectangle Object at 0x%lx\n",
87 obj));
89 return (IPTR) obj;
92 IPTR Rectangle__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
94 struct Rectangle_DATA *data = INST_DATA(cl, obj);
96 if (data->BarTitle)
97 mui_free(data->BarTitle);
99 return DoSuperMethodA(cl, obj, msg);
103 IPTR Rectangle__OM_GET(struct IClass *cl, Object *obj, struct opGet *msg)
105 /*---------------------------------------------------------------------------*/
106 /* small macro to simplify return value storage */
107 /*---------------------------------------------------------------------------*/
108 #define STORE *(msg->opg_Storage)
110 struct Rectangle_DATA *data = INST_DATA(cl, obj);
112 switch (msg->opg_AttrID)
114 case MUIA_Version:
115 STORE = __version;
116 return TRUE;
118 case MUIA_Revision:
119 STORE = __revision;
120 return TRUE;
122 case MUIA_Rectangle_BarTitle:
123 STORE = (IPTR) data->BarTitle;
124 return TRUE;
126 case MUIA_Rectangle_HBar:
127 STORE = (data->Type == RECTANGLE_TYPE_HBAR);
128 return TRUE;
130 case MUIA_Rectangle_VBar:
131 STORE = (data->Type == RECTANGLE_TYPE_VBAR);
132 return TRUE;
135 /* our handler didn't understand the attribute, we simply pass
136 ** it to our superclass now
138 return DoSuperMethodA(cl, obj, (Msg) msg);
139 #undef STORE
142 IPTR Rectangle__MUIM_Setup(struct IClass *cl, Object *obj,
143 struct MUIP_Setup *msg)
145 struct Rectangle_DATA *data = INST_DATA(cl, obj);
147 if (!(DoSuperMethodA(cl, obj, (Msg) msg)))
148 return FALSE;
150 if (data->BarTitle)
152 data->ztext = zune_text_new(NULL, data->BarTitle,
153 ZTEXT_ARG_NONE, 0);
156 return TRUE;
159 IPTR Rectangle__MUIM_Cleanup(struct IClass *cl, Object *obj,
160 struct MUIP_Cleanup *msg)
162 struct Rectangle_DATA *data = INST_DATA(cl, obj);
164 if (data->ztext)
165 zune_text_destroy(data->ztext);
167 return DoSuperMethodA(cl, obj, (Msg) msg);
170 /**************************************************************************
171 MUIM_AskMinMax
173 AskMinMax method will be called before the window is opened
174 and before layout takes place. We need to tell MUI the
175 minimum, maximum and default size of our object.
176 **************************************************************************/
177 IPTR Rectangle__MUIM_AskMinMax(struct IClass *cl, Object *obj,
178 struct MUIP_AskMinMax *msg)
180 struct Rectangle_DATA *data = INST_DATA(cl, obj);
183 ** let our superclass first fill in what it thinks about sizes.
184 ** this will e.g. add the size of frame and inner spacing.
186 DoSuperMethodA(cl, obj, (Msg) msg);
189 ** now add the values specific to our object. note that we
190 ** indeed need to *add* these values, not just set them!
193 if (!data->BarTitle)
195 /* msg->MinMaxInfo->MinWidth += 1; */
196 /* msg->MinMaxInfo->MinHeight += 1; */
197 if (data->Type == RECTANGLE_TYPE_HBAR)
199 msg->MinMaxInfo->MinHeight += 2;
201 else if (data->Type == RECTANGLE_TYPE_VBAR)
203 msg->MinMaxInfo->MinWidth += 2;
206 else
208 zune_text_get_bounds(data->ztext, obj);
209 msg->MinMaxInfo->MinWidth += data->ztext->width;
210 msg->MinMaxInfo->MinHeight += data->ztext->height;
211 D(bug("rect: minheight %ld\n", data->ztext->height));
212 if (muiGlobalInfo(obj)->mgi_Prefs->group_title_color ==
213 GROUP_TITLE_COLOR_3D)
215 msg->MinMaxInfo->MinWidth += 1;
216 msg->MinMaxInfo->MinHeight += 1;
220 msg->MinMaxInfo->DefWidth = msg->MinMaxInfo->MinWidth;
221 msg->MinMaxInfo->DefHeight = msg->MinMaxInfo->MinHeight;
223 msg->MinMaxInfo->MaxWidth = MUI_MAXMAX;
224 msg->MinMaxInfo->MaxHeight = MUI_MAXMAX;
226 return TRUE;
230 /**************************************************************************
231 MUIM_Draw
233 Draw method is called whenever MUI feels we should render
234 our object. This usually happens after layout is finished
235 or when we need to refresh in a simplerefresh window.
236 Note: You may only render within the rectangle
237 _mleft(obj), _mtop(obj), _mwidth(obj), _mheight(obj).
238 **************************************************************************/
239 IPTR Rectangle__MUIM_Draw(struct IClass *cl, Object *obj,
240 struct MUIP_Draw *msg)
242 struct Rectangle_DATA *data = INST_DATA(cl, obj);
245 ** let our superclass draw itself first, area class would
246 ** e.g. draw the frame and clear the whole region. What
247 ** it does exactly depends on msg->flags.
250 DoSuperMethodA(cl, obj, (Msg) msg);
253 ** if MADF_DRAWOBJECT isn't set, we shouldn't draw anything.
254 ** MUI just wanted to update the frame or something like that.
257 if (!(msg->flags & MADF_DRAWOBJECT))
258 return 0;
261 D(bug("Draw Rectangle(0x%lx) %ldx%ldx%ldx%ld mw=%ld mh=%ld\n", obj,
262 _left(obj), _top(obj), _right(obj), _bottom(obj), _mwidth(obj),
263 _mheight(obj)));
265 if (_mwidth(obj) < 1 || _mheight(obj) < 1)
266 return TRUE;
269 * ok, everything ready to render...
271 if (data->BarTitle)
274 * Rewrite me, I'm ugly ! (but right :)
276 int tw;
277 int th;
278 int x1;
279 int x2;
280 int yt;
282 /* D(bug("muimaster.library/rectangle.c: Draw Rectangle Object "
283 "at 0x%lx %ldx%ldx%ldx%ld\n mw=%ld mh=%ld\n",
284 obj, _left(obj), _top(obj), _right(obj), _bottom(obj),
285 _mwidth(obj), _mheight(obj))); */
287 SetAPen(_rp(obj), _pens(obj)[MPEN_SHADOW]);
288 if (muiGlobalInfo(obj)->mgi_Prefs->group_title_color ==
289 GROUP_TITLE_COLOR_3D)
291 tw = data->ztext->width + 1;
292 th = data->ztext->height + 1;
293 x1 = _mleft(obj) + (_mwidth(obj) - tw) / 2;
294 x1 -= 1;
295 x2 = x1 + tw;
296 yt = _mtop(obj) + (_mheight(obj) - th) / 2;
297 zune_text_draw(data->ztext, obj, x1 + 1, x2, yt + 1);
298 SetAPen(_rp(obj), _pens(obj)[MPEN_SHINE]);
299 zune_text_draw(data->ztext, obj, x1, x2 - 1, yt);
301 if (data->Type == RECTANGLE_TYPE_HBAR)
303 int y = yt + data->ztext->height / 2;
305 if ((x1 - 2) > _mleft(obj) && (x2 + 2) < _mright(obj))
307 SetAPen(_rp(obj), _pens(obj)[MPEN_SHADOW]);
308 draw_line(_rp(obj), _mleft(obj), y, x1 - 2, y);
309 draw_line(_rp(obj), x2 + 3, y, _mright(obj), y);
311 SetAPen(_rp(obj), _pens(obj)[MPEN_SHINE]);
312 draw_line(_rp(obj), _mleft(obj), y + 1, x1 - 2, y + 1);
313 draw_line(_rp(obj), x2 + 3, y + 1, _mright(obj), y + 1);
317 else /* black or white */
319 if (muiGlobalInfo(obj)->mgi_Prefs->group_title_color ==
320 GROUP_TITLE_COLOR_HILITE)
321 SetAPen(_rp(obj), _pens(obj)[MPEN_SHINE]);
323 tw = data->ztext->width;
324 th = data->ztext->height;
325 x1 = _mleft(obj) + (_mwidth(obj) - tw) / 2;
326 x2 = x1 + tw;
327 yt = _mtop(obj) + (_mheight(obj) - th) / 2;
329 zune_text_draw(data->ztext, obj, x1, x2 - 1, yt);
331 if (data->Type == RECTANGLE_TYPE_HBAR)
333 int y = yt + data->ztext->height / 2;
335 if ((x1 - 2) > _mleft(obj) && (x2 + 2) < _mright(obj))
337 SetAPen(_rp(obj), _pens(obj)[MPEN_SHADOW]);
338 draw_line(_rp(obj), _mleft(obj), y, x1 - 3, y);
339 draw_line(_rp(obj), x2 + 2, y, _mright(obj), y);
341 SetAPen(_rp(obj), _pens(obj)[MPEN_SHINE]);
342 draw_line(_rp(obj), _mleft(obj), y + 1, x1 - 3, y + 1);
343 draw_line(_rp(obj), x2 + 2, y + 1, _mright(obj), y + 1);
348 else /* no bar title */
350 if (data->Type == RECTANGLE_TYPE_HBAR)
352 int y = _mtop(obj) + _mheight(obj) / 2 - 1;
354 SetAPen(_rp(obj), _pens(obj)[MPEN_SHADOW]);
355 draw_line(_rp(obj), _mleft(obj), y, _mright(obj), y);
357 SetAPen(_rp(obj), _pens(obj)[MPEN_SHINE]);
358 draw_line(_rp(obj), _mleft(obj), y + 1, _mright(obj), y + 1);
360 else if (data->Type == RECTANGLE_TYPE_VBAR)
362 int x = _mleft(obj) + _mwidth(obj) / 2 - 1;
364 SetAPen(_rp(obj), _pens(obj)[MPEN_SHADOW]);
365 draw_line(_rp(obj), x, _mtop(obj), x, _mbottom(obj));
367 SetAPen(_rp(obj), _pens(obj)[MPEN_SHINE]);
368 draw_line(_rp(obj), x + 1, _mtop(obj), x + 1, _mbottom(obj));
370 else
372 #ifdef MYDEBUG
373 WORD pnts[] =
374 { _mleft(obj), _mtop(obj), _mleft(obj), _mbottom(obj),
375 _mright(obj), _mbottom(obj), _mright(obj), _mtop(obj)
377 SetAPen(_rp(obj), _pens(obj)[MPEN_SHADOW]);
378 Move(_rp(obj), _mright(obj), _mtop(obj));
379 PolyDraw(_rp(obj), 4, pnts);
380 #endif
383 return TRUE;
387 BOOPSI_DISPATCHER(IPTR, Rectangle_Dispatcher, cl, obj, msg)
389 switch (msg->MethodID)
391 case OM_NEW:
392 return Rectangle__OM_NEW(cl, obj, (struct opSet *)msg);
393 case OM_DISPOSE:
394 return Rectangle__OM_DISPOSE(cl, obj, msg);
395 case OM_GET:
396 return Rectangle__OM_GET(cl, obj, (struct opGet *)msg);
397 case MUIM_Setup:
398 return Rectangle__MUIM_Setup(cl, obj, (APTR) msg);
399 case MUIM_Cleanup:
400 return Rectangle__MUIM_Cleanup(cl, obj, (APTR) msg);
401 case MUIM_AskMinMax:
402 return Rectangle__MUIM_AskMinMax(cl, obj, (APTR) msg);
403 case MUIM_Draw:
404 return Rectangle__MUIM_Draw(cl, obj, (APTR) msg);
405 default:
406 return DoSuperMethodA(cl, obj, msg);
409 BOOPSI_DISPATCHER_END
411 const struct __MUIBuiltinClass _MUI_Rectangle_desc =
413 MUIC_Rectangle,
414 MUIC_Area,
415 sizeof(struct Rectangle_DATA),
416 (void *) Rectangle_Dispatcher