Drawing Pad Sample Program
' Just a simple drawing application
' Select a color on the toolbar and draw a picture
' click Save to save your job as a PNG file
' Click Open to open a previously saved PNG image
Program "Drawing Pad" icon "paint.png"
use "..\common\toolbar.bas"
$radius = 20
$buttonSize = 96
$color = "white"
SetLineWidth($radius * 2)
$buttons[1].color = "white"
$buttons[2].color = "black"
$buttons[3].color = "red"
$buttons[4].color = "green"
$buttons[5].color = "blue"
$buttons[6].color = "yellow"
$colorButtonsMax = 6
$newButtonNum = 7
$saveButtonNum = 8
$openButtonNum = 9
$buttons[$newButtonNum].image = #"new.png"
$buttons[$saveButtonNum].image = #"save.png"
$buttons[$openButtonNum].image = #"open.png"
function PrepareButtons()
ToolBar_SetButtons($buttons)
ToolBar_SetButtonSize($buttonSize)
end function
function OnMouseDrag(x, y)
if ToolBar_OnMouseDrag(x, y)
exit function
end if
if not $drawing
exit function
end if
SetColor($color)
DrawLine($lastX, $lastY, x, y)
DrawCircle(x, y, $radius)
$lastX = x
$lastY = y
ToolBar_Draw()
end function
function OnMouseDown(x, y)
if ToolBar_OnMouseDown(x, y)
exit function
end if
$drawing = 1
SetColor($color)
DrawCircle(x, y, $radius)
$lastX = x
$lastY = y
ToolBar_Draw()
end function
function ToolBar_OnButtonClick(i)
if i <= $colorButtonsMax
$color = $buttons[i].color
elseif i = $newButtonNum
ClearScreen()
elseif i = $saveButtonNum
image = Screenshot(0, ToolBar_GetHeight(), GetMaxWidth(), GetMaxHeight())
SaveFile(image, "png")
elseif i = $openButtonNum
image = OpenFile("png")
if IsImage(image)
ClearScreen()
DrawImage(0, ToolBar_GetHeight(), image)
end if
end if
end function
PrepareButtons()
ToolBar_Draw()