Added memory-stored debug output to safe mode.
[cake.git] / workbench / demos / winshape.c
blobb973e0b54607dd21fd85e62c51f65992610444ab
2 #include <intuition/intuition.h>
3 #include <graphics/gfx.h>
4 #include <graphics/gfxmacros.h>
5 #include <utility/tagitem.h>
6 #include <proto/exec.h>
7 #include <proto/intuition.h>
8 #include <proto/graphics.h>
9 #include <proto/layers.h>
10 #include <aros/debug.h>
12 #include <stdio.h>
13 #include <stdlib.h>
15 #define WINWIDTH 260
16 #define WINHEIGHT 260
17 #define WINCX (WINWIDTH / 2)
18 #define WINCY (WINHEIGHT / 2)
20 struct IntuitionBase *IntuitionBase;
21 struct GfxBase *GfxBase;
22 struct Library *LayersBase;
23 struct Screen *scr;
24 struct DrawInfo *dri;
25 struct Window *win;
26 struct RastPort *rp;
27 struct Region *shape;
28 WORD actshape;
31 static void cleanup(char *msg)
33 if(msg) printf("winshape: %s\n", msg);
35 if (win) CloseWindow(win);
37 // if (shape) DisposeRegion(shape);
39 if (dri) FreeScreenDrawInfo(scr, dri);
40 if (scr) UnlockPubScreen(0, scr);
42 if (LayersBase) CloseLibrary(LayersBase);
43 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
44 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
46 exit(0);
50 static void openlibs(void)
52 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
54 cleanup("Can't open intuition.library!");
57 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
59 cleanup("Can't open graphics.library!");
62 if (!(LayersBase = OpenLibrary("layers.library", 39)))
64 cleanup("Can't open layers.library!");
70 static void getvisual(void)
72 if (!(scr = LockPubScreen(0))) cleanup("Can't lock pub screen!");
73 if (!(dri = GetScreenDrawInfo(scr))) cleanup("Can't get drawinfo!");
77 static void makeshape(void)
79 struct Rectangle rect;
81 #if 1
82 if (!(shape = NewRectRegion(0, 0, WINWIDTH - 1, scr->WBorTop + scr->Font->ta_YSize + 1 - 1)))
83 cleanup("Can't create region!\n");
84 #else
85 if (!(shape = NewRegion())) cleanup("Can't create region!\n");
87 rect.MinX = 0;
88 rect.MinY = 0;
89 rect.MaxX = WINWIDTH - 1;
90 rect.MaxY = scr->WBorTop + scr->Font->ta_YSize + 1 - 1;
92 if (!(OrRectRegion(shape, &rect))) cleanup("Can't create region!\n");
93 #endif
95 rect.MinX = WINCX - 20;
96 rect.MinY = 20;
97 rect.MaxX = WINCX + 20;
98 rect.MaxY = WINHEIGHT - 1 - 20;
100 if (!(OrRectRegion(shape, &rect))) cleanup("Can't create region!\n");
102 rect.MinX = 20;
103 rect.MinY = WINCY - 20;
104 rect.MaxX = WINWIDTH - 1 - 20;
105 rect.MaxY = WINCY + 20;
107 if (!(OrRectRegion(shape, &rect))) cleanup("Can't create region!\n");
112 static void makewin(void)
114 UWORD pattern[] = {0x5555, 0xAAAA};
115 struct TagItem win_tags[] =
117 { WA_Left , 0 },
118 { WA_Top , 0 },
119 { WA_Width , WINWIDTH },
120 { WA_Height , WINHEIGHT },
121 { WA_Title , (IPTR)"Irregular shaped window" },
122 { WA_CloseGadget , TRUE },
123 { WA_DepthGadget , TRUE },
124 { WA_DragBar , TRUE },
125 { WA_IDCMP , IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY },
126 { WA_Activate , TRUE },
127 { WA_Shape , (IPTR)shape },
128 { TAG_DONE }
131 win = OpenWindowTagList(0, win_tags);
132 if (!win) cleanup("Can't create window!");
134 rp = win->RPort;
135 SetAPen(rp, dri->dri_Pens[FILLPEN]);
136 SetBPen(rp, dri->dri_Pens[SHINEPEN]);
137 SetDrMd(rp, JAM2);
139 SetAfPt(rp, pattern, 1);
140 RectFill(rp, win->BorderLeft,
141 win->BorderTop,
142 WINWIDTH - 1 - win->BorderRight,
143 WINHEIGHT - 1 - win->BorderBottom);
144 SetAfPt(rp, 0, 0);
146 SetAPen(rp, dri->dri_Pens[SHINEPEN]);
147 RectFill(rp, WINCX - 20, 20, WINCX + 20, 20);
148 RectFill(rp, WINCX - 20, 21, WINCX - 20, WINCY - 20);
149 RectFill(rp, 20, WINCY - 20, WINCX - 20, WINCY - 20);
150 RectFill(rp, 20, WINCY - 20, 20, WINCY + 20);
151 RectFill(rp, WINCX - 20, WINCY + 20, WINCX - 20, WINHEIGHT - 1 - 20);
152 RectFill(rp, WINCX + 20, WINCY - 20, WINWIDTH - 1 - 20, WINCY - 20);
154 SetAPen(rp, dri->dri_Pens[SHADOWPEN]);
155 RectFill(rp, WINCX + 20, 20, WINCX + 20, WINCY - 20);
156 RectFill(rp, WINCX + 20, WINCY + 20, WINWIDTH - 1 - 20, WINCY + 20);
157 RectFill(rp, WINWIDTH - 1 - 20, WINCY - 20, WINWIDTH - 1 - 20, WINCY + 20);
158 RectFill(rp, 20, WINCY + 20, WINCX - 20, WINCY + 20);
159 RectFill(rp, WINCX - 20, WINHEIGHT - 1 - 20, WINCX + 20, WINHEIGHT - 1 - 20);
160 RectFill(rp, WINCX + 20, WINCY + 20, WINCX + 20, WINHEIGHT - 1 - 20);
163 static void handleall(void)
165 struct IntuiMessage *imsg;
166 BOOL quitme = FALSE;
168 struct TagItem taglist[] = {
169 {LA_DESTWIDTH , 0 },
170 {LA_DESTHEIGHT , 0 },
171 {TAG_END , 0 }
174 while (!quitme)
176 WaitPort(win->UserPort);
178 while ((imsg = (struct IntuiMessage *)GetMsg(win->UserPort)))
180 switch (imsg->Class)
182 case IDCMP_CLOSEWINDOW:
183 quitme = TRUE;
184 break;
186 case IDCMP_VANILLAKEY:
187 switch (imsg->Code)
190 case 43:
192 * '+': enlarge the layer.
194 taglist[0].ti_Data = (win->Width*3)/2;
195 taglist[1].ti_Data = (win->Height*3)/2;
196 ScaleLayer(win->WLayer, taglist);
197 break;
199 case 45:
201 * '-': make layer smaller.
203 taglist[0].ti_Data = (win->Width*2)/3;
204 taglist[1].ti_Data = (win->Height*2)/3;
205 ScaleLayer(win->WLayer, taglist);
206 break;
208 default:
209 actshape = 1 - actshape;
210 ChangeWindowShape(win, (actshape ? NULL : shape), NULL);
211 break;
215 ReplyMsg((struct Message *)imsg);
221 int main(void)
223 openlibs();
224 getvisual();
225 makeshape();
226 makewin();
227 handleall();
228 cleanup(0);
230 return 0;