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
151 tX = (DR.right - DR.left) / Stretch;
152 tY = (DR.bottom - DR.top) / Stretch;
155 SR.left = mScrollX + mDestXOff;
156 SR.top = mScrollY + mDestYOff;
157 SR.right = SR.left + tX;
158 SR.bottom = SR.top + tY;
159 // If mWidth < SR.right Then
161 // DR.right = DR.left + Stretch * (SR.right - SR.left)
163 // If mHeight < SR.bottom Then
164 // SR.bottom = mHeight
165 // DR.bottom = DR.top + Stretch * (SR.bottom - SR.top)
167 // If (mScrollX + mDestXOff) < 0 Then
169 // DR.left = DR.left - Stretch * (mScrollX + mDestXOff)
171 // If (mScrollY + mDestYOff) < 0 Then
173 // DR.top = DR.top - Stretch * (mScrollY + mDestYOff)
179 printf("::: DDScrollBuffer.c: DDScrollBuffer_Blt(): blit from %d, %d [%ld, %ld] [%ld, %ld]\n",
180 SR.left, SR.top, mScrollX, mScrollY, mDestXOff, mDestYOff);
183 BlitBitmap(screenBitmap, window,
185 SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
190 // DDraw.WaitForVerticalBlank DDWAITVB_BLOCKBEGIN, 0
191 if (IS_NOTHING(&Buffer, sizeof(Buffer)))
194 if (IS_NOTHING(&PrimarySurface, sizeof(PrimarySurface)))
197 L = PrimarySurface.Blt(DR, &Buffer, SR, DDBLT_WAIT);
207 case DDERR_INVALIDCLIPLIST:
211 case DDERR_INVALIDOBJECT:
215 case DDERR_INVALIDPARAMS:
219 case DDERR_INVALIDRECT:
223 case DDERR_NOALPHAHW:
231 case DDERR_NOCLIPLIST:
235 case DDERR_NODDROPSHW:
239 case DDERR_NOMIRRORHW:
243 case DDERR_NORASTEROPHW:
247 case DDERR_NOROTATIONHW:
251 case DDERR_NOSTRETCHHW:
255 case DDERR_NOZBUFFERHW:
259 case DDERR_SURFACEBUSY:
264 case DDERR_SURFACELOST:
265 DDraw.RestoreAllSurfaces();
266 if (! PrimarySurface.isLost())
272 // RestorePrimarySurface
277 case DDERR_UNSUPPORTED:
281 case DDERR_WASSTILLDRAWING:
293 // Buffer.UpdateOverlay SR, PrimarySurface, DR, DDOVER_SHOW
295 FMark.RefreshMarker();
301 void DDScrollBuffer_ScrollTo(int X, int Y)
314 printf("::: DDScrollBuffer.c: DDScrollBuffer_ScrollTo(): mScroll: %ld, %ld [%d, %d]\n",
315 mScrollX, mScrollY, X, Y);
319 void DDScrollBuffer_ScrollTowards(int X, int Y, double Step)
330 r = Sqr(dx * dx + dY * dY);
331 if (r == 0) // we are there already
339 mScrollX = mScrollX + dx * r;
340 mScrollY = mScrollY + dY * r;
345 printf("::: DDScrollBuffer.c: DDScrollBuffer_ScrollTowards(): mScroll: %ld, %ld\n",
350 void DDScrollBuffer_SoftScrollTo(int X, int Y, long TimeMS, int FPS)
354 TickCountObject Tick;
358 long oldX, oldY, maxD;
359 static boolean AlreadyRunning = False;
369 AlreadyRunning = True;
374 maxD = (Abs(dx) < Abs(dY) ? Abs(dY) : Abs(dY));
375 StepCount = FPS * (TimeMS / (double)1000);
376 if (StepCount > maxD)
383 tStep = (double)1 / StepCount;
386 // R = Sqr(dX * dX + dY * dY)
387 // If R = 0 Then Exit Sub 'we are there already
388 for (T = (double)tStep; T <= (double)1; T += tStep)
393 // If Claim Then Exit For
396 Tick.DelayMS(dT, False);
399 mScrollX = oldX + T * dx;
400 mScrollY = oldY + T * dY;
410 Tick.DelayMS(dT, False);
420 AlreadyRunning = False;
423 printf("::: DDScrollBuffer.c: DDScrollBuffer_SoftScrollTo(): mScroll: %ld, %ld\n",