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
25 struct Layer
*lay
; /* not valid for layerinfo backfill hook!!! */
26 struct Rectangle bounds
;
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
;
52 printf("scrbackfill: %s\n",msg
);
58 if (win
) CloseWindow(win
);
62 InstallLayerInfoHook(&scr
->LayerInfo
,old_layerinfohook
);
64 tempwin
= OpenWindowTags(0,WA_PubScreen
,(IPTR
)scr
,
68 WA_Height
,scr
->Height
,
71 WA_BackFill
,(IPTR
)LAYERS_NOBACKFILL
,
74 if (tempwin
) CloseWindow(tempwin
);
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
);
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
;
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;
162 } while (y1
<= y2
); /* while(y1 < y2) */
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,
201 GetBitMapAttr(scr
->RastPort
.BitMap
,BMA_DEPTH
),
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
]);
224 PATTERNWIDTH
/ 2 - 1,
225 PATTERNHEIGHT
/ 2 - 1);
227 RectFill(temprp
,PATTERNWIDTH
/ 2,
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
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
,
257 WA_Height
,scr
->Height
,
260 WA_BackFill
,(IPTR
)LAYERS_NOBACKFILL
,
263 if (tempwin
) CloseWindow(tempwin
);
267 static void MakeWin(void)
269 if (!(win
= OpenWindowTags(0,WA_PubScreen
,(IPTR
)scr
,
273 WA_Height
,dri
->dri_Font
->tf_YSize
+ scr
->WBorTop
+ 1,
275 WA_Title
,(IPTR
)"Screen Backfill Test",
276 WA_SimpleRefresh
,TRUE
,
280 WA_IDCMP
,IDCMP_CLOSEWINDOW
| IDCMP_REFRESHWINDOW
,
283 Cleanup("Can't open window!");
286 ScreenToFront(win
->WScreen
);
290 static void HandleAll(void)
292 struct IntuiMessage
*msg
;
298 WaitPort(win
->UserPort
);
300 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
304 case IDCMP_CLOSEWINDOW
:
308 case IDCMP_REFRESHWINDOW
:
310 EndRefresh(win
,TRUE
);
314 ReplyMsg((struct Message
*)msg
);