Microsoft Small Basic

Program Listing:
Embed this in your website
' Radio Button 0.1
' Copyright (c) 2013 Nonki Takahashi. All rights reserved.
'
' History:
' 0.1 2013-12-10 Created. ()
'
SB_Workaround()
Not = "False=True;True=False;"
gw = 624
gh = 443
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.Title = "Radio Button 0.1"
InitRadioButtons()
x = 150
y = 50
width = 300
height = 300
While "True"
  Clear()
  If selected = radioCircle Then
    GraphicsWindow.BrushColor = "Gold"
    GraphicsWindow.FillEllipse(x, y, width, height)
  ElseIf selected = radioRect Then
    GraphicsWindow.BrushColor = "Green"
    GraphicsWindow.FillRectangle(x, y, width, height)
  ElseIf selected = radioTri Then
    GraphicsWindow.BrushColor = "Red"
    GraphicsWindow.FillTriangle(x, y + height, x + width / 2, y, x + width, y + height)
  EndIf
  DrawGrid()
  WaitStatusChange()
EndWhile
end:
Sub WaitStatusChange
  While lastSelected = selected
    Control_GetSelectedRadioButton()
    selected = return
    Program.Delay(200)
  EndWhile
  lastSelected = selected
EndSub
Sub Clear
  GraphicsWindow.BrushColor = "LightGray"
  GraphicsWindow.FillRectangle(0, 0, gw, gh)
EndSub
Sub DrawGrid
  GraphicsWindow.PenColor = "Gray"
  If silverlight Then
    Program.Delay(msWait)
  EndIf
  GraphicsWindow.PenWidth = 2
  For _x = 100 To gw Step 100
    GraphicsWindow.DrawLine(_x, 0, _x, gh)
  EndFor
  For _y = 100 To gh Step 100
    GraphicsWindow.DrawLine(0, _y, gw, _y)
  EndFor
EndSub
Sub InitRadioButtons
  GraphicsWindow.BrushColor = "Black"
  param = "caption=Circle;left=30;top=40;"
  Control_AddRadioButton()
  radioCircle = return
  param = "caption=Rectangle;left=30;top=60;"
  Control_AddRadioButton()
  radioRect = return
  param = "caption=Triangle;left=30;top=80;"
  Control_AddRadioButton()
  radioTri = return
  selected = radioCircle
  lastSelected = selected
  GraphicsWindow.MouseDown = OnMouseDown
EndSub
Sub Control_AddRadioButton
  ' Control | Add Radio Button
  ' param["left"] - the x co-ordinate of the radio button
  ' param["top"] - the y co-ordinate of the radio button
  ' param["caption"] - caption for the radio button
  ' returns return - the radio button that was just added to the Graphics Window.
  radioColor = GraphicsWindow.BrushColor
  radioSize = GraphicsWindow.FontSize
  radioFont = GraphicsWindow.FontName
  radioPW = GraphicsWindow.PenWidth
  radioPC = GraphicsWindow.PenColor
  radioNum = radioNum + 1
  radioX0 = param["left"]
  radioX1 = radioX0 + radioSize + 1
  radioY0 = param["top"] + 1
  radioY1 = radioY0 + radioSize + 1
  GraphicsWindow.PenWidth = 1
  GraphicsWindow.PenColor = "Gray"
  GraphicsWindow.BrushColor = "White"
  radioButton = Shapes.AddEllipse(radioSize, radioSize)
  GraphicsWindow.PenColor = radioPC
  Shapes.Move(radioButton, radioX0, radioY0)
  radioObj[radioNum]["x0"] = radioX0
  radioObj[radioNum]["x1"] = radioX1
  radioObj[radioNum]["y0"] = radioY0
  radioObj[radioNum]["y1"] = radioY1
  GraphicsWindow.BrushColor = "CadetBlue"
  GraphicsWindow.PenWidth = 0
  radioMark = Shapes.AddEllipse(radioSize / 2, radioSize / 2)
  GraphicsWindow.PenWidth = radioPW
  Shapes.Move(radioMark, radioX0 + radioSize / 4, radioY0 + radioSize / 4)
  radioObj[radioNum]["mark"] = radioMark
  If radioNum = 1 Then
    radioObj[radioNum]["selected"] = "True"
  Else
    Shapes.HideShape(radioMark)
    radioObj[radioNum]["selected"] = "False"
  EndIf
  GraphicsWindow.FontName = radioFont
  GraphicsWindow.BrushColor = radioColor
  radioMark = Shapes.AddText(param["caption"])
  Shapes.Move(radioMark, param["left"] + radioSize * 1.5 , param["top"])
  return = "RadioButton" + radioNum
EndSub
Sub OnMouseDown
  mx = GraphicsWindow.MouseX
  my = GraphicsWindow.MouseY
  For iRadioButton = 1 To radioNum
    x0 = radioObj[iRadioButton]["x0"]
    x1 = radioObj[iRadioButton]["x1"]
    y0 = radioObj[iRadioButton]["y0"]
    y1 = radioObj[iRadioButton]["y1"]
    If x0 <= mx And mx <= x1 And y0 <= my And my <= y1 Then
      If Not[radioObj[iRadioButton]["selected"]] Then
        For i = 1 To radioNum
          If i = iRadioButton Then
            Shapes.ShowShape(radioObj[i]["mark"])
            radioObj[i]["selected"] = "True"
          Else
            Shapes.HideShape(radioObj[i]["mark"])
            radioObj[i]["selected"] = "False"
          EndIf
        EndFor
      EndIf
    EndIf
  EndFor
EndSub
Sub Control_GetSelectedRadioButton
  ' Control | Get Selected Radio Button
  ' return - selected radio button
  For iRadioButton = 1 To radioNum
    If radioObj[iRadioButton]["selected"] Then
      return = "RadioButton" + iRadioButton
      Goto cgsr_return
    EndIf
  EndFor
  cgsr_return:
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
Copyright (c) Microsoft Corporation. All rights reserved.