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>
18 #define PATTERNWIDTH 32
19 #define PATTERNHEIGHT 32
20 #define PATTERNCOL1 SHADOWPEN
21 #define PATTERNCOL2 SHINEPEN
26 struct Rectangle bounds
;
31 extern ULONG
HookEntry();
33 struct IntuitionBase
*IntuitionBase
;
34 struct GfxBase
*GfxBase
;
35 struct Library
*LayersBase
;
37 static struct Screen
*scr
;
38 static struct Window
*win
;
39 static struct DrawInfo
*dri
;
40 static struct BitMap
*patternbm
;
42 static struct Hook backfillhook
;
45 static void Cleanup(char *msg
)
51 printf("winbackfill: %s\n",msg
);
59 if (win
) CloseWindow(win
);
64 FreeBitMap(patternbm
);
67 if (dri
) FreeScreenDrawInfo(scr
,dri
);
68 UnlockPubScreen(0,scr
);
70 if (LayersBase
) CloseLibrary(LayersBase
);
71 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
72 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
78 static void OpenLibs(void)
80 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library",39)))
82 Cleanup("Can't open intuition.library V39!");
85 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library",39)))
87 Cleanup("Can't open graphics.library V39!");
90 if (!(LayersBase
= OpenLibrary("layers.library",39)))
92 Cleanup("Can't open layers.library V39!");
97 static void MyBackfillFunc(struct Hook
*hook
,struct RastPort
*rp
,
98 struct LayerHookMsg
*msg
)
100 struct RastPort myrp
;
102 WORD x1
,y1
,x2
,y2
,px
,py
,pw
,ph
;
109 x1
= msg
->bounds
.MinX
;
110 y1
= msg
->bounds
.MinY
;
111 x2
= msg
->bounds
.MaxX
;
112 y2
= msg
->bounds
.MaxY
;
114 px
= (x1
- lay
->bounds
.MinX
) % PATTERNWIDTH
;
116 pw
= PATTERNWIDTH
- px
;
120 y1
= msg
->bounds
.MinY
;
121 py
= (y1
- lay
->bounds
.MinY
) % PATTERNHEIGHT
;
123 ph
= PATTERNHEIGHT
- py
;
125 if (pw
> (x2
- x1
+ 1)) pw
= x2
- x1
+ 1;
129 if (ph
> (y2
- y1
+ 1)) ph
= y2
- y1
+ 1;
148 } while (y1
<= y2
); /* while(y1 < y2) */
155 } while (x1
<= x2
); /* while (x1 < x2) */
159 static void InitBackfillHook(void)
161 backfillhook
.h_Entry
= HookEntry
;
162 backfillhook
.h_SubEntry
= (HOOKFUNC
)MyBackfillFunc
;
166 static void GetVisual(void)
168 if (!(scr
= LockPubScreen(0)))
170 Cleanup("Can't lock pub screen!");
173 if (!(dri
= GetScreenDrawInfo(scr
)))
175 Cleanup("Can't get drawinfo!");
180 static void MakePattern(void)
182 struct RastPort
*temprp
;
184 if (!(patternbm
= AllocBitMap(PATTERNWIDTH
* 2,
186 GetBitMapAttr(scr
->RastPort
.BitMap
,BMA_DEPTH
),
188 scr
->RastPort
.BitMap
)))
190 Cleanup("Can't create pattern bitmap!");
193 if (!(temprp
= CreateRastPort()))
195 Cleanup("Can't create rastport!");
198 temprp
->BitMap
= patternbm
;
200 SetAPen(temprp
,dri
->dri_Pens
[PATTERNCOL1
]);
202 RectFill(temprp
,0,0,10,10);
204 RectFill(temprp
,0,0,PATTERNWIDTH
- 1,PATTERNHEIGHT
- 1);
206 SetAPen(temprp
,dri
->dri_Pens
[PATTERNCOL2
]);
209 PATTERNWIDTH
/ 2 - 1,
210 PATTERNHEIGHT
/ 2 - 1);
212 RectFill(temprp
,PATTERNWIDTH
/ 2,
217 FreeRastPort(temprp
);
221 static void MakeWin(void)
223 if (!(win
= OpenWindowTags(0,WA_PubScreen
,(IPTR
)scr
,
228 WA_Title
,(IPTR
)"Window Backfill Test",
229 WA_SimpleRefresh
,TRUE
,
236 WA_MaxWidth
,scr
->Width
,
237 WA_MaxHeight
,scr
->Height
,
238 WA_IDCMP
,IDCMP_CLOSEWINDOW
| IDCMP_REFRESHWINDOW
,
239 WA_BackFill
,(IPTR
)&backfillhook
,
242 Cleanup("Can't open window!");
245 ScreenToFront(win
->WScreen
);
250 static void HandleAll(void)
252 struct IntuiMessage
*msg
;
258 WaitPort(win
->UserPort
);
260 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
264 case IDCMP_CLOSEWINDOW
:
268 case IDCMP_REFRESHWINDOW
:
270 EndRefresh(win
,TRUE
);
274 ReplyMsg((struct Message
*)msg
);