2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
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>
23 #include "asl_intern.h"
29 #include <aros/debug.h>
34 #define NewRectRegion(_MinX,_MinY,_MaxX,_MaxY) \
35 ({ struct Region *_region; \
36 if ((_region = NewRegion())) \
37 { struct Rectangle _rect; \
42 if (!OrRectRegion(_region, &_rect)) { DisposeRegion(_region); _region = NULL; } \
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
},
72 o
= (Object
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
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
;
84 data
->drawstyle
= FS_NORMAL
;
91 /***********************************************************************************/
93 IPTR
AslFontPreview__OM_DISPOSE(Class
* cl
, Object
* o
, Msg msg
)
95 struct AslFontPreviewData
*data
;
98 data
= INST_DATA(cl
, o
);
99 if (data
->frame
) DisposeObject(data
->frame
);
101 retval
= DoSuperMethodA(cl
, o
, msg
);
106 /***********************************************************************************/
108 IPTR
AslFontPreview__OM_SET(Class
* cl
, Object
* o
, struct opSet
* msg
)
110 struct AslFontPreviewData
*data
;
112 struct TagItem
*tstate
= msg
->ops_AttrList
;
117 data
= INST_DATA(cl
, o
);
119 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
121 while((tag
= NextTagItem(&tstate
)))
126 data
->apen
= tag
->ti_Data
;
131 data
->bpen
= tag
->ti_Data
;
136 data
->drawstyle
= tag
->ti_Data
;
141 data
->font
= (struct TextFont
*)tag
->ti_Data
;
149 if ((rp
= ObtainGIRPort(msg
->ops_GInfo
)))
153 gpr
.MethodID
= GM_RENDER
;
154 gpr
.gpr_GInfo
= msg
->ops_GInfo
;
156 gpr
.gpr_Redraw
= GREDRAW_UPDATE
;
158 DoMethodA(o
, (Msg
)&gpr
);
168 /***********************************************************************************/
170 IPTR
AslFontPreview__GM_HITTEST(Class
*cl
, Object
*o
, struct gpHitTest
*msg
)
176 /***********************************************************************************/
178 IPTR
AslFontPreview__GM_RENDER(Class
*cl
, struct Gadget
*g
, struct gpRender
*msg
)
180 struct AslFontPreviewData
*data
;
182 struct TagItem im_tags
[] =
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
);
197 if (msg
->gpr_Redraw
== GREDRAW_REDRAW
)
201 im_tags
[0].ti_Data
= w
;
202 im_tags
[1].ti_Data
= h
;
204 SetAttrsA(data
->frame
, im_tags
);
207 (struct Image
*)data
->frame
,
211 msg
->gpr_GInfo
->gi_DrInfo
);
215 struct IBox ibox
, fbox
;
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
,
232 msg
->gpr_GInfo
->gi_DrInfo
->dri_Pens
[BACKGROUNDPEN
],
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
;
249 IPTR did_remap_colorfonts
;
250 WORD textlen
, pixellen
;
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
);
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
);
294 /***********************************************************************************/