Microsoft Small Basic

Program Listing: KTR748-3
' Small Basic Known Issue - Scaled Shapes Move (Desktop vs Silverlight)
' Copyright © 2018 Nonki Takahashi. The MIT License.
' Program ID KTR748-3

GraphicsWindow.Title = "Known Issue - Scaled Shapes Move"
Not = "False=True;True=False;"
SB_Workaround()
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontSize = 20
txt = Shapes.AddText("Workaround Off")
Shapes.Move(txt, 10, 10)
workaround = "False"
GraphicsWindow.MouseDown = OnMouseDown
w = 100
h = 80
GraphicsWindow.PenColor = "Gray"
GraphicsWindow.DrawLine(0, (gh - h) / 2, gw, (gh - h) / 2)
GraphicsWindow.DrawLine(0, gh / 2, gw, gh / 2)
GraphicsWindow.DrawLine(0, (gh + h) / 2, gw, (gh + h) / 2)
x[1] = 20 + (((gw - 40) / 3) - w) / 2
GraphicsWindow.DrawLine(x[1], 0, x[1], gh)
x[2] = x[1] + (gw - 40) / 3
GraphicsWindow.DrawLine(x[2], 0, x[2], gh)
x[3] = x[2] + (gw - 40) / 3
GraphicsWindow.DrawLine(x[3], 0, x[3], gh)
GraphicsWindow.PenColor = "Red"
For i = 1 To 3
d1[i] = Shapes.AddLine(-5, -5, 5, 5)
d2[i] = Shapes.AddLine(-5, 5, 5, -5)
EndFor
GraphicsWindow.PenColor = "Black"
GraphicsWindow.BrushColor = "Orange"
shp[1] = Shapes.AddEllipse(w, h)
y = (gh - h) / 2
Shapes.Move(shp[1], x[1], y)
Shapes.Move(d1[1], x[1], y)
Shapes.Move(d2[1], x[1], y)
GraphicsWindow.BrushColor = "DeepSkyBlue"
shp[2] = Shapes.AddRectangle(w, h)
Shapes.Move(shp[2], x[2], y)
Shapes.Move(d1[2], x[2], y)
Shapes.Move(d2[2], x[2], y)
GraphicsWindow.BrushColor = "YellowGreen"
shp[3] = Shapes.AddTriangle(0, h / 2, w, 0, w, h)
Shapes.Move(shp[3], x[3], y)
Shapes.Move(d1[3], x[3], y)
Shapes.Move(d2[3], x[3], y)
scaleX = 0.5
scaleY = 1.5
While "True"
Program.Delay(2000)
' Scale and Move
For i = 1 To 3
Shapes.Zoom(shp[i], scaleX, scaleY)
If workaround And silverlight And (i = 3) Then
_x = x[i]
_y = y + (1 - scaleY) * h / 2
Else
_x = x[i] + (scaleX - 1) * w / 2
_y = y
EndIf
Shapes.Move(shp[i], _x, _y)
Shapes.Move(d1[i], _x, _y)
Shapes.Move(d2[i], _x, _y)
EndFor
Program.Delay(2000)
' Original Position
For i = 1 To 3
Shapes.Zoom(shp[i], 1, 1)
_x = x[i]
_y = y
Shapes.Move(shp[i], _x, _y)
Shapes.Move(d1[i], _x, _y)
Shapes.Move(d2[i], _x, _y)
EndFor
EndWhile

Sub OnMouseDown
workaround = Not[workaround]
If workaround Then
Shapes.SetText(txt, "Workaround On")
Else
Shapes.SetText(txt, "Workaround Off")
EndIf
EndSub

Sub SB_Workaround
bc = GraphicsWindow.BrushColor
If 7 < Text.GetLength(bc) Then
silverlight = "True"
Else
silverlight = "False"
EndIf
EndSub