Microsoft Small Basic

Program Listing: TQN341-7
' Known Issue: 24270 - Shape Image is Not Zoomed from Center in Remote
' Copyright (c) Nonki Takahashi.
'
' Lisence:
' The MIT Lisence (MIT)
' http://en.wikipedia.org/wiki/MIT_License
'
' History:
' 0.44 2014-05-09 Added wait. (TQN341-7)
' 0.32 2014-05-02 Minor changed. (TQN341-3)
' 0.2 2014-05-02 Rewrote with Shapes.AddImage. (TQN341-0)
' 0.1 2014-05-02 Created. (TQN341)
'
SB_Workaround()
GraphicsWindow.Title = "Known Issue: 24270 - Shape Image is Not Zoomed from Center in Remote"
GraphicsWindow.FontName = "Verdana"
gw = 598
gh = 428
gap = 40
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
InitWorkaround()
While "True"
DrawGrid()
DrawRectangle()
DrawTurtle()
WaitStatusChange()
EndWhile
Sub DrawRectangle
GraphicsWindow.PenColor = "DimGray"
GraphicsWindow.BrushColor = "Lime"
x = 8 * gap
y = 3 * gap
width = 6 * gap
height = 6 * gap
pw = gap / 2
If silverlight Then
Program.Delay(msWait)
EndIf
GraphicsWindow.PenWidth = pw
If rect = "" Then
rect = Shapes.AddRectangle(width, height)
EndIf
If zoom Then
Shapes.Zoom(rect, 0.5, 0.5)
Else
Shapes.Zoom(rect, 1, 1)
EndIf
Shapes.Move(rect, x, y)
Shapes.SetOpacity(rect, 70)
EndSub
Sub DrawTurtle
x = gap
y = 3 * gap
width = 6 * gap
height = 6 * gap
pw = gap / 2
If silverlight Then
Program.Delay(msWait)
EndIf
GraphicsWindow.PenWidth = pw
If ttl = "" Then
url = "http://www.nonkit.com/smallbasic.files/"
ttl = Shapes.AddImage(url + "Turtle.png")
Else
Shapes.Remove(ttl)
ttl = Shapes.AddImage(url + "Turtle.png")
EndIf
If silverlight And workaround Then
Program.Delay(msWait)
EndIf
If zoom Then
scale = 0.5
Else
scale = 1
EndIf
Shapes.Zoom(ttl, scale, scale)
If "False" Then
Shapes.Move(ttl, x - (scale - 1) * width / 2, y - (scale - 1) * height / 2)
Else
Shapes.Move(ttl, x, y)
EndIf
Shapes.SetOpacity(ttl, 70)
EndSub
Sub WaitStatusChange
While lastWorkaround = workaround And lastzoom = zoom
param["checkBoxName"] = cboxW
Controls_IsChecked()
workaround = return
param["checkBoxName"] = cboxZ
Controls_IsChecked()
zoom = return
Program.Delay(200)
EndWhile
lastWorkaround = workaround
lastzoom = zoom
EndSub
Sub DrawGrid
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillRectangle(0, 0, gw, gh)
GraphicsWindow.PenColor = "Gray"
GraphicsWindow.PenWidth = 2
For x = gap To gw Step gap
GraphicsWindow.DrawLine(x, 0, x, gh)
EndFor
For y = gap To gh Step gap
GraphicsWindow.DrawLine(0, y, gw, y)
EndFor
EndSub
Sub InitWorkaround
GraphicsWindow.BrushColor = "Black"
zoom = "False"
lastzoom = "False"
param = "caption=Zoom x0.5;left=14;top=20;"
Controls_AddCheckBox()
cboxZ = return
workaround = "False"
lastWorkaround = "False"
param = "caption=Workaround;left=14;top=50;"
Controls_AddCheckBox()
cboxW = return
GraphicsWindow.MouseDown = OnMouseDown
EndSub
Sub Controls_AddCheckBox
' param["left"] - the x co-ordinate of the check box
' param["top"] - the y co-ordinate of the check box
' returns return - the check box that was just added to the Graphics Window.
cboxColor = GraphicsWindow.BrushColor
cboxSize = GraphicsWindow.FontSize
cboxFont = GraphicsWindow.FontName
cboxPW = GraphicsWindow.PenWidth
cboxPC = GraphicsWindow.PenColor
cboxNum = cboxNum + 1
cboxX0 = param["left"]
cboxX1 = cboxX0 + cboxSize + 1
cboxY0 = param["top"] + 1
cboxY1 = cboxY0 + cboxSize + 1
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "Gray"
GraphicsWindow.BrushColor = "White"
cboxRect = Shapes.AddRectangle(cboxSize, cboxSize)
GraphicsWindow.PenWidth = cboxPW
GraphicsWindow.PenColor = cboxPC
Shapes.Move(cboxRect, cboxX0, cboxY0)
cboxObj[cboxNum]["x0"] = cboxX0
cboxObj[cboxNum]["x1"] = cboxX1
cboxObj[cboxNum]["y0"] = cboxY0
cboxObj[cboxNum]["y1"] = cboxY1
GraphicsWindow.BrushColor = cboxColor
cboxMark = Shapes.AddText("x")
Shapes.Move(cboxMark, param["left"] + 2, param["top"] - 1)
Shapes.HideShape(cboxMark)
cboxObj[cboxNum]["checkmark"] = cboxMark
cboxObj[cboxNum]["checked"] = "False"
GraphicsWindow.FontName = cboxFont
cboxMark = Shapes.AddText(param["caption"])
Shapes.Move(cboxMark, param["left"] + cboxSize * 1.5 , param["top"])
return = "CheckBox" + cboxNum
EndSub
Sub OnMouseDown
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
For iCheckBox = 1 To cboxNum
x0 = cboxObj[iCheckBox]["x0"]
x1 = cboxObj[iCheckBox]["x1"]
y0 = cboxObj[iCheckBox]["y0"]
y1 = cboxObj[iCheckBox]["y1"]
If x0 <= mx And mx <= x1 And y0 <= my And my <= y1 Then
If cboxObj[iCheckBox]["checked"] Then
Shapes.HideShape(cboxObj[iCheckBox]["checkmark"])
cboxObj[iCheckBox]["checked"] = "false"
Else
Shapes.ShowShape(cboxObj[iCheckBox]["checkmark"])
cboxObj[iCheckBox]["checked"] = "true"
EndIf
EndIf
EndFor
EndSub
Sub Controls_IsChecked
' param["checkBoxName"] - check box name
' return - "True" if checked
iCheckBox = Text.GetSubTextToEnd(param["checkBoxName"], 9)
return = cboxObj[iCheckBox]["checked"]
EndSub
Sub SB_Workaround
' Small Basic | Workaround for Silverlight
' returns silverlight - "True" if in remote
color = GraphicsWindow.GetPixel(0, 0)
If Text.GetLength(color) > 7 Then
silverlight = "True"
msWait = 300
Else
silverlight = "False"
EndIf
EndSub