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 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;
157 } while (y1
<= y2
); /* while(y1 < y2) */
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!");
189 static struct RastPort temprp
;
191 static void MakePattern(void)
193 if (!(patternbm
= AllocBitMap(PATTERNWIDTH
* 2,
195 GetBitMapAttr(scr
->RastPort
.BitMap
,BMA_DEPTH
),
197 scr
->RastPort
.BitMap
)))
199 Cleanup("Can't create pattern bitmap!");
202 InitRastPort(&temprp
);
203 temprp
.BitMap
= patternbm
;
205 SetAPen(&temprp
, dri
->dri_Pens
[PATTERNCOL1
]);
207 RectFill(&temprp
, 0, 0, 10, 10);
208 RectFill(&temprp
, 0, 0, PATTERNWIDTH
- 1, PATTERNHEIGHT
- 1);
210 SetAPen(&temprp
, dri
->dri_Pens
[PATTERNCOL2
]);
211 RectFill(&temprp
, 0, 0, PATTERNWIDTH
/ 2 - 1, PATTERNHEIGHT
/ 2 - 1);
212 RectFill(&temprp
, PATTERNWIDTH
/ 2, PATTERNHEIGHT
/ 2, PATTERNWIDTH
- 1, PATTERNHEIGHT
- 1);
216 static void StartBackfillHook(void)
218 struct Window
*tempwin
;
220 old_layerinfohook
= InstallLayerInfoHook(&scr
->LayerInfo
,&backfillhook
);
222 hook_installed
= TRUE
;
224 /* The non-window area is not automatically backefilled with
225 the new hook, which is ok, since this is also true for the
228 So we usa a little trick: We Open a backdrop window with the
229 size of the screen and close it immediately. Layers library will then
230 automatically backfill in DeleteLayer().*/
232 tempwin
= OpenWindowTags(0,WA_PubScreen
,(IPTR
)scr
,
236 WA_Height
,scr
->Height
,
239 WA_BackFill
,(IPTR
)LAYERS_NOBACKFILL
,
242 if (tempwin
) CloseWindow(tempwin
);
246 static void MakeWin(void)
248 if (!(win
= OpenWindowTags(0,WA_PubScreen
,(IPTR
)scr
,
252 WA_Height
,dri
->dri_Font
->tf_YSize
+ scr
->WBorTop
+ 1,
254 WA_Title
,(IPTR
)"Screen Backfill Test",
255 WA_SimpleRefresh
,TRUE
,
259 WA_IDCMP
,IDCMP_CLOSEWINDOW
| IDCMP_REFRESHWINDOW
,
262 Cleanup("Can't open window!");
265 ScreenToFront(win
->WScreen
);
269 static void HandleAll(void)
271 struct IntuiMessage
*msg
;
277 WaitPort(win
->UserPort
);
279 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
283 case IDCMP_CLOSEWINDOW
:
287 case IDCMP_REFRESHWINDOW
:
289 EndRefresh(win
,TRUE
);
293 ReplyMsg((struct Message
*)msg
);