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
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
'sprite
Graphic Bitmap Load "images\sprite.bmp", 0, 0 To hBMP
Graphic Attach hBMP, 0
Graphic Get Canvas To imgW, imgH
Graphic Get DC To hDC
'sprite Mask
Graphic Bitmap Load "images\sprite.bmp", 0, 0 To hBMPMask
Graphic Attach hBMPMask,0
Graphic Get DC To hDCMask
For y = 0 To imgH-1
For x = 0 To imgW-1
Graphic Get Pixel (x,y) To iColor
If iColor <> %Black Then Graphic Set Pixel (x,y), %White 'white is bg color
Next x
Next y
'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,50,10,imgW,imgH,hDC,0,0,imgW,imgH,%Black
Graphic ReDraw
Case %IDC_Erase
TransparentBlt hGraphicDC,50,10,imgW,imgH,hDCMask,0,0,imgW,imgH,%Black
Graphic ReDraw
End Select
End Select
End Function
'gbs_01421
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm