grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / intuition / boolgadgets.c
blobdc58351be508db263de1482392788b287adb34e1
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
6 Routines for BOOL Gadgets
7 */
9 /****************************************************************************************/
11 #include <proto/graphics.h>
12 #include <proto/intuition.h>
13 #include <intuition/cghooks.h>
14 #include <intuition/imageclass.h>
15 #include <graphics/gfxmacros.h>
17 #include <string.h>
19 #include "intuition_intern.h"
20 #include "gadgets.h"
22 #define DEBUG_REFRESHBOOLGADGET(x) ;
24 /****************************************************************************************/
26 #define RENDERGADGET(win,gad,rend) \
27 if (rend) \
28 { \
29 if (gad->Flags & GFLG_GADGIMAGE) \
30 { \
31 DrawImageState (rp \
32 , (struct Image *)rend \
33 , bbox.Left \
34 , bbox.Top \
35 , state \
36 , dri \
37 ); \
38 } \
39 else \
40 { \
41 DrawBorder (rp \
42 , (struct Border *)rend \
43 , bbox.Left \
44 , bbox.Top \
45 ); \
46 } \
49 #define GETRENDER(gad) (gad->SelectRender && (gad->Flags & GFLG_SELECTED)) ? \
50 gad->SelectRender : gad->GadgetRender;
52 #define BOXSIZEX 4
53 #define BOXSIZEY 4
55 /****************************************************************************************/
57 static void RenderBoolLabel(struct RastPort *rp, struct Gadget *gadget, struct BBox *bbox,
58 struct DrawInfo *dri, struct IntuitionBase *IntuitionBase)
60 struct GfxBase *GfxBase = GetPrivIBase(IntuitionBase)->GfxBase;
61 /* FIXME: Amiga handmade (non-boopsi) bool gadgets do not seem to know anything about
62 * GFLG_LABELSTRING/GFLG_LABELIMAGE. Instead they always assume GadgetText to
63 * point to a struct IntuiText!!!
66 if (gadget->GadgetText)
68 SetFont(rp, dri->dri_Font);
70 switch (gadget->Flags & GFLG_LABELMASK)
72 case GFLG_LABELITEXT:
73 PrintIText (rp, gadget->GadgetText, bbox->Left, bbox->Top);
74 break;
76 case GFLG_LABELSTRING:
78 STRPTR text = (STRPTR) gadget->GadgetText;
79 int len, labelwidth, labelheight;
81 len = strlen (text);
83 labelwidth = LabelWidth (rp, text, len, IntuitionBase);
84 labelheight = rp->Font->tf_YSize;
86 SetAPen (rp, 1);
87 SetDrMd (rp, JAM1);
89 Move (rp, bbox->Left + bbox->Width / 2 - labelwidth / 2,
90 bbox->Top + bbox->Height / 2 - labelheight / 2 + rp->Font->tf_Baseline);
92 RenderLabel (rp, text, len, IntuitionBase);
93 break;
96 case GFLG_LABELIMAGE:
97 DrawImageState (rp, (struct Image *)gadget->GadgetText,
98 bbox->Left,
99 bbox->Top,
100 IDS_NORMAL,
101 dri);
102 break;
104 } /* switch (gadget->Flags & GFLG_LABELMASK) */
106 } /* GadgetText */
110 /****************************************************************************************/
112 void RefreshBoolGadget (struct Gadget * gadget, struct Window * window,
113 struct Requester * requester, struct IntuitionBase * IntuitionBase)
115 struct GfxBase *GfxBase = GetPrivIBase(IntuitionBase)->GfxBase;
116 struct RastPort *rp;
117 struct GadgetInfo gi;
118 struct DrawInfo *dri;
119 struct BBox bbox;
120 ULONG state;
121 APTR render;
123 DEBUG_REFRESHBOOLGADGET(dprintf("RefreshBoolGadget: gadget %p window %p req %p\n",
124 gadget, window, requester));
126 CalcBBox (window, requester, gadget, &bbox);
128 state = GetGadgetState(window, gadget);
130 SetupGInfo(&gi, window, requester, gadget, IntuitionBase);
132 rp = ObtainGIRPort(&gi);
133 if (!rp) return;
135 dri = GetScreenDrawInfo(window->WScreen);
137 SetDrMd (rp, JAM1);
139 switch (gadget->Flags & GFLG_GADGHIGHBITS)
141 case GFLG_GADGHIMAGE:
142 render = GETRENDER(gadget);
143 RENDERGADGET(window,gadget,render);
144 break;
146 case GFLG_GADGHCOMP:
147 case GFLG_GADGHNONE:
148 case GFLG_GADGHBOX:
149 render = gadget->GadgetRender;
150 RENDERGADGET(window,gadget,render);
151 break;
153 } /* switch GadgetHighlightMethod */
155 RenderBoolLabel(rp, gadget, &bbox, dri, IntuitionBase);
157 if ((bbox.Width >= 1) && (bbox.Height >= 1))
159 switch (gadget->Flags & GFLG_GADGHIGHBITS)
161 case GFLG_GADGHCOMP:
162 if (gadget->Flags & GFLG_SELECTED)
164 SetDrMd (rp, COMPLEMENT);
166 RectFill (rp, bbox.Left,
167 bbox.Top,
168 bbox.Left + bbox.Width - 1,
169 bbox.Top + bbox.Height - 1);
171 break;
173 case GFLG_GADGHBOX:
174 if (gadget->Flags & GFLG_SELECTED)
176 SetDrMd (rp, COMPLEMENT);
178 RectFill (rp, bbox.Left - BOXSIZEX,
179 bbox.Top - BOXSIZEY,
180 bbox.Left + bbox.Width - 1 + BOXSIZEX,
181 bbox.Top + bbox.Height - 1 + BOXSIZEY);
183 RectFill (rp, bbox.Left,
184 bbox.Top,
185 bbox.Left + bbox.Width - 1,
186 bbox.Top + bbox.Height - 1);
189 break;
191 } /* Highlight after contents have been drawn */
193 if ( gadget->Flags & GFLG_DISABLED )
195 RenderDisabledPattern(rp, dri, bbox.Left,
196 bbox.Top,
197 bbox.Left + bbox.Width - 1,
198 bbox.Top + bbox.Height - 1,
199 IntuitionBase );
202 } /* if ((bbox.Width >= 1) && (bbox.Height >= 1)) */
204 FreeScreenDrawInfo(window->WScreen, dri);
206 ReleaseGIRPort(rp);
208 } /* RefreshBoolGadget */
210 /*****************************************************************************************
212 This function is called by Intuition's InputHandler when the GFLG_SELECTED state changed
214 *****************************************************************************************/
216 void RefreshBoolGadgetState(struct Gadget * gadget, struct Window * window,
217 struct Requester * requester, struct IntuitionBase *IntuitionBase)
219 struct GfxBase *GfxBase = GetPrivIBase(IntuitionBase)->GfxBase;
220 struct GadgetInfo gi;
221 struct RastPort *rp;
222 struct DrawInfo *dri;
223 struct BBox bbox;
224 ULONG state;
225 APTR render;
227 DEBUG_REFRESHBOOLGADGET(dprintf("RefreshBoolGadgetState: gadget %p window %p req %p\n",
228 gadget, window, requester));
230 if ((gadget->Flags & GFLG_GADGHIGHBITS) == GFLG_GADGHNONE) return;
232 CalcBBox (window, requester, gadget, &bbox);
234 state = GetGadgetState(window, gadget);
236 SetupGInfo(&gi, window, requester, gadget, IntuitionBase);
238 rp = ObtainGIRPort(&gi);
239 if (!rp) return;
241 dri = GetScreenDrawInfo(window->WScreen);
243 SetDrMd (rp, JAM1);
245 switch (gadget->Flags & GFLG_GADGHIGHBITS)
247 case GFLG_GADGHIMAGE:
248 render = GETRENDER(gadget);
249 RENDERGADGET(window,gadget,render);
250 RenderBoolLabel(rp, gadget, &bbox, dri, IntuitionBase);
251 break;
253 } /* switch GadgetHighlightMethod */
255 if ((bbox.Width >= 1) && (bbox.Height >= 1))
257 switch (gadget->Flags & GFLG_GADGHIGHBITS)
259 case GFLG_GADGHCOMP:
260 SetDrMd (rp, COMPLEMENT);
262 RectFill (rp, bbox.Left,
263 bbox.Top,
264 bbox.Left + bbox.Width - 1,
265 bbox.Top + bbox.Height - 1);
266 break;
268 case GFLG_GADGHBOX:
269 SetDrMd (rp, COMPLEMENT);
271 RectFill (rp, bbox.Left - BOXSIZEX,
272 bbox.Top - BOXSIZEY,
273 bbox.Left + bbox.Width - 1 + BOXSIZEX,
274 bbox.Top + bbox.Height - 1 + BOXSIZEY);
276 RectFill (rp, bbox.Left,
277 bbox.Top,
278 bbox.Left + bbox.Width - 1,
279 bbox.Top + bbox.Height - 1);
280 break;
282 } /* switch (gadget->Flags & GFLG_GADGHIGHBITS) */
284 } /* if ((bbox.Width >= 1) && (bbox.Height >= 1)) */
286 FreeScreenDrawInfo(window->WScreen, dri);
288 ReleaseGIRPort(rp);
291 /****************************************************************************************/