1 #include <graphics/gfxbase.h>
2 #include <graphics/rastport.h>
3 #include <graphics/text.h>
4 #include <intuition/intuition.h>
5 #include <intuition/imageclass.h>
6 #include <intuition/intuition.h>
8 #include <aros/asmcall.h>
15 extern struct IClass
*ButtonImgClass
;
17 extern ULONG ASM
myTextLength (ASM_REGPARAM(a1
, const char *,),
18 ASM_REGPARAM(a0
, struct TextAttr
*,),
19 ASM_REGPARAM(a3
, UBYTE
*,),
20 ASM_REGPARAM(a2
, struct Image
*,),
21 ASM_REGPARAM(d7
, ULONG
,));
23 const UWORD defaultpens
[] =
25 1, 0, 1, 2, 1, 3, 1, 0, 2
28 /****************************************************************************************/
30 char KeyFromStr(char *string
, char underchar
)
34 while ((c
= *string
++))
38 ret
= ToUpper(*string
);
46 /****************************************************************************************/
48 ULONG
myTextLength(const char *str
, struct TextAttr
*attr
, UBYTE
*underscore
,
49 struct Image
*im
, ULONG do_lod
)
51 struct RastPort temprp
;
52 struct TextFont
*font
= NULL
;
55 InitRastPort(&temprp
);
59 font
= OpenFont(attr
);
62 SetFont(&temprp
, font
);
66 SetFont(&temprp
, GfxBase
->DefaultFont
);
71 SetFont(&temprp
, GfxBase
->DefaultFont
);
76 struct LocalObjData
*lod
= (struct LocalObjData
*)0xDEADBEAF;
79 WORD len
= strlen(str
), underoff
;
85 lod
= INST_DATA(ButtonImgClass
, im
);
86 lod
->lod_UnderOff
= len
;
88 im
->Height
= temprp
.TxHeight
;
91 pixellen
= TextLength(&temprp
, str
, len
);
101 if (c
== *underscore
)
103 pixellen
-= TextLength(&temprp
, underscore
, 1);
107 im
->PlaneOnOff
= *str2
; /* store code of underscored key */
108 lod
->lod_UnderOff
= underoff
; /* store offset of underscore */
109 lod
->lod_RestLen
= len
- underoff
- 1; /* store len of remaining string */
110 lod
->lod_UnderY
= temprp
.TxBaseline
+ 2; /* Y position of underscore */
112 lod
->lod_UnderWidth
= TextLength(&temprp
, str2
, 1);
120 if (font
) CloseFont(font
);
125 /****************************************************************************************/
127 #define imsg ((struct impDraw *)msg)
130 AROS_UFH3(IPTR
, myBoopsiDispatch
,
131 AROS_UFHA(Class
*, cl
, A0
),
132 AROS_UFHA(struct Image
*, im
, A2
),
133 AROS_UFHA(Msg
, msg
, A1
))
137 IPTR
myBoopsiDispatch(REGPARAM(a0
, Class
*, cl
),
138 REGPARAM(a2
, struct Image
*, im
),
139 REGPARAM(a1
, Msg
, msg
))
142 struct LocalObjData
*data
;
143 struct TextFont
*font
, *oldfont
;
150 switch(msg
->MethodID
)
153 retval
= DoSuperMethodA(cl
, (Object
*)im
, msg
);
156 UBYTE underscorechar
;
165 im
= (struct Image
*)retval
;
167 data
= INST_DATA(cl
, im
);
168 data
->lod_IData
= *(struct InitData
*)im
->ImageData
;
170 underscorechar
= (UBYTE
)data
->lod_IData
.idata_Underscore
;
172 im
->Width
= myTextLength(data
->lod_IData
.idata_Label
,
173 data
->lod_IData
.idata_TextAttr
,
176 cl
->cl_InstOffset
/* for C Routines its not really more than a flag */
179 /* Calculate text position if we have a gadget */
181 if ((gad
= data
->lod_IData
.idata_Gadget
))
183 im
->LeftEdge
= (gad
->Width
- im
->Width
) / 2;
184 im
->TopEdge
= (gad
->Height
- im
->Height
) / 2;
188 im
->ImageData
= (UWORD
*)im
;
189 __tmp
.magic
= BUTTON_MAGIC_LONGWORD
;
190 im
->Width
= __tmp
.size
.Width
;
191 im
->Height
= __tmp
.size
.Height
;
196 data
= INST_DATA(cl
, im
);
198 rp
= imsg
->imp_RPort
;
202 font
= OpenFont(data
->lod_IData
.idata_TextAttr
);
207 SetFont(rp
, GfxBase
->DefaultFont
);
209 SetSoftStyle(rp
, data
->lod_IData
.idata_TextAttr
->ta_Style
, data
->lod_IData
.idata_TextAttr
->ta_Style
);
211 xpos
= imsg
->imp_Offset
.X
;
212 ypos
= imsg
->imp_Offset
.Y
;
214 pens
= imsg
->imp_DrInfo
->dri_Pens
;
215 if (!pens
) pens
= (UWORD
*)defaultpens
;
217 if ((gad
= data
->lod_IData
.idata_Gadget
))
219 xpos
= gad
->LeftEdge
;
222 SetAPen(rp
, pens
[(imsg
->imp_State
== IDS_SELECTED
) ? FILLPEN
: BACKGROUNDPEN
]);
226 gad
->LeftEdge
+ gad
->Width
- 1,
227 gad
->TopEdge
+ gad
->Height
-1 );
228 im
->PlanePick
= (imsg
->imp_State
== IDS_SELECTED
) ? FILLTEXTPEN
: TEXTPEN
;
231 xpos
+= im
->LeftEdge
;
234 SetAPen(rp
, pens
[im
->PlanePick
]);
236 Move(rp
, xpos
, ypos
+ rp
->TxBaseline
);
238 /* Draw first part of text (entire text if no underscore */
240 if (data
->lod_UnderOff
)
241 Text(rp
, data
->lod_IData
.idata_Label
, data
->lod_UnderOff
);
243 /* Is there an underscore in text */
247 /* First draw rest of text */
251 Text(rp
, data
->lod_IData
.idata_Label
+ data
->lod_UnderOff
+ 1, data
->lod_RestLen
);
253 /* Draw underscore */
255 Move(rp
, xpos
, ypos
+ data
->lod_UnderY
);
256 Draw(rp
, xpos
+ data
->lod_UnderWidth
- 1, ypos
+ data
->lod_UnderY
);
261 struct TagItem beveltags
[] =
263 {GT_VisualInfo
, (IPTR
)data
->lod_IData
.idata_VisualInfo
},
264 {GTBB_Recessed
, TRUE
},
268 if (imsg
->imp_State
!= IDS_SELECTED
) beveltags
[1].ti_Tag
= TAG_IGNORE
;
270 /* draw bevelbox around gadget container (recessed if selected) */
280 SetFont(rp
, oldfont
);
281 if (font
) CloseFont(font
);
285 retval
= DoSuperMethodA(cl
, (Object
*)im
, msg
);
288 } /* switch(msg->MethodID) */
296 /****************************************************************************************/
297 /****************************************************************************************/