2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Basic help functions needed by gadtools.library.
9 #include <proto/exec.h>
10 #include <exec/types.h>
11 #include <exec/memory.h>
12 #include <intuition/intuition.h>
13 #include <intuition/screens.h>
14 #include <proto/graphics.h>
15 #include <graphics/rastport.h>
16 #include <graphics/rpattr.h>
17 #include <graphics/text.h>
18 #include <graphics/gfxmacros.h>
19 #include <proto/utility.h>
20 #include <utility/tagitem.h>
21 #include <libraries/gadtools.h>
22 #include <aros/debug.h>
23 #include <intuition/gadgetclass.h>
24 #include "gadtools_intern.h"
26 /**********************************************************************************************/
28 #define HIGH_COLOR 0 /* instead of underscore use different color to highlight key */
30 #define EG(x) ((struct ExtGadget *)(x))
41 /**********************************************************************************************/
43 void freeitext(struct GadToolsBase_intern
*GadToolsBase
,
44 struct IntuiText
*itext
)
46 if (itext
) FreeVec(itext
);
49 /**********************************************************************************************/
51 /* Create a struct IntuiText accordings to a struct NewGadget */
52 struct IntuiText
*makeitext(struct GadToolsBase_intern
*GadToolsBase
,
54 struct TagItem
*taglist
)
57 struct DrawInfo
*dri
= ((struct VisualInfo
*)ng
->ng_VisualInfo
)->vi_dri
;
58 struct TextFont
*font
= NULL
;
59 struct RastPort temprp
;
69 BOOL fontopened
= FALSE
;
70 UBYTE underscore
= 1; /* default for GT_Underscore = a char which hopefully a normal
71 string never contains */
73 underscore
= (UBYTE
)GetTagData(GT_Underscore
, underscore
, taglist
);
74 underscorepos
= strchr(ng
->ng_GadgetText
, underscore
);
75 gadgettextlen
= strlen(ng
->ng_GadgetText
);
79 font
= OpenFont(ng
->ng_TextAttr
);
80 if (!font
) return NULL
;
84 fontname
= ng
->ng_TextAttr
->ta_Name
;
85 fontysize
= ng
->ng_TextAttr
->ta_YSize
;
86 fontstyle
= ng
->ng_TextAttr
->ta_Style
;
87 fontflags
= ng
->ng_TextAttr
->ta_Flags
;
91 fontname
= dri
->dri_Font
->tf_Message
.mn_Node
.ln_Name
;
92 fontysize
= dri
->dri_Font
->tf_YSize
;
93 fontstyle
= dri
->dri_Font
->tf_Style
;
94 fontflags
= dri
->dri_Font
->tf_Flags
;
97 if (!fontname
) return NULL
;
99 fontnamelen
= strlen(fontname
);
101 alloclen
= sizeof(struct GTIText
) + fontnamelen
+ 1 + gadgettextlen
+ 1 + 2; /* 2 for safety */
103 gtit
= (struct GTIText
*)AllocVec(alloclen
, MEMF_PUBLIC
| MEMF_CLEAR
);
106 if (fontopened
) CloseFont(font
);
110 CopyMem(fontname
, gtit
->text
, fontnamelen
);
112 gtit
->ta
.ta_Name
= gtit
->text
;
113 gtit
->ta
.ta_YSize
= fontysize
;
114 gtit
->ta
.ta_Style
= fontstyle
;
115 gtit
->ta
.ta_Flags
= fontflags
;
117 gtit
->it
.FrontPen
= dri
->dri_Pens
[(ng
->ng_Flags
& NG_HIGHLABEL
) ? HIGHLIGHTTEXTPEN
: TEXTPEN
];
118 gtit
->it
.BackPen
= dri
->dri_Pens
[BACKGROUNDPEN
];
119 gtit
->it
.DrawMode
= JAM1
;
120 gtit
->it
.LeftEdge
= 0;
121 gtit
->it
.TopEdge
= 0;
122 gtit
->it
.ITextFont
= >it
->ta
;
126 gtit
->it
.IText
= gtit
->text
+ fontnamelen
+ 1;
127 gtit
->it
.NextText
= NULL
;
129 if (gadgettextlen
) CopyMem(ng
->ng_GadgetText
, gtit
->it
.IText
, gadgettextlen
);
134 underscorelen
= underscorepos
- ng
->ng_GadgetText
;
136 gtit
->it
.IText
= gtit
->text
+ fontnamelen
+ 1;
139 CopyMem(ng
->ng_GadgetText
, gtit
->it
.IText
, underscorelen
);
141 if (gadgettextlen
- underscorelen
)
143 CopyMem(underscorepos
+ 1, gtit
->it
.IText
+ underscorelen
, gadgettextlen
- underscorelen
);
146 gtit
->it
.NextText
= >it
->it2
;
148 gtit
->it2
= gtit
->it
;
149 gtit
->it2
.ITextFont
= >it
->ta2
;
150 gtit
->it2
.IText
= gtit
->it
.IText
+ gadgettextlen
+ 1;
151 gtit
->it2
.NextText
= NULL
;
153 gtit
->ta2
= gtit
->ta
;
156 gtit
->it2
.FrontPen
= dri
->dri_Pens
[(ng
->ng_Flags
& NG_HIGHLABEL
) ? TEXTPEN
: HIGHLIGHTTEXTPEN
];
158 gtit
->ta2
.ta_Style
|= FSF_UNDERLINED
;
164 gtit
->it2
.LeftEdge
= 0;
168 InitRastPort(&temprp
);
169 SetFont(&temprp
, font
);
171 gtit
->it2
.LeftEdge
= TextLength(&temprp
, ng
->ng_GadgetText
, underscorelen
);
173 DeinitRastPort(&temprp
);
176 gtit
->it2
.IText
[0] = underscorepos
[1];
179 if (fontopened
) CloseFont(font
);
184 /**********************************************************************************************/
186 struct TextFont
*preparefont(struct GadToolsBase_intern
*GadToolsBase
,
187 struct RastPort
*rport
, struct IntuiText
*itext
,
188 struct TextFont
**oldfont
)
190 struct TextFont
*font
;
192 if (itext
->ITextFont
)
194 *oldfont
= rport
->Font
;
195 font
= OpenFont(itext
->ITextFont
);
198 SetFont(rport
, font
);
199 SetSoftStyle(rport
, itext
->ITextFont
->ta_Style
, 0xffffffff);
207 SetABPenDrMd(rport
, itext
->FrontPen
, itext
->BackPen
, itext
->DrawMode
);
212 /**********************************************************************************************/
214 void closefont(struct GadToolsBase_intern
*GadToolsBase
,
215 struct RastPort
*rport
,
216 struct TextFont
*font
, struct TextFont
*oldfont
)
220 SetFont(rport
, oldfont
);
225 /**********************************************************************************************/
227 BOOL
renderlabel(struct GadToolsBase_intern
*GadToolsBase
,
228 struct Gadget
*gad
, struct RastPort
*rport
, LONG labelplace
)
230 struct TextFont
*font
= NULL
, *oldfont
;
231 struct TextExtent te
;
235 WORD gadleft
, gadtop
, gadwidth
, gadheight
;
237 if (EG(gad
)->MoreFlags
& GMORE_BOUNDS
)
239 gadleft
= EG(gad
)->BoundsLeftEdge
;
240 gadtop
= EG(gad
)->BoundsTopEdge
;
241 gadwidth
= EG(gad
)->BoundsWidth
;
242 gadheight
= EG(gad
)->BoundsHeight
;
244 gadleft
= gad
->LeftEdge
;
245 gadtop
= gad
->TopEdge
;
246 gadwidth
= gad
->Width
;
247 gadheight
= gad
->Height
;
252 /* Calculate offsets. */
253 if ((gad
->Flags
& GFLG_LABELSTRING
))
254 text
= (STRPTR
)gad
->GadgetText
;
255 else if ((gad
->Flags
& GFLG_LABELIMAGE
))
259 /* GFLG_LABELITEXT */
260 text
= gad
->GadgetText
->IText
;
261 font
= preparefont(GadToolsBase
,
262 rport
, gad
->GadgetText
, &oldfont
);
270 TextExtent(rport
, text
, len
, &te
);
272 height
= te
.te_Height
;
275 width
= ((struct Image
*)gad
->GadgetText
)->Width
;
276 height
= ((struct Image
*)gad
->GadgetText
)->Height
;
279 if (labelplace
== GV_LabelPlace_Right
)
281 x
= gadleft
+ gadwidth
+ 5;
282 y
= gadtop
+ (gadheight
- height
) / 2 + 1;
283 } else if (labelplace
== GV_LabelPlace_Above
)
285 x
= gadleft
+ (gadwidth
- width
) / 2;
286 y
= gadtop
- height
- 2;
287 } else if (labelplace
== GV_LabelPlace_Below
)
289 x
= gadleft
+ (gadwidth
- width
) / 2;
290 y
= gadtop
+ gadheight
+ 3;
291 } else if (labelplace
== GV_LabelPlace_In
)
293 x
= gadleft
+ (gadwidth
- width
) / 2;
294 y
= gadtop
+ (gadheight
- height
) / 2 + 1;
295 } else /* GV_LabelPlace_Left */
297 x
= gadleft
- width
- 4;
298 y
= gadtop
+ (gadheight
- height
) / 2 + 1;
301 if (gad
->Flags
& GFLG_LABELSTRING
)
303 SetABPenDrMd(rport
, 1, 0, JAM1
);
305 Text(rport
, text
, len
);
306 } else if (gad
->Flags
& GFLG_LABELIMAGE
)
307 DrawImage(rport
, (struct Image
*)gad
->GadgetText
, x
, y
);
310 PrintIText(rport
, gad
->GadgetText
, x
, y
);
311 closefont(GadToolsBase
, rport
, font
, oldfont
);
317 /**********************************************************************************************/
319 void DoDisabledPattern(struct RastPort
*rp
, WORD x1
, WORD y1
, WORD x2
, WORD y2
,
320 WORD pen
, struct GadToolsBase_intern
*GadToolsBase
)
322 UWORD pattern
[] = { 0x8888, 0x2222 };
326 SetAfPt( rp
, pattern
, 1);
328 /* render disable pattern */
329 RectFill(rp
, x1
, y1
, x2
, y2
);
331 SetAfPt (rp
, NULL
, 0);
335 /**********************************************************************************************/