- Handle multiple nodes having output volume control.
[AROS.git] / rom / graphics / gels_internal.c
blob2d1b8f7d9b0e955a585aad59c03dc14bdfd02e82
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 <aros/debug.h>
10 #include <graphics/gels.h>
11 #include <graphics/rastport.h>
12 #include <exec/memory.h>
13 #include <proto/graphics.h>
14 #include <proto/exec.h>
15 #include "gels_internal.h"
16 #include "graphics_intern.h"
18 struct IntVSprite * _CreateIntVSprite(struct VSprite * vs,
19 struct RastPort * rp,
20 struct GfxBase * GfxBase)
22 struct IntVSprite * ivs = AllocMem(sizeof(struct IntVSprite),
23 MEMF_CLEAR);
24 if (NULL != ivs) {
25 ivs -> VSprite = vs;
26 vs->IntVSprite = ivs;
28 /*
29 * Don't call the validate function when rp=NULL, i.e. when
30 * called by InitGels().
32 if (NULL != rp)
33 _ValidateIntVSprite(ivs,
34 rp,
35 FALSE,
36 GfxBase);
38 return ivs;
42 VOID _DeleteIntVSprite(struct VSprite * vs,
43 struct GfxBase * GfxBase)
45 struct IntVSprite * ivs = vs->IntVSprite;
47 if (NULL != ivs) {
48 if (NULL != ivs->ImageData)
49 FreeBitMap(ivs->ImageData);
51 if (NULL != ivs->SaveBuffer)
52 FreeBitMap(ivs->SaveBuffer);
54 FreeMem(ivs, sizeof(struct IntVSprite));
55 vs->IntVSprite = NULL;
61 * Check whether the appearance of the VSprite has been changed
62 * somehow. If for example the Image Data has changed, then
63 * I will try to update the BitMap of the IntVSprite structure
64 * to the new image data.
66 BOOL _ValidateIntVSprite(struct IntVSprite * ivs,
67 struct RastPort * rp,
68 BOOL force_change,
69 struct GfxBase * GfxBase)
71 struct VSprite * vs = ivs->VSprite;
73 * Check whether the ImageData pointer has changed
75 if (vs->ImageData != ivs->OrigImageData ||
76 force_change) {
77 struct BitMap bm;
79 #if 0
80 kprintf("%s: Imagedata has changed (old:%p-new:%p)!\n",
81 __FUNCTION__,
82 vs->ImageData,
83 ivs->OrigImageData);
84 kprintf("PlanePick: %02x, rp->BitMap:%p\n",vs->PlanePick,rp->BitMap);
85 #endif
87 * Only need to get a new bitmap if
88 * something in the size of the bob has changed.
90 if ((ivs->Width != vs->Width ) ||
91 (ivs->Height != vs->Height) ||
92 (ivs->Depth != vs->Depth ) ) {
93 if (NULL != ivs->ImageData)
94 FreeBitMap(ivs->ImageData);
96 if (NULL != ivs->SaveBuffer)
97 FreeBitMap(ivs->SaveBuffer);
99 * Now get a new bitmap
102 ivs->ImageData = AllocBitMap(vs->Width<<4,
103 vs->Height,
104 vs->Depth,
105 BMF_CLEAR,
106 rp->BitMap);
108 ivs->SaveBuffer = AllocBitMap(vs->Width<<4,
109 vs->Height,
110 vs->Depth,
112 rp->BitMap);
113 ivs->Width = vs->Width;
114 ivs->Height = vs->Height;
115 ivs->Depth = vs->Depth;
118 ivs->OrigImageData = vs->ImageData;
121 * Blit the image data from the VSprite into the
122 * ImageData (BitMap) of the IntVSprite
124 InitBitMap(&bm,
125 ivs->Depth,
126 ivs->Width<<4,
127 ivs->Height);
130 UBYTE *imagedata = (UBYTE *)vs->ImageData;
131 WORD d, shift;
133 for (d = 0, shift = 1; d < 8; d++, shift *= 2)
135 if (vs->PlanePick & shift)
137 bm.Planes[d] = imagedata;
138 imagedata += (bm.Rows * bm.BytesPerRow);
140 else
142 bm.Planes[d] = (vs->PlaneOnOff & shift) ? (PLANEPTR)-1 : NULL;
148 BltBitMap(&bm,
151 ivs->ImageData,
154 ivs->Width << 4,
155 ivs->Height,
156 0x0c0,
157 vs->PlanePick,
158 NULL);
162 return TRUE;
166 * Erase the VSprite from the list and follow the clear path
167 * first, if necessary! This way of organizing the ClearPath
168 * makes it easy to implement RemIBob but it leads to a recursion!
169 * RemIBob could simply call this function here and then redraw
170 * all cleared Bobs.
171 * If a recursion is not what we want this can be easily
172 * changed.
175 void _ClearBobAndFollowClearPath(struct VSprite * CurVSprite,
176 struct RastPort * rp,
177 struct GfxBase * GfxBase)
180 * If the bob has not been drawn, yet, then don't do anything.
181 * If the bob has already been cleared, then also leave here!
182 * It does happen that this routine gets called for
183 * a sprite that has been cleared already.
185 if (0 != (CurVSprite->VSBob->Flags & (BWAITING|BOBNIX))) {
186 CurVSprite->VSBob->Flags &= ~BWAITING;
187 return;
190 if (NULL != CurVSprite->ClearPath) {
192 * Clear the next one first. (recursion!!!)
194 _ClearBobAndFollowClearPath(CurVSprite->ClearPath,
196 GfxBase);
197 CurVSprite->ClearPath = NULL;
202 * Only restore the background if the bob image
203 * that is currently there is to be replaced by
204 * the background. If SAVEBOB is set the user
205 * might want some kind of a brush effect.
208 if (0 == (CurVSprite->Flags & SAVEBOB)) {
209 if (0 != (CurVSprite->Flags & BACKSAVED)) {
210 BltBitMapRastPort(CurVSprite->IntVSprite->SaveBuffer,
214 CurVSprite->OldX,
215 CurVSprite->OldY,
216 CurVSprite->Width << 4,
217 CurVSprite->Height,
218 0x0c0);
219 CurVSprite->Flags &= ~BACKSAVED;
221 } /* if (0 != (CurVSprite->Flags & BACKSAVED)) */
222 else {
224 * No background was saved. So let's restore the
225 * standard background!
227 EraseRect(rp,
228 CurVSprite->OldX,
229 CurVSprite->OldY,
230 CurVSprite->OldX + ( CurVSprite->Width << 4 ) - 1,
231 CurVSprite->OldY + CurVSprite->Height - 1);
234 * Mark the BOB as cleared.
236 CurVSprite->VSBob->Flags |= BOBNIX;
237 } /* if (0 == (CurVSprite->Flags & SAVEBOB)) */