Fix IRQ name
[AROS.git] / workbench / demos / scrbackfill.c
blob2487839bc71575e53e5b338fef69e67fdd3ad8a9
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 <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; /* not valid for layerinfo backfill hook!!! */
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, *old_layerinfohook;
41 static BOOL hook_installed;
44 static void Cleanup(char *msg)
46 struct Window *tempwin;
48 WORD rc;
50 if (msg)
52 printf("scrbackfill: %s\n",msg);
53 rc = RETURN_WARN;
54 } else {
55 rc = RETURN_OK;
58 if (win) CloseWindow(win);
60 if (hook_installed)
62 InstallLayerInfoHook(&scr->LayerInfo,old_layerinfohook);
64 tempwin = OpenWindowTags(0,WA_PubScreen,(IPTR)scr,
65 WA_Left,0,
66 WA_Top,0,
67 WA_Width,scr->Width,
68 WA_Height,scr->Height,
69 WA_Borderless,TRUE,
70 WA_Backdrop,TRUE,
71 WA_BackFill,(IPTR)LAYERS_NOBACKFILL,
72 TAG_DONE);
74 if (tempwin) CloseWindow(tempwin);
77 if (patternbm)
79 WaitBlit();
80 FreeBitMap(patternbm);
83 if (dri) FreeScreenDrawInfo(scr,dri);
84 UnlockPubScreen(0,scr);
86 if (LayersBase) CloseLibrary(LayersBase);
87 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
88 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
90 exit(rc);
94 static void OpenLibs(void)
96 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",39)))
98 Cleanup("Can't open intuition.library V39!");
101 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",39)))
103 Cleanup("Can't open graphics.library V39!");
106 if (!(LayersBase = OpenLibrary("layers.library",39)))
108 Cleanup("Can't open layers.library V39!");
113 static void MyBackfillFunc(struct Hook *hook,struct RastPort *rp,
114 struct LayerHookMsg *msg)
116 WORD x1,y1,x2,y2,px,py,pw,ph;
118 x1 = msg->bounds.MinX;
119 y1 = msg->bounds.MinY;
120 x2 = msg->bounds.MaxX;
121 y2 = msg->bounds.MaxY;
123 px = x1 % PATTERNWIDTH;
125 pw = PATTERNWIDTH - px;
129 y1 = msg->bounds.MinY;
130 py = y1 % PATTERNHEIGHT;
132 ph = PATTERNHEIGHT - py;
134 if (pw > (x2 - x1 + 1)) pw = x2 - x1 + 1;
138 if (ph > (y2 - y1 + 1)) ph = y2 - y1 + 1;
140 BltBitMap(patternbm,
143 rp->BitMap,
148 192,
149 255,
152 y1 += ph;
154 py = 0;
155 ph = PATTERNHEIGHT;
157 } while (y1 <= y2); /* while(y1 < y2) */
159 x1 += pw;
161 px = 0;
162 pw = PATTERNWIDTH;
164 } while (x1 <= x2); /* while (x1 < x2) */
169 static void InitBackfillHook(void)
171 backfillhook.h_Entry = HookEntry;
172 backfillhook.h_SubEntry = (HOOKFUNC)MyBackfillFunc;
176 static void GetVisual(void)
178 if (!(scr = LockPubScreen(0)))
180 Cleanup("Can't lock pub screen!");
183 if (!(dri = GetScreenDrawInfo(scr)))
185 Cleanup("Can't get drawinfo!");
190 static void MakePattern(void)
192 struct RastPort *temprp;
194 if (!(patternbm = AllocBitMap(PATTERNWIDTH * 2,
195 PATTERNHEIGHT * 2,
196 GetBitMapAttr(scr->RastPort.BitMap,BMA_DEPTH),
197 BMF_CLEAR,
198 scr->RastPort.BitMap)))
200 Cleanup("Can't create pattern bitmap!");
203 if (!(temprp = CreateRastPort()))
205 Cleanup("Can't create rastport!");
208 temprp->BitMap = patternbm;
210 SetAPen(temprp,dri->dri_Pens[PATTERNCOL1]);
212 RectFill(temprp,0,0,10,10);
214 RectFill(temprp,0,0,PATTERNWIDTH - 1,PATTERNHEIGHT - 1);
216 SetAPen(temprp,dri->dri_Pens[PATTERNCOL2]);
217 RectFill(temprp,0,
219 PATTERNWIDTH / 2 - 1,
220 PATTERNHEIGHT / 2 - 1);
222 RectFill(temprp,PATTERNWIDTH / 2,
223 PATTERNHEIGHT / 2,
224 PATTERNWIDTH - 1,
225 PATTERNHEIGHT - 1);
227 FreeRastPort(temprp);
232 static void StartBackfillHook(void)
234 struct Window *tempwin;
236 old_layerinfohook = InstallLayerInfoHook(&scr->LayerInfo,&backfillhook);
238 hook_installed = TRUE;
240 /* The non-window area is not automatically backefilled with
241 the new hook, which is ok, since this is also true for the
242 real Amiga.
244 So we usa a little trick: We Open a backdrop window with the
245 size of the screen and close it immediately. Layers library will then
246 automatically backfill in DeleteLayer().*/
248 tempwin = OpenWindowTags(0,WA_PubScreen,(IPTR)scr,
249 WA_Left,0,
250 WA_Top,0,
251 WA_Width,scr->Width,
252 WA_Height,scr->Height,
253 WA_Borderless,TRUE,
254 WA_Backdrop,TRUE,
255 WA_BackFill,(IPTR)LAYERS_NOBACKFILL,
256 TAG_DONE);
258 if (tempwin) CloseWindow(tempwin);
262 static void MakeWin(void)
264 if (!(win = OpenWindowTags(0,WA_PubScreen,(IPTR)scr,
265 WA_Left,10,
266 WA_Top,10,
267 WA_Width,200,
268 WA_Height,dri->dri_Font->tf_YSize + scr->WBorTop + 1,
269 WA_AutoAdjust,TRUE,
270 WA_Title,(IPTR)"Screen Backfill Test",
271 WA_SimpleRefresh,TRUE,
272 WA_CloseGadget,TRUE,
273 WA_DepthGadget,TRUE,
274 WA_DragBar,TRUE,
275 WA_IDCMP,IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW,
276 TAG_DONE)))
278 Cleanup("Can't open window!");
281 ScreenToFront(win->WScreen);
285 static void HandleAll(void)
287 struct IntuiMessage *msg;
289 BOOL quitme = FALSE;
291 while (!quitme)
293 WaitPort(win->UserPort);
295 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
297 switch (msg->Class)
299 case IDCMP_CLOSEWINDOW:
300 quitme = TRUE;
301 break;
303 case IDCMP_REFRESHWINDOW:
304 BeginRefresh(win);
305 EndRefresh(win,TRUE);
306 break;
309 ReplyMsg((struct Message *)msg);
315 int main(void)
317 OpenLibs();
318 InitBackfillHook();
319 GetVisual();
320 MakePattern();
321 StartBackfillHook();
322 MakeWin();
323 HandleAll();
324 Cleanup(0);
326 return 0;