Trust uboot's device list only if it does not look suspicious.
[AROS.git] / test / truecolorpens.c
blobebbe746f39babb88b0b72acb921f5bd9ff55fb92
2 #include <dos/dos.h>
3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <graphics/rpattr.h>
6 #include <cybergraphx/cybergraphics.h>
7 #include <gadgets/colorwheel.h>
8 #include <proto/exec.h>
9 #include <proto/dos.h>
10 #include <proto/graphics.h>
11 #include <proto/cybergraphics.h>
12 #include <proto/colorwheel.h>
13 #include <proto/intuition.h>
15 #include <math.h>
16 #include <stdio.h>
17 #include <stdlib.h>
19 #define SCREENWIDTH 300
20 #define SCREENHEIGHT 200
21 #define SCREENCY (SCREENHEIGHT / 2)
23 /***********************************************************************************/
25 struct IntuitionBase *IntuitionBase;
26 struct GfxBase *GfxBase;
27 struct Library *CyberGfxBase;
28 struct Library *ColorWheelBase;
29 struct Screen *scr;
30 struct Window *win;
31 struct RastPort *rp;
33 ULONG cgfx_coltab[256];
34 UBYTE Keys[128];
36 /***********************************************************************************/
38 static void cleanup(char *msg)
40 if (msg)
42 printf("TrueColorPens: %s\n",msg);
45 if (win) CloseWindow(win);
47 if (scr) UnlockPubScreen(0, scr);
49 if (ColorWheelBase) CloseLibrary(ColorWheelBase);
50 if (CyberGfxBase) CloseLibrary(CyberGfxBase);
51 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
52 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
54 exit(0);
57 /***********************************************************************************/
59 static void openlibs(void)
61 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
63 cleanup("Can't open intuition.library V39!");
66 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
68 cleanup("Can't open graphics.library V39!");
71 if (!(CyberGfxBase = OpenLibrary("cybergraphics.library",0)))
73 cleanup("Can't open cybergraphics.library!");
76 if (!(ColorWheelBase = OpenLibrary("gadgets/colorwheel.gadget",0)))
78 cleanup("Can't open colorwheel.gadget!");
83 /***********************************************************************************/
85 static void getvisual(void)
87 if (!(scr = LockPubScreen(NULL)))
89 cleanup("Can't lock pub screen!");
92 if (GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH) <= 8)
94 cleanup("Need hi or true color screen!");
98 /***********************************************************************************/
100 static void makewin(void)
102 win = OpenWindowTags(NULL, WA_CustomScreen , (IPTR)scr,
103 WA_InnerWidth , SCREENWIDTH,
104 WA_InnerHeight , SCREENHEIGHT,
105 WA_Title , (IPTR)"TrueColorPens: Press SPACE!",
106 WA_DragBar , TRUE,
107 WA_DepthGadget , TRUE,
108 WA_CloseGadget , TRUE,
109 WA_Activate , TRUE,
110 WA_GimmeZeroZero , TRUE,
111 WA_IDCMP , IDCMP_CLOSEWINDOW |
112 IDCMP_RAWKEY,
113 TAG_DONE);
115 if (!win) cleanup("Can't open window");
117 rp = win->RPort;
120 /***********************************************************************************/
122 #define KC_LEFT 0x4F
123 #define KC_RIGHT 0x4E
124 #define KC_UP 0x4C
125 #define KC_DOWN 0x4D
126 #define KC_ESC 0x45
127 #define KC_SPACE 0x40
129 /***********************************************************************************/
131 static void getevents(void)
133 struct IntuiMessage *msg;
135 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
137 switch(msg->Class)
139 case IDCMP_CLOSEWINDOW:
140 Keys[KC_ESC] = 1;
141 break;
143 case IDCMP_RAWKEY:
145 WORD code = msg->Code & ~IECODE_UP_PREFIX;
147 Keys[code] = (code == msg->Code) ? 1 : 0;
150 break;
153 ReplyMsg((struct Message *)msg);
158 /***********************************************************************************/
160 static void action(void)
162 LONG mode = 0;
163 ULONG hue = 0, rgb;
164 WORD x = 20, y = 0;
165 WORD dx = 2, dy = 3;
167 while(!Keys[KC_ESC])
169 struct ColorWheelHSB cwhsb = {hue, 0xFFFFFFFF, 0xFFFFFFFF};
170 struct ColorWheelRGB cwrgb;
172 WaitTOF();
174 ConvertHSBToRGB(&cwhsb, &cwrgb);
176 rgb = (cwrgb.cw_Red & 0xFF000000) >> 8;
177 rgb += (cwrgb.cw_Green & 0xFF000000) >> 16;
178 rgb += (cwrgb.cw_Blue & 0xFF000000) >> 24;
180 SetRPAttrs(rp, RPTAG_FgColor, rgb,
181 RPTAG_BgColor, 0xFFFFFF - rgb,
182 TAG_DONE);
184 switch(mode)
186 case 0:
187 SetDrMd(rp, JAM1);
188 WritePixel(rp, x, y);
189 WritePixel(rp, x + 1, y);
190 WritePixel(rp, x, y + 1);
191 WritePixel(rp, x + 1, y + 1);
192 break;
194 case 1:
195 SetDrMd(rp, JAM1);
196 Move(rp, x, y);
197 Text(rp, "Text JAM1", 4);
198 break;
200 case 2:
201 SetDrMd(rp, JAM2);
202 Move(rp, x, y);
203 Text(rp, "Text JAM2", 4);
204 break;
206 case 3:
207 SetDrMd(rp, JAM1);
208 RectFill(rp, x, y, x + 30, y + 30);
209 break;
211 case 4:
212 SetDrMd(rp, JAM1);
213 Move(rp, x, y);
214 Draw(rp, x + 30, y);
215 Draw(rp, x + 30, y + 30);
216 Draw(rp, x, y + 30);
217 Draw(rp, x, y);
218 break;
220 case 5:
221 SetDrMd(rp, JAM1);
222 DrawEllipse(rp, x, y, 30, 30);
223 break;
227 getevents();
229 if (Keys[KC_SPACE])
231 Keys[KC_SPACE] = 0;
232 mode = (mode + 1) % 6;
233 hue = 0;
236 x += dx; if ((x > SCREENWIDTH) || (x < 0)) dx = -dx;
237 y += dy; if ((y > SCREENHEIGHT) || (y < 0)) dy = -dy;
239 hue += 0x1000000;
241 } /* while(!Keys[KC_ESC]) */
244 /***********************************************************************************/
246 int main(void)
248 openlibs();
249 getvisual();
250 makewin();
251 action();
252 cleanup(0);
254 return 0; /* keep compiler happy */
257 /***********************************************************************************/