2 Copyright 2004-2008, The AROS Development Team. All rights reserved.
6 #include "portable_macros.h"
9 #define MUIMASTER_YES_INLINE_STDARG
12 #define WANDERER_MODULE_BACKFILL_ENABLED
16 #include <aros/debug.h>
19 #include <exec/types.h>
20 #include <libraries/mui.h>
23 #include <zune/customclasses.h>
25 #include <zune_AROS/customclasses.h>
29 #include <proto/utility.h>
31 #include <proto/graphics.h>
33 #include <proto/exec.h>
34 #include <proto/datatypes.h>
37 #include <proto/dos.h>
42 #include <intuition/screens.h>
43 #include <datatypes/pictureclass.h>
44 #include <clib/macros.h>
47 #include <clib/alib_protos.h>
50 #include <graphics/scale.h>
53 #include <prefs/wanderer.h>
55 #include <prefs_AROS/wanderer.h>
58 #if defined(__AMIGA__) && !defined(__PPC__)
59 #define NO_INLINE_STDARG
61 #ifndef _PROTO_INTUITION_H
62 #include <proto/intuition.h>
64 #include <proto/muimaster.h>
67 #include "wandererprefs.h"
68 #include "iconwindow.h"
69 #include "iconwindow_iconlist.h"
70 #include "iconwindowbackfill.h"
71 #include "Classes/iconlistview.h"
72 #include "Classes/iconlist_attributes.h"
79 #define D(x) if (DEBUG) x
81 #define bug DebugPrintF
90 /*** Global Data **********************************************************/
92 static struct IconWindow_BackFill_Descriptor image_backfill_descriptor
;
93 static char image_backfill_name
[] = "Default Image BackFill\0";
94 static struct List image_backfill_images
;
96 /*** Internal functions *********************************************************/
98 ///ImageBackFill_FindSourceRecord()
99 static struct BackFillSourceImageRecord
*ImageBackFill_FindSourceRecord(char *source_name
, IPTR source_mode
)
101 struct BackFillSourceImageRecord
*source_record
= NULL
;
103 ForeachNode(&image_backfill_images
, source_record
)
105 Foreach_Node(&image_backfill_images
, source_record
);
108 if ((strcmp(source_record
->bfsir_SourceImage
, source_name
)==0) && (source_record
->bfsir_BackGroundRenderMode
== source_mode
)) return source_record
;
114 ///ImageBackFill_FindBufferRecord()
115 static struct BackFillSourceImageBuffer
*ImageBackFill_FindBufferRecord(struct BackFillSourceImageRecord
*source_record
, WORD buffer_width
, WORD buffer_height
)
117 struct BackFillSourceImageBuffer
*buffer_record
= NULL
;
120 ForeachNode(&source_record
->bfsir_Buffers
, buffer_record
)
122 Foreach_Node(&source_record
->bfsir_Buffers
, buffer_record
);
125 if ((buffer_record
->bfsib_BitMapWidth
== buffer_width
) && (buffer_record
->bfsib_BitMapHeight
== buffer_height
)) return buffer_record
;
131 ///ImageBackFill_CloseSourceRecord()
132 static void ImageBackFill_CloseSourceRecord(struct BackFillSourceImageRecord
*this_Record
)
134 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CloseSourceRecord()\n"));
135 if (this_Record
->bfsir_OpenerCount
>= 2)
137 this_Record
->bfsir_OpenerCount
-= 1;
138 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CloseSourceRecord: %d Openers Remaining for '%s'\n", this_Record
->bfsir_OpenerCount
, this_Record
->bfsir_SourceImage
));
143 Remove((struct Node
*)this_Record
);
144 this_Record
->bfsir_OpenerCount
= 0;
146 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CloseSourceRecord: Closing Record for '%s'\n", this_Record
->bfsir_SourceImage
));
148 this_Record
->bfsir_DTRastPort
->BitMap
= NULL
;
149 FreeRastPort(this_Record
->bfsir_DTRastPort
);
150 DisposeDTObject(this_Record
->bfsir_DTPictureObject
);
151 FreeVec(this_Record
->bfsir_SourceImage
);
152 FreeMem(this_Record
, sizeof(struct BackFillSourceImageRecord
));
157 ///ImageBackFill_CloseSourceBuffer()
158 static void ImageBackFill_CloseSourceBuffer(struct BackFillSourceImageRecord
*this_Record
, struct BackFillSourceImageBuffer
*this_Buffer
)
160 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CloseSourceBuffer()\n"));
161 if (this_Buffer
->bfsib_OpenerCount
>= 2)
163 this_Buffer
->bfsib_OpenerCount
-= 1;
164 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CloseSourceBuffer: %d Openers Remaining\n", this_Buffer
->bfsib_OpenerCount
));
169 Remove((struct Node
*)this_Buffer
);
170 this_Buffer
->bfsib_OpenerCount
= 0;
171 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CloseSourceBuffer: Closing Buffer [%d x %d] of '%s'\n", this_Buffer
->bfsib_BitMapWidth
, this_Buffer
->bfsib_BitMapHeight
, this_Record
->bfsir_SourceImage
));
173 this_Buffer
->bfsib_BitMapRastPort
->BitMap
= NULL
;
174 FreeRastPort(this_Buffer
->bfsib_BitMapRastPort
);
175 FreeBitMap(this_Buffer
->bfsib_BitMap
);
176 FreeMem(this_Buffer
, sizeof(struct BackFillSourceImageBuffer
));
181 ///ImageBackFill_CopyScaledBitMap()
182 static void ImageBackFill_CopyScaledBitMap
184 struct RastPort
*SrcRast
,
185 WORD SrcOffsetX
, WORD SrcOffsetY
,
186 WORD SrcSizeX
, WORD SrcSizeY
,
187 struct RastPort
*DstRast
,
188 struct Rectangle
*DstAreaBounds
,
189 struct Rectangle
*DstFillBounds
,
193 struct BitScaleArgs Scale_Args
;
194 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyScaledBitMap()\n"));
196 Scale_Args
.bsa_SrcX
= SrcOffsetX
;
197 Scale_Args
.bsa_SrcY
= SrcOffsetY
;
198 Scale_Args
.bsa_SrcWidth
= SrcSizeX
;
199 Scale_Args
.bsa_SrcHeight
= SrcSizeY
;
200 Scale_Args
.bsa_XSrcFactor
= SrcSizeX
;
201 Scale_Args
.bsa_YSrcFactor
= SrcSizeY
;
202 Scale_Args
.bsa_DestX
= DstFillBounds
->MinX
;
203 Scale_Args
.bsa_DestY
= DstFillBounds
->MinY
;
204 Scale_Args
.bsa_XDestFactor
= (DstFillBounds
->MaxX
- DstFillBounds
->MinX
) + 1;
205 Scale_Args
.bsa_YDestFactor
= (DstFillBounds
->MaxY
- DstFillBounds
->MinY
) + 1;
207 Scale_Args
.bsa_SrcBitMap
= SrcRast
->BitMap
;
208 Scale_Args
.bsa_DestBitMap
= DstRast
->BitMap
;
210 BitMapScale(&Scale_Args
);
214 ///ImageBackFill_CopyTiledBitMap()
215 static void ImageBackFill_CopyTiledBitMap
217 struct RastPort
*SrcRast
,
218 WORD SrcOffsetX
, WORD SrcOffsetY
,
219 WORD SrcSizeX
, WORD SrcSizeY
,
220 struct RastPort
*DstRast
,
221 struct Rectangle
*DstAreaBounds
,
222 struct Rectangle
*DstFillBounds
,
227 WORD FirstSizeX
; // the width of the rectangle to blit as the first column
228 WORD FirstSizeY
; // the height of the rectangle to blit as the first row
229 WORD SecondMinX
; // the left edge of the second column
230 WORD SecondMinY
; // the top edge of the second column
231 WORD SecondSizeX
; // the width of the second column
232 WORD SecondSizeY
; // the height of the second column
233 WORD PosX
, PosY
; // used as starting position in the "exponential" blit
234 WORD SizeX
, SizeY
; // used as bitmap size in the "exponential" blit
235 WORD SrcX
, SrcY
; // used as bitmap size in the "exponential" blit
237 struct BitMap
*Src
= SrcRast
->BitMap
;
238 struct BitMap
*Dst
= DstRast
->BitMap
;
246 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap(mode %d)\n", blit_MODE
));
248 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: SrcRast @ %x, DstRast @ %x\n", SrcRast
, DstRast
));
250 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: AreaBounds @ %x, FillBounds @ %x\n", DstAreaBounds
, DstFillBounds
));
252 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: AreaBounds.MinX %d\n", DstAreaBounds
->MinX
));
253 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: AreaBounds.MinY %d\n", DstAreaBounds
->MinY
));
254 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: AreaBounds.MaxX %d\n", DstAreaBounds
->MaxX
));
255 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: AreaBounds.MaxY %d\n", DstAreaBounds
->MaxY
));
256 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: AreaBounds Width %d Height %d\n", (DstAreaBounds
->MaxX
- DstAreaBounds
->MinX
) + 1, (DstAreaBounds
->MaxY
- DstAreaBounds
->MinY
) + 1));
258 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: FillBounds.MinX %d\n", DstFillBounds
->MinX
));
259 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: FillBounds.MinY %d\n", DstFillBounds
->MinY
));
260 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: FillBounds.MaxX %d\n", DstFillBounds
->MaxX
));
261 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: FillBounds.MaxY %d\n", DstFillBounds
->MaxY
));
262 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: FillBounds Width %d Height %d\n", (DstAreaBounds
->MaxX
- DstAreaBounds
->MinX
) + 1, (DstAreaBounds
->MaxY
- DstAreaBounds
->MinY
) + 1));
264 FirstSizeX
= MIN(SrcSizeX
- SrcOffsetX
, RECTSIZEX(DstFillBounds
)); // the width of the first tile, this is either the rest of the tile right to SrcOffsetX or the width of the dest rect, if the rect is narrow
265 SecondMinX
= DstFillBounds
->MinX
+ FirstSizeX
; // the start for the second tile (if used)
266 SecondSizeX
= MIN(SrcOffsetX
, DstFillBounds
->MaxX
-SecondMinX
+ 1); // the width of the second tile (we want the whole tile to be SrcSizeX pixels wide, if we use SrcSizeX-SrcOffsetX pixels for the left part we'll use SrcOffsetX for the right part)
268 FirstSizeY
= MIN(SrcSizeY
- SrcOffsetY
, RECTSIZEY(DstFillBounds
)); // the same values are calculated for y direction
269 SecondMinY
= DstFillBounds
->MinY
+ FirstSizeY
;
270 SecondSizeY
= MIN(SrcOffsetY
, DstFillBounds
->MaxY
- SecondMinY
+ 1);
272 if (blit_MODE
== blit_MODE_Blit
) // blit the first piece of the tile
274 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: 1st Tile Part @ %d,%d [%d x %d]\n", DstFillBounds
->MinX
, DstFillBounds
->MinY
, FirstSizeX
, FirstSizeY
));
276 SrcOffsetX
, SrcOffsetY
,
278 DstFillBounds
->MinX
, DstFillBounds
->MinY
,
279 FirstSizeX
, FirstSizeY
,
283 if (SecondSizeX
> 0) // if SrcOffset was 0 or the dest rect was too narrow, we won't need a second column
285 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: 2nd Tile Part @ %d,%d [%d x %d]\n", SecondMinX
, DstFillBounds
->MinY
, SecondSizeX
, FirstSizeY
));
289 SecondMinX
, DstFillBounds
->MinY
,
290 SecondSizeX
, FirstSizeY
,
294 if (SecondSizeY
> 0) // is a second row necessary?
296 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: 3rd Tile Part @ %d,%d [%d x %d]\n", DstFillBounds
->MinX
, SecondMinY
, FirstSizeX
, SecondSizeY
));
300 DstFillBounds
->MinX
, SecondMinY
,
301 FirstSizeX
, SecondSizeY
,
306 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: 4th Tile Part @ %d,%d [%d x %d]\n", SecondMinX
, SecondMinY
, SecondSizeX
, SecondSizeY
));
310 SecondMinX
, SecondMinY
,
311 SecondSizeX
, SecondSizeY
,
319 //Generates the first row of the tiles ....
320 for (PosX
= DstFillBounds
->MinX
+ SrcSizeX
, SizeX
= MIN(SrcSizeX
, (DstFillBounds
->MaxX
- PosX
) + 1);PosX
<= DstFillBounds
->MaxX
;)
323 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: Row 1 Tile %d @ %d,%d [%d x %d]\n", xcount
, PosX
, DstFillBounds
->MinY
, SizeX
, MIN(SrcSizeY
, RECTSIZEY(DstFillBounds
))));
327 DstFillBounds
->MinX
, DstFillBounds
->MinY
,
329 PosX
, DstFillBounds
->MinY
,
330 SizeX
, MIN(SrcSizeY
, RECTSIZEY(DstFillBounds
)),
334 SizeX
= MIN(SrcSizeX
, (DstFillBounds
->MaxX
- PosX
) + 1);
340 // .. now Blit the first row down several times to fill the whole dest rect
341 for (PosY
= DstFillBounds
->MinY
+ SrcSizeY
, SizeY
= MIN(SrcSizeY
, (DstFillBounds
->MaxY
- PosY
) + 1);PosY
<= DstFillBounds
->MaxY
;)
344 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: Row %d @ %d,%d [%d x %d]\n", ycount
, DstFillBounds
->MinX
, PosY
, MIN(SrcSizeX
, RECTSIZEX(DstFillBounds
)), SizeY
));
348 DstFillBounds
->MinX
, DstFillBounds
->MinY
,
350 DstFillBounds
->MinX
, PosY
,
351 MIN(SrcSizeX
, RECTSIZEX(DstFillBounds
)), SizeY
,
355 SizeY
= MIN(SrcSizeY
, (DstFillBounds
->MaxY
- PosY
) + 1);
358 else if (blit_MODE
== blit_MODE_Clip
)
360 for (SrcY
= MOD(SrcOffsetY
+ MOD((DstFillBounds
->MinY
- DstAreaBounds
->MinY
), SrcSizeY
- 1), SrcSizeY
- 1), PosY
= DstFillBounds
->MinY
, SizeY
= MIN((SrcSizeY
- SrcY
), (DstFillBounds
->MaxY
- DstFillBounds
->MinY
) + 1); PosY
<= DstFillBounds
->MaxY
;)
362 for (SrcX
= MOD(SrcOffsetX
+ MOD((DstFillBounds
->MinX
- DstAreaBounds
->MinX
), SrcSizeY
- 1), SrcSizeX
- 1), PosX
= DstFillBounds
->MinX
, SizeX
= MIN((SrcSizeX
- SrcX
), (DstFillBounds
->MaxX
- DstFillBounds
->MinX
) + 1); PosX
<= DstFillBounds
->MaxX
;)
364 D(bug("[IconWindow.ImageBackFill] ImageBackFill_CopyTiledBitMap: ClipBlit @ %d,%d [%d x %d]\n", PosX
, PosY
, SizeX
, SizeY
));
373 if (SrcX
!= 0) SrcX
= 0;
376 SizeX
= MIN(SrcSizeX
, (DstFillBounds
->MaxX
- PosX
) + 1);
379 if (SrcY
!= 0) SrcY
= 0;
382 SizeY
= MIN(SrcSizeY
, (DstFillBounds
->MaxY
- PosY
) + 1);
388 /*** Methods ****************************************************************/
389 ///ImageBackFill__MUIM_IconWindow_BackFill_ProcessBackground()
390 IPTR ImageBackFill__MUIM_IconWindow_BackFill_ProcessBackground
392 Class
*CLASS
, Object
*self
, struct MUIP_IconWindow_BackFill_ProcessBackground
*message
397 Object
*_IconWindows_PrefsObj
= NULL
,
398 *_IconWindows_WindowObj
= NULL
;
399 Object
*_IconWindows_IconListObj
= NULL
;
401 BOOL options_changed
= FALSE
;
403 IPTR prefs_processing
= 0;
405 IPTR BackGround_Attrib
= 0,
407 BackGround_RenderMode
= 0,
408 BackGround_TileMode
= 0,
409 BackGround_XOffset
= 0,
410 BackGround_YOffset
= 0;
412 struct BackFillInfo
*this_BFI
=(struct BackFillInfo
*) message
->BackFill_Data
;
415 char *this_ImageName
;
417 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground()\n"));
419 GET(_app(self
), MUIA_Wanderer_Prefs
, &_IconWindows_PrefsObj
);
421 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: PrefsObj @ %x\n", _IconWindows_PrefsObj
));
423 GET(self
, MUIA_IconWindow_Window
, &_IconWindows_WindowObj
);
424 GET(self
, MUIA_IconWindow_IconList
, &_IconWindows_IconListObj
);
426 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: MUIA_IconWindow_Window = %x\n", _IconWindows_WindowObj
));
428 if ((_IconWindows_PrefsObj
== NULL
) || (_IconWindows_WindowObj
== NULL
) || (_IconWindows_IconListObj
== NULL
)) return FALSE
;
430 GET(_IconWindows_PrefsObj
, MUIA_WandererPrefs_Processing
, &prefs_processing
);
433 if (prefs_processing
)
435 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Wanderer Prefs (re)loading detected\n"));
439 GET(_IconWindows_WindowObj
, MUIA_IconWindow_BackgroundAttrib
, &BackGround_Attrib
);
441 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Background Attrib = '%s'\n", BackGround_Attrib
));
443 if (BackGround_Attrib
== (IPTR
) NULL
) return FALSE
;
445 if ((BackGround_Base
= DoMethod(_IconWindows_PrefsObj
, MUIM_WandererPrefs_ViewSettings_GetAttribute
,
446 BackGround_Attrib
, MUIA_Background
)) == -1)
449 if ((BackGround_RenderMode
= DoMethod(_IconWindows_PrefsObj
, MUIM_WandererPrefs_ViewSettings_GetAttribute
,
450 BackGround_Attrib
, MUIA_IconWindowExt_ImageBackFill_BGRenderMode
)) == -1)
451 BackGround_RenderMode
= IconWindowExt_ImageBackFill_RenderMode_Tiled
;
453 this_bgtype
= (UBYTE
*)BackGround_Base
;
454 this_ImageName
= (char *)(BackGround_Base
+ 2);
456 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: BackFillInfo @ %x\n", this_BFI
));
457 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Background '%s', mode %d\n", BackGround_Base
, BackGround_RenderMode
));
459 if ((this_bgtype
[0] - 48) != 5)
461 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Background is NOT an image - letting our windoclass handle it ..\n"));
463 goto pb_cleanup_buffer
;
466 GET(self
, MUIA_Window_Screen
, &this_BFI
->bfi_Screen
);
467 GET(_IconWindows_IconListObj
, MUIA_IconList_BufferRastport
, &this_BFI
->bfi_RastPort
);
469 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Wanderers Screen @ %x, Using RastPort @ %x\n", this_BFI
->bfi_Screen
, this_BFI
->bfi_RastPort
));
471 if (this_BFI
->bfi_Source
)
473 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: BackFillInfo has existing source record @ %x\n", this_BFI
->bfi_Source
));
474 if ((strcmp(this_BFI
->bfi_Source
->bfsir_SourceImage
, this_ImageName
) == 0) && (this_BFI
->bfi_Source
->bfsir_BackGroundRenderMode
== BackGround_RenderMode
))
476 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: existing BackFillInfo Using the same background / mode\n"));
477 goto check_imagebuffer
;
481 if (this_BFI
->bfi_Buffer
)
483 ImageBackFill_CloseSourceBuffer(this_BFI
->bfi_Source
, this_BFI
->bfi_Buffer
);
484 this_BFI
->bfi_Buffer
= NULL
;
486 ImageBackFill_CloseSourceRecord(this_BFI
->bfi_Source
);
487 this_BFI
->bfi_Source
= NULL
;
491 if (!(this_BFI
->bfi_Source
)) this_BFI
->bfi_Source
= ImageBackFill_FindSourceRecord(this_ImageName
, BackGround_RenderMode
);
493 if (!(this_BFI
->bfi_Source
))
495 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Creating NEW ImageSource Record\n"));
496 if (!(this_BFI
->bfi_Source
= AllocMem(sizeof(struct BackFillSourceImageRecord
), MEMF_CLEAR
|MEMF_PUBLIC
)))
498 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Couldnt allocate enough mem for source record!\n"));
502 if (!(this_BFI
->bfi_Source
->bfsir_SourceImage
= AllocVec(strlen(this_ImageName
) +1, MEMF_CLEAR
|MEMF_PUBLIC
)))
504 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Couldnt allocate enough mem for source image name store\n"));
505 FreeMem(this_BFI
->bfi_Source
, sizeof(struct BackFillSourceImageRecord
));
508 strcpy(this_BFI
->bfi_Source
->bfsir_SourceImage
, this_ImageName
);
510 if ((this_BFI
->bfi_Source
->bfsir_DTPictureObject
= NewDTObject(this_BFI
->bfi_Source
->bfsir_SourceImage
,
511 DTA_SourceType
, DTST_FILE
,
512 DTA_GroupID
, GID_PICTURE
,
513 PDTA_DestMode
, PMODE_V43
,
515 PDTA_Screen
, this_BFI
->bfi_Screen
,
516 PDTA_FreeSourceBitMap
, TRUE
,
517 OBP_Precision
, PRECISION_IMAGE
,
520 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Opened Datatype Object @ %x for image '%s'\n", this_BFI
->bfi_Source
->bfsir_DTPictureObject
, this_BFI
->bfi_Source
->bfsir_SourceImage
));
521 if (DoMethod(this_BFI
->bfi_Source
->bfsir_DTPictureObject
, DTM_PROCLAYOUT
, NULL
, 1))
523 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Caused Datatype Object LAYOUT\n"));
525 GetDTAttrs(this_BFI
->bfi_Source
->bfsir_DTPictureObject
, PDTA_BitMapHeader
, &this_BFI
->bfi_Source
->bfsir_DTBitMapHeader
, TAG_DONE
);
526 GetDTAttrs(this_BFI
->bfi_Source
->bfsir_DTPictureObject
, PDTA_DestBitMap
, &this_BFI
->bfi_Source
->bfsir_DTBitMap
, TAG_DONE
);
528 if (!this_BFI
->bfi_Source
->bfsir_DTBitMap
)
529 GetDTAttrs(this_BFI
->bfi_Source
->bfsir_DTPictureObject
, PDTA_BitMap
, &this_BFI
->bfi_Source
->bfsir_DTBitMap
, TAG_DONE
);
531 if (this_BFI
->bfi_Source
->bfsir_DTBitMap
)
533 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Datatype Object BitMap @ %x\n", this_BFI
->bfi_Source
->bfsir_DTBitMap
));
535 if ((this_BFI
->bfi_Source
->bfsir_DTRastPort
= CreateRastPort()))
537 this_BFI
->bfi_Source
->bfsir_DTRastPort
->BitMap
= this_BFI
->bfi_Source
->bfsir_DTBitMap
;
538 this_BFI
->bfi_Source
->bfsir_BackGroundRenderMode
= BackGround_RenderMode
;
539 this_BFI
->bfi_Source
->bfsir_OpenerCount
= 0x01;
541 NewList(&this_BFI
->bfi_Source
->bfsir_Buffers
);
543 AddTail(&image_backfill_images
, &this_BFI
->bfi_Source
->bfsir_Node
);
544 goto check_imagebuffer
;
547 /* Failed to obtain datatype object's BM */
549 /* Failed to Layout datatype object */
551 /* Failed to open datatype object */
553 if (!this_BFI
->bfi_Source
->bfsir_DTRastPort
)
555 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Failed to create ImageSource RastPort\n"));
559 if (this_BFI
->bfi_Source
->bfsir_DTBitMap
)
561 FreeBitMap(this_BFI
->bfi_Source
->bfsir_DTBitMap
);
562 this_BFI
->bfi_Source
->bfsir_DTBitMap
= NULL
;
567 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Failed to create ImageSource BitMap\n"));
571 if (this_BFI
->bfi_Source
->bfsir_DTPictureObject
)
573 DisposeDTObject(this_BFI
->bfi_Source
->bfsir_DTPictureObject
);
574 this_BFI
->bfi_Source
->bfsir_DTPictureObject
= NULL
;
579 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Failed to create ImageSource Datatype Object\n"));
582 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Failed to create ImageSource Record\n"));
583 if (this_BFI
->bfi_Source
->bfsir_SourceImage
) FreeVec(this_BFI
->bfi_Source
->bfsir_SourceImage
);
584 FreeMem(this_BFI
->bfi_Source
, sizeof(struct BackFillSourceImageRecord
));
585 this_BFI
->bfi_Source
= NULL
;
590 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Using existing ImageSource Record\n"));
591 this_BFI
->bfi_Source
->bfsir_OpenerCount
+= 1;
596 Depth
= GetBitMapAttr(this_BFI
->bfi_Source
->bfsir_DTBitMap
, BMA_DEPTH
);
597 this_BFI
->bfi_CopyWidth
= this_BFI
->bfi_Source
->bfsir_DTBitMapHeader
->bmh_Width
;
598 this_BFI
->bfi_CopyHeight
= this_BFI
->bfi_Source
->bfsir_DTBitMapHeader
->bmh_Height
;
600 switch (BackGround_RenderMode
)
602 case IconWindowExt_ImageBackFill_RenderMode_Scale
:
604 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED mode\n"));
606 this_BFI
->bfi_Options
.bfo_TileMode
= IconWindowExt_ImageBackFill_TileMode_Fixed
;
608 SET(_IconWindows_IconListObj
, MUIA_IconListview_FixedBackground
, TRUE
);
609 SET(_IconWindows_IconListObj
, MUIA_IconListview_ScaledBackground
, TRUE
);
611 if ((BOOL
)XGET(self
, MUIA_IconWindow_IsRoot
))
613 struct BackFillSourceImageBuffer
*this_Buffer
;
614 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED - Root Window = TRUE!\n"));
615 this_BFI
->bfi_CopyWidth
= GetBitMapAttr(this_BFI
->bfi_Screen
->RastPort
.BitMap
, BMA_WIDTH
);
616 this_BFI
->bfi_CopyHeight
= GetBitMapAttr(this_BFI
->bfi_Screen
->RastPort
.BitMap
, BMA_HEIGHT
);
618 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED - Base Dimensions (%d x %d)\n", this_BFI
->bfi_CopyWidth
, this_BFI
->bfi_CopyHeight
));
620 if (!((BOOL
)XGET(self
, MUIA_IconWindow_IsBackdrop
)))
622 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED - Adjusting for window border Dimensions ..\n"));
623 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED - WBorTop %d, WBorLeft %d, WBorRight %d, WBorBottom %d\n", this_BFI
->bfi_Screen
->WBorTop
, this_BFI
->bfi_Screen
->WBorLeft
, this_BFI
->bfi_Screen
->WBorRight
, this_BFI
->bfi_Screen
->WBorBottom
));
624 this_BFI
->bfi_CopyWidth
-= (this_BFI
->bfi_Screen
->WBorLeft
+ this_BFI
->bfi_Screen
->WBorRight
);
625 this_BFI
->bfi_CopyHeight
-= (this_BFI
->bfi_Screen
->WBorTop
+ this_BFI
->bfi_Screen
->WBorBottom
);;
628 this_BFI
->bfi_CopyHeight
-= (this_BFI
->bfi_Screen
->BarHeight
+ 1);
632 if (this_BFI
->bfi_Buffer
)
634 if ((this_BFI
->bfi_Buffer
->bfsib_BitMapWidth
== this_BFI
->bfi_CopyWidth
) && (this_BFI
->bfi_Buffer
->bfsib_BitMapHeight
== this_BFI
->bfi_CopyHeight
))
636 goto pb_backfillsetup_complete
;
640 ImageBackFill_CloseSourceBuffer(this_BFI
->bfi_Source
, this_BFI
->bfi_Buffer
);
641 this_BFI
->bfi_Buffer
= NULL
;
645 if (!(this_Buffer
= ImageBackFill_FindBufferRecord(this_BFI
->bfi_Source
, this_BFI
->bfi_CopyWidth
, this_BFI
->bfi_CopyHeight
)))
647 this_Buffer
= AllocMem(sizeof(struct BackFillSourceImageBuffer
), MEMF_CLEAR
|MEMF_PUBLIC
);
648 this_Buffer
->bfsib_BitMapWidth
= this_BFI
->bfi_CopyWidth
;
649 this_Buffer
->bfsib_BitMapHeight
= this_BFI
->bfi_CopyHeight
;
651 if (!(this_Buffer
->bfsib_BitMapRastPort
= CreateRastPort()))
653 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED - Failed to create RastPort for BackFill BitMap\n"));
657 if ((this_Buffer
->bfsib_BitMap
= AllocBitMap(this_BFI
->bfi_CopyWidth
, this_BFI
->bfi_CopyHeight
, Depth
, Depth
== 8 ? BMF_MINPLANES
: 0L, this_BFI
->bfi_Screen
->RastPort
.BitMap
)))
659 struct Rectangle CopyBounds
;
661 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED - Scale Dimensions (%d x %d)\n", this_BFI
->bfi_CopyWidth
, this_BFI
->bfi_CopyHeight
));
664 this_Buffer
->bfsib_BitMapRastPort
->BitMap
= this_Buffer
->bfsib_BitMap
;
665 this_BFI
->bfi_Buffer
= this_Buffer
;
669 CopyBounds
.MaxX
= this_BFI
->bfi_CopyWidth
- 1;
670 CopyBounds
.MaxY
= this_BFI
->bfi_CopyHeight
- 1;
673 ImageBackFill_CopyScaledBitMap(this_BFI
->bfi_Source
->bfsir_DTRastPort
,
675 this_BFI
->bfi_Source
->bfsir_DTBitMapHeader
->bmh_Width
,
676 this_BFI
->bfi_Source
->bfsir_DTBitMapHeader
->bmh_Height
,
677 this_Buffer
->bfsib_BitMapRastPort
,
678 &CopyBounds
, &CopyBounds
, blit_MODE_Blit
);
680 this_Buffer
->bfsib_OpenerCount
= 0x01;
682 AddTail(&this_BFI
->bfi_Source
->bfsir_Buffers
, &this_Buffer
->bfsib_Node
);
684 goto pb_backfillsetup_complete
;
690 this_BFI
->bfi_Buffer
= this_Buffer
;
691 this_Buffer
->bfsib_OpenerCount
+= 1;
692 goto pb_backfillsetup_complete
;
695 // We arent the "ROOT" (desktop) window so only tile ...
696 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED - Drawer window scaling unsupported ...\n"));
700 struct BackFillSourceImageBuffer
*this_Buffer
;
701 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: TILED mode\n"));
702 if ((BackGround_TileMode
= DoMethod(_IconWindows_PrefsObj
, MUIM_WandererPrefs_ViewSettings_GetAttribute
,
703 BackGround_Attrib
, MUIA_IconWindowExt_ImageBackFill_BGTileMode
)) == -1)
704 BackGround_TileMode
= IconWindowExt_ImageBackFill_TileMode_Float
;
706 if ((BackGround_XOffset
= DoMethod(_IconWindows_PrefsObj
, MUIM_WandererPrefs_ViewSettings_GetAttribute
,
707 BackGround_Attrib
, MUIA_IconWindowExt_ImageBackFill_BGXOffset
)) == -1)
708 BackGround_XOffset
= 0;
710 if ((BackGround_YOffset
= DoMethod(_IconWindows_PrefsObj
, MUIM_WandererPrefs_ViewSettings_GetAttribute
,
711 BackGround_Attrib
, MUIA_IconWindowExt_ImageBackFill_BGYOffset
)) == -1)
712 this_BFI
->bfi_Options
.bfo_OffsetY
= 0;
714 if (this_BFI
->bfi_Options
.bfo_TileMode
!= BackGround_TileMode
)
716 this_BFI
->bfi_Options
.bfo_TileMode
= BackGround_TileMode
;
717 options_changed
= TRUE
;
720 if (this_BFI
->bfi_Options
.bfo_OffsetX
!= BackGround_XOffset
)
722 this_BFI
->bfi_Options
.bfo_OffsetX
= BackGround_XOffset
;
723 options_changed
= TRUE
;
726 if (this_BFI
->bfi_Options
.bfo_OffsetY
!= BackGround_YOffset
)
728 this_BFI
->bfi_Options
.bfo_OffsetY
= BackGround_YOffset
;
729 options_changed
= TRUE
;
732 if (this_BFI
->bfi_Options
.bfo_TileMode
== IconWindowExt_ImageBackFill_TileMode_Float
)
733 SET(_IconWindows_IconListObj
, MUIA_IconListview_FixedBackground
, FALSE
);
735 SET(_IconWindows_IconListObj
, MUIA_IconListview_FixedBackground
, TRUE
);
737 SET(_IconWindows_IconListObj
, MUIA_IconListview_ScaledBackground
, FALSE
);
741 if (this_BFI
->bfi_Buffer
)
743 if ((this_BFI
->bfi_Buffer
->bfsib_BitMapWidth
== this_BFI
->bfi_CopyWidth
) && (this_BFI
->bfi_Buffer
->bfsib_BitMapHeight
== this_BFI
->bfi_CopyHeight
))
745 goto pb_backfillsetup_complete
;
749 ImageBackFill_CloseSourceBuffer(this_BFI
->bfi_Source
, this_BFI
->bfi_Buffer
);
750 this_BFI
->bfi_Buffer
= NULL
;
754 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Dimensions Width %d, Height %d\n", this_BFI
->bfi_CopyWidth
, this_BFI
->bfi_CopyHeight
));
756 if (!(this_Buffer
= ImageBackFill_FindBufferRecord(this_BFI
->bfi_Source
, this_BFI
->bfi_CopyWidth
, this_BFI
->bfi_CopyHeight
)))
758 this_Buffer
= AllocMem(sizeof(struct BackFillSourceImageBuffer
), MEMF_CLEAR
|MEMF_PUBLIC
);
759 this_Buffer
->bfsib_BitMapWidth
= this_BFI
->bfi_CopyWidth
;
760 this_Buffer
->bfsib_BitMapHeight
= this_BFI
->bfi_CopyHeight
;
762 if ((this_Buffer
->bfsib_BitMap
= AllocBitMap(this_BFI
->bfi_CopyWidth
, this_BFI
->bfi_CopyHeight
, Depth
, Depth
== 8 ? BMF_MINPLANES
: 0L, this_BFI
->bfi_Screen
->RastPort
.BitMap
)))
764 struct Rectangle CopyBounds
;
766 if (!(this_Buffer
->bfsib_BitMapRastPort
= CreateRastPort()))
768 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: TILED - Failed to create RastPort for BackFill BitMap\n"));
772 this_Buffer
->bfsib_BitMapRastPort
->BitMap
= this_Buffer
->bfsib_BitMap
;
773 this_BFI
->bfi_Buffer
= this_Buffer
;
777 CopyBounds
.MaxX
= this_BFI
->bfi_CopyWidth
- 1;
778 CopyBounds
.MaxY
= this_BFI
->bfi_CopyHeight
- 1;
780 ImageBackFill_CopyTiledBitMap(this_BFI
->bfi_Source
->bfsir_DTRastPort
,
782 this_BFI
->bfi_Source
->bfsir_DTBitMapHeader
->bmh_Width
,
783 this_BFI
->bfi_Source
->bfsir_DTBitMapHeader
->bmh_Height
,
784 this_BFI
->bfi_Buffer
->bfsib_BitMapRastPort
,
785 &CopyBounds
, &CopyBounds
, blit_MODE_Blit
);
787 this_Buffer
->bfsib_OpenerCount
= 0x01;
789 AddTail(&this_BFI
->bfi_Source
->bfsir_Buffers
, &this_BFI
->bfi_Buffer
->bfsib_Node
);
791 goto pb_backfillsetup_complete
;
797 this_BFI
->bfi_Buffer
= this_Buffer
;
798 this_Buffer
->bfsib_OpenerCount
+= 1;
799 goto pb_backfillsetup_complete
;
804 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Failed to create image datatype object\n"));
808 if (this_BFI
->bfi_Buffer
)
810 ImageBackFill_CloseSourceBuffer(this_BFI
->bfi_Source
, this_BFI
->bfi_Buffer
);
811 this_BFI
->bfi_Buffer
= NULL
;
815 if (this_BFI
->bfi_Source
)
817 ImageBackFill_CloseSourceRecord(this_BFI
->bfi_Source
);
818 this_BFI
->bfi_Source
= NULL
;
823 pb_backfillsetup_complete
:
824 if ((prefs_processing
) && (options_changed
))
825 SET(self
, MUIA_IconWindow_Changed
, TRUE
);
831 ///ImageBackFill__MUIM_IconWindow_BackFill_Setup()
832 IPTR ImageBackFill__MUIM_IconWindow_BackFill_Setup
834 Class
*CLASS
, Object
*self
, struct MUIP_IconWindow_BackFill_Setup
*message
837 struct BackFillInfo
*this_BFI
= NULL
;
839 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_Setup()\n"));
841 this_BFI
= AllocVec(sizeof(struct BackFillInfo
), MEMF_CLEAR
|MEMF_PUBLIC
);
842 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_Setup: Allocated BackFillInfo @ %x\n", this_BFI
));
844 return (IPTR
)this_BFI
;
848 ///ImageBackFill__MUIM_IconWindow_BackFill_Cleanup()
849 IPTR ImageBackFill__MUIM_IconWindow_BackFill_Cleanup
851 Class
*CLASS
, Object
*self
, struct MUIP_IconWindow_BackFill_Cleanup
*message
854 struct BackFillInfo
*this_BFI
= (struct BackFillInfo
*)message
->BackFill_Data
;
856 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_Cleanup()\n"));
858 if (this_BFI
->bfi_Buffer
)
860 ImageBackFill_CloseSourceBuffer(this_BFI
->bfi_Source
, this_BFI
->bfi_Buffer
);
861 this_BFI
->bfi_Buffer
= NULL
;
863 if (this_BFI
->bfi_Source
)
865 ImageBackFill_CloseSourceRecord(this_BFI
->bfi_Source
);
866 this_BFI
->bfi_Source
= NULL
;
874 ///ImageBackFill__MUIM_IconWindow_BackFill_DrawBackground()
875 IPTR ImageBackFill__MUIM_IconWindow_BackFill_DrawBackground
877 Class
*CLASS
, Object
*self
, struct MUIP_IconWindow_BackFill_DrawBackground
*message
880 struct BackFillInfo
*this_BFI
= NULL
;
882 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_DrawBackground()\n"));
884 if ((this_BFI
= (struct BackFillInfo
*)message
->BackFill_Data
) != NULL
)
886 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_DrawBackground: Got BackFill_Data @ %x\n", this_BFI
));
887 this_BFI
->bfi_RastPort
= (struct RastPort
*)message
->draw_RastPort
;
889 if ((this_BFI
->bfi_Buffer
) && (this_BFI
->bfi_RastPort
))
892 #warning "TODO: Make Base Tile Offset preference settable"
893 WORD OffsetX
= this_BFI
->bfi_Options
.bfo_OffsetX
; // the offset within the tile in x direction
894 WORD OffsetY
= this_BFI
->bfi_Options
.bfo_OffsetY
; // the offset within the tile in y direction
896 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_DrawBackground: BackFill_Data has suitable Buffer and RastPort ..\n"));
898 if (this_BFI
->bfi_Options
.bfo_TileMode
== IconWindowExt_ImageBackFill_TileMode_Float
)
900 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_DrawBackground: Rendering using floating backdrop mode\n"));
901 OffsetX
+= message
->draw_BFM
->OffsetX
;
902 OffsetY
+= message
->draw_BFM
->OffsetY
;
905 ImageBackFill_CopyTiledBitMap(this_BFI
->bfi_Buffer
->bfsib_BitMapRastPort
,
907 this_BFI
->bfi_CopyWidth
, this_BFI
->bfi_CopyHeight
,
908 this_BFI
->bfi_RastPort
,
909 &message
->draw_BFM
->AreaBounds
,
910 &message
->draw_BFM
->DrawBounds
,
916 D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_DrawBackground: Causing parent to render .. \n"));
921 /*** SPECIAL : Early Setup ****************************************************************/
922 ///ImageBackFill__SetupClass()
923 IPTR
ImageBackFill__SetupClass()
925 struct MUIP_IconWindow_BackFill_Register message
;
927 D(bug("[IconWindow.ImageBackFill] ImageBackFill__SetupClass()\n"));
929 image_backfill_descriptor
.bfd_BackFillID
= image_backfill_name
;
931 image_backfill_descriptor
.bfd_MUIM_IconWindow_BackFill_Setup
= ImageBackFill__MUIM_IconWindow_BackFill_Setup
;
932 image_backfill_descriptor
.bfd_MUIM_IconWindow_BackFill_Cleanup
= ImageBackFill__MUIM_IconWindow_BackFill_Cleanup
;
933 image_backfill_descriptor
.bfd_MUIM_IconWindow_BackFill_ProcessBackground
= ImageBackFill__MUIM_IconWindow_BackFill_ProcessBackground
;
934 image_backfill_descriptor
.bfd_MUIM_IconWindow_BackFill_DrawBackground
= ImageBackFill__MUIM_IconWindow_BackFill_DrawBackground
;
936 message
.register_Node
= &image_backfill_descriptor
;
938 NewList(&image_backfill_images
);
940 #if defined(WANDERER_MODULE_BACKFILL_ENABLED)
941 IconWindow__MUIM_IconWindow_BackFill_Register(NULL
, NULL
, &message
);
948 /* Make sure and run _AFTER_ IconWindow__SetupClass() */
949 ADD2INIT(ImageBackFill__SetupClass
, 10);