2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Internal function for improved gels handling.
8 #include <graphics/gels.h>
9 #include <graphics/rastport.h>
10 #include <exec/memory.h>
11 #include <proto/graphics.h>
12 #include <proto/exec.h>
13 #include "gels_internal.h"
14 #include "graphics_intern.h"
17 #include <aros/debug.h>
19 struct IntVSprite
* _CreateIntVSprite(struct VSprite
* vs
,
21 struct GfxBase
* GfxBase
)
23 struct IntVSprite
* ivs
= AllocMem(sizeof(struct IntVSprite
),
30 * Don't call the validate function when rp=NULL, i.e. when
31 * called by InitGels().
34 _ValidateIntVSprite(ivs
,
43 VOID
_DeleteIntVSprite(struct VSprite
* vs
,
44 struct GfxBase
* GfxBase
)
46 struct IntVSprite
* ivs
= vs
->IntVSprite
;
49 if (NULL
!= ivs
->ImageData
)
50 FreeBitMap(ivs
->ImageData
);
52 if (NULL
!= ivs
->SaveBuffer
)
53 FreeBitMap(ivs
->SaveBuffer
);
55 FreeMem(ivs
, sizeof(struct IntVSprite
));
56 vs
->IntVSprite
= NULL
;
62 * Check whether the appearance of the VSprite has been changed
63 * somehow. If for example the Image Data has changed, then
64 * I will try to update the BitMap of the IntVSprite structure
65 * to the new image data.
67 BOOL
_ValidateIntVSprite(struct IntVSprite
* ivs
,
70 struct GfxBase
* GfxBase
)
72 struct VSprite
* vs
= ivs
->VSprite
;
74 * Check whether the ImageData pointer has changed
76 if (vs
->ImageData
!= ivs
->OrigImageData
||
81 kprintf("%s: Imagedata has changed (old:%p-new:%p)!\n",
85 kprintf("PlanePick: %02x, rp->BitMap:%p\n",vs
->PlanePick
,rp
->BitMap
);
88 * Only need to get a new bitmap if
89 * something in the size of the bob has changed.
91 if ((ivs
->Width
!= vs
->Width
) ||
92 (ivs
->Height
!= vs
->Height
) ||
93 (ivs
->Depth
!= vs
->Depth
) ) {
94 if (NULL
!= ivs
->ImageData
)
95 FreeBitMap(ivs
->ImageData
);
97 if (NULL
!= ivs
->SaveBuffer
)
98 FreeBitMap(ivs
->SaveBuffer
);
100 * Now get a new bitmap
103 ivs
->ImageData
= AllocBitMap(vs
->Width
<<4,
109 ivs
->SaveBuffer
= AllocBitMap(vs
->Width
<<4,
114 ivs
->Width
= vs
->Width
;
115 ivs
->Height
= vs
->Height
;
116 ivs
->Depth
= vs
->Depth
;
119 ivs
->OrigImageData
= vs
->ImageData
;
122 * Blit the image data from the VSprite into the
123 * ImageData (BitMap) of the IntVSprite
131 UBYTE
*imagedata
= (UBYTE
*)vs
->ImageData
;
134 for (d
= 0, shift
= 1; d
< 8; d
++, shift
*= 2)
136 if (vs
->PlanePick
& shift
)
138 bm
.Planes
[d
] = imagedata
;
139 imagedata
+= (bm
.Rows
* bm
.BytesPerRow
);
143 bm
.Planes
[d
] = (vs
->PlaneOnOff
& shift
) ? (PLANEPTR
)-1 : NULL
;
167 * Erase the VSprite from the list and follow the clear path
168 * first, if necessary! This way of organizing the ClearPath
169 * makes it easy to implement RemIBob but it leads to a recursion!
170 * RemIBob could simply call this function here and then redraw
172 * If a recursion is not what we want this can be easily
176 void _ClearBobAndFollowClearPath(struct VSprite
* CurVSprite
,
177 struct RastPort
* rp
,
178 struct GfxBase
* GfxBase
)
181 * If the bob has not been drawn, yet, then don't do anything.
182 * If the bob has already been cleared, then also leave here!
183 * It does happen that this routine gets called for
184 * a sprite that has been cleared already.
186 if (0 != (CurVSprite
->VSBob
->Flags
& (BWAITING
|BOBNIX
))) {
187 CurVSprite
->VSBob
->Flags
&= ~BWAITING
;
191 if (NULL
!= CurVSprite
->ClearPath
) {
193 * Clear the next one first. (recursion!!!)
195 _ClearBobAndFollowClearPath(CurVSprite
->ClearPath
,
198 CurVSprite
->ClearPath
= NULL
;
203 * Only restore the background if the bob image
204 * that is currently there is to be replaced by
205 * the background. If SAVEBOB is set the user
206 * might want some kind of a brush effect.
209 if (0 == (CurVSprite
->Flags
& SAVEBOB
)) {
210 if (0 != (CurVSprite
->Flags
& BACKSAVED
)) {
211 BltBitMapRastPort(CurVSprite
->IntVSprite
->SaveBuffer
,
217 CurVSprite
->Width
<< 4,
220 CurVSprite
->Flags
&= ~BACKSAVED
;
222 } /* if (0 != (CurVSprite->Flags & BACKSAVED)) */
225 * No background was saved. So let's restore the
226 * standard background!
231 CurVSprite
->OldX
+ ( CurVSprite
->Width
<< 4 ) - 1,
232 CurVSprite
->OldY
+ CurVSprite
->Height
- 1);
235 * Mark the BOB as cleared.
237 CurVSprite
->VSBob
->Flags
|= BOBNIX
;
238 } /* if (0 == (CurVSprite->Flags & SAVEBOB)) */