Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Draw
IDC_Erase
IDC_Graphic
End Enum
Global hDlg,hGraphicDC,hDC,hBMP,hBMPMask,hDCMask As Dword, imgW, imgH As Long
Global Sprite(), Screen(), SpriteX, SpriteY As Long, SpriteString$, GraphicString$
Function PBMain() As Long
Dialog New Pixels, 0, "Sprite Test",300,300,200,100, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Draw,"Draw", 10,10,60,20
Control Add Button, hDlg, %IDC_Erase,"Erase", 80,10,60,20
Control Add Graphic, hDlg, %IDC_Graphic, "", 0,40,200,100
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local x,y,iColor As Long
Select Case Cb.Msg
Case %WM_InitDialog
SpriteX = 50 : SpriteY = 10
'sprite
Graphic Bitmap Load "images\spriteb.bmp", 0, 0 To hBMP
Graphic Attach hBMP, 0
Graphic Get Canvas To imgW, imgH
Graphic Get DC To hDC
Graphic Get Bits To SpriteString$
ReDim Sprite(imgW-1,imgH-1) As Long At StrPtr(SpriteString$) + 8
'main graphic
Graphic Attach hDlg, %IDC_Graphic, ReDraw
Graphic Get DC To hGraphicDC
Graphic Color %Black, %White
Graphic Clear
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Draw
Graphic Line (10,20)-(100,20), %Red
TransparentBlt hGraphicDC,SpriteX, SpriteY,imgW,imgH,hDC,0,0,imgW,imgH,%Black
Graphic Get Bits To GraphicString$
ReDim Screen(200-1,100-1) As Long At StrPtr(GraphicString$) + 8
Graphic ReDraw
Case %IDC_Erase
For y = 0 To imgH-1
For x = 0 To imgW-1
If Sprite(x,y) <> Bgr(%Black) Then Screen(x+SpriteX,y+SpriteY) = Bgr(%White)
Next x
Next y
Graphic Set Bits GraphicString$
Graphic ReDraw
End Select
End Select
End Function
'gbs_01422
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm