grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / muimaster / bubbleengine.c
blob0d62e85edea8e2de6059091bc5e1f7a6e637c26e
1 /*
2 Copyright © 1999, David Le Corfec.
3 Copyright © 2002, The AROS Development Team.
4 All rights reserved.
6 $Id$
7 */
9 #include <ctype.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdio.h>
14 #include <exec/types.h>
15 #include <exec/memory.h>
17 #include <clib/alib_protos.h>
18 #include <intuition/screens.h>
19 #include <proto/exec.h>
20 #include <proto/graphics.h>
21 #include <proto/utility.h>
22 #include <proto/intuition.h>
23 #include <proto/muimaster.h>
25 #include "mui.h"
26 #include "textengine.h"
27 #include "bubbleengine.h"
28 #include "support.h"
30 #include "muimaster_intern.h"
32 //#define MYDEBUG 1
33 #include "debug.h"
35 extern struct Library *MUIMasterBase;
37 /************************************************************************/
39 #define WA_Shape WA_ShapeRegion
41 /************************************************************************/
43 typedef struct ZBubble
45 struct Window *win;
46 ZText *ztext;
47 STRPTR text;
48 UBYTE flags;
49 struct Region *shape;
50 } ZBubble;
52 #define WINLEFT (_window(obj)->LeftEdge + x)
53 #define WINTOP (_window(obj)->TopEdge + y)
55 #define WINWIDTH (bubble->ztext->width + (ROUNDEDGE_SIZE + BORDER_X) * 2)
56 #define WINHEIGHT \
57 ((bubble->ztext->height + BORDER_Y * 2) < ROUNDEDGE_SIZE * 2 + 1) ? \
58 ROUNDEDGE_SIZE * 2 + 1 : (bubble->ztext->height + BORDER_Y * 2)
60 #define BUBBLEF_CREATESHORTHELP_CALLED 1
62 /************************************************************************/
65 /* [][][][]
66 [][]
67 [][]
81 #define ROUNDEDGE_SIZE 13
82 #define BORDER_X 5
83 #define BORDER_Y 5
85 static WORD roundtab[ROUNDEDGE_SIZE] =
102 static struct Region *zune_bubble_shape_create(Object *obj,
103 ZBubble *bubble, WORD w, WORD h)
105 struct Region *shape = NewRegion();
106 struct Rectangle r;
107 WORD y;
109 if (!shape)
110 return NULL;
112 for (y = 0; y < ROUNDEDGE_SIZE; y++)
114 r.MinX = roundtab[y];
115 r.MinY = y;
116 r.MaxX = w - 1 - r.MinX;
117 r.MaxY = y;
119 OrRectRegion(shape, &r);
121 r.MinY = h - 1 - y;
122 r.MaxY = h - 1 - y;
124 OrRectRegion(shape, &r);
127 r.MinX = 0;
128 r.MinY = y;
129 r.MaxX = w - 1;
130 r.MaxY = h - 1 - y;
132 OrRectRegion(shape, &r);
134 return shape;
138 static void zune_bubble_draw(Object *obj, ZBubble *bubble)
140 struct RastPort *rp = bubble->win->RPort, *objrp;
141 WORD x1, x2, y, w, h, prev_x1 = -1;
143 w = bubble->win->Width;
144 h = bubble->win->Height;
146 for (y = 0; y < ROUNDEDGE_SIZE; y++, prev_x1 = x1)
148 x1 = roundtab[y];
149 x2 = w - 1 - x1;
151 if (prev_x1 == -1)
153 SetAPen(rp, _pens(obj)[MPEN_SHADOW]);
155 else
157 SetAPen(rp, _pens(obj)[MPEN_SHINE]);
160 RectFill(rp, x1, y, x2, y);
161 RectFill(rp, x1, h - 1 - y, x2, h - 1 - y);
163 if (prev_x1 != -1)
165 if (prev_x1 != x1)
166 prev_x1--;
167 SetAPen(rp, _pens(obj)[MPEN_SHADOW]);
168 RectFill(rp, x1, y, prev_x1, y);
169 RectFill(rp, x1, h - 1 - y, prev_x1, h - 1 - y);
170 RectFill(rp, w - 1 - prev_x1, y, w - 1 - x1, y);
171 RectFill(rp, w - 1 - prev_x1, h - 1 - y, w - 1 - x1, h - 1 - y);
176 SetAPen(rp, _pens(obj)[MPEN_SHINE]);
177 RectFill(rp, 1, y, w - 2, h - 1 - y);
179 SetAPen(rp, _pens(obj)[MPEN_SHADOW]);
180 RectFill(rp, 0, y, 0, h - 1 - y);
181 RectFill(rp, w - 1, y, w - 1, h - 1 - y);
183 objrp = _rp(obj);
184 _rp(obj) = rp;
186 zune_text_draw(bubble->ztext, obj, ROUNDEDGE_SIZE + BORDER_X,
187 ROUNDEDGE_SIZE + BORDER_X + bubble->ztext->width - 1,
188 (bubble->win->Height - bubble->ztext->height + 1) / 2);
190 _rp(obj) = objrp;
193 APTR zune_bubble_create(Object *obj, LONG x, LONG y, char *text,
194 ULONG flags)
196 ZBubble *bubble;
198 if (!(_flags(obj) & MADF_CANDRAW))
199 return NULL;
201 bubble = mui_alloc_struct(ZBubble);
202 if (!bubble)
203 return NULL;
205 if (!text)
207 text = (STRPTR) DoMethod(obj, MUIM_CreateShortHelp, x, y);
208 bubble->flags |= BUBBLEF_CREATESHORTHELP_CALLED;
211 if (!text)
213 mui_free(bubble);
214 return NULL;
217 bubble->text = text;
219 bubble->ztext = zune_text_new(NULL, bubble->text, ZTEXT_ARG_NONE, 0);
220 if (!bubble->ztext)
222 zune_bubble_delete(obj, bubble);
223 return NULL;
226 zune_text_get_bounds(bubble->ztext, obj);
228 bubble->shape =
229 zune_bubble_shape_create(obj, bubble, WINWIDTH, WINHEIGHT);
231 bubble->win = OpenWindowTags(NULL, WA_CustomScreen, (IPTR) _screen(obj),
232 WA_Left, WINLEFT,
233 WA_Top, WINTOP,
234 WA_Width, WINWIDTH,
235 WA_Height, WINHEIGHT,
236 WA_AutoAdjust, TRUE,
237 WA_Activate, FALSE,
238 WA_Borderless, TRUE,
239 WA_BackFill, (IPTR) LAYERS_NOBACKFILL,
240 WA_ShapeRegion, (IPTR) bubble->shape, TAG_DONE);
242 if (!bubble->win)
244 zune_bubble_delete(obj, bubble);
245 return NULL;
248 zune_bubble_draw(obj, bubble);
250 return bubble;
253 void zune_bubble_delete(Object *obj, APTR bubble)
255 ZBubble *b = (ZBubble *) bubble;
257 if (b)
259 if (b->win)
260 CloseWindow(b->win);
261 if (b->shape)
262 DisposeRegion(b->shape);
263 if (b->ztext)
264 zune_text_destroy(b->ztext);
266 if (b->flags & BUBBLEF_CREATESHORTHELP_CALLED)
268 DoMethod(obj, MUIM_DeleteShortHelp, (IPTR) b->text);
271 mui_free(b);