revert between 56095 -> 55830 in arch
[AROS.git] / workbench / classes / gadgets / arosmutualexclude / support.c
blobba4b21062111b0787dec089446e58c874fc383e8
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Support functions for AROSMutualExcludeClass.
6 Lang: english
7 */
9 /***********************************************************************************/
11 #include <string.h>
12 #include <exec/types.h>
13 #include <proto/intuition.h>
14 #include <proto/graphics.h>
15 #include <graphics/rastport.h>
16 #include <graphics/text.h>
17 #include <libraries/gadtools.h>
19 #include "arosmutualexclude_intern.h"
21 /***********************************************************************************/
23 UWORD disabledpattern[2] = {0x4444, 0x1111};
25 /***********************************************************************************/
27 /* draws a disabled pattern */
28 void drawdisabledpattern(struct RastPort *rport, UWORD pen,
29 WORD left, WORD top, UWORD width, UWORD height
32 SetABPenDrMd(rport, pen, 0, JAM1);
33 rport->AreaPtrn = disabledpattern;
34 rport->AreaPtSz = 1;
35 RectFill(rport, left, top, left+width-1, top+height-1);
38 /***********************************************************************************/
40 struct TextFont *preparefont(struct RastPort *rport, struct IntuiText *itext,
41 struct TextFont **oldfont
44 struct TextFont *font;
46 if (itext->ITextFont)
48 *oldfont = rport->Font;
49 font = OpenFont(itext->ITextFont);
50 if (font)
52 SetFont(rport, font);
53 SetSoftStyle(rport, itext->ITextFont->ta_Style, 0xffffffff);
54 } else
55 font = rport->Font;
56 } else
58 *oldfont = NULL;
59 font = rport->Font;
61 SetABPenDrMd(rport, itext->FrontPen, itext->BackPen, itext->DrawMode);
63 return font;
66 /***********************************************************************************/
68 void closefont(struct RastPort *rport,
69 struct TextFont *font, struct TextFont *oldfont
72 if (oldfont)
74 SetFont(rport, oldfont);
75 CloseFont(font);
79 /***********************************************************************************/
81 BOOL renderlabel(struct Gadget *gad, struct RastPort *rport, struct MXData *data)
83 struct TextFont *font = NULL, *oldfont;
84 struct TextExtent te;
85 STRPTR text;
86 int len = 0, x, y;
87 UWORD width, height;
89 if (gad->GadgetText)
91 /* Calculate offsets. */
92 if ((gad->Flags & GFLG_LABELSTRING))
93 text = (STRPTR)gad->GadgetText;
94 else if ((gad->Flags & GFLG_LABELIMAGE))
95 text = NULL;
96 else
98 /* GFLG_LABELITEXT */
99 text = gad->GadgetText->IText;
100 font = preparefont(rport, gad->GadgetText, &oldfont);
101 if (!font)
102 return FALSE;
105 if (text)
107 len = strlen(text);
108 TextExtent(rport, text, len, &te);
109 width = te.te_Width;
110 height = te.te_Height;
111 } else
113 width = ((struct Image *)gad->GadgetText)->Width;
114 height = ((struct Image *)gad->GadgetText)->Height;
117 if (data->labelplace == GV_LabelPlace_Right)
119 x = data->bbox.MaxX + 5;
120 y = (data->bbox.MinY + data->bbox.MaxY - height) / 2;
121 } else if (data->labelplace == GV_LabelPlace_Above)
123 x = (data->bbox.MinX + data->bbox.MaxX - width) / 2;
124 y = data->bbox.MinY - height - 2;
125 } else if (data->labelplace == GV_LabelPlace_Below)
127 x = (data->bbox.MinX + data->bbox.MaxX - width) / 2;
128 y = gad->TopEdge + gad->Height + 3;
129 } else if (data->labelplace == GV_LabelPlace_In)
131 x = (data->bbox.MinX + data->bbox.MaxX - width) / 2;
132 y = (data->bbox.MinY + data->bbox.MaxY - height) / 2;
133 } else /* GV_LabelPlace_Left */
135 x = data->bbox.MinX - width - 4;
136 y = (data->bbox.MinY + data->bbox.MaxY - height) / 2;
139 if (gad->Flags & GFLG_LABELSTRING)
141 SetABPenDrMd(rport, 1, 0, JAM1);
142 Move(rport, x, y + rport->TxBaseline);
143 Text(rport, text, len);
144 } else if (gad->Flags & GFLG_LABELIMAGE)
145 DrawImage(rport, (struct Image *)gad->GadgetText, x, y);
146 else
148 PrintIText(rport, gad->GadgetText, x, y);
149 closefont(rport, font, oldfont);
153 return TRUE;
156 /***********************************************************************************/