revert between 56095 -> 55830 in arch
[AROS.git] / workbench / demos / roundwindow.c
blob773fcc485a8a29cc978b160c58a66a2c01902428
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>
9 #include <clib/alib_protos.h>
10 #include <aros/debug.h>
12 #include <math.h>
13 #include <stdio.h>
14 #include <stdlib.h>
16 #define INSTALL_NULL_SHAPE_FIRST 0
18 #define WINWIDTH 150
19 #define WINHEIGHT 150
21 /***********************************************************************************/
23 struct IntuitionBase *IntuitionBase;
24 struct GfxBase *GfxBase;
25 struct Screen *scr;
26 struct Window *win;
27 struct Region *shape;
28 struct RastPort *rp;
29 struct Hook shapehook;
31 UBYTE Keys[128];
33 /***********************************************************************************/
35 static void cleanup(char *msg)
37 if (msg)
39 printf("roundshape: %s\n",msg);
42 if (win) CloseWindow(win);
43 if (shape) DisposeRegion(shape);
44 if (scr) UnlockPubScreen(0, scr);
46 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
47 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
49 exit(0);
52 /***********************************************************************************/
54 static void openlibs(void)
56 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
58 cleanup("Can't open intuition.library V39!");
61 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
63 cleanup("Can't open graphics.library V39!");
68 /***********************************************************************************/
70 static void getvisual(void)
72 if (!(scr = LockPubScreen(NULL)))
74 cleanup("Can't lock pub screen!");
78 /***********************************************************************************/
80 static BOOL shapefunc(struct Hook *hook, struct Layer *lay, struct ShapeHookMsg *msg)
82 struct Region *newshape;
83 WORD x2, y2;
84 BOOL success = TRUE;
86 switch(msg->Action)
88 case SHAPEHOOKACTION_CREATELAYER:
89 case SHAPEHOOKACTION_SIZELAYER:
90 case SHAPEHOOKACTION_MOVESIZELAYER:
91 x2 = msg->NewBounds->MaxX - msg->NewBounds->MinX;
92 y2 = msg->NewBounds->MaxY - msg->NewBounds->MinY;
94 if ((newshape = NewRegion()))
96 struct Rectangle rect;
98 rect.MinX = 9;
99 rect.MinY = 0;
100 rect.MaxX = x2 - 9;
101 rect.MaxY = y2;
102 success &= OrRectRegion(newshape, &rect);
104 rect.MinX = 6;
105 rect.MinY = 1;
106 rect.MaxX = x2 - 6;
107 rect.MaxY = y2 - 1;
108 success &= OrRectRegion(newshape, &rect);
110 rect.MinX = 4;
111 rect.MinY = 2;
112 rect.MaxX = x2 - 4;
113 rect.MaxY = y2 - 2;
114 success &= OrRectRegion(newshape, &rect);
116 rect.MinX = 3;
117 rect.MinY = 3;
118 rect.MaxX = x2 - 3;
119 rect.MaxY = y2 - 3;
120 success &= OrRectRegion(newshape, &rect);
122 rect.MinX = 2;
123 rect.MinY = 4;
124 rect.MaxX = x2 - 2;
125 rect.MaxY = y2 - 4;
126 success &= OrRectRegion(newshape, &rect);
128 rect.MinX = 1;
129 rect.MinY = 6;
130 rect.MaxX = x2 - 1;
131 rect.MaxY = y2 - 6;
132 success &= OrRectRegion(newshape, &rect);
134 rect.MinX = 0;
135 rect.MinY = 9;
136 rect.MaxX = x2;
137 rect.MaxY = y2 - 9;
138 success &= OrRectRegion(newshape, &rect);
140 if (success)
142 if (msg->OldShape) DisposeRegion(msg->OldShape);
143 msg->NewShape = shape = newshape;
145 else
147 DisposeRegion(newshape);
150 } /* if ((newshape = NewRegion())) */
152 } /* switch(msg->Action) */
154 return success;
157 /***********************************************************************************/
159 static void makewin(void)
161 shapehook.h_Entry = HookEntry;
162 shapehook.h_SubEntry = (HOOKFUNC)shapefunc;
165 win = OpenWindowTags(NULL, WA_CustomScreen , (IPTR)scr,
166 WA_InnerWidth , WINWIDTH,
167 WA_InnerHeight , WINHEIGHT,
168 WA_Title , (IPTR)"Round Edged Window",
169 WA_DragBar , TRUE,
170 //WA_DepthGadget , TRUE,
171 //WA_CloseGadget , TRUE,
172 WA_Activate , TRUE,
173 WA_MinWidth , 160,
174 WA_MinHeight , 160,
175 WA_MaxWidth , 2000,
176 WA_MaxHeight , 2000,
177 WA_SizeGadget , TRUE,
178 WA_SizeBBottom , TRUE,
179 WA_NoCareRefresh , TRUE,
180 WA_ShapeHook , (IPTR)&shapehook,
181 WA_IDCMP , IDCMP_CLOSEWINDOW |
182 IDCMP_RAWKEY |
183 IDCMP_NEWSIZE,
184 TAG_DONE);
186 if (!win) cleanup("Can't open window");
188 rp = win->RPort;
192 /***********************************************************************************/
194 #define KC_ESC 0x45
196 /***********************************************************************************/
198 static void action(void)
200 struct IntuiMessage *msg;
204 WaitPort(win->UserPort);
206 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
208 switch (msg->Class)
210 case IDCMP_CLOSEWINDOW:
211 Keys[KC_ESC] = 1;
212 break;
214 case IDCMP_RAWKEY:
216 WORD code = msg->Code & ~IECODE_UP_PREFIX;
218 Keys[code] = (code == msg->Code) ? 1 : 0;
222 break;
225 ReplyMsg((struct Message *)msg);
228 } while(!Keys[KC_ESC]);
231 /***********************************************************************************/
233 int main(void)
235 openlibs();
236 getvisual();
237 makewin();
238 action();
239 cleanup(0);
241 return 0;
244 /***********************************************************************************/