grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / classes / gadgets / aroscheckbox / support.c
blob7d1d33d2a7834623e560705abfb277a0c9f53a25
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Support functions for AROSCheckboxClass.
6 Lang: english
7 */
8 #include <string.h>
9 #include <exec/types.h>
10 #include <proto/intuition.h>
11 #include <proto/graphics.h>
12 #include <graphics/rastport.h>
13 #include <graphics/text.h>
14 #include <libraries/gadtools.h>
16 #include "aroscheckbox_intern.h"
19 UWORD disabledpattern[2] = {0x4444, 0x1111};
21 /* draws a disabled pattern */
22 void drawdisabledpattern(struct RastPort *rport, UWORD pen,
23 WORD left, WORD top, UWORD width, UWORD height
26 SetABPenDrMd(rport, pen, 0, JAM1);
27 rport->AreaPtrn = disabledpattern;
28 rport->AreaPtSz = 1;
29 RectFill(rport, left, top, left+width-1, top+height-1);
31 /* FIXME: drawdisabledpattern ??? Fix what? */
32 /*FIXME for (y=0; y<(height-1); y++)
34 for (x=0; x<(width-1); x++)
36 if (y%2)
38 if (!((x+1)%4))
40 Move(rport, left + x, top + y);
41 Draw(rport, left + x, top + y);
43 } else
45 if (!((x+3)%4))
47 Move(rport, left + x, top + y);
48 Draw(rport, left + x, top + y);
52 } */
56 struct TextFont *preparefont(struct RastPort *rport, struct IntuiText *itext,
57 struct TextFont **oldfont
60 struct TextFont *font;
62 if(itext->ITextFont)
64 *oldfont = rport->Font;
65 font = OpenFont(itext->ITextFont);
66 if(font != NULL)
68 SetFont(rport, font);
69 SetSoftStyle(rport, itext->ITextFont->ta_Style, 0xffffffff);
71 else
72 font = rport->Font;
74 else
76 *oldfont = NULL;
77 font = rport->Font;
80 SetABPenDrMd(rport, itext->FrontPen, itext->BackPen, itext->DrawMode);
82 return font;
86 void closefont(struct RastPort *rport,
87 struct TextFont *font, struct TextFont *oldfont
90 if(oldfont)
92 SetFont(rport, oldfont);
93 CloseFont(font);
98 BOOL renderlabel(struct Gadget *gad, struct RastPort *rport, LONG labelplace)
100 struct TextFont *font = NULL, *oldfont;
101 struct TextExtent te;
102 STRPTR text;
103 int len = 0, x, y;
104 UWORD width, height;
106 if (gad->GadgetText)
108 /* Calculate offsets. */
109 if ((gad->Flags & GFLG_LABELSTRING))
110 text = (STRPTR)gad->GadgetText;
111 else if ((gad->Flags & GFLG_LABELIMAGE))
112 text = NULL;
113 else
115 /* GFLG_LABELITEXT */
116 text = gad->GadgetText->IText;
117 font = preparefont(rport, gad->GadgetText, &oldfont);
118 if (!font)
119 return FALSE;
122 if (text)
124 len = strlen(text);
125 TextExtent(rport, text, len, &te);
126 width = te.te_Width;
127 height = te.te_Height;
128 } else
130 width = ((struct Image *)gad->GadgetText)->Width;
131 height = ((struct Image *)gad->GadgetText)->Height;
134 if (labelplace == GV_LabelPlace_Right)
136 x = gad->LeftEdge + gad->Width + 5;
137 y = gad->TopEdge + (gad->Height - height) / 2 + 1;
138 } else if (labelplace == GV_LabelPlace_Above)
140 x = gad->LeftEdge - (width - gad->Width) / 2;
141 y = gad->TopEdge - height - 2;
142 } else if (labelplace == GV_LabelPlace_Below)
144 x = gad->LeftEdge - (width - gad->Width) / 2;
145 y = gad->TopEdge + gad->Height + 3;
146 } else if (labelplace == GV_LabelPlace_In)
148 x = gad->LeftEdge - (width - gad->Width) / 2;
149 y = gad->TopEdge + (gad->Height - height) / 2 + 1;
150 } else /* GV_LabelPlace_Left */
152 x = gad->LeftEdge - width - 4;
153 y = gad->TopEdge + (gad->Height - height) / 2 + 1;
156 if (gad->Flags & GFLG_LABELSTRING)
158 SetABPenDrMd(rport, 1, 0, JAM1);
159 Move(rport, x, y);
160 Text(rport, text, len);
161 } else if (gad->Flags & GFLG_LABELIMAGE)
162 DrawImage(rport, (struct Image *)gad->GadgetText, x, y);
163 else
165 PrintIText(rport, gad->GadgetText, x, y);
166 closefont(rport, font, oldfont);
169 return TRUE;