1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
5 #include "DDSpriteBuffer.h"
7 static void Blt(int pX, int pY, int SpriteX, int SpriteY);
9 // --- VERSION 1.0 CLASS
11 // --- MultiUse = -1 'True // True
12 // --- Persistable = 0 'NotPersistable // NotPersistable
13 // --- DataBindingBehavior = 0 'vbNone // vbNone
14 // --- DataSourceBehavior = 0 'vbNone // vbNone
15 // --- MTSTransactionMode = 0 'NotAnMTSObject // NotAnMTSObject
18 // static char *VB_Name = "DDSpriteBuffer";
19 // static boolean VB_GlobalNameSpace = False;
20 // static boolean VB_Creatable = True;
21 // static boolean VB_PredeclaredId = False;
22 // static boolean VB_Exposed = False;
23 // --- Option Explicit
25 // needs reference to: DirectX7 for Visual Basic Type Library
27 DirectDrawSurface7 Buffer;
28 DirectDrawSurface7 mDest;
29 long mXSpriteCount, mYSpriteCount;
30 long mSpriteWidth, mSpriteHeight;
31 long mDestXOff, mDestYOff;
33 void DDSpriteBuffer_Let_DestXOff(long NewVal)
38 long DDSpriteBuffer_Get_DestXOff()
47 void DDSpriteBuffer_Let_DestYOff(long NewVal)
52 long DDSpriteBuffer_Get_DestYOff()
61 int DDSpriteBuffer_Set_DestinationSurface(DirectDrawSurface7 DSurface)
63 int DestinationSurface;
67 return DestinationSurface;
70 DirectDrawSurface7 DDSpriteBuffer_Get_Surface()
72 DirectDrawSurface7 Surface;
79 long DDSpriteBuffer_Get_Width()
83 Width = mSpriteWidth * mXSpriteCount;
88 int DDSpriteBuffer_Get_Height()
92 Height = mSpriteHeight * mYSpriteCount;
97 boolean DDSpriteBuffer_CreateFromFile(char *Path, long xSprites, long ySprites)
99 boolean CreateFromFile;
104 SD.lFlags = DDSD_CAPS; // Or DDSD_WIDTH Or DDSD_HEIGHT
105 SD.ddsCaps.lCaps = DDSCAPS_VIDEOMEMORY; // DDSCAPS_SYSTEMMEMORY 'DDSCAPS_OFFSCREENPLAIN
108 // --- On Error GoTo CreateFromFileEH
109 Buffer = DDraw.CreateSurfaceFromFile(Path, SD);
110 // --- On Error GoTo 0
112 Buffer.GetSurfaceDesc(SD);
113 mSpriteWidth = SD.LWidth / xSprites;
114 mSpriteHeight = SD.LHeight / ySprites;
115 mXSpriteCount = xSprites;
116 mYSpriteCount = ySprites;
117 CreateFromFile = True;
118 return CreateFromFile;
121 CreateFromFile = False;
123 return CreateFromFile;
126 boolean DDSpriteBuffer_CreateAtSize(long Width, long Height, long xSprites, long ySprites)
128 boolean CreateAtSize;
133 SD.lFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
134 SD.ddsCaps.lCaps = DDSCAPS_VIDEOMEMORY;
135 // SD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
140 // --- On Error GoTo CreateAtSizeEH
141 Buffer = DDraw.CreateSurface(SD);
142 // --- On Error GoTo 0
144 mSpriteWidth = Width / xSprites;
145 mSpriteHeight = Height / ySprites;
146 mXSpriteCount = xSprites;
147 mYSpriteCount = ySprites;
152 CreateAtSize = False;
157 void DDSpriteBuffer_Cls(int BackColor)
161 Buffer.BltColorFill(EmptyRect, BackColor);
164 static void Blt(int pX, int pY, int SpriteX, int SpriteY)
173 DR.left = pX + mDestXOff;
174 DR.top = pY + mDestYOff;
175 DR.right = pX + mSpriteWidth + mDestXOff;
176 DR.bottom = pY + mSpriteHeight + mDestYOff;
179 SR.left = mSpriteWidth * (SpriteX - 1);
180 SR.top = mSpriteHeight * (SpriteY - 1);
181 SR.right = SR.left + mSpriteWidth;
182 SR.bottom = SR.top + mSpriteHeight;
184 Tmp = mDest.Blt(DR, &Buffer, SR, DDBLT_WAIT);
187 void DDSpriteBuffer_BltEx(int pX, int pY, int SpritePos)
194 XPos = (SpritePos % mXSpriteCount) + 1;
195 YPos = (SpritePos / mXSpriteCount) + 1;
196 Blt(pX, pY, XPos, YPos);
199 // Public Function GetStretchCopy(Stretch!) As DDSpriteBuffer
200 // Dim SR As RECT, DR As RECT, Y%, X%, pX%, pY%, Tmp&
201 // // Set GetStretchCopy = New DDSpriteBuffer // (handle this later, if needed)
202 // If Not GetStretchCopy.CreateAtSize(Stretch * Width, Stretch * Height, mXSpriteCount, mYSpriteCount) Then
203 // Set GetStretchCopy = Nothing
205 // For Y = 0 To mYSpriteCount - 1
206 // pY = Y * Stretch * mSpriteHeight
207 // For X = 0 To mXSpriteCount - 1
208 // pX = X * Stretch * mSpriteWidth
212 // .right = pX + mSpriteWidth * Stretch
213 // .bottom = pY + mSpriteHeight * Stretch
216 // .left = mSpriteWidth * X
217 // .top = mSpriteHeight * Y
218 // .right = .left + mSpriteWidth
219 // .bottom = .top + mSpriteHeight
221 // Tmp = GetStretchCopy.Surface.Blt(DR, Buffer, SR, DDBLT_WAIT)
224 // 'GetStretchCopy.Surface.Blt DR, Buffer, DR, DDBLT_WAIT
230 static void Class_Initialize()