define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / workbench / demos / childchild.c
blob115b57a46222e64faa80336e70a83019f1f1ef05
1 #include <intuition/intuition.h>
2 #include <graphics/gfx.h>
3 #include <graphics/gfxmacros.h>
4 #include <proto/exec.h>
5 #include <proto/intuition.h>
6 #include <proto/graphics.h>
7 #include <proto/alib.h>
9 #include <stdio.h>
10 #include <stdlib.h>
12 #define WINWIDTH 400
13 #define WINHEIGHT 400
14 #define WINCX (WINWIDTH / 2)
15 #define WINCY (WINHEIGHT / 2)
17 #define PATTERNWIDTH 32
18 #define PATTERNHEIGHT 32
19 #define PATTERNCOL1 SHADOWPEN
20 #define PATTERNCOL2 SHINEPEN
22 struct LayerHookMsg
24 struct Layer *lay;
25 struct Rectangle bounds;
26 LONG offsetx;
27 LONG offsety;
30 struct IntuitionBase *IntuitionBase;
31 struct GfxBase *GfxBase;
32 struct Screen *scr;
33 struct DrawInfo *dri;
34 struct Window *win, *win2, *win3;
35 struct RastPort *rp;
36 struct BitMap *patternbm;
37 struct Hook backfillhook;
39 static void cleanup(char *msg)
41 if(msg) printf("childchild: %s\n", msg);
43 if (win3) CloseWindow(win3);
44 if (win2) CloseWindow(win2);
45 if (win) CloseWindow(win);
47 if (patternbm) FreeBitMap(patternbm);
49 if (dri) FreeScreenDrawInfo(scr, dri);
50 if (scr) UnlockPubScreen(0, scr);
52 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
53 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
55 exit(0);
58 static void openlibs(void)
60 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
62 cleanup("Can't open intuition.library!");
65 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
67 cleanup("Can't open graphics.library!");
72 static void getvisual(void)
74 if (!(scr = LockPubScreen(0))) cleanup("Can't lock pub screen!");
75 if (!(dri = GetScreenDrawInfo(scr))) cleanup("Can't get drawinfo!");
79 static void MyBackfillFunc(struct Hook *hook,struct RastPort *rp,
80 struct LayerHookMsg *msg)
82 struct RastPort myrp;
83 struct Layer *lay;
84 WORD x1,y1,x2,y2,px,py,pw,ph;
86 myrp = *rp;
87 lay = msg->lay;
89 myrp.Layer = 0;
91 x1 = msg->bounds.MinX;
92 y1 = msg->bounds.MinY;
93 x2 = msg->bounds.MaxX;
94 y2 = msg->bounds.MaxY;
96 px = (x1 - lay->bounds.MinX) % PATTERNWIDTH;
98 pw = PATTERNWIDTH - px;
102 y1 = msg->bounds.MinY;
103 py = (y1 - lay->bounds.MinY) % PATTERNHEIGHT;
105 ph = PATTERNHEIGHT - py;
107 if (pw > (x2 - x1 + 1)) pw = x2 - x1 + 1;
111 if (ph > (y2 - y1 + 1)) ph = y2 - y1 + 1;
113 BltBitMap(patternbm,
116 rp->BitMap,
121 192,
122 255,
125 y1 += ph;
127 py = 0;
128 ph = PATTERNHEIGHT;
130 } while (y1 <= y2); /* while(y1 < y2) */
132 x1 += pw;
134 px = 0;
135 pw = PATTERNWIDTH;
137 } while (x1 <= x2); /* while (x1 < x2) */
141 static void InitBackfillHook(void)
143 backfillhook.h_Entry = HookEntry;
144 backfillhook.h_SubEntry = (HOOKFUNC)MyBackfillFunc;
148 static void MakePattern(void)
150 struct RastPort *temprp;
152 if (!(patternbm = AllocBitMap(PATTERNWIDTH * 2,
153 PATTERNHEIGHT * 2,
154 GetBitMapAttr(scr->RastPort.BitMap,BMA_DEPTH),
155 BMF_CLEAR,
156 scr->RastPort.BitMap)))
158 cleanup("Can't create pattern bitmap!");
161 if (!(temprp = CreateRastPort()))
163 cleanup("Can't create rastport!");
166 temprp->BitMap = patternbm;
168 SetAPen(temprp,dri->dri_Pens[PATTERNCOL1]);
170 RectFill(temprp,0,0,10,10);
172 RectFill(temprp,0,0,PATTERNWIDTH - 1,PATTERNHEIGHT - 1);
174 SetAPen(temprp,dri->dri_Pens[PATTERNCOL2]);
175 RectFill(temprp,0,
177 PATTERNWIDTH / 2 - 1,
178 PATTERNHEIGHT / 2 - 1);
180 RectFill(temprp,PATTERNWIDTH / 2,
181 PATTERNHEIGHT / 2,
182 PATTERNWIDTH - 1,
183 PATTERNHEIGHT - 1);
185 FreeRastPort(temprp);
188 static void makewin(void)
190 win = OpenWindowTags(0, WA_PubScreen, (IPTR)scr,
191 WA_Left, 20,
192 WA_Top, 20,
193 WA_Width, WINWIDTH,
194 WA_Height, WINHEIGHT,
195 WA_Title, (IPTR)"Parent",
196 WA_CloseGadget, TRUE,
197 WA_DragBar, TRUE,
198 WA_DepthGadget, TRUE,
199 WA_IDCMP, IDCMP_CLOSEWINDOW,
200 WA_Activate, TRUE,
201 WA_SimpleRefresh, TRUE,
202 WA_NoCareRefresh,TRUE,
203 WA_BackFill, (IPTR)&backfillhook,
204 WA_SizeGadget, TRUE,
205 WA_MinWidth,20,
206 WA_MinHeight,20,
207 WA_MaxWidth,1000,
208 WA_MaxHeight,1000,
209 TAG_DONE);
212 if (!win) cleanup("Can't create parent window!");
214 win2 = OpenWindowTags(0, WA_PubScreen, (IPTR)scr,
215 WA_Parent, (IPTR)win,
216 WA_Left, 20,
217 WA_Top, 20,
218 WA_Width, WINWIDTH * 2 / 3,
219 WA_Height, WINHEIGHT * 2 / 3,
220 WA_Title, (IPTR)"Child",
221 WA_DragBar, TRUE,
222 WA_DepthGadget, TRUE,
223 WA_SimpleRefresh, TRUE,
224 WA_NoCareRefresh,TRUE,
225 WA_MinWidth,20,
226 WA_MinHeight,20,
227 WA_MaxWidth,1000,
228 WA_MaxHeight,1000,
229 WA_SizeGadget,TRUE,
230 TAG_DONE);
233 if (!win2) cleanup("Can't create child window!");
235 win3 = OpenWindowTags(0, WA_PubScreen, (IPTR)scr,
236 WA_Parent, (IPTR)win2,
237 WA_Left, 20,
238 WA_Top, 20,
239 WA_Width, WINWIDTH / 2,
240 WA_Height, WINHEIGHT / 2,
241 WA_Title, (IPTR)"Grand Child",
242 WA_DragBar, TRUE,
243 WA_DepthGadget, TRUE,
244 WA_SimpleRefresh, TRUE,
245 WA_NoCareRefresh,TRUE,
246 WA_SizeGadget, TRUE,
247 WA_MinWidth,20,
248 WA_MinHeight,20,
249 WA_MaxWidth,1000,
250 WA_MaxHeight,1000,
251 WA_NoCareRefresh,TRUE,
252 TAG_DONE);
255 if (!win3) cleanup("Can't create grand child window!");
259 static void handleall(void)
261 WaitPort(win->UserPort);
264 int main(void)
266 openlibs();
267 getvisual();
268 MakePattern();
269 InitBackfillHook();
270 makewin();
271 handleall();
272 cleanup(0);
274 return 0;