2 Copyright © 2000-2013, The AROS Development Team. All rights reserved.
7 /*****************************************************************************************/
10 #include <intuition/intuition.h>
11 #include <intuition/gadgetclass.h>
12 #include <intuition/icclass.h>
13 #include <intuition/imageclass.h>
14 #include <intuition/screens.h>
15 #include <gadgets/gradientslider.h>
16 #include <gadgets/colorwheel.h>
17 #include <proto/dos.h>
18 #include <proto/exec.h>
19 #include <proto/intuition.h>
20 #include <proto/colorwheel.h>
21 #include <proto/graphics.h>
22 #include <proto/utility.h>
29 * We won't allow to decrease gamma more than down to 128.
30 * Otherwise the playing user might end up in a completely
31 * black screen with zeroed out gamma.
33 #define BOTTOM_LIMIT 128
35 struct Library
*GradientSliderBase
;
36 struct Library
*ColorWheelBase
;
38 static struct RDArgs
*rda
;
39 static struct Screen
*scr
;
40 static struct DrawInfo
*dri
;
41 static struct ViewPort
*vp
;
42 static struct ColorMap
*cm
;
43 static struct Window
*win
;
44 static WORD penr
= -1, peng
= -1, penb
= -1;
45 static struct Gadget
*rgad
, *ggad
, *bgad
, *wheelgad
;
47 static WORD pensr
[] = {2, 1, ~0};
48 static WORD pensg
[] = {2, 1, ~0};
49 static WORD pensb
[] = {2, 1, ~0};
57 static struct myargs args
=
63 static UBYTE gamma_r
[256];
64 static UBYTE gamma_b
[256];
65 static UBYTE gamma_g
[256];
67 static void gen_gamma(UBYTE r
, UBYTE b
, UBYTE g
)
71 printf("Generating gamma: %02X %02X %02X\n", r
, g
, b
);
73 for (i
= 0; i
< 256; i
++)
75 gamma_r
[i
] = (i
< r
) ? i
: r
;
76 gamma_b
[i
] = (i
< b
) ? i
: b
;
77 gamma_g
[i
] = (i
< g
) ? i
: g
;
81 /*****************************************************************************************/
83 static void cleanup(char *msg
)
85 if (msg
) printf("colorwheel: %s\n", msg
);
89 if (wheelgad
) RemoveGadget(win
, wheelgad
);
90 if (rgad
) RemoveGadget(win
, rgad
);
91 if (ggad
) RemoveGadget(win
, ggad
);
92 if (bgad
) RemoveGadget(win
, bgad
);
96 if (wheelgad
) DisposeObject((Object
*)wheelgad
);
97 if (rgad
) DisposeObject((Object
*)rgad
);
98 if (ggad
) DisposeObject((Object
*)ggad
);
99 if (bgad
) DisposeObject((Object
*)bgad
);
101 if (penr
!= -1) ReleasePen(cm
, penr
);
102 if (peng
!= -1) ReleasePen(cm
, peng
);
103 if (penb
!= -1) ReleasePen(cm
, penb
);
105 if (dri
) FreeScreenDrawInfo(scr
, dri
);
106 if (scr
) CloseScreen(scr
);
108 if (rda
) FreeArgs(rda
);
110 if (ColorWheelBase
) CloseLibrary(ColorWheelBase
);
111 if (GradientSliderBase
) CloseLibrary(GradientSliderBase
);
116 /*****************************************************************************************/
118 static void openlibs(void)
120 if (!(GradientSliderBase
= OpenLibrary("Gadgets/gradientslider.gadget", 0)))
122 cleanup("Can't open gradientslider.gadget!");
125 if (!(ColorWheelBase
= OpenLibrary("Gadgets/colorwheel.gadget", 0)))
127 cleanup("Can't open colorwheel.gadget!");
131 /*****************************************************************************************/
133 static void getvisual(void)
135 struct TagItem tags
[] =
137 {SA_LikeWorkbench
, TRUE
},
138 {SA_GammaControl
, TRUE
},
139 {SA_GammaRed
, (IPTR
)gamma_r
},
140 {SA_GammaBlue
, (IPTR
)gamma_b
},
141 {SA_GammaGreen
, (IPTR
)gamma_g
},
142 {SA_Title
, (IPTR
)"Gamma test"},
146 rda
= ReadArgs("MODEID/K,NOGAMMA/S", (IPTR
*)&args
, NULL
);
148 cleanup("Failed to parse arguments!");
150 gen_gamma(255, 255, 255);
154 tags
[0].ti_Tag
= SA_DisplayID
;
155 tags
[0].ti_Data
= strtoul(args
.mode
, NULL
, 16);
157 tags
[1].ti_Data
= !args
.nogamma
;
159 scr
= OpenScreenTagList(NULL
, tags
);
162 cleanup("Can't open screen!");
165 if (!(dri
= GetScreenDrawInfo(scr
)))
167 cleanup("Can't get screen drawinfo!");
173 penr
= ObtainBestPen(cm
, 0xFFFFFFFF, 0, 0, OBP_Precision
, PRECISION_GUI
);
174 peng
= ObtainBestPen(cm
, 0, 0xFFFFFFFF, 0, OBP_Precision
, PRECISION_GUI
);
175 penb
= ObtainBestPen(cm
, 0, 0, 0xFFFFFFFF, OBP_Precision
, PRECISION_GUI
);
177 if (penr
!= -1) pensr
[0] = penr
;
178 if (peng
!= -1) pensg
[0] = peng
;
179 if (penb
!= -1) pensb
[0] = penb
;
182 /*****************************************************************************************/
190 static void makegads(void)
193 WORD sizeheight
= 14;
194 WORD gradx
, grady
, gradw
, gradh
;
195 WORD wheelx
, wheely
, wheelw
, wheelh
;
197 im
= NewObject(NULL
, SYSICLASS
, SYSIA_DrawInfo
, (IPTR
)dri
, SYSIA_Which
, SIZEIMAGE
, TAG_DONE
);
200 sizeheight
= ((struct Image
*)im
)->Height
;
204 wheelx
= scr
->WBorLeft
+ BORDERX
;
205 wheely
= scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 + BORDERY
;
206 wheelw
= -(scr
->WBorLeft
+ scr
->WBorRight
+ BORDERX
* 2 + SPACINGX
+ GRADWIDTH
* 3);
207 wheelh
= -(scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 + sizeheight
+ BORDERY
* 2);
209 gradx
= -(scr
->WBorRight
+ BORDERX
+ GRADWIDTH
) + 1;
210 grady
= scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 + BORDERY
;
212 gradh
= -(scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 + sizeheight
+ BORDERY
* 2);
214 rgad
= (struct Gadget
*)NewObject(0, "gradientslider.gadget",
215 GA_RelRight
, gradx
- gradw
* 2,
218 GA_RelHeight
, gradh
,
219 GRAD_PenArray
, (IPTR
)pensr
,
221 GRAD_MaxVal
, BOTTOM_LIMIT
,
222 PGA_Freedom
, LORIENT_VERT
,
223 ICA_TARGET
, ICTARGET_IDCMP
,
226 if (!rgad
) cleanup("Can't create red slider!");
228 ggad
= (struct Gadget
*)NewObject(0, "gradientslider.gadget",
229 GA_RelRight
, gradx
- gradw
,
232 GA_RelHeight
, gradh
,
233 GRAD_PenArray
, (IPTR
)pensg
,
235 GRAD_MaxVal
, BOTTOM_LIMIT
,
236 PGA_Freedom
, LORIENT_VERT
,
237 ICA_TARGET
, ICTARGET_IDCMP
,
241 if (!ggad
) cleanup("Can't create green slider!");
243 bgad
= (struct Gadget
*)NewObject(0, "gradientslider.gadget",
247 GA_RelHeight
, gradh
,
248 GRAD_PenArray
, (IPTR
)pensb
,
250 GRAD_MaxVal
, BOTTOM_LIMIT
,
251 PGA_Freedom
, LORIENT_VERT
,
252 ICA_TARGET
, ICTARGET_IDCMP
,
256 if (!bgad
) cleanup("Can't create blue slider!");
259 wheelgad
= (struct Gadget
*)NewObject(0, "colorwheel.gadget",
262 GA_RelWidth
, wheelw
,
263 GA_RelHeight
, wheelh
,
266 WHEEL_BevelBox
, TRUE
,
270 if (!wheelgad
) cleanup("Can't create colorwheel gadget!");
274 /*****************************************************************************************/
276 static void makewin(void)
278 win
= OpenWindowTags(0,
279 WA_CustomScreen
, scr
,
288 WA_AutoAdjust
, TRUE
,
289 WA_Title
, "Gamma test",
290 WA_CloseGadget
, TRUE
,
292 WA_DepthGadget
, TRUE
,
293 WA_SizeGadget
, TRUE
,
294 WA_SizeBBottom
, TRUE
,
296 WA_ReportMouse
, TRUE
,
297 WA_IDCMP
, IDCMP_CLOSEWINDOW
| IDCMP_IDCMPUPDATE
,
301 if (!win
) cleanup("Can't open window!");
304 /*****************************************************************************************/
306 static void handleall(void)
308 struct IntuiMessage
*msg
;
314 WaitPort(win
->UserPort
);
316 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
320 case IDCMP_CLOSEWINDOW
:
324 case IDCMP_IDCMPUPDATE
:
325 GetAttr(GRAD_CurVal
, (Object
*)rgad
, &r
);
326 GetAttr(GRAD_CurVal
, (Object
*)ggad
, &g
);
327 GetAttr(GRAD_CurVal
, (Object
*)bgad
, &b
);
329 /* Values are reversed (largest down, smallest up) */
330 gen_gamma(255 - r
, 255 - g
, 255 - b
);
333 SA_GammaRed
, gamma_r
,
334 SA_GammaBlue
, gamma_b
,
335 SA_GammaGreen
, gamma_g
,
338 } /* switch(msg->Class) */
340 ReplyMsg((struct Message
*)msg
);
342 } /* while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) */
344 } /* while(!quitme) */
348 /*****************************************************************************************/
362 /*****************************************************************************************/