Added missing properties.
[tangerine.git] / workbench / demos / roundshape.c
blob3dbf306a1fb3c1131cca6486628588dff5a4832f
2 #include <dos/dos.h>
3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <proto/exec.h>
6 #include <proto/dos.h>
7 #include <proto/graphics.h>
8 #include <proto/intuition.h>
10 #include <math.h>
11 #include <stdio.h>
12 #include <stdlib.h>
14 #define INSTALL_NULL_SHAPE_FIRST 0
16 #define WINWIDTH 150
17 #define WINHEIGHT 150
19 /***********************************************************************************/
21 struct IntuitionBase *IntuitionBase;
22 struct GfxBase *GfxBase;
23 struct Screen *scr;
24 struct Window *win;
25 struct Region *shape;
26 struct RastPort *rp;
28 UBYTE Keys[128];
30 /***********************************************************************************/
32 static void cleanup(char *msg)
34 if (msg)
36 printf("roundshape: %s\n",msg);
39 if (win) CloseWindow(win);
40 if (shape) DisposeRegion(shape);
41 if (scr) UnlockPubScreen(0, scr);
43 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
44 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
46 exit(0);
49 /***********************************************************************************/
51 static void openlibs(void)
53 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
55 cleanup("Can't open intuition.library V39!");
58 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
60 cleanup("Can't open graphics.library V39!");
65 /***********************************************************************************/
67 static void getvisual(void)
69 if (!(scr = LockPubScreen(NULL)))
71 cleanup("Can't lock pub screen!");
75 /***********************************************************************************/
77 static void makewin(void)
79 win = OpenWindowTags(NULL, WA_CustomScreen , (IPTR)scr,
80 WA_InnerWidth , WINWIDTH,
81 WA_InnerHeight , WINHEIGHT,
82 WA_Title , (IPTR)"Round Shape",
83 WA_DragBar , TRUE,
84 WA_DepthGadget , TRUE,
85 WA_CloseGadget , TRUE,
86 WA_Activate , TRUE,
87 WA_MinWidth , 160,
88 WA_MinHeight , 160,
89 WA_MaxWidth , 2000,
90 WA_MaxHeight , 2000,
91 WA_SizeGadget , TRUE,
92 WA_SizeBBottom , TRUE,
93 WA_SizeBRight , TRUE,
94 WA_NoCareRefresh , TRUE,
95 WA_Shape , 0,
96 WA_IDCMP , IDCMP_CLOSEWINDOW |
97 IDCMP_RAWKEY |
98 IDCMP_NEWSIZE,
99 TAG_DONE);
101 if (!win) cleanup("Can't open window");
103 rp = win->RPort;
107 /***********************************************************************************/
109 static void renderwin(void)
111 struct Region *oldshape;
112 struct Rectangle rect;
113 WORD cx, cy, r, y;
115 static WORD oldheight = 0;
116 static WORD oldwidth = 0;
118 if (oldheight == win->GZZHeight && oldwidth == win->GZZWidth)
119 return;
121 oldheight = win->GZZHeight;
122 oldwidth = win->GZZWidth;
124 cx = win->BorderLeft + win->GZZWidth / 2;
125 cy = win->BorderTop + win->GZZHeight / 2;
127 r = ((win->GZZWidth < win->GZZHeight) ? win->GZZWidth : win->GZZHeight) / 2 - 10;
129 #if INSTALL_NULL_SHAPE_FIRST
130 oldshape = ChangeWindowShape(win, shape, NULL);
131 if (oldshape) DisposeRegion(oldshape);
132 #endif
134 shape = NewRectRegion(0, 0, win->Width - 1, win->BorderTop - 1);
136 rect.MinX = win->Width - win->BorderRight;
137 rect.MinY = win->Height - win->BorderBottom;
138 rect.MaxX = win->Width - 1;
139 rect.MaxY = win->Height - 1;
141 OrRectRegion(shape, &rect);
143 for(y = 0; y < r; y++)
145 WORD dx = (WORD)sqrt((double)(r * r - y * y));
147 SetAPen(rp, 3);
148 RectFill(rp, cx - dx, cy - y, cx + dx, cy - y);
149 RectFill(rp, cx - dx, cy + y, cx + dx, cy + y);
151 SetAPen(rp, 2);
152 WritePixel(rp, cx - dx, cy - y);
153 WritePixel(rp, cx - dx, cy + y);
155 SetAPen(rp, 1);
156 WritePixel(rp, cx + dx, cy - y);
157 WritePixel(rp, cx + dx, cy + y);
159 rect.MinX = cx - dx;
160 rect.MinY = cy - y;
161 rect.MaxX = cx + dx;
162 rect.MaxY = cy - y;
164 OrRectRegion(shape, &rect);
166 rect.MinX = cx - dx;
167 rect.MinY = cy + y;
168 rect.MaxX = cx + dx;
169 rect.MaxY = cy + y;
171 OrRectRegion(shape, &rect);
174 oldshape = ChangeWindowShape(win, shape, NULL);
175 if (oldshape) DisposeRegion(oldshape);
177 RefreshWindowFrame(win);
180 /***********************************************************************************/
182 #define KC_ESC 0x45
184 /***********************************************************************************/
186 static void action(void)
188 struct IntuiMessage *msg;
192 WaitPort(win->UserPort);
194 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
196 switch (msg->Class)
198 case IDCMP_CLOSEWINDOW:
199 Keys[KC_ESC] = 1;
200 break;
202 case IDCMP_RAWKEY:
204 WORD code = msg->Code & ~IECODE_UP_PREFIX;
206 Keys[code] = (code == msg->Code) ? 1 : 0;
210 break;
212 case IDCMP_NEWSIZE:
213 renderwin();
214 break;
216 ReplyMsg((struct Message *)msg);
219 } while(!Keys[KC_ESC]);
222 /***********************************************************************************/
224 int main(void)
226 openlibs();
227 getvisual();
228 makewin();
229 renderwin();
230 action();
231 cleanup(0);
233 return 0;
236 /***********************************************************************************/