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_Ext(Bitmap *target_bitmap)
148 DR.right = SCR_FIELDX * TILEX;
149 DR.bottom = SCR_FIELDY * TILEY;
151 // --- On Error GoTo BltEH
152 DirectX.GetWindowRect(mhWnd, DR);
153 // --- On Error GoTo 0
157 tX = (DR.right - DR.left) / Stretch;
158 tY = (DR.bottom - DR.top) / Stretch;
161 SR.left = mScrollX + mDestXOff;
162 SR.top = mScrollY + mDestYOff;
163 SR.right = SR.left + tX;
164 SR.bottom = SR.top + tY;
165 // If mWidth < SR.right Then
167 // DR.right = DR.left + Stretch * (SR.right - SR.left)
169 // If mHeight < SR.bottom Then
170 // SR.bottom = mHeight
171 // DR.bottom = DR.top + Stretch * (SR.bottom - SR.top)
173 // If (mScrollX + mDestXOff) < 0 Then
175 // DR.left = DR.left - Stretch * (mScrollX + mDestXOff)
177 // If (mScrollY + mDestYOff) < 0 Then
179 // DR.top = DR.top - Stretch * (mScrollY + mDestYOff)
184 SR.left = (SR.left < 0 ? 0 : SR.left);
185 SR.top = (SR.top < 0 ? 0 : SR.top);
190 int full_xsize = (FieldWidth - (menBorder.Checked ? 0 : 1)) * TILEX;
191 int full_ysize = (FieldHeight - (menBorder.Checked ? 0 : 1)) * TILEY;
192 int sxsize = SCR_FIELDX * TILEX;
193 int sysize = SCR_FIELDY * TILEY;
195 tX = (full_xsize < sxsize ? full_xsize : tX);
196 tY = (full_ysize < sysize ? full_ysize : tY);
197 sX = SX + (full_xsize < sxsize ? (sxsize - full_xsize) / 2 : 0);
198 sY = SY + (full_ysize < sysize ? (sysize - full_ysize) / 2 : 0);
203 if (!menBorder.Checked)
213 printf("::: DDScrollBuffer.c: DDScrollBuffer_Blt(): blit from %d, %d [%ld, %ld] [%ld, %ld] [%ld, %ld]\n",
214 SR.left, SR.top, mScrollX, mScrollY, mDestXOff, mDestYOff, tX, tY);
218 /* !!! quick and dirty -- FIX THIS !!! */
219 if (tape.playing && tape.fast_forward &&
220 target_bitmap == window &&
221 (FrameCounter % 2) != 0)
222 printf("::: FrameCounter == %d\n", FrameCounter);
230 BlitBitmap(screenBitmap, target_bitmap,
231 SR.left, SR.top, tX, tY, sX, sY);
233 BlitBitmap(screenBitmap, target_bitmap,
235 SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
246 // DDraw.WaitForVerticalBlank DDWAITVB_BLOCKBEGIN, 0
247 if (IS_NOTHING(&Buffer, sizeof(Buffer)))
250 if (IS_NOTHING(&PrimarySurface, sizeof(PrimarySurface)))
253 L = PrimarySurface.Blt(DR, &Buffer, SR, DDBLT_WAIT);
263 case DDERR_INVALIDCLIPLIST:
267 case DDERR_INVALIDOBJECT:
271 case DDERR_INVALIDPARAMS:
275 case DDERR_INVALIDRECT:
279 case DDERR_NOALPHAHW:
287 case DDERR_NOCLIPLIST:
291 case DDERR_NODDROPSHW:
295 case DDERR_NOMIRRORHW:
299 case DDERR_NORASTEROPHW:
303 case DDERR_NOROTATIONHW:
307 case DDERR_NOSTRETCHHW:
311 case DDERR_NOZBUFFERHW:
315 case DDERR_SURFACEBUSY:
320 case DDERR_SURFACELOST:
321 DDraw.RestoreAllSurfaces();
322 if (! PrimarySurface.isLost())
328 // RestorePrimarySurface
333 case DDERR_UNSUPPORTED:
337 case DDERR_WASSTILLDRAWING:
349 // Buffer.UpdateOverlay SR, PrimarySurface, DR, DDOVER_SHOW
351 FMark.RefreshMarker();
357 void DDScrollBuffer_Blt()
359 DDScrollBuffer_Blt_Ext(window);
362 void DDScrollBuffer_ScrollTo(int X, int Y)
375 printf("::: DDScrollBuffer.c: DDScrollBuffer_ScrollTo(): mScroll: %ld, %ld [%d, %d]\n",
376 mScrollX, mScrollY, X, Y);
380 void DDScrollBuffer_ScrollTowards(int X, int Y, double Step)
388 printf("::: DDScrollBuffer.c: DDScrollBuffer_ScrollTowards(): (1) mScroll: %ld, %ld [%d, %d, %f]\n",
389 mScrollX, mScrollY, X, Y, Step);
396 r = Sqr(dx * dx + dY * dY);
397 if (r == 0) // we are there already
405 mScrollX = mScrollX + dx * r;
406 mScrollY = mScrollY + dY * r;
411 printf("::: DDScrollBuffer.c: DDScrollBuffer_ScrollTowards(): (2) mScroll: %ld, %ld [%d, %d, %f]\n",
412 mScrollX, mScrollY, X, Y, Step);
416 void DDScrollBuffer_SoftScrollTo(int X, int Y, long TimeMS, int FPS)
420 TickCountObject Tick;
424 long oldX, oldY, maxD;
425 static boolean AlreadyRunning = False;
435 AlreadyRunning = True;
440 maxD = (Abs(dx) < Abs(dY) ? Abs(dY) : Abs(dx));
441 StepCount = FPS * (TimeMS / (double)1000);
442 if (StepCount > maxD)
449 tStep = (double)1 / StepCount;
452 // R = Sqr(dX * dX + dY * dY)
453 // If R = 0 Then Exit Sub 'we are there already
454 for (T = (double)tStep; T <= (double)1; T += tStep)
459 // If Claim Then Exit For
462 Tick.DelayMS(dT, False);
465 mScrollX = oldX + T * dx;
466 mScrollY = oldY + T * dY;
476 Tick.DelayMS(dT, False);
486 AlreadyRunning = False;
489 printf("::: DDScrollBuffer.c: DDScrollBuffer_SoftScrollTo(): mScroll: %ld, %ld\n",