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>
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
25 struct Rectangle bounds
;
30 struct IntuitionBase
*IntuitionBase
;
31 struct GfxBase
*GfxBase
;
34 struct Window
*win
, *win2
, *win3
;
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
);
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
)
83 WORD x1
,y1
,x2
,y2
,px
,py
,pw
,ph
;
87 x1
= msg
->bounds
.MinX
;
88 y1
= msg
->bounds
.MinY
;
89 x2
= msg
->bounds
.MaxX
;
90 y2
= msg
->bounds
.MaxY
;
92 px
= (x1
- lay
->bounds
.MinX
) % PATTERNWIDTH
;
94 pw
= PATTERNWIDTH
- px
;
98 y1
= msg
->bounds
.MinY
;
99 py
= (y1
- lay
->bounds
.MinY
) % PATTERNHEIGHT
;
101 ph
= PATTERNHEIGHT
- py
;
103 if (pw
> (x2
- x1
+ 1)) pw
= x2
- x1
+ 1;
107 if (ph
> (y2
- y1
+ 1)) ph
= y2
- y1
+ 1;
126 } while (y1
<= y2
); /* while(y1 < y2) */
133 } while (x1
<= x2
); /* while (x1 < x2) */
137 static void InitBackfillHook(void)
139 backfillhook
.h_Entry
= HookEntry
;
140 backfillhook
.h_SubEntry
= (HOOKFUNC
)MyBackfillFunc
;
143 static struct RastPort temprp
;
145 static void MakePattern(void)
147 if (!(patternbm
= AllocBitMap(PATTERNWIDTH
* 2,
149 GetBitMapAttr(scr
->RastPort
.BitMap
,BMA_DEPTH
),
151 scr
->RastPort
.BitMap
)))
153 cleanup("Can't create pattern bitmap!");
156 InitRastPort(&temprp
);
158 temprp
.BitMap
= patternbm
;
160 SetAPen(&temprp
,dri
->dri_Pens
[PATTERNCOL1
]);
162 RectFill(&temprp
, 0, 0, 10, 10);
163 RectFill(&temprp
, 0, 0, PATTERNWIDTH
- 1, PATTERNHEIGHT
- 1);
165 SetAPen(&temprp
, dri
->dri_Pens
[PATTERNCOL2
]);
167 RectFill(&temprp
, 0, 0, PATTERNWIDTH
/ 2 - 1, PATTERNHEIGHT
/ 2 - 1);
168 RectFill(&temprp
, PATTERNWIDTH
/ 2, PATTERNHEIGHT
/ 2, PATTERNWIDTH
- 1, PATTERNHEIGHT
- 1);
171 static void makewin(void)
173 win
= OpenWindowTags(0, WA_PubScreen
, (IPTR
)scr
,
177 WA_Height
, WINHEIGHT
,
178 WA_Title
, (IPTR
)"Parent",
179 WA_CloseGadget
, TRUE
,
181 WA_DepthGadget
, TRUE
,
182 WA_IDCMP
, IDCMP_CLOSEWINDOW
,
184 WA_SimpleRefresh
, TRUE
,
185 WA_NoCareRefresh
,TRUE
,
186 WA_BackFill
, (IPTR
)&backfillhook
,
195 if (!win
) cleanup("Can't create parent window!");
197 win2
= OpenWindowTags(0, WA_PubScreen
, (IPTR
)scr
,
198 WA_Parent
, (IPTR
)win
,
201 WA_Width
, WINWIDTH
* 2 / 3,
202 WA_Height
, WINHEIGHT
* 2 / 3,
203 WA_Title
, (IPTR
)"Child",
205 WA_DepthGadget
, TRUE
,
206 WA_SimpleRefresh
, TRUE
,
207 WA_NoCareRefresh
,TRUE
,
216 if (!win2
) cleanup("Can't create child window!");
218 win3
= OpenWindowTags(0, WA_PubScreen
, (IPTR
)scr
,
219 WA_Parent
, (IPTR
)win2
,
222 WA_Width
, WINWIDTH
/ 2,
223 WA_Height
, WINHEIGHT
/ 2,
224 WA_Title
, (IPTR
)"Grand Child",
226 WA_DepthGadget
, TRUE
,
227 WA_SimpleRefresh
, TRUE
,
228 WA_NoCareRefresh
,TRUE
,
234 WA_NoCareRefresh
,TRUE
,
238 if (!win3
) cleanup("Can't create grand child window!");
242 static void handleall(void)
244 WaitPort(win
->UserPort
);