(sanity) make sure we don't try to free the affinity_all special marker.
[AROS.git] / workbench / demos / winshape.c
blobb49af11f27beb35f2e98a5e1d0baa8ffca457c16
2 #include <intuition/intuition.h>
3 #include <graphics/gfx.h>
4 #include <graphics/gfxmacros.h>
5 #include <utility/tagitem.h>
6 #include <proto/alib.h>
7 #include <proto/exec.h>
8 #include <proto/intuition.h>
9 #include <proto/graphics.h>
10 #include <proto/layers.h>
11 #include <aros/debug.h>
13 #include <stdio.h>
14 #include <stdlib.h>
16 #define WINWIDTH 260
17 #define WINHEIGHT 260
18 #define WINCX (WINWIDTH / 2)
19 #define WINCY (WINHEIGHT / 2)
21 struct IntuitionBase *IntuitionBase;
22 struct GfxBase *GfxBase;
23 struct Library *LayersBase;
24 struct Screen *scr;
25 struct DrawInfo *dri;
26 struct Window *win;
27 struct RastPort *rp;
28 struct Region *shape;
29 WORD actshape;
32 static void cleanup(char *msg)
34 if(msg) printf("winshape: %s\n", msg);
36 if (win) CloseWindow(win);
38 // if (shape) DisposeRegion(shape);
40 if (dri) FreeScreenDrawInfo(scr, dri);
41 if (scr) UnlockPubScreen(0, scr);
43 if (LayersBase) CloseLibrary(LayersBase);
44 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
45 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
47 exit(0);
51 static void openlibs(void)
53 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
55 cleanup("Can't open intuition.library!");
58 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
60 cleanup("Can't open graphics.library!");
63 if (!(LayersBase = OpenLibrary("layers.library", 39)))
65 cleanup("Can't open layers.library!");
71 static void getvisual(void)
73 if (!(scr = LockPubScreen(0))) cleanup("Can't lock pub screen!");
74 if (!(dri = GetScreenDrawInfo(scr))) cleanup("Can't get drawinfo!");
78 static void makeshape(void)
80 struct Rectangle rect;
82 #if 1
83 if (!(shape = NewRectRegion(0, 0, WINWIDTH - 1, scr->WBorTop + scr->Font->ta_YSize + 1 - 1)))
84 cleanup("Can't create region!\n");
85 #else
86 if (!(shape = NewRegion())) cleanup("Can't create region!\n");
88 rect.MinX = 0;
89 rect.MinY = 0;
90 rect.MaxX = WINWIDTH - 1;
91 rect.MaxY = scr->WBorTop + scr->Font->ta_YSize + 1 - 1;
93 if (!(OrRectRegion(shape, &rect))) cleanup("Can't create region!\n");
94 #endif
96 rect.MinX = WINCX - 20;
97 rect.MinY = 20;
98 rect.MaxX = WINCX + 20;
99 rect.MaxY = WINHEIGHT - 1 - 20;
101 if (!(OrRectRegion(shape, &rect))) cleanup("Can't create region!\n");
103 rect.MinX = 20;
104 rect.MinY = WINCY - 20;
105 rect.MaxX = WINWIDTH - 1 - 20;
106 rect.MaxY = WINCY + 20;
108 if (!(OrRectRegion(shape, &rect))) cleanup("Can't create region!\n");
113 static void makewin(void)
115 UWORD pattern[] = {0x5555, 0xAAAA};
116 struct TagItem win_tags[] =
118 { WA_Left , 0 },
119 { WA_Top , 0 },
120 { WA_Width , WINWIDTH },
121 { WA_Height , WINHEIGHT },
122 { WA_Title , (IPTR)"Irregular shaped window" },
123 { WA_CloseGadget , TRUE },
124 { WA_DepthGadget , TRUE },
125 { WA_DragBar , TRUE },
126 { WA_IDCMP , IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY },
127 { WA_Activate , TRUE },
128 { WA_ShapeRegion , (IPTR)shape },
129 { TAG_DONE }
132 win = OpenWindowTagList(0, win_tags);
133 if (!win) cleanup("Can't create window!");
135 rp = win->RPort;
136 SetAPen(rp, dri->dri_Pens[FILLPEN]);
137 SetBPen(rp, dri->dri_Pens[SHINEPEN]);
138 SetDrMd(rp, JAM2);
140 SetAfPt(rp, pattern, 1);
141 RectFill(rp, win->BorderLeft,
142 win->BorderTop,
143 WINWIDTH - 1 - win->BorderRight,
144 WINHEIGHT - 1 - win->BorderBottom);
145 SetAfPt(rp, 0, 0);
147 SetAPen(rp, dri->dri_Pens[SHINEPEN]);
148 RectFill(rp, WINCX - 20, 20, WINCX + 20, 20);
149 RectFill(rp, WINCX - 20, 21, WINCX - 20, WINCY - 20);
150 RectFill(rp, 20, WINCY - 20, WINCX - 20, WINCY - 20);
151 RectFill(rp, 20, WINCY - 20, 20, WINCY + 20);
152 RectFill(rp, WINCX - 20, WINCY + 20, WINCX - 20, WINHEIGHT - 1 - 20);
153 RectFill(rp, WINCX + 20, WINCY - 20, WINWIDTH - 1 - 20, WINCY - 20);
155 SetAPen(rp, dri->dri_Pens[SHADOWPEN]);
156 RectFill(rp, WINCX + 20, 20, WINCX + 20, WINCY - 20);
157 RectFill(rp, WINCX + 20, WINCY + 20, WINWIDTH - 1 - 20, WINCY + 20);
158 RectFill(rp, WINWIDTH - 1 - 20, WINCY - 20, WINWIDTH - 1 - 20, WINCY + 20);
159 RectFill(rp, 20, WINCY + 20, WINCX - 20, WINCY + 20);
160 RectFill(rp, WINCX - 20, WINHEIGHT - 1 - 20, WINCX + 20, WINHEIGHT - 1 - 20);
161 RectFill(rp, WINCX + 20, WINCY + 20, WINCX + 20, WINHEIGHT - 1 - 20);
164 static void handleall(void)
166 struct IntuiMessage *imsg;
167 BOOL quitme = FALSE;
169 struct TagItem taglist[] = {
170 {LA_DESTWIDTH , 0 },
171 {LA_DESTHEIGHT , 0 },
172 {TAG_END , 0 }
175 while (!quitme)
177 WaitPort(win->UserPort);
179 while ((imsg = (struct IntuiMessage *)GetMsg(win->UserPort)))
181 switch (imsg->Class)
183 case IDCMP_CLOSEWINDOW:
184 quitme = TRUE;
185 break;
187 case IDCMP_VANILLAKEY:
188 switch (imsg->Code)
191 case 43:
193 * '+': enlarge the layer.
195 taglist[0].ti_Data = (win->Width*3)/2;
196 taglist[1].ti_Data = (win->Height*3)/2;
197 ScaleLayer(win->WLayer, taglist);
198 break;
200 case 45:
202 * '-': make layer smaller.
204 taglist[0].ti_Data = (win->Width*2)/3;
205 taglist[1].ti_Data = (win->Height*2)/3;
206 ScaleLayer(win->WLayer, taglist);
207 break;
209 default:
210 actshape = 1 - actshape;
211 ChangeWindowShape(win, (actshape ? NULL : shape), NULL);
212 break;
216 ReplyMsg((struct Message *)imsg);
222 int main(void)
224 openlibs();
225 getvisual();
226 makeshape();
227 makewin();
228 handleall();
229 cleanup(0);
231 return 0;