Fix IRQ name
[AROS.git] / workbench / demos / winbackfill.c
blob95b6be8bc34c87659924589b2b0622a23343eb30
2 #include <dos/dos.h>
3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <utility/hooks.h>
7 #include <proto/exec.h>
8 #include <proto/intuition.h>
9 #include <proto/graphics.h>
10 #include <proto/layers.h>
12 #include <clib/alib_protos.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <stdlib.h>
18 #define PATTERNWIDTH 32
19 #define PATTERNHEIGHT 32
20 #define PATTERNCOL1 SHADOWPEN
21 #define PATTERNCOL2 SHINEPEN
23 struct LayerHookMsg
25 struct Layer *lay;
26 struct Rectangle bounds;
27 LONG offsetx;
28 LONG offsety;
31 struct IntuitionBase *IntuitionBase;
32 struct GfxBase *GfxBase;
33 struct Library *LayersBase;
35 static struct Screen *scr;
36 static struct Window *win;
37 static struct DrawInfo *dri;
38 static struct BitMap *patternbm;
40 static struct Hook backfillhook;
43 static void Cleanup(char *msg)
45 WORD rc;
47 if (msg)
49 printf("winbackfill: %s\n",msg);
50 rc = RETURN_WARN;
52 else
54 rc = RETURN_OK;
57 if (win) CloseWindow(win);
59 if (patternbm)
61 WaitBlit();
62 FreeBitMap(patternbm);
65 if (dri) FreeScreenDrawInfo(scr,dri);
66 UnlockPubScreen(0,scr);
68 if (LayersBase) CloseLibrary(LayersBase);
69 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
70 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
72 exit(rc);
76 static void OpenLibs(void)
78 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",39)))
80 Cleanup("Can't open intuition.library V39!");
83 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",39)))
85 Cleanup("Can't open graphics.library V39!");
88 if (!(LayersBase = OpenLibrary("layers.library",39)))
90 Cleanup("Can't open layers.library V39!");
95 static void MyBackfillFunc(struct Hook *hook,struct RastPort *rp,
96 struct LayerHookMsg *msg)
98 struct Layer *lay;
99 WORD x1,y1,x2,y2,px,py,pw,ph;
101 lay = msg->lay;
103 x1 = msg->bounds.MinX;
104 y1 = msg->bounds.MinY;
105 x2 = msg->bounds.MaxX;
106 y2 = msg->bounds.MaxY;
108 px = (x1 - lay->bounds.MinX) % PATTERNWIDTH;
110 pw = PATTERNWIDTH - px;
114 y1 = msg->bounds.MinY;
115 py = (y1 - lay->bounds.MinY) % PATTERNHEIGHT;
117 ph = PATTERNHEIGHT - py;
119 if (pw > (x2 - x1 + 1)) pw = x2 - x1 + 1;
123 if (ph > (y2 - y1 + 1)) ph = y2 - y1 + 1;
125 BltBitMap(patternbm,
128 rp->BitMap,
133 192,
134 255,
137 y1 += ph;
139 py = 0;
140 ph = PATTERNHEIGHT;
142 } while (y1 <= y2); /* while(y1 < y2) */
144 x1 += pw;
146 px = 0;
147 pw = PATTERNWIDTH;
149 } while (x1 <= x2); /* while (x1 < x2) */
153 static void InitBackfillHook(void)
155 backfillhook.h_Entry = HookEntry;
156 backfillhook.h_SubEntry = (HOOKFUNC)MyBackfillFunc;
160 static void GetVisual(void)
162 if (!(scr = LockPubScreen(0)))
164 Cleanup("Can't lock pub screen!");
167 if (!(dri = GetScreenDrawInfo(scr)))
169 Cleanup("Can't get drawinfo!");
174 static void MakePattern(void)
176 struct RastPort *temprp;
178 if (!(patternbm = AllocBitMap(PATTERNWIDTH * 2,
179 PATTERNHEIGHT * 2,
180 GetBitMapAttr(scr->RastPort.BitMap,BMA_DEPTH),
181 BMF_CLEAR,
182 scr->RastPort.BitMap)))
184 Cleanup("Can't create pattern bitmap!");
187 if (!(temprp = CreateRastPort()))
189 Cleanup("Can't create rastport!");
192 temprp->BitMap = patternbm;
194 SetAPen(temprp,dri->dri_Pens[PATTERNCOL1]);
196 RectFill(temprp,0,0,10,10);
198 RectFill(temprp,0,0,PATTERNWIDTH - 1,PATTERNHEIGHT - 1);
200 SetAPen(temprp,dri->dri_Pens[PATTERNCOL2]);
201 RectFill(temprp,0,
203 PATTERNWIDTH / 2 - 1,
204 PATTERNHEIGHT / 2 - 1);
206 RectFill(temprp,PATTERNWIDTH / 2,
207 PATTERNHEIGHT / 2,
208 PATTERNWIDTH - 1,
209 PATTERNHEIGHT - 1);
211 FreeRastPort(temprp);
215 static void MakeWin(void)
217 if (!(win = OpenWindowTags(0,WA_PubScreen,(IPTR)scr,
218 WA_Left,10,
219 WA_Top,10,
220 WA_Width,300,
221 WA_Height,150,
222 WA_Title,(IPTR)"Window Backfill Test",
223 WA_SimpleRefresh,TRUE,
224 WA_CloseGadget,TRUE,
225 WA_DepthGadget,TRUE,
226 WA_DragBar,TRUE,
227 WA_SizeGadget,TRUE,
228 WA_MinWidth,50,
229 WA_MinHeight,50,
230 WA_MaxWidth,scr->Width,
231 WA_MaxHeight,scr->Height,
232 WA_IDCMP,IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW,
233 WA_BackFill,(IPTR)&backfillhook,
234 TAG_DONE)))
236 Cleanup("Can't open window!");
239 ScreenToFront(win->WScreen);
244 static void HandleAll(void)
246 struct IntuiMessage *msg;
248 BOOL quitme = FALSE;
250 while (!quitme)
252 WaitPort(win->UserPort);
254 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
256 switch (msg->Class)
258 case IDCMP_CLOSEWINDOW:
259 quitme = TRUE;
260 break;
262 case IDCMP_REFRESHWINDOW:
263 BeginRefresh(win);
264 EndRefresh(win,TRUE);
265 break;
268 ReplyMsg((struct Message *)msg);
274 int main(void)
276 OpenLibs();
277 InitBackfillHook();
278 GetVisual();
279 MakePattern();
280 MakeWin();
281 HandleAll();
282 Cleanup(0);
284 return 0;