Microsoft Small Basic

Program Listing: SJG122
' Generated by GetShapes Excel VBA Version 0.3
' Copyright © 2015 Nonki Takahashi. The MIT License.
' Last update 2015-11-02
'
WQ = Text.GetCharacter(34)
bg = "White"
GraphicsWindow.BackgroundColor = bg
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
' initialize shapes
Shapes_Init()
' add shapes
scale = 1
angle = 0
iMin = 1
iMax = 29
Shapes_Convert()
'Shapes_Dump()
Shapes_Add()
Sub Shapes_Dump
For i = iMin To iMax
TextWindow.WriteLine("shape[" + i + "]=" + WQ + shape[i] + WQ)
EndFor
EndSub
Sub Shapes_Init
' Shapes | Initialize shapes data
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 0 ' x offset
shY = 0 ' y offset
shape = ""
shape[1] = "func=ell;x=158;y=305;width=67;height=29;pw=6;pc=#000000;bc=#999900;name=Oval 34;"
shape[2] = "func=ell;x=157;y=238;width=67;height=29;pw=6;pc=#000000;bc=#999900;name=Oval 35;"
shape[3] = "func=ell;x=87;y=235;width=67;height=29;pw=6;pc=#000000;bc=#999900;name=Oval 36;"
shape[4] = "func=ell;x=90;y=305;width=67;height=29;pw=6;pc=#000000;bc=#999900;name=Oval 37;"
shape[5] = "func=ell;x=142;y=309;width=22;height=43;pw=6;pc=#000000;bc=#999900;name=Oval 38;"
shape[6] = "func=ell;x=115;y=177;width=82;height=60;pw=6;pc=#000000;bc=#339900;name=Oval 39;"
shape[7] = "func=ell;x=99;y=224;width=110;height=111;pw=6;pc=#000000;bc=#335323;name=Oval 40;"
shape[8] = "func=hex;x=133;y=256;width=43;height=49;ratio=0.25;angle=90;pw=6;pc=#338F05;bc=#AFEC00;name=Hexagon 41;"
shape[9] = "func=hex;x=162;y=231;width=27;height=36;ratio=0.25;angle=90;pw=6;pc=#338F05;bc=#AFEC00;name=Hexagon 42;"
shape[10] = "func=hex;x=119;y=233;width=27;height=33;ratio=0.25;angle=90;pw=6;pc=#338F05;bc=#AFEC00;name=Hexagon 43;"
shape[11] = "func=hex;x=121;y=295;width=25;height=33;ratio=0.25;angle=90;pw=6;pc=#338F05;bc=#AFEC00;name=Hexagon 44;"
shape[12] = "func=hex;x=161;y=296;width=25;height=33;ratio=0.25;angle=90;pw=6;pc=#338F05;bc=#AFEC00;name=Hexagon 45;"
shape[13] = "func=hex;x=176;y=272;width=32;height=18;ratio=0.25;angle=90;pw=6;pc=#338F05;bc=#AFEC00;name=Hexagon 46;"
shape[14] = "func=hex;x=100;y=271;width=32;height=20;ratio=0.25;angle=90;pw=6;pc=#338F05;bc=#AFEC00;name=Hexagon 47;"
shape[15] = "func=ell;x=171;y=200;width=12;height=11;angle=90;pw=0;bc=#000000;name=Oval 48;"
shape[16] = "func=ell;x=135;y=200;width=12;height=11;angle=90;pw=0;bc=#000000;name=Oval 49;"
shape[17] = "func=rect;x=299;y=167;width=152;height=170;pw=5;pc=#339966;bc=#FFFFFF;name=Rectangle 55;"
shape[18] = "func=trap;x=226;y=211;width=229;height=81;ratio=0.35448;angle=270;pw=0;bc=#339966;name=Trapezoid 56;"
shape[19] = "func=text;text=X;fn=Trebuchet MS;fs=96;fb=True;fi=False;x=304;y=191;width=72;height=119;pw=0;bc=#FFFFFF;name=TextBox 57;"
shape[20] = "func=rect;x=370;y=187;width=61;height=131;pw=1;pc=#339966;bc=#00FFFFFF;name=Rectangle 1;"
shape[21] = "func=line;x=390;y=187;x1=0;y1=0;x2=0;y2=130;pw=1;pc=#339966;bc=#000000;name=Straight Connector 3;"
shape[22] = "func=line;x=377;y=205;x1=0;y1=0;x2=53;y2=0;pw=1;pc=#339966;bc=#000000;name=Straight Connector 5;"
shape[23] = "func=line;x=377;y=223;x1=0;y1=0;x2=53;y2=0;pw=1;pc=#339966;bc=#000000;name=Straight Connector 29;"
shape[24] = "func=line;x=377;y=243;x1=0;y1=0;x2=53;y2=0;pw=1;pc=#339966;bc=#000000;name=Straight Connector 30;"
shape[25] = "func=line;x=378;y=262;x1=0;y1=0;x2=53;y2=0;pw=1;pc=#339966;bc=#000000;name=Straight Connector 31;"
shape[26] = "func=line;x=378;y=283;x1=0;y1=0;x2=53;y2=0;pw=1;pc=#339966;bc=#000000;name=Straight Connector 52;"
shape[27] = "func=line;x=377;y=301;x1=0;y1=0;x2=53;y2=0;pw=1;pc=#339966;bc=#000000;name=Straight Connector 53;"
shape[28] = "func=line;x=446;y=7;x1=0;y1=118;x2=136;y2=0;pw=5;pc=#FFC000;bc=#000000;name=Straight Connector 9;"
shape[29] = "func=text;text=GetShapes for Excel VBA;fn=Trebuchet MS;fs=40;fb=True;fi=False;x=45;y=31;width=478;height=54;pw=0;bc=#339966;name=TextBox 50;"
EndSub
Sub Math_CartesianToPolar
' Math | convert cartesian coodinate to polar coordinate
' param x, y - cartesian coordinate
' return r, a - polar coordinate
r = Math.SquareRoot(x * x + y * y)
If x = 0 And y > 0 Then
a = 90 ' [degree]
ElseIf x = 0 And y < 0 Then
a = -90
ElseIf x = 0 Then
a = 0
Else
a = Math.ArcTan(y / x) * 180 / Math.Pi
EndIf
If x < 0 Then
a = a + 180
ElseIf x > 0 And y < 0 Then
a = a + 360
EndIf
EndSub
Sub SB_RotateWorkaround
' Small Basic | Rotate workaround for Silverlight
' param shp - current shape
' param x, y - original coordinate
' param alpha - angle [radian]
' returns x, y - workaround coordinate
If shp["func"] = "tri" Then
x1 = -Math.Floor(shp["x3"] / 2)
y1 = -Math.Floor(shp["y3"] / 2)
ElseIf shp["func"] = "line" Then
x1 = -Math.Floor(Math.Abs(shp["x1"] - shp["x2"]) / 2)
y1 = -Math.Floor(Math.Abs(shp["y1"] - shp["y2"]) / 2)
EndIf
ox = x - x1
oy = y - y1
x = x1 * Math.Cos(alpha) - y1 * Math.Sin(alpha) + ox
y = x1 * Math.Sin(alpha) + y1 * Math.Cos(alpha) + oy
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
Sub Shapes_Add
' Shapes | add shapes as shapes data
' param iMin, iMax - shape indices to add
' param shape - array of shapes
' param scale - 1 if same scale
' return shWidth, shHeight - total size of shapes
' return shAngle - current angle of shapes
Stack.PushValue("local", i)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
Shapes_CalcWidthAndHeight()
s = scale
For i = iMin To iMax
shp = shape[i]
GraphicsWindow.PenWidth = shp["pw"] * s
If shp["pw"] > 0 Then
GraphicsWindow.PenColor = shp["pc"]
EndIf
If Text.IsSubText("rect|ell|tri|text", shp["func"]) Then
GraphicsWindow.BrushColor = shp["bc"]
EndIf
If shp["func"] = "rect" Then
shp["obj"] = Shapes.AddRectangle(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "ell" Then
shp["obj"] = Shapes.AddEllipse(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "tri" Then
shp["obj"] = Shapes.AddTriangle(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s, shp["x3"] * s, shp["y3"] * s)
ElseIf shp["func"] = "line" Then
shp["obj"] = Shapes.AddLine(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s)
ElseIf shp["func"] = "text" Then
If silverlight Then
fs = Math.Floor(shp["fs"] * 0.9)
Else
fs = shp["fs"]
EndIf
GraphicsWindow.FontSize = fs * s
GraphicsWindow.FontName = shp["fn"]
shp["obj"] = Shapes.AddText(shp["text"])
EndIf
x = shp["x"]
y = shp["y"]
shp["rx"] = x
shp["ry"] = y
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
alpha = Math.GetRadians(shp["angle"])
SB_RotateWorkaround()
shp["wx"] = x
shp["wy"] = y
EndIf
Shapes.Move(shp["obj"], shX + x * s, shY + y * s)
If Text.IsSubText("rect|ell|tri|line|text", shp["func"]) And (shp["angle"] <> 0) And (shp["angle"] <> "") Then
Shapes.Rotate(shp["obj"], shp["angle"])
EndIf
shape[i] = shp
EndFor
shAngle = 0
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub
Sub Shapes_Convert
' Shapes | Convert virtual function to function
' return iMax
For i = iMin To iMax
shp = shape[i]
If shp["func"] = "hex" Then
If shp["name"] = "" Then
shp["name"] = "Hexagon"
EndIf
For j = iMax To i + 1 Step -1
shape[j + 8] = shape[j]
EndFor
_x[1] = shp["x"] + shp["height"] * shp["ratio"]
_y[1] = shp["y"]
_x[2] = shp["x"] + shp["width"] - shp["height"] * shp["ratio"]
_y[2] = shp["y"]
_x[3] = shp["x"] + shp["width"]
_y[3] = shp["y"] + shp["height"] / 2
_x[4] = shp["x"] + shp["width"] - shp["height"] * shp["ratio"]
_y[4] = shp["y"] + shp["height"]
_x[5] = shp["x"] + shp["height"] * shp["ratio"]
_y[5] = shp["y"] + shp["height"]
_x[6] = shp["x"]
_y[6] = shp["y"] + shp["height"] / 2
For j = 1 To 6
_x[j] = Math.Floor(_x[j] * 100) / 100
_y[j] = Math.Floor(_y[j] * 100) / 100
EndFor
_width = _y[5] - _y[1]
_height = _x[1] - _x[6]
x = (_x[1] + _x[6]) / 2 - _width / 2
y = (_y[1] + _y[5]) / 2 - _height / 2
_x1 = _width / 2
_y2 = _height
_x3 = _width
_y3 = _height
angle = 270
If shp["angle"] <> 0 Then
Shapes_CalcRotateFill()
EndIf
shape[i] = "func=tri;x="+x+";y="+y+";x1="+_x1+";y1=0;x2=0;y2="+_y2+";x3="+_x3+";y3="+_y3+";pw=0;bc="+shp["bc"]+";angle="+angle+";name="+shp["name"]+";"
_width = _x[2] - _x[1]
_height = _y[5] - _y[1]
x = _x[1]
y = _y[1]
angle = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateFill()
EndIf
shape[i + 1] = "func=rect;x="+x+";y="+y+";width="+_width+";height="+_height+";pw=0;bc="+shp["bc"]+";angle="+angle+";name="+shp["name"]+";"
_width = _y[5] - _y[1]
_height = _x[1] - _x[6]
x = (_x[2] + _x[3]) / 2 - _width / 2
y = (_y[2] + _y[4]) / 2 - _height / 2
_x1 = _width / 2
_y2 = _height
_x3 = _width
_y3 = _height
angle = 90
If shp["angle"] <> 0 Then
Shapes_CalcRotateFill()
EndIf
shape[i + 2] = "func=tri;x="+x+";y="+y+";x1="+_x1+";y1=0;x2=0;y2="+_y2+";x3="+_x3+";y3="+_y3+";pw=0;bc="+shp["bc"]+";angle="+angle+";name="+shp["name"]+";"
x = _x[1]
y = _y[1] + shp["pw"] / 2
_width = _x[2] - _x[1]
_height = 0
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 3] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
_width = _x[3] - _x[2]
_height = _y[3] - _y[2]
_a = Math.ArcTan(_width/_height)
x = _x[2] - shp["pw"] / 2 * Math.Cos(_a)
y = _y[2] + shp["pw"] / 2 * Math.Sin(_a)
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 4] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
_width = _x[3] - _x[4]
_height = _y[4] - _y[3]
_a = Math.ArcTan(_width/_height)
x = _x[4] - shp["pw"] / 2 * Math.Cos(_a)
y = _y[3] - shp["pw"] / 2 * Math.Sin(_a)
_x1 = 0
_y1 = _height
_x2 = _width
_y2 = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 5] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
x = _x[5]
y = _y[5] - shp["pw"] / 2
_width = _x[4] - _x[5]
_height = 0
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 6] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
_width = _x[5] - _x[6]
_height = _y[5] - _y[6]
_a = Math.ArcTan(_width/_height)
x = _x[6] + shp["pw"] / 2 * Math.Cos(_a)
y = _y[6] - shp["pw"] / 2 * Math.Sin(_a)
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 7] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
_width = _x[1] - _x[6]
_height = _y[6] - _y[1]
_a = Math.ArcTan(_width/_height)
x = _x[6] + shp["pw"] / 2 * Math.Cos(_a)
y = _y[1] + shp["pw"] / 2 * Math.Sin(_a)
_x1 = 0
_y1 = _height
_x2 = _width
_y2 = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 8] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
iMax = iMax + 8
ElseIf shp["func"] = "trap" Then
If shp["name"] = "" Then
shp["name"] = "Trapezoid"
EndIf
For j = iMax To i + 1 Step -1
shape[j + 6] = shape[j]
EndFor
_x[1] = shp["x"] + shp["height"] * shp["ratio"]
_y[1] = shp["y"]
_x[2] = shp["x"] + shp["width"] - shp["height"] * shp["ratio"]
_y[2] = shp["y"]
_x[3] = shp["x"] + shp["width"]
_y[3] = shp["y"] + shp["height"]
_x[4] = shp["x"]
_y[4] = shp["y"] + shp["height"]
_width = (_x[1] - _x[4]) * 2
_height = _y[4] - _y[1]
x = _x[4]
y = _y[1]
_x1 = _width / 2
_y2 = _height
_x3 = _width
_y3 = _height
angle = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateFill()
EndIf
shape[i] = "func=tri;x="+x+";y="+y+";x1="+_x1+";y1=0;x2=0;y2="+_y2+";x3="+_x3+";y3="+_y3+";angle="+angle+";pw=0;bc="+shp["bc"]+";name="+shp["name"]+";"
_width = _x[2] - _x[1]
_height = _y[4] - _y[1]
x = _x[1]
y = _y[1]
angle = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateFill()
EndIf
shape[i + 1] = "func=rect;x="+x+";y="+y+";width="+_width+";height="+_height+";angle="+angle+";pw=0;bc="+shp["bc"]+";name="+shp["name"]+";"
_width = (_x[3] - _x[2]) * 2
_height = _y[3] - _y[2]
x = _x[2] - _width / 2
y = _y[2]
_x1 = _width / 2
_y2 = _height
_x3 = _width
_y3 = _height
angle = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateFill()
EndIf
shape[i + 2] = "func=tri;x="+x+";y="+y+";x1="+_x1+";y1=0;x2=0;y2="+_y2+";x3="+_x3+";y3="+_y3+";angle="+angle+";pw=0;bc="+shp["bc"]+";name="+shp["name"]+";"
_width = _x[2] - _x[1]
_height = _y[2] - _y[1]
x = _x[1]
y = _y[1] + shp["pw"] / 2
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 3] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
_width = _x[3] - _x[2]
_height = _y[3] - _y[2]
_a = Math.ArcTan(_width/_height)
x = _x[2] - shp["pw"] / 2 * Math.Cos(_a)
y = _y[2] + shp["pw"] / 2 * Math.Sin(_a)
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 4] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
x = _x[4]
y = _y[4] - shp["pw"] / 2
_width = _x[3] - _x[4]
_height = 0
_x1 = 0
_y1 = 0
_x2 = _width
_y2 = _height
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 5] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
_width = _x[1] - _x[4]
_height = _y[4] - _y[1]
_a = Math.ArcTan(_width/_height)
x = _x[4] + shp["pw"] / 2 * Math.Cos(_a)
y = _y[1] + shp["pw"] / 2 * Math.Sin(_a)
_x1 = 0
_y1 = _height
_x2 = _width
_y2 = 0
If shp["angle"] <> 0 Then
Shapes_CalcRotateLine()
EndIf
shape[i + 6] = "func=line;x="+x+";y="+y+";x1="+_x1+";y1="+_y1+";x2="+_x2+";y2="+_y2+";pw="+shp["pw"]+";pc="+shp["pc"]+";name="+shp["name"]+";"
iMax = iMax + 6
EndIf
EndFor
EndSub
Sub Shapes_CalcRotateFill
' Shapes | Calculate position for rotated fill shape
' param x, y - shape position
' param angle - shape angle
' param shp["angle"] - rotate angle
' param shp["x"], shp["y"] - for rotate center
' param shp["width"], shp["height"] - for rotate center
' return x, y - rotated shape position
' return angle - rotated shape angle
param["x"] = x
param["y"] = y
param["width"] = _width
param["height"] = _height
param["cx"] = shp["x"] + shp["width"] / 2
param["cy"] = shp["y"] + shp["height"] / 2
param["angle"] = shp["angle"]
Shapes_CalcRotatePos()
angle = Math.Remainder(angle + shp["angle"], 360)
EndSub
Sub Shapes_CalcRotateLine
' Shapes | Calculate position for rotated line
' param["x"], param["y"] - line position
' param["angle"] - rotate angle
' param _x1, _y1, _x2, _y2 - relative position of the first and second point of the line
' return x, y - rotated line position
' return _x1, _y1, _x2, _y2 - rotated position of the line
cx = shp["x"] + shp["width"] / 2
cy = shp["y"] + shp["height"] / 2
_a = Math.GetRadians(shp["angle"])
_rx1 = (_x1 + x - cx) * Math.Cos(_a) + (_y1 + y - cy) * Math.Sin(_a) + cx
_ry1 = -(_x1 + x - cx) * Math.Sin(_a) + (_y1 + y - cy) * Math.Cos(_a) + cy
_rx2 = (_x2 + x - cx) * Math.Cos(_a) + (_y2 + y - cy) * Math.Sin(_a) + cx
_ry2 = -(_x2 + x - cx) * Math.Sin(_a) + (_y2 + y - cy) * Math.Cos(_a) + cy
x = Math.Min(_rx1, _rx2)
y = Math.Min(_ry1, _ry2)
_x1 = _rx1 - x
_x2 = _rx2 - x
_y1 = _ry1 - y
_y2 = _ry2 - y
EndSub
Sub Shapes_CalcRotatePos
' Shapes | Calculate position for rotated shape
' param["x"], param["y"] - position of a shape
' param["width"], param["height"] - size of a shape
' param ["cx"], param["cy"] - center of rotation
' param ["angle"] - rotate angle
' return x, y - rotated position of a shape
_cx = param["x"] + param["width"] / 2
_cy = param["y"] + param["height"] / 2
x = _cx - param["cx"]
y = _cy - param["cy"]
Math_CartesianToPolar()
a = a + param["angle"]
x = r * Math.Cos(a * Math.Pi / 180)
y = r * Math.Sin(a * Math.Pi / 180)
_cx = x + param["cx"]
_cy = y + param["cy"]
x = _cx - param["width"] / 2
y = _cy - param["height"] / 2
EndSub
Sub Shapes_CalcWidthAndHeight
' Shapes | Calculate total width and height of shapes
' param iMin, iMax - shape indices to add
' return shWidth, shHeight - total size of shapes
For i = iMin To iMax
shp = shape[i]
If shp["func"] = "tri" Or shp["func"] = "line" Then
xmin = shp["x1"]
xmax = shp["x1"]
ymin = shp["y1"]
ymax = shp["y1"]
If shp["x2"] < xmin Then
xmin = shp["x2"]
EndIf
If xmax < shp["x2"] Then
xmax = shp["x2"]
EndIf
If shp["y2"] < ymin Then
ymin = shp["y2"]
EndIf
If ymax < shp["y2"] Then
ymax = shp["y2"]
EndIf
If shp["func"] = "tri" Then
If shp["x3"] < xmin Then
xmin = shp["x3"]
EndIf
If xmax < shp["x3"] Then
xmax = shp["x3"]
EndIf
If shp["y3"] < ymin Then
ymin = shp["y3"]
EndIf
If ymax < shp["y3"] Then
ymax = shp["y3"]
EndIf
EndIf
shp["width"] = xmax - xmin
shp["height"] = ymax - ymin
EndIf
If i = 1 Then
shWidth = shp["x"] + shp["width"]
shHeight = shp["y"] + shp["height"]
Else
If shWidth < shp["x"] + shp["width"] Then
shWidth = shp["x"] + shp["width"]
EndIf
If shHeight < shp["y"] + shp["height"] Then
shHeight = shp["y"] + shp["height"]
EndIf
EndIf
shape[i] = shp
EndFor
EndSub
Sub Shapes_Move
' Shapes | Move shapes
' param iMin, iMax - shape indices to add
' param shape - array of shapes
' param scale - to zoom
' param x, y - position to move
' return shX, shY - new position of shapes
Stack.PushValue("local", i)
s = scale
shX = x
shY = y
For i = iMin To iMax
shp = shape[i]
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
_x = shp["wx"]
_y = shp["wy"]
Else
_x = shp["rx"]
_y = shp["ry"]
EndIf
Shapes.Move(shp["obj"], shX + _x * s, shY + _y * s)
EndFor
i = Stack.PopValue("local")
EndSub
Sub Shapes_Remove
' Shapes | Remove shapes
' param iMin, iMax - shapes indices to remove
' param shape - array of shapes
Stack.PushValue("local", i)
For i = iMin To iMax
shp = shape[i]
Shapes.Remove(shp["obj"])
EndFor
i = Stack.PopValue("local")
EndSub
Sub Shapes_Rotate
' Shapes | Rotate shapes
' param iMin, iMax - shapes indices to rotate
' param shape - array of shapes
' param cx, cy - rotation center
' param scale - to zoom
' param angle - to rotate
' param forConv - "True" if for conversion
Stack.PushValue("local", i)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
s = scale
param["angle"] = angle
If cx <> "" Then
param["cx"] = cx
Else
cx = "" ' to avoid syntax error
param["cx"] = shWidth / 2
EndIf
If cy <> "" Then
param["cy"] = cy
Else
cy = "" ' to avoid syntax error
param["cy"] = shHeight / 2
EndIf
For i = iMin To iMax
shp = shape[i]
param["x"] = shp["x"]
param["y"] = shp["y"]
param["width"] = shp["width"]
param["height"] = shp["height"]
Shapes_CalcRotatePos()
shp["rx"] = x
shp["ry"] = y
If silverlight And Text.IsSubText("tri|line", shp["func"]) Then
alpha = Math.GetRadians(angle + shp["angle"])
SB_RotateWorkAround()
shp["wx"] = x
shp["wy"] = y
EndIf
Shapes.Move(shp["obj"], shX + x * s, shY + y * s)
Shapes.Rotate(shp["obj"], angle + shp["angle"])
shape[i] = shp
EndFor
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub