1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
5 #include "DDScrollBuffer.h"
10 // --- VERSION 1.0 CLASS
12 // --- MultiUse = -1 'True // True
13 // --- Persistable = 0 'NotPersistable // NotPersistable
14 // --- DataBindingBehavior = 0 'vbNone // vbNone
15 // --- DataSourceBehavior = 0 'vbNone // vbNone
16 // --- MTSTransactionMode = 0 'NotAnMTSObject // NotAnMTSObject
19 static char *VB_Name = "DDScrollBuffer";
20 static boolean VB_GlobalNameSpace = False;
21 static boolean VB_Creatable = True;
22 static boolean VB_PredeclaredId = False;
23 static boolean VB_Exposed = False;
24 // --- Option Explicit
26 // needs reference to: DirectX7 for Visual Basic Type Library
28 DirectDrawSurface7 Buffer;
29 DirectDrawSurface7 mPrimary;
32 long mScrollX, mScrollY;
33 long mDestXOff, mDestYOff;
35 void DDScrollBuffer_Let_DestXOff(long NewVal)
40 long DDScrollBuffer_Get_DestXOff()
49 void DDScrollBuffer_Let_DestYOff(long NewVal)
54 long DDScrollBuffer_Get_DestYOff()
63 DirectDrawSurface7 DDScrollBuffer_Get_Surface()
65 DirectDrawSurface7 Surface;
72 long DDScrollBuffer_Get_Width()
81 int DDScrollBuffer_Get_Height()
90 long DDScrollBuffer_CreateAtSize(long Width, long Height, long hWndViewPort)
98 // Create ScrollBuffer:
100 SD.lFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
101 SD.ddsCaps.lCaps = DDSCAPS_VIDEOMEMORY;
102 // SD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
107 // --- On Error Resume Next
108 Buffer = DDraw.CreateSurface(SD);
112 // --- On Error GoTo 0
123 void DDScrollBuffer_Cls(int BackColor)
130 Buffer.BltColorFill(EmptyRect, BackColor);
133 void DDScrollBuffer_Blt()
144 // --- On Error GoTo BltEH
145 DirectX.GetWindowRect(mhWnd, DR);
146 // --- On Error GoTo 0
149 tX = (DR.right - DR.left) / Stretch;
150 tY = (DR.bottom - DR.top) / Stretch;
153 SR.left = mScrollX + mDestXOff;
154 SR.top = mScrollY + mDestYOff;
155 SR.right = SR.left + tX;
156 SR.bottom = SR.top + tY;
157 // If mWidth < SR.right Then
159 // DR.right = DR.left + Stretch * (SR.right - SR.left)
161 // If mHeight < SR.bottom Then
162 // SR.bottom = mHeight
163 // DR.bottom = DR.top + Stretch * (SR.bottom - SR.top)
165 // If (mScrollX + mDestXOff) < 0 Then
167 // DR.left = DR.left - Stretch * (mScrollX + mDestXOff)
169 // If (mScrollY + mDestYOff) < 0 Then
171 // DR.top = DR.top - Stretch * (mScrollY + mDestYOff)
174 // DDraw.WaitForVerticalBlank DDWAITVB_BLOCKBEGIN, 0
175 if (IS_NOTHING(&Buffer, sizeof(Buffer)))
178 if (IS_NOTHING(&PrimarySurface, sizeof(PrimarySurface)))
181 L = PrimarySurface_Blt(DR, Buffer, SR, DDBLT_WAIT);
190 case DDERR_INVALIDCLIPLIST:
194 case DDERR_INVALIDOBJECT:
198 case DDERR_INVALIDPARAMS:
202 case DDERR_INVALIDRECT:
206 case DDERR_NOALPHAHW:
214 case DDERR_NOCLIPLIST:
218 case DDERR_NODDROPSHW:
222 case DDERR_NOMIRRORHW:
226 case DDERR_NORASTEROPHW:
230 case DDERR_NOROTATIONHW:
234 case DDERR_NOSTRETCHHW:
238 case DDERR_NOZBUFFERHW:
242 case DDERR_SURFACEBUSY:
246 case DDERR_SURFACELOST:
247 DDraw.RestoreAllSurfaces();
248 if (! PrimarySurface.isLost())
254 // RestorePrimarySurface
258 case DDERR_UNSUPPORTED:
262 case DDERR_WASSTILLDRAWING:
273 // Buffer.UpdateOverlay SR, PrimarySurface, DR, DDOVER_SHOW
275 FMark.RefreshMarker();
281 void DDScrollBuffer_ScrollTo(int X, int Y)
294 void DDScrollBuffer_ScrollTowards(int X, int Y, double Step)
305 r = Sqr(dx * dx + dY * dY);
306 if (r == 0) // we are there already
314 mScrollX = mScrollX + dx * r;
315 mScrollY = mScrollY + dY * r;
320 void DDScrollBuffer_SoftScrollTo(int X, int Y, long TimeMS, int FPS)
323 TickCountObject Tick;
326 long oldX, oldY, maxD;
327 boolean AlreadyRunning;
337 AlreadyRunning = True;
342 maxD = (Abs(dx) < Abs(dY) ? Abs(dY) : Abs(dY));
343 StepCount = FPS * (TimeMS / (double)1000);
344 if (StepCount > maxD)
351 tStep = (double)1 / StepCount;
354 // R = Sqr(dX * dX + dY * dY)
355 // If R = 0 Then Exit Sub 'we are there already
356 for (T = (double)tStep; T <= (double)1; T += tStep)
361 // If Claim Then Exit For
362 Tick.DelayMS(dT, False);
363 mScrollX = oldX + T * dx;
364 mScrollY = oldY + T * dY;
373 Tick.DelayMS(dT, False);
381 AlreadyRunning = False;