Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / muimaster / bubbleengine.c
blob76b3cc0e58ae35082fda3be726fd886d76f4bde1
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 #ifndef __AROS__
40 #define WA_Shape WA_ShapeRegion
41 #endif
43 /************************************************************************/
45 typedef struct ZBubble
47 struct Window *win;
48 ZText *ztext;
49 STRPTR text;
50 UBYTE flags;
51 struct Region *shape;
52 } ZBubble;
54 #define BUBBLEF_CREATESHORTHELP_CALLED 1
56 /************************************************************************/
59 /* [][][][]
60 [][]
61 [][]
75 #define ROUNDEDGE_SIZE 13
76 #define BORDER_X 5
77 #define BORDER_Y 5
79 static WORD roundtab[ROUNDEDGE_SIZE] =
96 static struct Region *zune_bubble_shape_create(Object *obj, ZBubble *bubble, WORD w, WORD h)
98 struct Region *shape = NewRegion();
99 struct Rectangle r;
100 WORD y;
102 if (!shape) return NULL;
104 for(y = 0; y < ROUNDEDGE_SIZE; y++)
106 r.MinX = roundtab[y];
107 r.MinY = y;
108 r.MaxX = w - 1 - r.MinX;
109 r.MaxY = y;
111 OrRectRegion(shape, &r);
113 r.MinY = h - 1 - y;
114 r.MaxY = h - 1 - y;
116 OrRectRegion(shape, &r);
119 r.MinX = 0;
120 r.MinY = y;
121 r.MaxX = w - 1;
122 r.MaxY = h - 1 - y;
124 OrRectRegion(shape, &r);
126 return shape;
130 static void zune_bubble_draw(Object *obj, ZBubble *bubble)
132 struct RastPort *rp = bubble->win->RPort, *objrp;
133 WORD x1, x2, y, w, h, prev_x1 = -1;
135 w = bubble->win->Width;
136 h = bubble->win->Height;
138 for(y = 0; y < ROUNDEDGE_SIZE; y++, prev_x1 = x1)
140 x1 = roundtab[y];
141 x2 = w - 1 - x1;
143 if (prev_x1 == -1)
145 SetAPen(rp, _pens(obj)[MPEN_SHADOW]);
147 else
149 SetAPen(rp, _pens(obj)[MPEN_SHINE]);
152 RectFill(rp, x1, y, x2, y);
153 RectFill(rp, x1, h - 1 - y, x2, h - 1 - y);
155 if (prev_x1 != -1)
157 if (prev_x1 != x1) prev_x1--;
158 SetAPen(rp, _pens(obj)[MPEN_SHADOW]);
159 RectFill(rp, x1, y, prev_x1, y);
160 RectFill(rp, x1, h - 1 - y, prev_x1, h - 1 - y);
161 RectFill(rp, w - 1 - prev_x1, y, w - 1 - x1, y);
162 RectFill(rp, w - 1 - prev_x1, h - 1 - y, w - 1 - x1, h - 1 - y);
167 SetAPen(rp, _pens(obj)[MPEN_SHINE]);
168 RectFill(rp, 1, y, w - 2, h - 1 - y);
170 SetAPen(rp, _pens(obj)[MPEN_SHADOW]);
171 RectFill(rp, 0, y, 0, h - 1 - y);
172 RectFill(rp, w - 1, y, w - 1, h - 1 - y);
174 objrp = _rp(obj);
175 _rp(obj) = rp;
177 zune_text_draw(bubble->ztext, obj, ROUNDEDGE_SIZE + BORDER_X,
178 ROUNDEDGE_SIZE + BORDER_X + bubble->ztext->width - 1,
179 (bubble->win->Height - bubble->ztext->height + 1) / 2);
181 _rp(obj) = objrp;
184 APTR zune_bubble_create(Object *obj, LONG x, LONG y, char *text, ULONG flags)
186 ZBubble *bubble;
188 if (!(_flags(obj) & MADF_CANDRAW)) return NULL;
190 bubble = mui_alloc_struct(ZBubble);
191 if (!bubble) return NULL;
193 if (!text)
195 text = (STRPTR)DoMethod(obj, MUIM_CreateShortHelp, x, y);
196 bubble->flags |= BUBBLEF_CREATESHORTHELP_CALLED;
199 if (!text)
201 mui_free(bubble);
202 return NULL;
205 bubble->text = text;
207 bubble->ztext = zune_text_new(NULL, bubble->text, ZTEXT_ARG_NONE, 0);
208 if (!bubble->ztext)
210 zune_bubble_delete(obj, bubble);
211 return NULL;
214 zune_text_get_bounds(bubble->ztext, obj);
216 #define WINLEFT _window(obj)->LeftEdge + x
217 #define WINTOP _window(obj)->TopEdge + y
219 #define WINWIDTH bubble->ztext->width + (ROUNDEDGE_SIZE + BORDER_X) * 2
220 #define WINHEIGHT ((bubble->ztext->height + BORDER_Y * 2) < ROUNDEDGE_SIZE * 2 + 1) ? \
221 ROUNDEDGE_SIZE * 2 + 1 : (bubble->ztext->height + BORDER_Y * 2)
223 bubble->shape = zune_bubble_shape_create(obj, bubble, WINWIDTH, WINHEIGHT);
225 bubble->win = OpenWindowTags(NULL, WA_CustomScreen, (IPTR)_screen(obj),
226 WA_Left, WINLEFT,
227 WA_Top, WINTOP,
228 WA_Width, WINWIDTH,
229 WA_Height, WINHEIGHT,
230 WA_AutoAdjust, TRUE,
231 WA_Activate, FALSE,
232 WA_Borderless, TRUE,
233 WA_BackFill, (IPTR)LAYERS_NOBACKFILL,
234 WA_Shape, (IPTR)bubble->shape,
235 TAG_DONE);
237 if (!bubble->win)
239 zune_bubble_delete(obj, bubble);
240 return NULL;
243 zune_bubble_draw(obj, bubble);
245 return bubble;
248 void zune_bubble_delete(Object *obj, APTR bubble)
250 ZBubble *b = (ZBubble *)bubble;
252 if (b)
254 if (b->win) CloseWindow(b->win);
255 if (b->shape) DisposeRegion(b->shape);
256 if (b->ztext) zune_text_destroy(b->ztext);
258 if (b->flags & BUBBLEF_CREATESHORTHELP_CALLED)
260 DoMethod(obj, MUIM_DeleteShortHelp, (IPTR)b->text);
263 mui_free(b);