Workaround for includes conflict that stopped compilation with GCC 3.
[tangerine.git] / rom / graphics / gels_internal.c
blob278c850f6771e5cb3865f5f6049626c06392bc9e
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Internal function for improved gels handling.
6 Lang: english
7 */
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"
16 #define DEBUG 1
17 #include <aros/debug.h>
19 struct IntVSprite * _CreateIntVSprite(struct VSprite * vs,
20 struct RastPort * rp,
21 struct GfxBase * GfxBase)
23 struct IntVSprite * ivs = AllocMem(sizeof(struct IntVSprite),
24 MEMF_CLEAR);
25 if (NULL != ivs) {
26 ivs -> VSprite = vs;
27 vs->IntVSprite = ivs;
29 /*
30 * Don't call the validate function when rp=NULL, i.e. when
31 * called by InitGels().
33 if (NULL != rp)
34 _ValidateIntVSprite(ivs,
35 rp,
36 FALSE,
37 GfxBase);
39 return ivs;
43 VOID _DeleteIntVSprite(struct VSprite * vs,
44 struct GfxBase * GfxBase)
46 struct IntVSprite * ivs = vs->IntVSprite;
48 if (NULL != ivs) {
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,
68 struct RastPort * rp,
69 BOOL force_change,
70 struct GfxBase * GfxBase)
72 struct VSprite * vs = ivs->VSprite;
74 * Check whether the ImageData pointer has changed
76 if (vs->ImageData != ivs->OrigImageData ||
77 force_change) {
78 struct BitMap bm;
80 #if 0
81 kprintf("%s: Imagedata has changed (old:%p-new:%p)!\n",
82 __FUNCTION__,
83 vs->ImageData,
84 ivs->OrigImageData);
85 kprintf("PlanePick: %02x, rp->BitMap:%p\n",vs->PlanePick,rp->BitMap);
86 #endif
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,
104 vs->Height,
105 vs->Depth,
106 BMF_CLEAR,
107 rp->BitMap);
109 ivs->SaveBuffer = AllocBitMap(vs->Width<<4,
110 vs->Height,
111 vs->Depth,
113 rp->BitMap);
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
125 InitBitMap(&bm,
126 ivs->Depth,
127 ivs->Width<<4,
128 ivs->Height);
131 UBYTE *imagedata = (UBYTE *)vs->ImageData;
132 WORD d, shift;
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);
141 else
143 bm.Planes[d] = (vs->PlaneOnOff & shift) ? (PLANEPTR)-1 : NULL;
149 BltBitMap(&bm,
152 ivs->ImageData,
155 ivs->Width << 4,
156 ivs->Height,
157 0x0c0,
158 vs->PlanePick,
159 NULL);
163 return TRUE;
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
171 * all cleared Bobs.
172 * If a recursion is not what we want this can be easily
173 * changed.
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;
188 return;
191 if (NULL != CurVSprite->ClearPath) {
193 * Clear the next one first. (recursion!!!)
195 _ClearBobAndFollowClearPath(CurVSprite->ClearPath,
197 GfxBase);
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,
215 CurVSprite->OldX,
216 CurVSprite->OldY,
217 CurVSprite->Width << 4,
218 CurVSprite->Height,
219 0x0c0);
220 CurVSprite->Flags &= ~BACKSAVED;
222 } /* if (0 != (CurVSprite->Flags & BACKSAVED)) */
223 else {
225 * No background was saved. So let's restore the
226 * standard background!
228 EraseRect(rp,
229 CurVSprite->OldX,
230 CurVSprite->OldY,
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)) */