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/text.h>
23 #include "asl_intern.h"
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] =
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
},
58 o
= (Object
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
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];
86 /***********************************************************************************/
88 IPTR
AslFontStyle__OM_DISPOSE(Class
* cl
, Object
* o
, Msg msg
)
90 struct AslFontStyleData
*data
;
93 data
= INST_DATA(cl
, o
);
94 if (data
->frame
) DisposeObject(data
->frame
);
96 retval
= DoSuperMethodA(cl
, o
, msg
);
101 /***********************************************************************************/
103 IPTR
AslFontStyle__OM_SET(Class
* cl
, Object
* o
, struct opSet
* msg
)
105 struct AslFontStyleData
*data
;
107 struct TagItem
*tstate
= msg
->ops_AttrList
;
112 data
= INST_DATA(cl
, o
);
114 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
116 while((tag
= NextTagItem(&tstate
)))
121 data
->style
= tag
->ti_Data
;
130 if ((rp
= ObtainGIRPort(msg
->ops_GInfo
)))
134 gpr
.MethodID
= GM_RENDER
;
135 gpr
.gpr_GInfo
= msg
->ops_GInfo
;
137 gpr
.gpr_Redraw
= GREDRAW_UPDATE
;
139 DoMethodA(o
, (Msg
)&gpr
);
149 /***********************************************************************************/
151 IPTR
AslFontStyle__OM_GET(Class
*cl
, Object
*o
, struct opGet
*msg
)
153 struct AslFontStyleData
*data
= INST_DATA(cl
, o
);
157 switch(msg
->opg_AttrID
)
160 *msg
->opg_Storage
= data
->style
;
164 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
172 /***********************************************************************************/
174 IPTR
AslFontStyle__GM_RENDER(Class
*cl
, struct Gadget
*g
, struct gpRender
*msg
)
176 struct AslFontStyleData
*data
;
178 WORD x
, y
, w
, h
, i
, sw
;
180 getgadgetcoords(g
, msg
->gpr_GInfo
, &x
, &y
, &w
, &h
);
182 data
= INST_DATA(cl
, g
);
189 SetAttrs(data
->frame
, IA_Width
, sw
,
194 for(i
= 0; i
< 3; i
++)
196 struct TextExtent te
;
199 set
= (data
->style
& gadindextostylemap
[i
]) ? TRUE
: FALSE
;
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
]);
216 TextExtent(rp
, data
->text
[i
], strlen(data
->text
[i
]), &te
);
217 w
= te
.te_Extent
.MaxX
- te
.te_Extent
.MinX
+ 1;
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
]));
230 /***********************************************************************************/
232 IPTR
AslFontStyle__GM_GOACTIVE(Class
*cl
, struct Gadget
*g
, struct gpInput
*msg
)
234 struct AslFontStyleData
*data
;
238 if (!msg
->gpi_IEvent
) return GMR_NOREUSE
;
240 getgadgetcoords(g
, msg
->gpi_GInfo
, &x
, &y
, &w
, &h
);
242 data
= INST_DATA(cl
, g
);
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
)))
254 gpr
.MethodID
= GM_RENDER
;
255 gpr
.gpr_GInfo
= msg
->gpi_GInfo
;
257 gpr
.gpr_Redraw
= GREDRAW_UPDATE
;
259 DoMethodA((Object
*)g
, (Msg
)&gpr
);
264 *msg
->gpi_Termination
= data
->style
;
266 return GMR_NOREUSE
| GMR_VERIFY
;
270 /***********************************************************************************/