define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / test / truecolorpens.c
blob41df5b683675d72803f3b2288d3ba294746229f6
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 Move(rp, x, y);
189 Text(rp, "Text JAM1", 4);
190 break;
192 case 1:
193 SetDrMd(rp, JAM2);
194 Move(rp, x, y);
195 Text(rp, "Text JAM2", 4);
196 break;
198 case 2:
199 SetDrMd(rp, JAM1);
200 RectFill(rp, x, y, x + 30, y + 30);
201 break;
203 case 3:
204 SetDrMd(rp, JAM1);
205 Move(rp, x, y);
206 Draw(rp, x + 30, y);
207 Draw(rp, x + 30, y + 30);
208 Draw(rp, x, y + 30);
209 Draw(rp, x, y);
210 break;
212 case 4:
213 SetDrMd(rp, JAM1);
214 DrawEllipse(rp, x, y, 30, 30);
215 break;
218 getevents();
220 if (Keys[KC_SPACE])
222 Keys[KC_SPACE] = 0;
223 mode = (mode + 1) % 5;
224 hue = 0;
227 x += dx; if ((x > SCREENWIDTH) || (x < 0)) dx = -dx;
228 y += dy; if ((y > SCREENHEIGHT) || (y < 0)) dy = -dy;
230 hue += 0x1000000;
232 } /* while(!Keys[KC_ESC]) */
235 /***********************************************************************************/
237 int main(void)
239 openlibs();
240 getvisual();
241 makewin();
242 action();
243 cleanup(0);
245 return 0; /* keep compiler happy */
248 /***********************************************************************************/