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;
25 // --- Option Explicit
27 // needs reference to: DirectX7 for Visual Basic Type Library
29 DirectDrawSurface7 Buffer;
30 DirectDrawSurface7 mPrimary;
33 long mScrollX, mScrollY;
34 long mDestXOff, mDestYOff;
36 void DDScrollBuffer_Let_DestXOff(long NewVal)
41 long DDScrollBuffer_Get_DestXOff()
50 void DDScrollBuffer_Let_DestYOff(long NewVal)
55 long DDScrollBuffer_Get_DestYOff()
64 DirectDrawSurface7 DDScrollBuffer_Get_Surface()
66 DirectDrawSurface7 Surface;
73 long DDScrollBuffer_Get_Width()
82 int DDScrollBuffer_Get_Height()
91 long DDScrollBuffer_CreateAtSize(long Width, long Height, long hWndViewPort)
99 // Create ScrollBuffer:
101 SD.lFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
102 SD.ddsCaps.lCaps = DDSCAPS_VIDEOMEMORY;
103 // SD.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
108 // --- On Error Resume Next
109 Buffer = DDraw.CreateSurface(SD);
113 // --- On Error GoTo 0
124 void DDScrollBuffer_Cls(int BackColor)
131 Buffer.BltColorFill(EmptyRect, BackColor);
134 void DDScrollBuffer_Blt()
145 // --- On Error GoTo BltEH
146 DirectX.GetWindowRect(mhWnd, DR);
147 // --- On Error GoTo 0
150 tX = (DR.right - DR.left) / Stretch;
151 tY = (DR.bottom - DR.top) / Stretch;
154 SR.left = mScrollX + mDestXOff;
155 SR.top = mScrollY + mDestYOff;
156 SR.right = SR.left + tX;
157 SR.bottom = SR.top + tY;
158 // If mWidth < SR.right Then
160 // DR.right = DR.left + Stretch * (SR.right - SR.left)
162 // If mHeight < SR.bottom Then
163 // SR.bottom = mHeight
164 // DR.bottom = DR.top + Stretch * (SR.bottom - SR.top)
166 // If (mScrollX + mDestXOff) < 0 Then
168 // DR.left = DR.left - Stretch * (mScrollX + mDestXOff)
170 // If (mScrollY + mDestYOff) < 0 Then
172 // DR.top = DR.top - Stretch * (mScrollY + mDestYOff)
175 // DDraw.WaitForVerticalBlank DDWAITVB_BLOCKBEGIN, 0
176 if (IS_NOTHING(&Buffer, sizeof(Buffer)))
179 if (IS_NOTHING(&PrimarySurface, sizeof(PrimarySurface)))
182 L = PrimarySurface.Blt(DR, &Buffer, SR, DDBLT_WAIT);
192 case DDERR_INVALIDCLIPLIST:
196 case DDERR_INVALIDOBJECT:
200 case DDERR_INVALIDPARAMS:
204 case DDERR_INVALIDRECT:
208 case DDERR_NOALPHAHW:
216 case DDERR_NOCLIPLIST:
220 case DDERR_NODDROPSHW:
224 case DDERR_NOMIRRORHW:
228 case DDERR_NORASTEROPHW:
232 case DDERR_NOROTATIONHW:
236 case DDERR_NOSTRETCHHW:
240 case DDERR_NOZBUFFERHW:
244 case DDERR_SURFACEBUSY:
249 case DDERR_SURFACELOST:
250 DDraw.RestoreAllSurfaces();
251 if (! PrimarySurface.isLost())
257 // RestorePrimarySurface
262 case DDERR_UNSUPPORTED:
266 case DDERR_WASSTILLDRAWING:
278 // Buffer.UpdateOverlay SR, PrimarySurface, DR, DDOVER_SHOW
280 FMark.RefreshMarker();
286 void DDScrollBuffer_ScrollTo(int X, int Y)
299 void DDScrollBuffer_ScrollTowards(int X, int Y, double Step)
310 r = Sqr(dx * dx + dY * dY);
311 if (r == 0) // we are there already
319 mScrollX = mScrollX + dx * r;
320 mScrollY = mScrollY + dY * r;
325 void DDScrollBuffer_SoftScrollTo(int X, int Y, long TimeMS, int FPS)
329 TickCountObject Tick;
333 long oldX, oldY, maxD;
334 static boolean AlreadyRunning = False;
337 printf("::: 1: DDScrollBuffer.c: DDScrollBuffer_SoftScrollTo: X,Y == %d, %d [%f]\n", X, Y, Stretch);
348 AlreadyRunning = True;
353 maxD = (Abs(dx) < Abs(dY) ? Abs(dY) : Abs(dY));
354 StepCount = FPS * (TimeMS / (double)1000);
355 if (StepCount > maxD)
362 printf("::: 2: DDScrollBuffer.c: DDScrollBuffer_SoftScrollTo: %f, %d, %ld, %ld [%d, %d, %ld, %ld]\n",
363 tStep, FPS, TimeMS, maxD,
364 X, Y, mScrollX, mScrollY);
368 tStep = (double)1 / StepCount;
371 // R = Sqr(dX * dX + dY * dY)
372 // If R = 0 Then Exit Sub 'we are there already
373 for (T = (double)tStep; T <= (double)1; T += tStep)
378 // If Claim Then Exit For
381 Tick.DelayMS(dT, False);
384 mScrollX = oldX + T * dx;
385 mScrollY = oldY + T * dY;
395 Tick.DelayMS(dT, False);
405 AlreadyRunning = False;