2 Copyright © 2000-2001, 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 <gadgets/gradientslider.h>
15 #include <gadgets/colorwheel.h>
16 #include <proto/exec.h>
17 #include <proto/intuition.h>
18 #include <proto/colorwheel.h>
19 #include <proto/graphics.h>
20 #include <proto/utility.h>
26 /*****************************************************************************************/
28 struct IntuitionBase
*IntuitionBase
;
29 struct GfxBase
*GfxBase
;
30 struct UtilityBase
*UtilityBase
;
31 struct Library
*GradientSliderBase
;
32 struct Library
*ColorWheelBase
;
34 static struct Screen
*scr
;
35 static struct DrawInfo
*dri
;
36 static struct ViewPort
*vp
;
37 static struct ColorMap
*cm
;
38 static struct Window
*win
;
39 static struct Gadget
*gradgad
, *wheelgad
;
40 static WORD pen1
= -1, pen2
= -1;
41 static BOOL truecolor
;
43 static WORD pens
[] = {1, 2, ~0};
45 /*****************************************************************************************/
47 static void cleanup(char *msg
)
49 if (msg
) printf("colorwheel: %s\n", msg
);
53 if (wheelgad
) RemoveGadget(win
, wheelgad
);
54 if (gradgad
) RemoveGadget(win
, gradgad
);
58 if (wheelgad
) DisposeObject((Object
*)wheelgad
);
59 if (gradgad
) DisposeObject((Object
*)gradgad
);
61 if (pen1
!= -1) ReleasePen(cm
, pen1
);
62 if (pen2
!= -1) ReleasePen(cm
, pen2
);
64 if (dri
) FreeScreenDrawInfo(scr
, dri
);
65 if (scr
) UnlockPubScreen(0, scr
);
67 if (ColorWheelBase
) CloseLibrary(ColorWheelBase
);
68 if (GradientSliderBase
) CloseLibrary(GradientSliderBase
);
69 if (UtilityBase
) CloseLibrary((struct Library
*)UtilityBase
);
70 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
71 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
76 /*****************************************************************************************/
78 static void openlibs(void)
80 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 39)))
82 cleanup("Can't open intuition.library V39!");
85 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 39)))
87 cleanup("Can't open graphics.library V39!");
90 if (!(UtilityBase
= (struct UtilityBase
*)OpenLibrary("utility.library", 39)))
92 cleanup("Can't open utility.library V39!");
95 if (!(GradientSliderBase
= OpenLibrary("Gadgets/gradientslider.gadget", 0)))
97 cleanup("Can't open gradientslider.gadget!");
100 if (!(ColorWheelBase
= OpenLibrary("Gadgets/colorwheel.gadget", 0)))
102 cleanup("Can't open colorwheel.gadget!");
106 /*****************************************************************************************/
108 static void getvisual(void)
110 if (!(scr
= LockPubScreen(0)))
112 cleanup("Can't lock pub screen!");
115 if (!(dri
= GetScreenDrawInfo(scr
)))
117 cleanup("Can't get screen drawinfo!");
123 pen1
= ObtainPen(cm
, -1, 0, 0, 0, PENF_EXCLUSIVE
);
124 pen2
= ObtainPen(cm
, -1, 0, 0, 0, PENF_EXCLUSIVE
);
129 if ((pen1
== -1) || (pen2
== -1)) cleanup("Can't obtain 2 pens!");
131 if (GetBitMapAttr(scr
->RastPort
.BitMap
, BMA_DEPTH
) >= 15) truecolor
= TRUE
;
134 /*****************************************************************************************/
142 static void makegads(void)
144 struct ColorWheelRGB rgb
;
145 struct ColorWheelHSB hsb
;
147 WORD sizeheight
= 14;
148 WORD gradx
, grady
, gradw
, gradh
;
149 WORD wheelx
, wheely
, wheelw
, wheelh
;
151 im
= NewObject(NULL
, SYSICLASS
, SYSIA_DrawInfo
, (IPTR
)dri
, SYSIA_Which
, SIZEIMAGE
, TAG_DONE
);
154 sizeheight
= ((struct Image
*)im
)->Height
;
158 wheelx
= scr
->WBorLeft
+ BORDERX
;
159 wheely
= scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 + BORDERY
;
160 wheelw
= -(scr
->WBorLeft
+ scr
->WBorRight
+ BORDERX
* 2 + SPACINGX
+ GRADWIDTH
);
161 wheelh
= -(scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 + sizeheight
+ BORDERY
* 2);
163 gradx
= -(scr
->WBorRight
+ BORDERX
+ GRADWIDTH
) + 1;
164 grady
= scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 + BORDERY
;
166 gradh
= -(scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 + sizeheight
+ BORDERY
* 2);
168 gradgad
= (struct Gadget
*)NewObject(0, "gradientslider.gadget", GA_RelRight
, gradx
,
171 GA_RelHeight
, gradh
,
172 GRAD_PenArray
, (IPTR
)pens
,
173 GRAD_KnobPixels
, 10,
174 PGA_Freedom
, LORIENT_VERT
,
177 if (!gradgad
) cleanup("Can't create gradientslider gadget!");
179 wheelgad
= (struct Gadget
*)NewObject(0, "colorwheel.gadget", GA_Left
, wheelx
,
181 GA_RelWidth
, wheelw
,
182 GA_RelHeight
, wheelh
,
184 WHEEL_Screen
, (IPTR
)scr
,
185 WHEEL_BevelBox
, TRUE
,
186 WHEEL_GradientSlider
, (IPTR
)gradgad
,
187 GA_Previous
, (IPTR
)gradgad
,
188 ICA_TARGET
, ICTARGET_IDCMP
,
191 if (!wheelgad
) cleanup("Can't create colorwheel gadget!");
193 GetAttr(WHEEL_HSB
, (Object
*)wheelgad
, (IPTR
*)&hsb
);
194 hsb
.cw_Brightness
= 0xFFFFFFFF;
195 ConvertHSBToRGB(&hsb
, &rgb
);
197 SetRGB32(vp
, pen1
, rgb
.cw_Red
, rgb
.cw_Green
, rgb
.cw_Blue
);
200 /*****************************************************************************************/
202 static void makewin(void)
204 win
= OpenWindowTags(0, WA_PubScreen
, (IPTR
)scr
,
213 WA_AutoAdjust
, TRUE
,
214 WA_Title
, (IPTR
)"ColorWheel",
215 WA_CloseGadget
, TRUE
,
217 WA_DepthGadget
, TRUE
,
218 WA_SizeGadget
, TRUE
,
219 WA_SizeBBottom
, TRUE
,
221 WA_ReportMouse
, TRUE
,
222 WA_IDCMP
, IDCMP_CLOSEWINDOW
| IDCMP_IDCMPUPDATE
,
223 WA_Gadgets
, (IPTR
)gradgad
,
226 if (!win
) cleanup("Can't open window!");
230 /*****************************************************************************************/
232 static void handleall(void)
234 struct IntuiMessage
*msg
;
239 WaitPort(win
->UserPort
);
241 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
245 case IDCMP_CLOSEWINDOW
:
249 case IDCMP_IDCMPUPDATE
:
251 struct ColorWheelRGB rgb
;
252 struct ColorWheelHSB hsb
;
253 struct TagItem
*tags
= (struct TagItem
*)msg
->IAddress
;
255 hsb
.cw_Hue
= GetTagData(WHEEL_Hue
, 0, tags
);
256 hsb
.cw_Saturation
= GetTagData(WHEEL_Saturation
, 0, tags
);
257 hsb
.cw_Brightness
= 0xFFFFFFFF;
259 ConvertHSBToRGB(&hsb
, &rgb
);
261 SetRGB32(vp
, pen1
, rgb
.cw_Red
, rgb
.cw_Green
, rgb
.cw_Blue
);
265 RefreshGList(gradgad
, win
, 0, 1);
270 } /* switch(msg->Class) */
272 ReplyMsg((struct Message
*)msg
);
274 } /* while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) */
276 } /* while(!quitme) */
280 /*****************************************************************************************/
294 /*****************************************************************************************/