Microsoft Small Basic

Program Listing: CBF139-0
' Polyline Editor
' Copyright © 2014 Nonki Takahashi. The MIT License.
' Version 0.2a
' Last update 2014-11-20
' Program ID CBF139-0
'
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.Title = "Polyline Editor 0.2a"
GraphicsWindow.BackgroundColor = "LightGray"
fw = 550
fh = 340
x0 = (gw - fw) / 2
y0 = (gh - fh) / 2 + 32
x1 = x0 + fw - 1
y1 = y0 + fh - 1
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(x0, y0, fw, fh)
nPos = 0
pw = 2
pc = "#000000"
GraphicsWindow.PenWidth = pw
GraphicsWindow.PenColor = pc
GraphicsWindow.BrushColor = pc
fname = Controls.AddTextBox(x0, 10)
bNew = Controls.AddButton("New", x0, 40)
bOpen = Controls.AddButton("Open", x0 + 46, 40)
bSave = Controls.AddButton("Save", x0 + 97, 40)
output = Controls.AddMultiLineTextBox(gw / 2 - 100, 10)
Controls.SetSize(output, fw / 2 + 100, 54)
header = "" + CRLF
header = header + " footer = footer + " style='fill:none;stroke:" + Text.ConvertToLowerCase(pc) + ";stroke-width:" + pw + "' />" + CRLF
footer = footer + ""
mouseDown = "False"
mouseUp = "False"
mouseMove = "False"
buttonClicked = "False"
GraphicsWindow.MouseDown = OnMouseDown
GraphicsWindow.MouseUp = OnMouseUp
GraphicsWindow.MouseMove = OnMouseMove
Controls.ButtonClicked = OnButtonClicked
While "True"
If buttonClicked Then
If button = bNew Then
New()
ElseIf button = bOpen Then
Open()
ElseIf button = bSave Then
Save()
EndIf
buttonClicked = "False"
ElseIf mouseDown Then
If x0 <= dx And dx <= x1 And y0 <= dy And dy <= y1 Then
nPos = nPos + 1
pos["n"] = nPos
pos["x"] = dx - x0
pos["y"] = dy - y0
polyline[nPos] = pos
If nPos = 1 Then
shape[nPos] = Shapes.AddRectangle(pw, pw)
Shapes.Move(shape[nPos], dx, dy)
Else
body = body + " "
posLast = polyline[nPos - 1]
shape[nPos] = Shapes.AddLine(posLast["x"] + x0, posLast["y"] + y0, dx, dy)
EndIf
body = body + pos["x"] + "," + pos["y"]
Controls.SetTextBoxText(output, header + body + footer)
EndIf
mouseDown = "False"
ElseIf mouseUp Then
mouseUp = "False"
ElseIf mouseMove Then
mouseMove = "False"
Else
Program.Delay(300)
EndIf
EndWhile
Sub OnButtonClicked
button = Controls.LastClickedButton
buttonClicked = "True"
EndSub
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
Sub New
For i = 1 To nPos
Shapes.Remove(shape[i])
EndFor
shape = ""
Controls.SetTextBoxText(fname, "")
Controls.SetTextBoxText(output, "")
nPos = 0
polyline = ""
body = ""
EndSub
Sub Open
EndSub
Sub Save
EndSub