Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe "tiled.exe"
#Dim All
%Unicode = 1
#Include "Win32API.inc"
#Resource Bitmap tile "tile.bmp"
Enum Equates Singular
IDC_Graphic = 500
IDC_Up
IDC_Down
IDC_Left
IDC_Right
IDC_DiagUpLeft
IDC_DiagDownRight
ID_Timer
End Enum
Global hDlg,hBMP As Dword, imgW, imgH, ddx, ddy As Long
Function PBMain() As Long
Dialog New Pixels, 0, "Continuous Tile Scrolling",300,300,600,600, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Up, "Up", 10,10,50,20
Control Add Button, hDlg, %IDC_Down, "Down", 80,10,50,20
Control Add Button, hDlg, %IDC_Left, "Left", 150,10,50,20
Control Add Button, hDlg, %IDC_Right, "Right", 220,10,50,20
Control Add Button, hDlg, %IDC_DiagUpLeft, "DiagUpLeft", 290,10,70,20
Control Add Button, hDlg, %IDC_DiagDownRight, "DiagDownRight", 380,10,90,20
Control Add Graphic, hDlg, %IDC_Graphic,"",0,40,300,300, %WS_Border
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long
Select Case Cb.Msg
Case %WM_InitDialog
'load the *.bmp image to a memory bitmap
Graphic Bitmap Load "tile", 0,0 To hBMP
Graphic Attach hBMP, 0
Graphic Get Canvas To imgW,imgH
Graphic Attach hDlg, %IDC_Graphic, ReDraw
Graphic Color %rgb_LightBlue, %rgb_LightBlue
SetTimer hDlg, %ID_Timer, 50, 0
Case %WM_Destroy
KillTimer hDlg, %ID_Timer
Case %WM_Timer
ScrollImage
Graphic ReDraw
Case %WM_Size
Dialog Get Client hDlg To w,h
Control Set Client hDlg, %IDC_Graphic, w,h
ScrollImage
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Up : ddx = 0 : ddy = 1
Case %IDC_Left : ddx = 1 : ddy = 0
Case %IDC_DiagUpLeft : ddx = 1 : ddy = 1
Case %IDC_Down : ddx = 0 : ddy = -1
Case %IDC_Right : ddx = -1 : ddy = 0
Case %IDC_DiagDownRight : ddx = -1 : ddy = -1
End Select
End Select
End Function
Sub ScrollImage
Local i,j,canvasW,canvasH,imgCountX,imgCountY,x0,y0,xNew,yNew As Long
Static imgX,imgY As Long
'grid size
Graphic Get Canvas To CanvasW, CanvasH
imgCountX = CanvasW\imgW + 2 : imgCountY = CanvasH\imgH + 2 'grid size
'starting position of image grid (xNew,yNew)
x0 = imgX Mod imgW : y0 = imgY Mod imgH 'x0,y0 is position within image
x0 = IIf(imgX > 0, 0, -imgW) - x0 : y0 = IIf(imgY > 0, 0, -imgH) - y0 'x0,y0 is position within image
'create grid of images
xNew = x0 : yNew = y0 '(xNew,yNew) is position of each new grid element to display
For j = 1 To imgCountY 'column of images
For i = 1 To imgCountX 'row of images
Graphic Copy hBMP, 0, (0,0)-(imgW-1,imgH-1) To (xNew,yNew) 'copy whole image to xNew,yNew
xNew += imgW
Next i
xNew = x0 : yNew += imgH
Next j
'scroll for next frame
imgX += ddx : imgY += ddy
End Sub
'gbs_01426
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm