added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / libs / asl / fontpreviewclass.c
blob8239a71b0456a95ea74fabcc8a0b57d9c5be3eb8
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <proto/utility.h>
8 #include <proto/intuition.h>
9 #include <proto/graphics.h>
10 #include <proto/layers.h>
12 #include <exec/memory.h>
13 #include <intuition/screens.h>
14 #include <intuition/cghooks.h>
15 #include <intuition/imageclass.h>
16 #include <intuition/gadgetclass.h>
17 #include <graphics/gfx.h>
18 #include <graphics/rpattr.h>
20 #include <string.h>
22 #include "asl_intern.h"
23 #include "layout.h"
25 #define SDEBUG 0
26 #define DEBUG 0
28 #include <aros/debug.h>
31 #ifdef __MORPHOS__
32 #ifndef NewRectRegion
33 #define NewRectRegion(_MinX,_MinY,_MaxX,_MaxY) \
34 ({ struct Region *_region; \
35 if ((_region = NewRegion())) \
36 { struct Rectangle _rect; \
37 _rect.MinX = _MinX; \
38 _rect.MinY = _MinY; \
39 _rect.MaxX = _MaxX; \
40 _rect.MaxY = _MaxY; \
41 if (!OrRectRegion(_region, &_rect)) { DisposeRegion(_region); _region = NULL; } \
42 } \
43 _region; \
45 #endif
46 #endif
49 #define CLASS_ASLBASE ((struct AslBase_intern *)cl->cl_UserData)
50 #define HOOK_ASLBASE ((struct AslBase_intern *)hook->h_Data)
52 #define AslBase CLASS_ASLBASE
54 #define PREVIEW_TEXT "123 AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz!@#$%^&*()"
55 #define PREVIEW_BORDER_X 4
56 #define PREVIEW_BORDER_Y 4
58 /********************** ASL FONTPREVIEW CLASS **************************************************/
60 IPTR AslFontPreview__OM_NEW(Class * cl, Object * o, struct opSet * msg)
62 struct AslFontPreviewData *data;
63 struct TagItem fitags[] =
65 {IA_FrameType, FRAME_BUTTON},
66 {IA_EdgesOnly, TRUE },
67 {IA_Recessed , TRUE },
68 {TAG_DONE, 0UL}
71 o = (Object *)DoSuperMethodA(cl, o, (Msg)msg);
73 if (o)
75 data = INST_DATA(cl, o);
77 data->frame = NewObjectA(NULL, FRAMEICLASS, fitags);
78 data->previewtext = (STRPTR)GetTagData(ASLFP_SampleText, 0, msg->ops_AttrList);
79 if (!data->previewtext) data->previewtext = PREVIEW_TEXT;
81 data->apen = 1;
82 data->bpen = 0;
83 data->drawstyle = FS_NORMAL;
85 } /* if (o) */
87 return (IPTR)o;
90 /***********************************************************************************/
92 IPTR AslFontPreview__OM_DISPOSE(Class * cl, Object * o, Msg msg)
94 struct AslFontPreviewData *data;
95 IPTR retval;
97 data = INST_DATA(cl, o);
98 if (data->frame) DisposeObject(data->frame);
100 retval = DoSuperMethodA(cl, o, msg);
102 return retval;
105 /***********************************************************************************/
107 IPTR AslFontPreview__OM_SET(Class * cl, Object * o, struct opSet * msg)
109 struct AslFontPreviewData *data;
110 struct TagItem *tag;
111 const struct TagItem *tstate = msg->ops_AttrList;
112 struct RastPort *rp;
113 BOOL redraw = FALSE;
114 IPTR retval;
116 data = INST_DATA(cl, o);
118 retval = DoSuperMethodA(cl, o, (Msg)msg);
120 while((tag = NextTagItem(&tstate)))
122 switch(tag->ti_Tag)
124 case ASLFP_APen:
125 data->apen = tag->ti_Data;
126 redraw = TRUE;
127 break;
129 case ASLFP_BPen:
130 data->bpen = tag->ti_Data;
131 redraw = TRUE;
132 break;
134 case ASLFP_Style:
135 data->drawstyle = tag->ti_Data;
136 redraw = TRUE;
137 break;
139 case ASLFP_Font:
140 data->font = (struct TextFont *)tag->ti_Data;
141 redraw = TRUE;
142 break;
146 if (redraw)
148 if ((rp = ObtainGIRPort(msg->ops_GInfo)))
150 struct gpRender gpr;
152 gpr.MethodID = GM_RENDER;
153 gpr.gpr_GInfo = msg->ops_GInfo;
154 gpr.gpr_RPort = rp;
155 gpr.gpr_Redraw = GREDRAW_UPDATE;
157 DoMethodA(o, (Msg)&gpr);
159 ReleaseGIRPort(rp);
163 return retval;
167 /***********************************************************************************/
169 IPTR AslFontPreview__GM_HITTEST(Class *cl, Object *o, struct gpHitTest *msg)
171 return 0;
175 /***********************************************************************************/
177 IPTR AslFontPreview__GM_RENDER(Class *cl, struct Gadget *g, struct gpRender *msg)
179 struct AslFontPreviewData *data;
180 struct RastPort *rp;
181 struct TagItem im_tags[] =
183 {IA_Width , 0 },
184 {IA_Height , 0 },
185 {TAG_DONE }
187 struct Region *clip, *oldclip;
189 WORD x, y, w, h, x2, y2;
191 getgadgetcoords(g, msg->gpr_GInfo, &x, &y, &w, &h);
193 data = INST_DATA(cl, g);
194 rp = msg->gpr_RPort;
196 if (msg->gpr_Redraw == GREDRAW_REDRAW)
198 if (data->frame)
200 im_tags[0].ti_Data = w;
201 im_tags[1].ti_Data = h;
203 SetAttrsA(data->frame, im_tags);
205 DrawImageState(rp,
206 (struct Image *)data->frame,
209 IDS_NORMAL,
210 msg->gpr_GInfo->gi_DrInfo);
212 #if AVOID_FLICKER
214 struct IBox ibox, fbox;
216 fbox.Left = x;
217 fbox.Top = y;
218 fbox.Width = w;
219 fbox.Height = h;
221 ibox.Left = x + PREVIEW_BORDER_X;
222 ibox.Top = y + PREVIEW_BORDER_Y;
223 ibox.Width = w - PREVIEW_BORDER_X * 2;
224 ibox.Height = h - PREVIEW_BORDER_Y * 2;
226 PaintInnerFrame(msg->gpr_RPort,
227 msg->gpr_GInfo->gi_DrInfo,
228 data->frame,
229 &fbox,
230 &ibox,
231 msg->gpr_GInfo->gi_DrInfo->dri_Pens[BACKGROUNDPEN],
232 AslBase);
234 #endif
238 x2 = x + w - 1 - PREVIEW_BORDER_X;
239 y2 = y + h - 1 - PREVIEW_BORDER_Y;
240 x += PREVIEW_BORDER_X;
241 y += PREVIEW_BORDER_Y;
243 if ((clip = NewRectRegion(x, y, x2, y2)))
245 struct TextFont *font;
246 struct Layer *lay = msg->gpr_GInfo->gi_Layer;
247 STRPTR text;
248 IPTR did_remap_colorfonts;
249 WORD textlen, pixellen;
250 BOOL updating;
252 updating = (lay->Flags & LAYERUPDATING) != 0;
253 if (updating) EndUpdate(lay, FALSE);
255 font = data->font ? data->font : msg->gpr_GInfo->gi_DrInfo->dri_Font;
256 text = data->font ? data->previewtext : (STRPTR)"???";
258 oldclip = InstallClipRegion(lay, clip);
260 if (updating) BeginUpdate(lay);
262 SetAPen(rp, data->bpen);
263 RectFill(rp, x, y, x2, y2);
265 SetABPenDrMd(rp, data->apen, data->bpen, JAM2);
266 SetFont(rp, font);
267 SetSoftStyle(rp, data->drawstyle, AskSoftStyle(rp));
269 textlen = strlen(text);
270 pixellen = TextLength(rp, text, textlen);
271 if (pixellen <= (x2 - x + 1))
273 x += (x2 - x + 1 - pixellen) / 2;
276 GetRPAttrs(rp, RPTAG_RemapColorFonts, &did_remap_colorfonts, TAG_DONE);
277 SetRPAttrs(rp, RPTAG_RemapColorFonts, TRUE, TAG_DONE);
279 Move(rp, x, (y + y2 + 1 - font->tf_YSize) / 2 + font->tf_Baseline);
280 Text(rp, text, textlen);
282 SetRPAttrs(rp, RPTAG_RemapColorFonts, did_remap_colorfonts, TAG_DONE);
284 if (updating) EndUpdate(lay, FALSE);
285 InstallClipRegion(lay, oldclip);
286 if (updating) BeginUpdate(lay);
288 DisposeRegion(clip);
290 return 0;
293 /***********************************************************************************/