2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
6 Routines for BOOL Gadgets
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>
19 #include "intuition_intern.h"
22 #define DEBUG_REFRESHBOOLGADGET(x) ;
24 /****************************************************************************************/
26 #define RENDERGADGET(win,gad,rend) \
29 if (gad->Flags & GFLG_GADGIMAGE) \
32 , (struct Image *)rend \
42 , (struct Border *)rend \
49 #define GETRENDER(gad) (gad->SelectRender && (gad->Flags & GFLG_SELECTED)) ? \
50 gad->SelectRender : gad->GadgetRender;
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
)
73 PrintIText (rp
, gadget
->GadgetText
, bbox
->Left
, bbox
->Top
);
76 case GFLG_LABELSTRING
:
78 STRPTR text
= (STRPTR
) gadget
->GadgetText
;
79 int len
, labelwidth
, labelheight
;
83 labelwidth
= LabelWidth (rp
, text
, len
, IntuitionBase
);
84 labelheight
= rp
->Font
->tf_YSize
;
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
);
97 DrawImageState (rp
, (struct Image
*)gadget
->GadgetText
,
104 } /* switch (gadget->Flags & GFLG_LABELMASK) */
110 /****************************************************************************************/
112 void RefreshBoolGadget (struct Gadget
* gadget
, struct Window
* window
,
113 struct Requester
* requester
, struct IntuitionBase
* IntuitionBase
)
115 struct GfxBase
*GfxBase
= GetPrivIBase(IntuitionBase
)->GfxBase
;
117 struct GadgetInfo gi
;
118 struct DrawInfo
*dri
;
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
);
135 dri
= GetScreenDrawInfo(window
->WScreen
);
139 switch (gadget
->Flags
& GFLG_GADGHIGHBITS
)
141 case GFLG_GADGHIMAGE
:
142 render
= GETRENDER(gadget
);
143 RENDERGADGET(window
,gadget
,render
);
149 render
= gadget
->GadgetRender
;
150 RENDERGADGET(window
,gadget
,render
);
153 } /* switch GadgetHighlightMethod */
155 RenderBoolLabel(rp
, gadget
, &bbox
, dri
, IntuitionBase
);
157 if ((bbox
.Width
>= 1) && (bbox
.Height
>= 1))
159 switch (gadget
->Flags
& GFLG_GADGHIGHBITS
)
162 if (gadget
->Flags
& GFLG_SELECTED
)
164 SetDrMd (rp
, COMPLEMENT
);
166 RectFill (rp
, bbox
.Left
,
168 bbox
.Left
+ bbox
.Width
- 1,
169 bbox
.Top
+ bbox
.Height
- 1);
174 if (gadget
->Flags
& GFLG_SELECTED
)
176 SetDrMd (rp
, COMPLEMENT
);
178 RectFill (rp
, bbox
.Left
- BOXSIZEX
,
180 bbox
.Left
+ bbox
.Width
- 1 + BOXSIZEX
,
181 bbox
.Top
+ bbox
.Height
- 1 + BOXSIZEY
);
183 RectFill (rp
, bbox
.Left
,
185 bbox
.Left
+ bbox
.Width
- 1,
186 bbox
.Top
+ bbox
.Height
- 1);
191 } /* Highlight after contents have been drawn */
193 if ( gadget
->Flags
& GFLG_DISABLED
)
195 RenderDisabledPattern(rp
, dri
, bbox
.Left
,
197 bbox
.Left
+ bbox
.Width
- 1,
198 bbox
.Top
+ bbox
.Height
- 1,
202 } /* if ((bbox.Width >= 1) && (bbox.Height >= 1)) */
204 FreeScreenDrawInfo(window
->WScreen
, dri
);
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
;
222 struct DrawInfo
*dri
;
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
);
241 dri
= GetScreenDrawInfo(window
->WScreen
);
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
);
253 } /* switch GadgetHighlightMethod */
255 if ((bbox
.Width
>= 1) && (bbox
.Height
>= 1))
257 switch (gadget
->Flags
& GFLG_GADGHIGHBITS
)
260 SetDrMd (rp
, COMPLEMENT
);
262 RectFill (rp
, bbox
.Left
,
264 bbox
.Left
+ bbox
.Width
- 1,
265 bbox
.Top
+ bbox
.Height
- 1);
269 SetDrMd (rp
, COMPLEMENT
);
271 RectFill (rp
, bbox
.Left
- BOXSIZEX
,
273 bbox
.Left
+ bbox
.Width
- 1 + BOXSIZEX
,
274 bbox
.Top
+ bbox
.Height
- 1 + BOXSIZEY
);
276 RectFill (rp
, bbox
.Left
,
278 bbox
.Left
+ bbox
.Width
- 1,
279 bbox
.Top
+ bbox
.Height
- 1);
282 } /* switch (gadget->Flags & GFLG_GADGHIGHBITS) */
284 } /* if ((bbox.Width >= 1) && (bbox.Height >= 1)) */
286 FreeScreenDrawInfo(window
->WScreen
, dri
);
291 /****************************************************************************************/