grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / asl / fontstyleclass.c
blob3ba6c61ebc53d852d201f998d66897169c397da0
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/text.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>
31 #define CLASS_ASLBASE ((struct AslBase_intern *)cl->cl_UserData)
32 #define HOOK_ASLBASE ((struct AslBase_intern *)hook->h_Data)
34 #define AslBase CLASS_ASLBASE
36 /********************** ASL FONTPREVIEW CLASS **************************************************/
38 static const UBYTE gadindextostylemap[3] =
40 FSF_BOLD,
41 FSF_ITALIC,
42 FSF_UNDERLINED
45 /***********************************************************************************/
47 IPTR AslFontStyle__OM_NEW(Class * cl, Object * o, struct opSet * msg)
49 struct AslFontStyleData *data;
50 struct TagItem fitags[] =
52 {IA_FrameType, FRAME_BUTTON},
53 {IA_EdgesOnly, FALSE },
54 {TAG_DONE, 0UL}
56 STRPTR *labelarray;
58 o = (Object *)DoSuperMethodA(cl, o, (Msg)msg);
60 if (o)
62 data = INST_DATA(cl, o);
64 data->frame = NewObjectA(NULL, FRAMEICLASS, fitags);
66 data->style = GetTagData(ASLFS_Style, FS_NORMAL, msg->ops_AttrList);
68 if ((labelarray = (STRPTR *)GetTagData(ASLFS_LabelArray, 0, msg->ops_AttrList)))
70 data->text[0] = labelarray[0];
71 data->text[1] = labelarray[1];
72 data->text[2] = labelarray[2];
74 else
76 data->text[0] = "B";
77 data->text[1] = "I";
78 data->text[2] = "U";
81 } /* if (o) */
83 return (IPTR)o;
86 /***********************************************************************************/
88 IPTR AslFontStyle__OM_DISPOSE(Class * cl, Object * o, Msg msg)
90 struct AslFontStyleData *data;
91 IPTR retval;
93 data = INST_DATA(cl, o);
94 if (data->frame) DisposeObject(data->frame);
96 retval = DoSuperMethodA(cl, o, msg);
98 return retval;
101 /***********************************************************************************/
103 IPTR AslFontStyle__OM_SET(Class * cl, Object * o, struct opSet * msg)
105 struct AslFontStyleData *data;
106 struct TagItem *tag;
107 struct TagItem *tstate = msg->ops_AttrList;
108 struct RastPort *rp;
109 BOOL redraw = FALSE;
110 IPTR retval;
112 data = INST_DATA(cl, o);
114 retval = DoSuperMethodA(cl, o, (Msg)msg);
116 while((tag = NextTagItem(&tstate)))
118 switch(tag->ti_Tag)
120 case ASLFS_Style:
121 data->style = tag->ti_Data;
122 redraw = TRUE;
123 break;
128 if (redraw)
130 if ((rp = ObtainGIRPort(msg->ops_GInfo)))
132 struct gpRender gpr;
134 gpr.MethodID = GM_RENDER;
135 gpr.gpr_GInfo = msg->ops_GInfo;
136 gpr.gpr_RPort = rp;
137 gpr.gpr_Redraw = GREDRAW_UPDATE;
139 DoMethodA(o, (Msg)&gpr);
141 ReleaseGIRPort(rp);
145 return retval;
149 /***********************************************************************************/
151 IPTR AslFontStyle__OM_GET(Class *cl, Object *o, struct opGet *msg)
153 struct AslFontStyleData *data = INST_DATA(cl, o);
155 IPTR retval = 1;
157 switch(msg->opg_AttrID)
159 case ASLFS_Style:
160 *msg->opg_Storage = data->style;
161 break;
163 default:
164 retval = DoSuperMethodA(cl, o, (Msg)msg);
165 break;
168 return retval;
172 /***********************************************************************************/
174 IPTR AslFontStyle__GM_RENDER(Class *cl, struct Gadget *g, struct gpRender *msg)
176 struct AslFontStyleData *data;
177 struct RastPort *rp;
178 WORD x, y, w, h, i, sw;
180 getgadgetcoords(g, msg->gpr_GInfo, &x, &y, &w, &h);
182 data = INST_DATA(cl, g);
183 rp = msg->gpr_RPort;
185 sw = w / 3;
187 if (data->frame)
189 SetAttrs(data->frame, IA_Width, sw,
190 IA_Height, h,
191 TAG_DONE);
194 for(i = 0; i < 3; i++)
196 struct TextExtent te;
197 BOOL set;
199 set = (data->style & gadindextostylemap[i]) ? TRUE : FALSE;
201 if (data->frame)
204 DrawImageState(rp,
205 (struct Image *)data->frame,
208 set ? IDS_SELECTED : IDS_NORMAL,
209 msg->gpr_GInfo->gi_DrInfo);
212 SetSoftStyle(rp, gadindextostylemap[i], AskSoftStyle(rp));
213 SetAPen(rp, msg->gpr_GInfo->gi_DrInfo->dri_Pens[set ? HIGHLIGHTTEXTPEN : TEXTPEN]);
214 SetDrMd(rp, JAM1);
216 TextExtent(rp, data->text[i], strlen(data->text[i]), &te);
217 w = te.te_Extent.MaxX - te.te_Extent.MinX + 1;
219 Move(rp,
220 x + (sw - w) / 2 - te.te_Extent.MinX,
221 y + (h - rp->TxHeight) / 2 + rp->TxBaseline);
222 Text(rp, data->text[i], strlen(data->text[i]));
224 x += sw;
227 return 0;
230 /***********************************************************************************/
232 IPTR AslFontStyle__GM_GOACTIVE(Class *cl, struct Gadget *g, struct gpInput *msg)
234 struct AslFontStyleData *data;
235 struct RastPort *rp;
236 WORD x, y, w, h;
238 if (!msg->gpi_IEvent) return GMR_NOREUSE;
240 getgadgetcoords(g, msg->gpi_GInfo, &x, &y, &w, &h);
242 data = INST_DATA(cl, g);
244 w /= 3;
245 x = msg->gpi_Mouse.X / w;
246 if (x < 0) x = 0; else if (x > 2) x = 2;
248 data->style ^= gadindextostylemap[x];
250 if ((rp = ObtainGIRPort(msg->gpi_GInfo)))
252 struct gpRender gpr;
254 gpr.MethodID = GM_RENDER;
255 gpr.gpr_GInfo = msg->gpi_GInfo;
256 gpr.gpr_RPort = rp;
257 gpr.gpr_Redraw = GREDRAW_UPDATE;
259 DoMethodA((Object *)g, (Msg)&gpr);
261 ReleaseGIRPort(rp);
264 *msg->gpi_Termination = data->style;
266 return GMR_NOREUSE | GMR_VERIFY;
270 /***********************************************************************************/