Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / demos / scrbackfill.c
blob5b8bcaaa9fd570a66b1e6c3153eb2fd2ac2fd13c
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 struct RastPort myrp;
117 WORD x1,y1,x2,y2,px,py,pw,ph;
119 myrp = *rp;
121 myrp.Layer = 0;
123 x1 = msg->bounds.MinX;
124 y1 = msg->bounds.MinY;
125 x2 = msg->bounds.MaxX;
126 y2 = msg->bounds.MaxY;
128 px = x1 % PATTERNWIDTH;
130 pw = PATTERNWIDTH - px;
134 y1 = msg->bounds.MinY;
135 py = y1 % PATTERNHEIGHT;
137 ph = PATTERNHEIGHT - py;
139 if (pw > (x2 - x1 + 1)) pw = x2 - x1 + 1;
143 if (ph > (y2 - y1 + 1)) ph = y2 - y1 + 1;
145 BltBitMap(patternbm,
148 rp->BitMap,
153 192,
154 255,
157 y1 += ph;
159 py = 0;
160 ph = PATTERNHEIGHT;
162 } while (y1 <= y2); /* while(y1 < y2) */
164 x1 += pw;
166 px = 0;
167 pw = PATTERNWIDTH;
169 } while (x1 <= x2); /* while (x1 < x2) */
174 static void InitBackfillHook(void)
176 backfillhook.h_Entry = HookEntry;
177 backfillhook.h_SubEntry = (HOOKFUNC)MyBackfillFunc;
181 static void GetVisual(void)
183 if (!(scr = LockPubScreen(0)))
185 Cleanup("Can't lock pub screen!");
188 if (!(dri = GetScreenDrawInfo(scr)))
190 Cleanup("Can't get drawinfo!");
195 static void MakePattern(void)
197 struct RastPort *temprp;
199 if (!(patternbm = AllocBitMap(PATTERNWIDTH * 2,
200 PATTERNHEIGHT * 2,
201 GetBitMapAttr(scr->RastPort.BitMap,BMA_DEPTH),
202 BMF_CLEAR,
203 scr->RastPort.BitMap)))
205 Cleanup("Can't create pattern bitmap!");
208 if (!(temprp = CreateRastPort()))
210 Cleanup("Can't create rastport!");
213 temprp->BitMap = patternbm;
215 SetAPen(temprp,dri->dri_Pens[PATTERNCOL1]);
217 RectFill(temprp,0,0,10,10);
219 RectFill(temprp,0,0,PATTERNWIDTH - 1,PATTERNHEIGHT - 1);
221 SetAPen(temprp,dri->dri_Pens[PATTERNCOL2]);
222 RectFill(temprp,0,
224 PATTERNWIDTH / 2 - 1,
225 PATTERNHEIGHT / 2 - 1);
227 RectFill(temprp,PATTERNWIDTH / 2,
228 PATTERNHEIGHT / 2,
229 PATTERNWIDTH - 1,
230 PATTERNHEIGHT - 1);
232 FreeRastPort(temprp);
237 static void StartBackfillHook(void)
239 struct Window *tempwin;
241 old_layerinfohook = InstallLayerInfoHook(&scr->LayerInfo,&backfillhook);
243 hook_installed = TRUE;
245 /* The non-window area is not automatically backefilled with
246 the new hook, which is ok, since this is also true for the
247 real Amiga.
249 So we usa a little trick: We Open a backdrop window with the
250 size of the screen and close it immediately. Layers library will then
251 automatically backfill in DeleteLayer().*/
253 tempwin = OpenWindowTags(0,WA_PubScreen,(IPTR)scr,
254 WA_Left,0,
255 WA_Top,0,
256 WA_Width,scr->Width,
257 WA_Height,scr->Height,
258 WA_Borderless,TRUE,
259 WA_Backdrop,TRUE,
260 WA_BackFill,(IPTR)LAYERS_NOBACKFILL,
261 TAG_DONE);
263 if (tempwin) CloseWindow(tempwin);
267 static void MakeWin(void)
269 if (!(win = OpenWindowTags(0,WA_PubScreen,(IPTR)scr,
270 WA_Left,10,
271 WA_Top,10,
272 WA_Width,200,
273 WA_Height,dri->dri_Font->tf_YSize + scr->WBorTop + 1,
274 WA_AutoAdjust,TRUE,
275 WA_Title,(IPTR)"Screen Backfill Test",
276 WA_SimpleRefresh,TRUE,
277 WA_CloseGadget,TRUE,
278 WA_DepthGadget,TRUE,
279 WA_DragBar,TRUE,
280 WA_IDCMP,IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW,
281 TAG_DONE)))
283 Cleanup("Can't open window!");
286 ScreenToFront(win->WScreen);
290 static void HandleAll(void)
292 struct IntuiMessage *msg;
294 BOOL quitme = FALSE;
296 while (!quitme)
298 WaitPort(win->UserPort);
300 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
302 switch (msg->Class)
304 case IDCMP_CLOSEWINDOW:
305 quitme = TRUE;
306 break;
308 case IDCMP_REFRESHWINDOW:
309 BeginRefresh(win);
310 EndRefresh(win,TRUE);
311 break;
314 ReplyMsg((struct Message *)msg);
320 int main(void)
322 OpenLibs();
323 InitBackfillHook();
324 GetVisual();
325 MakePattern();
326 StartBackfillHook();
327 MakeWin();
328 HandleAll();
329 Cleanup(0);
331 return 0;