Microsoft Small Basic

Program Listing: CBF139
' Polyline Editor
' Copyright © 2014 Nonki Takahashi. The MIT License.
' Version 0.1a
' Last update 2014-11-16
'
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.Title = "Polyline Editor 0.1a"
GraphicsWindow.BackgroundColor = "LightGray"
fw = 550
fh = 340
x0 = (gw - fw) / 2
y0 = (gh - fh) / 2 + 20
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(x0, y0, fw, fh)
nPos = 0
pw = 2
pc = "#000000"
GraphicsWindow.PenWidth = 2
GraphicsWindow.PenColor = pc
GraphicsWindow.BrushColor = pc
GraphicsWindow.MouseDown = OnMouseDown
GraphicsWindow.MouseUp = OnMouseUp
GraphicsWindow.MouseMove = OnMouseMove
While "True"
If mouseDown Then
pos["x"] = dx
pos["y"] = dy
nPos = nPos + 1
polyline[nPos] = pos
If nPos = 1 Then
GraphicsWindow.FillRectangle(dx, dy, pw, pw)
Else
posLast = polyline[nPos - 1]
GraphicsWindow.DrawLine(posLast["x"], posLast["y"], dx, dy)
EndIf
mouseDown = "False"
ElseIf mouseUp Then
mouseUp = "False"
ElseIf mouseMove Then
mouseMove = "False"
Else
Program.Delay(300)
EndIf
EndWhile
Sub OnMouseDown
dx = GraphicsWindow.MouseX
dy = GraphicsWindow.MouseY
mouseDown = "True"
EndSub
Sub OnMouseUp
ux = GraphicsWindow.MouseX
uy = GraphicsWindow.MouseY
mouseUp = "True"
EndSub
Sub OnMouseMove
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
mouseMove = "True"
EndSub