Date: 02-16-2022
Return to Index
created by gbSnippets
'This approach to gradient file simply draws lines to fill in an area.
'It's not fast, but is fairly simple. Check out other snippets for
'API-based gradient fill methods.
'Primary Code:
'Example#1: lines displayed as they are drawn (No bufferring)
Graphic Attach hDlg, 200
For y& = 0 To gWidth&
Graphic Line (0, y&) - (gWidth&, y&), Rgb(0, 0, y&)
Next
'Example#2: faster - lines bufferred (not drawn until Graphic Redraw statement)
Graphic Attach hDlg, 200, Redraw
For y& = 0 To gWidth&
Graphic Line (0, y&) - (gWidth&, y&), Rgb(0, 0, y&)
Next
Graphic Redraw
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10 (using buffered approach)
#Compile EXE
#Dim All
%Unicode=1
Global hDlg as Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Gradient Fill",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, 500,"", 0,0,200,200, %WS_Visible
Control Add Button, hDlg, 100,"Top to Bottom", 50,10,100,20
Control Add Button, hDlg, 200,"Bottom to Top", 50,40,100,20
Control Add Button, hDlg, 300,"Left to Right", 50,70,100,20
Control Add Button, hDlg, 400,"Right to Left", 50,100,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Dim x&, y&
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Graphic Attach hDlg, 500, Redraw
For y& = 0 To 200 : Graphic Line (0, y&) - (200, y&), Rgb(0, 0, y&) : Next
Dialog Redraw hDlg 'to make the button show through
End If
If CB.Msg = %WM_Command AND CB.Ctl = 200 AND CB.Ctlmsg = %BN_Clicked Then
Graphic Attach hDlg, 500, Redraw
For y& = 0 To 200 : Graphic Line (0, y&) - (200, y&), Rgb(0, 0, 200-y&) : Next
Dialog Redraw hDlg 'to make the button show through
End If
If CB.Msg = %WM_Command AND CB.Ctl = 300 AND CB.Ctlmsg = %BN_Clicked Then
Graphic Attach hDlg, 500, Redraw
For x& = 0 To 200 : Graphic Line (x&,0) - (x&,200), Rgb(0, 0, x&) : Next
Dialog Redraw hDlg 'to make the button show through
End If
If CB.Msg = %WM_Command AND CB.Ctl = 400 AND CB.Ctlmsg = %BN_Clicked Then
Graphic Attach hDlg, 500, Redraw
For x& = 0 To 200 : Graphic Line (x&,0) - (x&,200), Rgb(0, 0, 200-x&) : Next
Dialog Redraw hDlg 'to make the button show through
End If
End Function
'gbs_00169
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm