2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
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>
22 #include "asl_intern.h"
28 #include <aros/debug.h>
33 #define NewRectRegion(_MinX,_MinY,_MaxX,_MaxY) \
34 ({ struct Region *_region; \
35 if ((_region = NewRegion())) \
36 { struct Rectangle _rect; \
41 if (!OrRectRegion(_region, &_rect)) { DisposeRegion(_region); _region = NULL; } \
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
},
71 o
= (Object
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
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
;
83 data
->drawstyle
= FS_NORMAL
;
90 /***********************************************************************************/
92 IPTR
AslFontPreview__OM_DISPOSE(Class
* cl
, Object
* o
, Msg msg
)
94 struct AslFontPreviewData
*data
;
97 data
= INST_DATA(cl
, o
);
98 if (data
->frame
) DisposeObject(data
->frame
);
100 retval
= DoSuperMethodA(cl
, o
, msg
);
105 /***********************************************************************************/
107 IPTR
AslFontPreview__OM_SET(Class
* cl
, Object
* o
, struct opSet
* msg
)
109 struct AslFontPreviewData
*data
;
111 const struct TagItem
*tstate
= msg
->ops_AttrList
;
116 data
= INST_DATA(cl
, o
);
118 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
120 while((tag
= NextTagItem(&tstate
)))
125 data
->apen
= tag
->ti_Data
;
130 data
->bpen
= tag
->ti_Data
;
135 data
->drawstyle
= tag
->ti_Data
;
140 data
->font
= (struct TextFont
*)tag
->ti_Data
;
148 if ((rp
= ObtainGIRPort(msg
->ops_GInfo
)))
152 gpr
.MethodID
= GM_RENDER
;
153 gpr
.gpr_GInfo
= msg
->ops_GInfo
;
155 gpr
.gpr_Redraw
= GREDRAW_UPDATE
;
157 DoMethodA(o
, (Msg
)&gpr
);
167 /***********************************************************************************/
169 IPTR
AslFontPreview__GM_HITTEST(Class
*cl
, Object
*o
, struct gpHitTest
*msg
)
175 /***********************************************************************************/
177 IPTR
AslFontPreview__GM_RENDER(Class
*cl
, struct Gadget
*g
, struct gpRender
*msg
)
179 struct AslFontPreviewData
*data
;
181 struct TagItem im_tags
[] =
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
);
196 if (msg
->gpr_Redraw
== GREDRAW_REDRAW
)
200 im_tags
[0].ti_Data
= w
;
201 im_tags
[1].ti_Data
= h
;
203 SetAttrsA(data
->frame
, im_tags
);
206 (struct Image
*)data
->frame
,
210 msg
->gpr_GInfo
->gi_DrInfo
);
214 struct IBox ibox
, fbox
;
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
,
231 msg
->gpr_GInfo
->gi_DrInfo
->dri_Pens
[BACKGROUNDPEN
],
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
;
248 IPTR did_remap_colorfonts
;
249 WORD textlen
, pixellen
;
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
);
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
);
293 /***********************************************************************************/