Prefs/ScreenMode: change the way depth is selected
[AROS.git] / test / graphics / truecolorpens.c
blob53e9f52cc997968771538341e86ad9223d8cd47d
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <dos/dos.h>
7 #include <intuition/intuition.h>
8 #include <graphics/gfx.h>
9 #include <graphics/rpattr.h>
10 #include <cybergraphx/cybergraphics.h>
11 #include <gadgets/colorwheel.h>
12 #include <proto/exec.h>
13 #include <proto/dos.h>
14 #include <proto/graphics.h>
15 #include <proto/cybergraphics.h>
16 #include <proto/colorwheel.h>
17 #include <proto/intuition.h>
19 #include <math.h>
20 #include <stdio.h>
21 #include <stdlib.h>
23 #define SCREENWIDTH 300
24 #define SCREENHEIGHT 200
25 #define SCREENCY (SCREENHEIGHT / 2)
26 #define MAX_VECTORS 2
28 /***********************************************************************************/
30 struct IntuitionBase *IntuitionBase;
31 struct GfxBase *GfxBase;
32 struct Library *CyberGfxBase;
33 struct Library *ColorWheelBase;
34 struct Screen *scr;
35 struct Window *win;
36 struct RastPort *rp;
38 ULONG cgfx_coltab[256];
39 UBYTE Keys[128];
41 /***********************************************************************************/
43 static void cleanup(char *msg)
45 if (msg)
47 printf("TrueColorPens: %s\n",msg);
50 if (win) CloseWindow(win);
52 if (scr) UnlockPubScreen(0, scr);
54 if (ColorWheelBase) CloseLibrary(ColorWheelBase);
55 if (CyberGfxBase) CloseLibrary(CyberGfxBase);
56 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
57 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
59 exit(0);
62 /***********************************************************************************/
64 static void openlibs(void)
66 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
68 cleanup("Can't open intuition.library V39!");
71 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
73 cleanup("Can't open graphics.library V39!");
76 if (!(CyberGfxBase = OpenLibrary("cybergraphics.library",0)))
78 cleanup("Can't open cybergraphics.library!");
81 if (!(ColorWheelBase = OpenLibrary("gadgets/colorwheel.gadget",0)))
83 cleanup("Can't open colorwheel.gadget!");
88 /***********************************************************************************/
90 static void getvisual(void)
92 if (!(scr = LockPubScreen(NULL)))
94 cleanup("Can't lock pub screen!");
97 if (GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH) <= 8)
99 cleanup("Need hi or true color screen!");
103 /***********************************************************************************/
105 static void makewin(void)
107 win = OpenWindowTags(NULL, WA_CustomScreen , (IPTR)scr,
108 WA_InnerWidth , SCREENWIDTH,
109 WA_InnerHeight , SCREENHEIGHT,
110 WA_Title , (IPTR)"TrueColorPens: Press SPACE!",
111 WA_DragBar , TRUE,
112 WA_DepthGadget , TRUE,
113 WA_CloseGadget , TRUE,
114 WA_Activate , TRUE,
115 WA_GimmeZeroZero , TRUE,
116 WA_IDCMP , IDCMP_CLOSEWINDOW |
117 IDCMP_RAWKEY,
118 TAG_DONE);
120 if (!win) cleanup("Can't open window");
122 rp = win->RPort;
125 /***********************************************************************************/
127 #define KC_LEFT 0x4F
128 #define KC_RIGHT 0x4E
129 #define KC_UP 0x4C
130 #define KC_DOWN 0x4D
131 #define KC_ESC 0x45
132 #define KC_SPACE 0x40
134 /***********************************************************************************/
136 static void getevents(void)
138 struct IntuiMessage *msg;
140 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
142 switch(msg->Class)
144 case IDCMP_CLOSEWINDOW:
145 Keys[KC_ESC] = 1;
146 break;
148 case IDCMP_RAWKEY:
150 WORD code = msg->Code & ~IECODE_UP_PREFIX;
152 Keys[code] = (code == msg->Code) ? 1 : 0;
155 break;
158 ReplyMsg((struct Message *)msg);
163 /***********************************************************************************/
165 static void action(void)
167 LONG mode = 0;
168 ULONG hue = 0, rgb;
169 WORD x = 20, y = 0;
170 WORD dx = 2, dy = 3;
171 struct AreaInfo area_info;
172 UBYTE area_buffer[MAX_VECTORS * 5];
173 PLANEPTR raster;
174 struct TmpRas tmp_ras;
176 rp->AreaInfo = &area_info;
177 raster = AllocRaster(SCREENWIDTH, SCREENHEIGHT);
178 if (raster != NULL)
180 InitTmpRas(&tmp_ras, raster, RASSIZE(SCREENWIDTH, SCREENHEIGHT));
181 rp->TmpRas = &tmp_ras;
183 else
184 Keys[KC_ESC] = 1;
186 while(!Keys[KC_ESC])
188 struct ColorWheelHSB cwhsb = {hue, 0xFFFFFFFF, 0xFFFFFFFF};
189 struct ColorWheelRGB cwrgb;
191 WaitTOF();
193 ConvertHSBToRGB(&cwhsb, &cwrgb);
195 rgb = (cwrgb.cw_Red & 0xFF000000) >> 8;
196 rgb += (cwrgb.cw_Green & 0xFF000000) >> 16;
197 rgb += (cwrgb.cw_Blue & 0xFF000000) >> 24;
199 SetRPAttrs(rp, RPTAG_FgColor, rgb,
200 RPTAG_BgColor, 0xFFFFFF - rgb,
201 RPTAG_PenMode, FALSE,
202 TAG_DONE);
204 switch(mode)
206 case 0:
207 SetDrMd(rp, JAM1);
208 WritePixel(rp, x, y);
209 WritePixel(rp, x + 1, y);
210 WritePixel(rp, x, y + 1);
211 WritePixel(rp, x + 1, y + 1);
212 break;
214 case 1:
215 SetDrMd(rp, JAM1);
216 Move(rp, x, y);
217 Text(rp, "Text JAM1", 4);
218 break;
220 case 2:
221 SetDrMd(rp, JAM2);
222 Move(rp, x, y);
223 Text(rp, "Text JAM2", 4);
224 break;
226 case 3:
227 SetDrMd(rp, JAM1);
228 RectFill(rp, x, y, x + 30, y + 30);
229 break;
231 case 4:
232 SetDrMd(rp, JAM1);
233 Move(rp, x, y);
234 Draw(rp, x + 30, y);
235 Draw(rp, x + 30, y + 30);
236 Draw(rp, x, y + 30);
237 Draw(rp, x, y);
238 break;
240 case 5:
241 SetDrMd(rp, JAM1);
242 DrawEllipse(rp, x, y, 30, 30);
243 break;
245 case 6:
246 InitArea(&area_info, area_buffer, MAX_VECTORS);
247 AreaEllipse(rp, x, y, 30, 30);
248 AreaEnd(rp);
249 break;
252 getevents();
254 if (Keys[KC_SPACE])
256 Keys[KC_SPACE] = 0;
257 mode = (mode + 1) % 7;
258 hue = 0;
261 x += dx; if ((x > SCREENWIDTH) || (x < 0)) dx = -dx;
262 y += dy; if ((y > SCREENHEIGHT) || (y < 0)) dy = -dy;
264 hue += 0x1000000;
266 } /* while(!Keys[KC_ESC]) */
268 if (raster != NULL)
269 FreeRaster(raster, SCREENWIDTH, SCREENHEIGHT);
272 /***********************************************************************************/
274 int main(void)
276 openlibs();
277 getvisual();
278 makewin();
279 action();
280 cleanup(0);
282 return 0; /* keep compiler happy */
285 /***********************************************************************************/