2 Copyright © 1999, David Le Corfec.
3 Copyright © 2002-2006, The AROS Development Team.
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>
21 #include "muimaster_intern.h"
23 #include "textengine.h"
26 /* #define MYDEBUG 1 */
29 extern struct Library
*MUIMasterBase
;
31 static const int __version
= 1;
32 static const int __revision
= 1;
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
)
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
);
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
));)
74 case MUIA_Rectangle_BarTitle
:
75 data
->BarTitle
= StrDup((STRPTR
) tag
->ti_Data
);
77 case MUIA_Rectangle_HBar
:
78 data
->Type
= RECTANGLE_TYPE_HBAR
;
80 case MUIA_Rectangle_VBar
:
81 data
->Type
= RECTANGLE_TYPE_VBAR
;
86 D(bug("muimaster.library/rectangle.c: New Rectangle Object at 0x%lx\n",
92 IPTR
Rectangle__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
94 struct Rectangle_DATA
*data
= INST_DATA(cl
, obj
);
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
)
122 case MUIA_Rectangle_BarTitle
:
123 STORE
= (IPTR
) data
->BarTitle
;
126 case MUIA_Rectangle_HBar
:
127 STORE
= (data
->Type
== RECTANGLE_TYPE_HBAR
);
130 case MUIA_Rectangle_VBar
:
131 STORE
= (data
->Type
== RECTANGLE_TYPE_VBAR
);
135 /* our handler didn't understand the attribute, we simply pass
136 ** it to our superclass now
138 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
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
)))
152 data
->ztext
= zune_text_new(NULL
, data
->BarTitle
,
159 IPTR
Rectangle__MUIM_Cleanup(struct IClass
*cl
, Object
*obj
,
160 struct MUIP_Cleanup
*msg
)
162 struct Rectangle_DATA
*data
= INST_DATA(cl
, obj
);
165 zune_text_destroy(data
->ztext
);
167 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
170 /**************************************************************************
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!
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;
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
;
230 /**************************************************************************
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
))
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
),
265 if (_mwidth(obj
) < 1 || _mheight(obj
) < 1)
269 * ok, everything ready to render...
274 * Rewrite me, I'm ugly ! (but right :)
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;
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;
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
));
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
);
387 BOOPSI_DISPATCHER(IPTR
, Rectangle_Dispatcher
, cl
, obj
, msg
)
389 switch (msg
->MethodID
)
392 return Rectangle__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
394 return Rectangle__OM_DISPOSE(cl
, obj
, msg
);
396 return Rectangle__OM_GET(cl
, obj
, (struct opGet
*)msg
);
398 return Rectangle__MUIM_Setup(cl
, obj
, (APTR
) msg
);
400 return Rectangle__MUIM_Cleanup(cl
, obj
, (APTR
) msg
);
402 return Rectangle__MUIM_AskMinMax(cl
, obj
, (APTR
) msg
);
404 return Rectangle__MUIM_Draw(cl
, obj
, (APTR
) msg
);
406 return DoSuperMethodA(cl
, obj
, msg
);
409 BOOPSI_DISPATCHER_END
411 const struct __MUIBuiltinClass _MUI_Rectangle_desc
=
415 sizeof(struct Rectangle_DATA
),
416 (void *) Rectangle_Dispatcher