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
, 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(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;
78 WORD len
= strlen(str
), underoff
;
84 lod
= INST_DATA(ButtonImgClass
, im
);
85 lod
->lod_UnderOff
= len
;
87 im
->Height
= temprp
.TxHeight
;
90 pixellen
= TextLength(&temprp
, str
, len
);
100 if (c
== *underscore
)
102 pixellen
-= TextLength(&temprp
, underscore
, 1);
106 im
->PlaneOnOff
= *str2
; /* store code of underscored key */
107 lod
->lod_UnderOff
= underoff
; /* store offset of underscore */
108 lod
->lod_RestLen
= len
- underoff
- 1; /* store len of remaining string */
109 lod
->lod_UnderY
= temprp
.TxBaseline
+ 2; /* Y position of underscore */
111 lod
->lod_UnderWidth
= TextLength(&temprp
, str2
, 1);
120 DeinitRastPort(&temprp
);
123 if (font
) CloseFont(font
);
128 /****************************************************************************************/
130 #define imsg ((struct impDraw *)msg)
133 AROS_UFH3(IPTR
, myBoopsiDispatch
,
134 AROS_UFHA(Class
*, cl
, A0
),
135 AROS_UFHA(struct Image
*, im
, A2
),
136 AROS_UFHA(Msg
, msg
, A1
))
140 IPTR
myBoopsiDispatch(REGPARAM(a0
, Class
*, cl
),
141 REGPARAM(a2
, struct Image
*, im
),
142 REGPARAM(a1
, Msg
, msg
))
145 struct LocalObjData
*data
;
146 struct TextFont
*font
, *oldfont
;
153 switch(msg
->MethodID
)
156 retval
= DoSuperMethodA(cl
, (Object
*)im
, msg
);
159 UBYTE underscorechar
;
168 im
= (struct Image
*)retval
;
170 data
= INST_DATA(cl
, im
);
171 data
->lod_IData
= *(struct InitData
*)im
->ImageData
;
173 underscorechar
= (UBYTE
)data
->lod_IData
.idata_Underscore
;
175 im
->Width
= myTextLength(data
->lod_IData
.idata_Label
,
176 data
->lod_IData
.idata_TextAttr
,
179 cl
->cl_InstOffset
/* for C Routines its not really more than a flag */
182 /* Calculate text position if we have a gadget */
184 if ((gad
= data
->lod_IData
.idata_Gadget
))
186 im
->LeftEdge
= (gad
->Width
- im
->Width
) / 2;
187 im
->TopEdge
= (gad
->Height
- im
->Height
) / 2;
191 im
->ImageData
= (UWORD
*)im
;
192 __tmp
.magic
= BUTTON_MAGIC_LONGWORD
;
193 im
->Width
= __tmp
.size
.Width
;
194 im
->Height
= __tmp
.size
.Height
;
199 data
= INST_DATA(cl
, im
);
201 rp
= imsg
->imp_RPort
;
205 font
= OpenFont(data
->lod_IData
.idata_TextAttr
);
210 SetFont(rp
, GfxBase
->DefaultFont
);
212 SetSoftStyle(rp
, data
->lod_IData
.idata_TextAttr
->ta_Style
, data
->lod_IData
.idata_TextAttr
->ta_Style
);
214 xpos
= imsg
->imp_Offset
.X
;
215 ypos
= imsg
->imp_Offset
.Y
;
217 pens
= imsg
->imp_DrInfo
->dri_Pens
;
218 if (!pens
) pens
= (UWORD
*)defaultpens
;
220 if ((gad
= data
->lod_IData
.idata_Gadget
))
222 xpos
= gad
->LeftEdge
;
225 SetAPen(rp
, pens
[(imsg
->imp_State
== IDS_SELECTED
) ? FILLPEN
: BACKGROUNDPEN
]);
229 gad
->LeftEdge
+ gad
->Width
- 1,
230 gad
->TopEdge
+ gad
->Height
-1 );
231 im
->PlanePick
= (imsg
->imp_State
== IDS_SELECTED
) ? FILLTEXTPEN
: TEXTPEN
;
234 xpos
+= im
->LeftEdge
;
237 SetAPen(rp
, pens
[im
->PlanePick
]);
239 Move(rp
, xpos
, ypos
+ rp
->TxBaseline
);
241 /* Draw first part of text (entire text if no underscore */
243 if (data
->lod_UnderOff
)
244 Text(rp
, data
->lod_IData
.idata_Label
, data
->lod_UnderOff
);
246 /* Is there an underscore in text */
250 /* First draw rest of text */
254 Text(rp
, data
->lod_IData
.idata_Label
+ data
->lod_UnderOff
+ 1, data
->lod_RestLen
);
256 /* Draw underscore */
258 Move(rp
, xpos
, ypos
+ data
->lod_UnderY
);
259 Draw(rp
, xpos
+ data
->lod_UnderWidth
- 1, ypos
+ data
->lod_UnderY
);
264 struct TagItem beveltags
[] =
266 {GT_VisualInfo
, (IPTR
)data
->lod_IData
.idata_VisualInfo
},
267 {GTBB_Recessed
, TRUE
},
271 if (imsg
->imp_State
!= IDS_SELECTED
) beveltags
[1].ti_Tag
= TAG_IGNORE
;
273 /* draw bevelbox around gadget container (recessed if selected) */
283 SetFont(rp
, oldfont
);
284 if (font
) CloseFont(font
);
288 retval
= DoSuperMethodA(cl
, (Object
*)im
, msg
);
291 } /* switch(msg->MethodID) */
299 /****************************************************************************************/
300 /****************************************************************************************/