include/muimaster/macros.h: get() compiler delint
[AROS.git] / workbench / libs / asl / fontpreviewclass.c
blob82b409287744bd59c19220378ea9829f2e76f585
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/alib.h>
7 #include <proto/exec.h>
8 #include <proto/utility.h>
9 #include <proto/intuition.h>
10 #include <proto/graphics.h>
11 #include <proto/layers.h>
13 #include <exec/memory.h>
14 #include <intuition/screens.h>
15 #include <intuition/cghooks.h>
16 #include <intuition/imageclass.h>
17 #include <intuition/gadgetclass.h>
18 #include <graphics/gfx.h>
19 #include <graphics/rpattr.h>
21 #include <string.h>
23 #include "asl_intern.h"
24 #include "layout.h"
26 #define SDEBUG 0
27 #define DEBUG 0
29 #include <aros/debug.h>
32 #ifdef __MORPHOS__
33 #ifndef NewRectRegion
34 #define NewRectRegion(_MinX,_MinY,_MaxX,_MaxY) \
35 ({ struct Region *_region; \
36 if ((_region = NewRegion())) \
37 { struct Rectangle _rect; \
38 _rect.MinX = _MinX; \
39 _rect.MinY = _MinY; \
40 _rect.MaxX = _MaxX; \
41 _rect.MaxY = _MaxY; \
42 if (!OrRectRegion(_region, &_rect)) { DisposeRegion(_region); _region = NULL; } \
43 } \
44 _region; \
46 #endif
47 #endif
50 #define CLASS_ASLBASE ((struct AslBase_intern *)cl->cl_UserData)
51 #define HOOK_ASLBASE ((struct AslBase_intern *)hook->h_Data)
53 #define AslBase CLASS_ASLBASE
55 #define PREVIEW_TEXT "123 AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz!@#$%^&*()"
56 #define PREVIEW_BORDER_X 4
57 #define PREVIEW_BORDER_Y 4
59 /********************** ASL FONTPREVIEW CLASS **************************************************/
61 IPTR AslFontPreview__OM_NEW(Class * cl, Object * o, struct opSet * msg)
63 struct AslFontPreviewData *data;
64 struct TagItem fitags[] =
66 {IA_FrameType, FRAME_BUTTON},
67 {IA_EdgesOnly, TRUE },
68 {IA_Recessed , TRUE },
69 {TAG_DONE, 0UL}
72 o = (Object *)DoSuperMethodA(cl, o, (Msg)msg);
74 if (o)
76 data = INST_DATA(cl, o);
78 data->frame = NewObjectA(NULL, FRAMEICLASS, fitags);
79 data->previewtext = (STRPTR)GetTagData(ASLFP_SampleText, 0, msg->ops_AttrList);
80 if (!data->previewtext) data->previewtext = PREVIEW_TEXT;
82 data->apen = 1;
83 data->bpen = 0;
84 data->drawstyle = FS_NORMAL;
86 } /* if (o) */
88 return (IPTR)o;
91 /***********************************************************************************/
93 IPTR AslFontPreview__OM_DISPOSE(Class * cl, Object * o, Msg msg)
95 struct AslFontPreviewData *data;
96 IPTR retval;
98 data = INST_DATA(cl, o);
99 if (data->frame) DisposeObject(data->frame);
101 retval = DoSuperMethodA(cl, o, msg);
103 return retval;
106 /***********************************************************************************/
108 IPTR AslFontPreview__OM_SET(Class * cl, Object * o, struct opSet * msg)
110 struct AslFontPreviewData *data;
111 struct TagItem *tag;
112 struct TagItem *tstate = msg->ops_AttrList;
113 struct RastPort *rp;
114 BOOL redraw = FALSE;
115 IPTR retval;
117 data = INST_DATA(cl, o);
119 retval = DoSuperMethodA(cl, o, (Msg)msg);
121 while((tag = NextTagItem(&tstate)))
123 switch(tag->ti_Tag)
125 case ASLFP_APen:
126 data->apen = tag->ti_Data;
127 redraw = TRUE;
128 break;
130 case ASLFP_BPen:
131 data->bpen = tag->ti_Data;
132 redraw = TRUE;
133 break;
135 case ASLFP_Style:
136 data->drawstyle = tag->ti_Data;
137 redraw = TRUE;
138 break;
140 case ASLFP_Font:
141 data->font = (struct TextFont *)tag->ti_Data;
142 redraw = TRUE;
143 break;
147 if (redraw)
149 if ((rp = ObtainGIRPort(msg->ops_GInfo)))
151 struct gpRender gpr;
153 gpr.MethodID = GM_RENDER;
154 gpr.gpr_GInfo = msg->ops_GInfo;
155 gpr.gpr_RPort = rp;
156 gpr.gpr_Redraw = GREDRAW_UPDATE;
158 DoMethodA(o, (Msg)&gpr);
160 ReleaseGIRPort(rp);
164 return retval;
168 /***********************************************************************************/
170 IPTR AslFontPreview__GM_HITTEST(Class *cl, Object *o, struct gpHitTest *msg)
172 return 0;
176 /***********************************************************************************/
178 IPTR AslFontPreview__GM_RENDER(Class *cl, struct Gadget *g, struct gpRender *msg)
180 struct AslFontPreviewData *data;
181 struct RastPort *rp;
182 struct TagItem im_tags[] =
184 {IA_Width , 0 },
185 {IA_Height , 0 },
186 {TAG_DONE }
188 struct Region *clip, *oldclip;
190 WORD x, y, w, h, x2, y2;
192 getgadgetcoords(g, msg->gpr_GInfo, &x, &y, &w, &h);
194 data = INST_DATA(cl, g);
195 rp = msg->gpr_RPort;
197 if (msg->gpr_Redraw == GREDRAW_REDRAW)
199 if (data->frame)
201 im_tags[0].ti_Data = w;
202 im_tags[1].ti_Data = h;
204 SetAttrsA(data->frame, im_tags);
206 DrawImageState(rp,
207 (struct Image *)data->frame,
210 IDS_NORMAL,
211 msg->gpr_GInfo->gi_DrInfo);
213 #if AVOID_FLICKER
215 struct IBox ibox, fbox;
217 fbox.Left = x;
218 fbox.Top = y;
219 fbox.Width = w;
220 fbox.Height = h;
222 ibox.Left = x + PREVIEW_BORDER_X;
223 ibox.Top = y + PREVIEW_BORDER_Y;
224 ibox.Width = w - PREVIEW_BORDER_X * 2;
225 ibox.Height = h - PREVIEW_BORDER_Y * 2;
227 PaintInnerFrame(msg->gpr_RPort,
228 msg->gpr_GInfo->gi_DrInfo,
229 data->frame,
230 &fbox,
231 &ibox,
232 msg->gpr_GInfo->gi_DrInfo->dri_Pens[BACKGROUNDPEN],
233 AslBase);
235 #endif
239 x2 = x + w - 1 - PREVIEW_BORDER_X;
240 y2 = y + h - 1 - PREVIEW_BORDER_Y;
241 x += PREVIEW_BORDER_X;
242 y += PREVIEW_BORDER_Y;
244 if ((clip = NewRectRegion(x, y, x2, y2)))
246 struct TextFont *font;
247 struct Layer *lay = msg->gpr_GInfo->gi_Layer;
248 STRPTR text;
249 IPTR did_remap_colorfonts;
250 WORD textlen, pixellen;
251 BOOL updating;
253 updating = (lay->Flags & LAYERUPDATING) != 0;
254 if (updating) EndUpdate(lay, FALSE);
256 font = data->font ? data->font : msg->gpr_GInfo->gi_DrInfo->dri_Font;
257 text = data->font ? data->previewtext : (STRPTR)"???";
259 oldclip = InstallClipRegion(lay, clip);
261 if (updating) BeginUpdate(lay);
263 SetAPen(rp, data->bpen);
264 RectFill(rp, x, y, x2, y2);
266 SetABPenDrMd(rp, data->apen, data->bpen, JAM2);
267 SetFont(rp, font);
268 SetSoftStyle(rp, data->drawstyle, AskSoftStyle(rp));
270 textlen = strlen(text);
271 pixellen = TextLength(rp, text, textlen);
272 if (pixellen <= (x2 - x + 1))
274 x += (x2 - x + 1 - pixellen) / 2;
277 GetRPAttrs(rp, RPTAG_RemapColorFonts, &did_remap_colorfonts, TAG_DONE);
278 SetRPAttrs(rp, RPTAG_RemapColorFonts, TRUE, TAG_DONE);
280 Move(rp, x, (y + y2 + 1 - font->tf_YSize) / 2 + font->tf_Baseline);
281 Text(rp, text, textlen);
283 SetRPAttrs(rp, RPTAG_RemapColorFonts, did_remap_colorfonts, TAG_DONE);
285 if (updating) EndUpdate(lay, FALSE);
286 InstallClipRegion(lay, oldclip);
287 if (updating) BeginUpdate(lay);
289 DisposeRegion(clip);
291 return 0;
294 /***********************************************************************************/