2 Copyright © 1999, David Le Corfec.
3 Copyright © 2002, The AROS Development Team.
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>
26 #include "textengine.h"
27 #include "bubbleengine.h"
30 #include "muimaster_intern.h"
35 extern struct Library
*MUIMasterBase
;
37 /************************************************************************/
40 #define WA_Shape WA_ShapeRegion
43 /************************************************************************/
45 typedef struct ZBubble
54 #define BUBBLEF_CREATESHORTHELP_CALLED 1
56 /************************************************************************/
75 #define ROUNDEDGE_SIZE 13
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();
102 if (!shape
) return NULL
;
104 for(y
= 0; y
< ROUNDEDGE_SIZE
; y
++)
106 r
.MinX
= roundtab
[y
];
108 r
.MaxX
= w
- 1 - r
.MinX
;
111 OrRectRegion(shape
, &r
);
116 OrRectRegion(shape
, &r
);
124 OrRectRegion(shape
, &r
);
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
)
145 SetAPen(rp
, _pens(obj
)[MPEN_SHADOW
]);
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
);
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
);
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);
184 APTR
zune_bubble_create(Object
*obj
, LONG x
, LONG y
, char *text
, ULONG flags
)
188 if (!(_flags(obj
) & MADF_CANDRAW
)) return NULL
;
190 bubble
= mui_alloc_struct(ZBubble
);
191 if (!bubble
) return NULL
;
195 text
= (STRPTR
)DoMethod(obj
, MUIM_CreateShortHelp
, x
, y
);
196 bubble
->flags
|= BUBBLEF_CREATESHORTHELP_CALLED
;
207 bubble
->ztext
= zune_text_new(NULL
, bubble
->text
, ZTEXT_ARG_NONE
, 0);
210 zune_bubble_delete(obj
, bubble
);
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
),
229 WA_Height
, WINHEIGHT
,
233 WA_BackFill
, (IPTR
)LAYERS_NOBACKFILL
,
234 WA_Shape
, (IPTR
)bubble
->shape
,
239 zune_bubble_delete(obj
, bubble
);
243 zune_bubble_draw(obj
, bubble
);
248 void zune_bubble_delete(Object
*obj
, APTR bubble
)
250 ZBubble
*b
= (ZBubble
*)bubble
;
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
);