Use hardcoded settings for VIA VT1708S (they are reported to work
[AROS.git] / workbench / demos / childchild.c
blobd8e577c4cdc91812b9d5a74e5008c12633bd2738
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 Layer *lay;
83 WORD x1,y1,x2,y2,px,py,pw,ph;
85 lay = msg->lay;
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;
109 BltBitMap(patternbm,
112 rp->BitMap,
117 192,
118 255,
121 y1 += ph;
123 py = 0;
124 ph = PATTERNHEIGHT;
126 } while (y1 <= y2); /* while(y1 < y2) */
128 x1 += pw;
130 px = 0;
131 pw = PATTERNWIDTH;
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,
148 PATTERNHEIGHT * 2,
149 GetBitMapAttr(scr->RastPort.BitMap,BMA_DEPTH),
150 BMF_CLEAR,
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,
174 WA_Left, 20,
175 WA_Top, 20,
176 WA_Width, WINWIDTH,
177 WA_Height, WINHEIGHT,
178 WA_Title, (IPTR)"Parent",
179 WA_CloseGadget, TRUE,
180 WA_DragBar, TRUE,
181 WA_DepthGadget, TRUE,
182 WA_IDCMP, IDCMP_CLOSEWINDOW,
183 WA_Activate, TRUE,
184 WA_SimpleRefresh, TRUE,
185 WA_NoCareRefresh,TRUE,
186 WA_BackFill, (IPTR)&backfillhook,
187 WA_SizeGadget, TRUE,
188 WA_MinWidth,20,
189 WA_MinHeight,20,
190 WA_MaxWidth,1000,
191 WA_MaxHeight,1000,
192 TAG_DONE);
195 if (!win) cleanup("Can't create parent window!");
197 win2 = OpenWindowTags(0, WA_PubScreen, (IPTR)scr,
198 WA_Parent, (IPTR)win,
199 WA_Left, 20,
200 WA_Top, 20,
201 WA_Width, WINWIDTH * 2 / 3,
202 WA_Height, WINHEIGHT * 2 / 3,
203 WA_Title, (IPTR)"Child",
204 WA_DragBar, TRUE,
205 WA_DepthGadget, TRUE,
206 WA_SimpleRefresh, TRUE,
207 WA_NoCareRefresh,TRUE,
208 WA_MinWidth,20,
209 WA_MinHeight,20,
210 WA_MaxWidth,1000,
211 WA_MaxHeight,1000,
212 WA_SizeGadget,TRUE,
213 TAG_DONE);
216 if (!win2) cleanup("Can't create child window!");
218 win3 = OpenWindowTags(0, WA_PubScreen, (IPTR)scr,
219 WA_Parent, (IPTR)win2,
220 WA_Left, 20,
221 WA_Top, 20,
222 WA_Width, WINWIDTH / 2,
223 WA_Height, WINHEIGHT / 2,
224 WA_Title, (IPTR)"Grand Child",
225 WA_DragBar, TRUE,
226 WA_DepthGadget, TRUE,
227 WA_SimpleRefresh, TRUE,
228 WA_NoCareRefresh,TRUE,
229 WA_SizeGadget, TRUE,
230 WA_MinWidth,20,
231 WA_MinHeight,20,
232 WA_MaxWidth,1000,
233 WA_MaxHeight,1000,
234 WA_NoCareRefresh,TRUE,
235 TAG_DONE);
238 if (!win3) cleanup("Can't create grand child window!");
242 static void handleall(void)
244 WaitPort(win->UserPort);
247 int main(void)
249 openlibs();
250 getvisual();
251 MakePattern();
252 InitBackfillHook();
253 makewin();
254 handleall();
255 cleanup(0);
257 return 0;