2 Copyright © 2004, The AROS Development Team. All rights reserved.
9 /*********************************************************************************************/
13 #include <prefs/prefhdr.h>
14 #include <prefs/wbpattern.h>
15 #include <datatypes/pictureclass.h>
18 #include <aros/debug.h>
20 /*********************************************************************************************/
22 struct FileWBPatternPrefs
24 UBYTE wbp_Reserved
[4 * 4];
29 UBYTE wbp_DataLength
[2];
34 struct Layer
*lay
; /* not valid for layerinfo backfill hook!!! */
35 struct Rectangle bounds
;
42 struct BitMap
*pat_bm
;
47 /*********************************************************************************************/
49 static LONG stopchunks
[] =
54 /*********************************************************************************************/
56 static void RootPatternSetup(STRPTR filename
);
58 /*********************************************************************************************/
60 void WBPatternPrefs_Handler(STRPTR filename
)
62 struct IFFHandle
*iff
;
64 D(bug("In IPrefs:WBPatternPrefs_Handler\n"));
66 if ((iff
= CreateIFF(filename
, stopchunks
, 1)))
68 while(ParseIFF(iff
, IFFPARSE_SCAN
) == 0)
70 struct ContextNode
*cn
;
71 struct FileWBPatternPrefs wbpatternprefs
;
73 cn
= CurrentChunk(iff
);
75 D(bug("WBPatternPrefs_Handler: ParseIFF okay. Chunk Type = %c%c%c%c ChunkID = %c%c%c%c\n",
85 if ((cn
->cn_ID
== ID_PTRN
) && (cn
->cn_Size
> sizeof(wbpatternprefs
)))
87 D(bug("WBPatternPrefs_Handler: ID_FONT chunk with correct size found.\n"));
89 if (ReadChunkBytes(iff
, &wbpatternprefs
, sizeof(wbpatternprefs
)) == sizeof(wbpatternprefs
))
95 D(bug("WBPatternPrefs_Handler: Reading of ID_PTRN chunk okay.\n"));
97 type
= (wbpatternprefs
.wbp_Which
[0] << 8) + wbpatternprefs
.wbp_Which
[1];
98 len
= (wbpatternprefs
.wbp_DataLength
[0] << 8) + wbpatternprefs
.wbp_DataLength
[1];
100 D(bug("Type = %d Len = %d\n", type
, len
));
102 if (sizeof(wbpatternprefs
) + len
== cn
->cn_Size
)
104 filename
= (STRPTR
)AllocVec(len
+ 1, MEMF_ANY
);
105 if (filename
!= NULL
)
107 if (ReadChunkBytes(iff
, filename
, len
) == len
)
110 D(bug("Filename = %s\n", filename
));
114 RootPatternCleanup();
115 RootPatternSetup(filename
);
122 } /* if (ReadChunkBytes(iff, filename, len + 1) == len + 1) */
124 } /* if (filename != NULL) */
125 } /* if (sizeof(wbpatternprefs) + len + 1 == cn->cn_Size) */
126 } /* if (ReadChunkBytes(iff, &wbpatternprefs, sizeof(wbpatternprefs)) == sizeof(wbpatternprefs)) */
128 } /* if ((cn->cn_ID == ID_FONT) && (cn->cn_Size == sizeof(wbpatternprefs))) */
130 } /* while(ParseIFF(iff, IFFPARSE_SCAN) == 0) */
134 } /* if ((iff = CreateIFF(filename))) */
137 D(bug("In IPrefs:WBPatternPrefs_Handler. Done.\n", filename
));
140 /****************************************************************************************/
142 static void mybackfillfunc(struct Hook
*hook
,struct RastPort
*rp
, struct LayerHookMsg
*msg
)
144 struct LayerHookData
*data
= (struct LayerHookData
*)hook
->h_Data
;
145 WORD x1
,y1
,x2
,y2
,px
,py
,pw
,ph
;
147 x1
= msg
->bounds
.MinX
;
148 y1
= msg
->bounds
.MinY
;
149 x2
= msg
->bounds
.MaxX
;
150 y2
= msg
->bounds
.MaxY
;
152 px
= x1
% data
->pat_width
;
154 pw
= data
->pat_width
- px
;
158 y1
= msg
->bounds
.MinY
;
159 py
= y1
% data
->pat_height
;
161 ph
= data
->pat_height
- py
;
163 if (pw
> (x2
- x1
+ 1)) pw
= x2
- x1
+ 1;
167 if (ph
> (y2
- y1
+ 1)) ph
= y2
- y1
+ 1;
169 BltBitMap(data
->pat_bm
,
184 ph
= data
->pat_height
;
186 } while (y1
<= y2
); /* while(y1 < y2) */
191 pw
= data
->pat_width
;
193 } while (x1
<= x2
); /* while (x1 < x2) */
198 /****************************************************************************************/
200 static struct Hook
*installbackfillhook(struct Screen
*scr
, struct Hook
*backfillhook
,
201 struct LayerHookData
*data
)
203 struct Window
*tempwin
;
204 struct Hook
*oldhook
;
206 struct TagItem wintags
[] =
208 {WA_PubScreen
,(IPTR
)scr
},
211 {WA_Width
,scr
->Width
},
212 {WA_Height
,scr
->Height
},
213 {WA_Borderless
,TRUE
},
214 {WA_Backdrop
,TRUE
},
215 {WA_BackFill
,(IPTR
)LAYERS_NOBACKFILL
},
219 backfillhook
->h_Entry
= HookEntry
;
220 backfillhook
->h_SubEntry
= (HOOKFUNC
)mybackfillfunc
;
221 backfillhook
->h_Data
= data
;
223 oldhook
= InstallLayerInfoHook(&scr
->LayerInfo
, backfillhook
);
224 tempwin
= OpenWindowTagList(NULL
, wintags
);
225 if (tempwin
) CloseWindow(tempwin
);
229 /****************************************************************************************/
231 static void removebackfillhook(struct Screen
*scr
, struct Hook
*oldhook
)
233 struct TagItem wintags
[] =
235 { WA_PubScreen
, (IPTR
)scr
},
238 { WA_Width
, scr
->Width
},
239 { WA_Height
, scr
->Height
},
240 { WA_Borderless
, TRUE
},
241 { WA_Backdrop
, TRUE
},
242 { WA_BackFill
, (IPTR
)LAYERS_NOBACKFILL
},
245 struct Window
*tempwin
;
247 InstallLayerInfoHook(&scr
->LayerInfo
, oldhook
);
248 tempwin
= OpenWindowTagList(NULL
, wintags
);
249 if (tempwin
) CloseWindow(tempwin
);
252 /*********************************************************************************************/
254 static struct BitMap
*LoadDTBitmap (CONST_STRPTR filename
, struct Screen
*scr
,
255 Object
**obj
, ULONG
*width
, ULONG
*height
)
257 struct BitMapHeader
*bmhd
;
258 struct BitMap
*bitmap
= NULL
;
260 struct Process
*myproc
= (struct Process
*)FindTask(NULL
);
261 APTR oldwindowptr
= myproc
->pr_WindowPtr
;
263 myproc
->pr_WindowPtr
= (APTR
)-1;
265 o
= NewDTObject((APTR
)filename
,
266 DTA_GroupID
, GID_PICTURE
,
267 OBP_Precision
, PRECISION_EXACT
,
268 PDTA_Screen
, (IPTR
)scr
,
269 PDTA_FreeSourceBitMap
, TRUE
,
270 PDTA_DestMode
, PMODE_V43
,
271 PDTA_UseFriendBitMap
, TRUE
,
274 myproc
->pr_WindowPtr
= oldwindowptr
;
278 struct FrameInfo fri
= {0};
279 DoMethod(o
, DTM_FRAMEBOX
, (IPTR
) NULL
, (IPTR
) &fri
, (IPTR
) &fri
,
280 sizeof(struct FrameInfo
), 0);
282 if (fri
.fri_Dimensions
.Depth
> 0)
284 if (DoMethod(o
, DTM_PROCLAYOUT
, (IPTR
) NULL
, 1))
287 GetDTAttrs(o
, PDTA_BitMapHeader
, (IPTR
)&bmhd
, TAG_DONE
);
290 *width
= bmhd
->bmh_Width
;
291 *height
= bmhd
->bmh_Height
;
292 GetDTAttrs(o
, PDTA_DestBitMap
, (IPTR
)&bitmap
, TAG_DONE
);
294 GetDTAttrs(o
, PDTA_BitMap
, (IPTR
)&bitmap
, TAG_DONE
);
306 /*********************************************************************************************/
308 static Object
*myDTObject
= NULL
;
309 static struct Hook
*myOldHook
= (APTR
)-1; // NULL is a valid value
310 static struct Screen
*myScreen
= NULL
;
311 static struct LayerHookData myData
;
312 static struct Hook myBackFillHook
;
314 /*********************************************************************************************/
316 static void RootPatternSetup(STRPTR filename
)
318 struct BitMap
*patternbm
= NULL
;
322 if ((myScreen
= LockPubScreen(NULL
)) != NULL
)
324 D(bug("loading '%s'\n", filename
));
325 patternbm
= LoadDTBitmap(filename
, myScreen
, &myDTObject
, &w
, &h
);
329 myData
.pat_bm
= patternbm
;
330 myData
.pat_width
= w
;
331 myData
.pat_height
= h
;
333 myOldHook
= installbackfillhook(myScreen
, &myBackFillHook
, &myData
);
334 D(bug("oldhook=%p\n", myOldHook
));
339 /*********************************************************************************************/
341 void RootPatternCleanup (void)
343 if (myOldHook
!= (APTR
)-1)
345 D(bug("Reinstalling old backfillhook\n"));
346 removebackfillhook(myScreen
, myOldHook
);
347 myOldHook
= (APTR
)-1;
351 D(bug("Disposing DT obj\n"));
352 DisposeDTObject(myDTObject
);
357 D(bug("Unlock PubScreen\n"));
358 UnlockPubScreen(NULL
, myScreen
);