Sub GetClickedPoint
clicked = "False"
GraphicsWindow.MouseDown = OnMouseDown
GraphicsWindow.MouseUp = DoNothing
While clicked = "False"
Program.Delay(100)
EndWhile
x0 = mx
y0 = my
x1 = mx
y1 = my
EndSub
Sub GetReleasedPoint ' for sizing a shape
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "Black"
GraphicsWindow.BrushColor = "White"
GraphicsWindow.MouseMove = OnMouseMove
released = "False"
While released = "False"
If moved Then
GraphicsWindow.MouseMove = DoNothing
x1 = mx
y1 = my
If func = "rect" Then
If oRect <> "" Then
Shapes.Remove(oRect)
EndIf
xmin = Math.Min(x0, x1)
ymin = Math.Min(y0, y1)
xmax = Math.Max(x0, x1)
ymax = Math.Max(y0, y1)
oRect = Shapes.AddRectangle(xmax - xmin, ymax - ymin)
Shapes.Move(oRect, xmin, ymin)
Shapes.SetOpacity(oRect, 50)
ElseIf func = "ell" Then
If oEll <> "" Then
Shapes.Remove(oEll)
EndIf
xmin = Math.Min(x0, x1)
ymin = Math.Min(y0, y1)
xmax = Math.Max(x0, x1)
ymax = Math.Max(y0, y1)
oEll = Shapes.AddEllipse(xmax - xmin, ymax - ymin)
Shapes.Move(oEll, xmin, ymin)
Shapes.SetOpacity(oEll, 50)
ElseIf func = "tri" Then
If oTri <> "" Then
Shapes.Remove(oTri)
EndIf
oTri = Shapes.AddTriangle((x1 - x0) / 2, 0, 0, y1 - y0, x1 - x0, y1 - y0)
Shapes.Move(oTri, x0, y0)
Shapes.SetOpacity(oTri, 50)
ElseIf func = "line" Then
If oLine <> "" Then
Shapes.Remove(oLine)
EndIf
oLine = Shapes.AddLine(x0, y0, x1, y1)
Shapes.SetOpacity(oLine, 50)
EndIf
moved = "False"
GraphicsWindow.MouseMove = OnMouseMove
Else
Program.Delay(100)
EndIf
EndWhile
GraphicsWindow.MouseMove = DoNothing
If oRect <> "" Then
Shapes.Remove(oRect)
oRect = ""
EndIf
If oEll <> "" Then
Shapes.Remove(oEll)
oEll = ""
EndIf
If oTri <> "" Then
Shapes.Remove(oTri)
oTri = ""
EndIf
If oLine <> "" Then
Shapes.Remove(oLine)
oLine = ""
EndIf
EndSub
Sub GetReleasedPoint2 ' for moving a shape
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "Black"
GraphicsWindow.BrushColor = "White"
GraphicsWindow.MouseMove = OnMouseMove
released = "False"
_x = shape[i]["x"]
_y = shape[i]["y"]
While released = "False"
If moved Then
GraphicsWindow.MouseMove = DoNothing
x1 = mx
y1 = my
_x = shape[i]["x"] + x1 - x0
_y = shape[i]["y"] + y1 - y0
If func = "rect" Then
If oRect = "" Then
oRect = Shapes.AddRectangle(shape[i]["width"], shape[i]["height"])
Shapes.SetOpacity(oRect, 50)
EndIf
Shapes.Move(oRect, _x, _y)
ElseIf func = "ell" Then
If oEll = "" Then
oEll = Shapes.AddEllipse(shape[i]["width"], shape[i]["height"])
Shapes.SetOpacity(oEll, 50)
EndIf
Shapes.Move(oEll, _x, _y)
ElseIf func = "tri" Then
If oTri = "" Then
_x1 = shape[i]["x1"]
_y1 = shape[i]["y1"]
_x2 = shape[i]["x2"]
_y2 = shape[i]["y2"]
_x3 = shape[i]["x3"]
_y3 = shape[i]["y3"]
oTri = Shapes.AddTriangle(_x1, _y1, _x2, _y2, _x3, _y3)
Shapes.SetOpacity(oTri, 50)
EndIf
Shapes.Move(oTri, _x, _y)
ElseIf func = "line" Then
If oLine = "" Then
_x1 = shape[i]["x1"]
_y1 = shape[i]["y1"]
_x2 = shape[i]["x2"]
_y2 = shape[i]["y2"]
oLine = Shapes.AddLine(_x1, _y1, _x2, _y2)
Shapes.SetOpacity(oLine, 50)
EndIf
Shapes.Move(oLine, _x, _y)
EndIf
moved = "False"
GraphicsWindow.MouseMove = OnMouseMove
Else
Program.Delay(100)
EndIf
EndWhile
GraphicsWindow.MouseMove = DoNothing
shape[i]["x"] = _x
shape[i]["y"] = _y
Shapes.Move(shape[i]["obj"], _x, _y)
If shape[i]["func"] = "line" Then
_x1 = shape[i]["x"] + shape[i]["x1"] - size / 2
_y1 = shape[i]["y"] + shape[i]["y1"] - size / 2
_x2 = shape[i]["x"] + shape[i]["x2"] - size / 2
_y2 = shape[i]["y"] + shape[i]["y2"] - size / 2
Shapes.Move(oEll1, _x1, _y1)
Shapes.Move(oEll2, _x2, _y2)
Else
_x1 = shape[i]["x"] - size / 2
_y1 = shape[i]["y"] - size / 2
_x2 = shape[i]["x"] + shape[i]["width"] - size / 2
_y2 = shape[i]["y"] + shape[i]["height"] - size / 2
Shapes.Move(oEll1, _x1, _y1)
Shapes.Move(oEll2, _x2, _y1)
Shapes.Move(oEll3, _x1, _y2)
Shapes.Move(oEll4, _x2, _y2)
EndIf
If oRect <> "" Then
Shapes.Remove(oRect)
oRect = ""
EndIf
If oEll <> "" Then
Shapes.Remove(oEll)
oEll = ""
EndIf
If oTri <> "" Then
Shapes.Remove(oTri)
oTri = ""
EndIf
If oLine <> "" Then
Shapes.Remove(oLine)
oLine = ""
EndIf
EndSub
Sub ItemSelect
' i - menu index
' select - "True" if selected
If select Then
GraphicsWindow.PenColor = "Gray"
Else
GraphicsWindow.PenColor = "White"
EndIf
GraphicsWindow.PenWidth = 2
x = menu[i]["x0"] - 1
y = menu[i]["y0"] - 1
width = menu[i]["x1"] - x + 1
height = menu[i]["y1"] - y + 1
GraphicsWindow.DrawRectangle(x, y, width, height)
EndSub
Sub OnMouseDown
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
clicked = "True"
GraphicsWindow.MouseUp = OnMouseUp
EndSub
Sub DoNothing
EndSub
Sub OnMouseMove
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
moved = "True"
EndSub
Sub OnMouseUp
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
released = "True"
EndSub
Sub Scissors_Init
' return shX, shY - current position of shapes
' return shape - array of shapes
shX = 237 ' x offset
shY = 30 ' y offset
shape[1] = "func=tri;x=45;y=0;x1=22;y1=0;x2=0;y2=213;x3=44;y3=213;bc=#6E6E6E;pw=0;"
shape[2] = "func=rect;x=45;y=212;width=15;height=47;bc=#6E6E6E;pw=0;"
shape[3] = "func=ell;x=0;y=235;width=66;height=104;bc=LightGray;pc=#0C95BB;pw=16;"
shape[4] = "func=tri;x=45;y=0;x1=22;y1=0;x2=0;y2=213;x3=44;y3=213;bc=#939393;pw=0;"
shape[5] = "func=rect;x=75;y=212;width=14;height=49;bc=#919191;pw=0;"
shape[6] = "func=ell;x=61;y=163;width=13;height=15;bc=#6E6E6E;pw=0;"
shape[7] = "func=ell;x=70;y=236;width=64;height=104;bc=LightGray;pc=#0C95BB;pw=16;"
EndSub
Sub SearchClickedObject
' return obj
Stack.PushValue("local", i)
obj = ""
For i = 1 To nMenu
If menu[i]["x0"] <= mx And mx <= menu[i]["x1"] And menu[i]["y0"] <= my And my <= menu[i]["y1"] Then
obj = "menu" + i
Goto sco_exit
EndIf
EndFor
For i = nShapes To 1 Step -1
_x0 = shape[i]["x"]
_x1 = shape[i]["x"] + shape[i]["width"]
_y0 = shape[i]["y"]
_y1 = shape[i]["y"] + shape[i]["height"]
If _x0 <= mx And mx <= _x1 And _y0 <= my And my <= _y1 Then
If shape[i]["func"] = "rect" Then
obj = "shape" + i
Goto sco_exit
ElseIf shape[i]["func"] = "ell" Then
width = shape[i]["width"]
height = shape[i]["height"]
x = (mx - (_x0 + width / 2)) / width * 2
y = (my - (_y0 + height / 2)) / height * 2
r = Math.SquareRoot(x * x + y * y)
If r <= 1 Then
obj = "shape" + i
Goto sco_exit
EndIf
ElseIf shape[i]["func"] = "tri" Then
width = shape[i]["width"]
height = shape[i]["height"]
x = (mx - (_x0 + width / 2)) / width * 2
If shape[i]["y1"] = 0 Then
y = (my - _y1) / height
r = Math.Abs(x) + Math.Abs(y)
If r <= 1 And y <= 0 Then
obj = "shape" + i
Goto sco_exit
EndIf
Else
y = (my - _y0) / height
r = Math.Abs(x) + Math.Abs(y)
If r <= 1 And y >= 0 Then
obj = "shape" + i
Goto sco_exit
EndIf
EndIf
ElseIf shape[i]["func"] = "line" Then
_x1 = _x0 + shape[i]["x1"]
_y1 = _y0 + shape[i]["y1"]
_x2 = _x0 + shape[i]["x2"]
_y2 = _y0 + shape[i]["y2"]
r1 = Math.SquareRoot(Math.Power(_x1 - mx, 2) + Math.Power(_y1 - my, 2))
r2 = Math.SquareRoot(Math.Power(_x2 - mx, 2) + Math.Power(_y2 - my, 2))
r = Math.SquareRoot(Math.Power(_x2 - _x1, 2) + Math.Power(_y2 - _y1, 2))
If r1 + r2 <= (r * 1.0001) Then
obj = "shape" + i
Goto sco_exit
EndIf
EndIf
EndIf
EndFor
sco_exit:
i = Stack.PopValue("local")
EndSub
Sub CS_DrawColorRect
' param color - color of rectangle
' param x, y - position of rectangle
' param width, height - size of rectangle
' return oRect - rectangle object
GraphicsWindow.BrushColor = color
GraphicsWindow.PenColor = BORDERCOLOR
If oRect <> "" Then
Shapes.Remove(oRect)
EndIf
oRect = Shapes.AddRectangle(width, height)
Shapes.Move(oRect, x, y)
EndSub
Sub CS_GetColor
' return color
oSlider = oRed
Slider_GetLevel()
red = level
oSlider = oGreen
Slider_GetLevel()
green = level
oSlider = oBlue
Slider_GetLevel()
blue = level
color = GraphicsWindow.GetColorFromRGB(red, green, blue)
EndSub
Sub CS_Init
' Initialize sliders
width = 256
min = 0
max = 255
left = 200
' add red slider
top = TOPY
caption = "R"
Slider_Add()
oRed = oSlider
' add green slider
top = top + DELTAY
caption = "G"
Slider_Add()
oGreen = oSlider
' add blue slider
top = top + DELTAY
caption = "B"
Slider_Add()
oBlue = oSlider
' add hue slider
width = 360
top = top + DELTAY
max = 360
caption = "H"
Slider_Add()
oHue = oSlider
' add saturation slider
width = 100
top = top + DELTAY
max = 100
caption = "S"
Slider_Add()
oSaturation = oSlider
' add lightness slider
width = 100
top = top + DELTAY
max = 100
caption = "L"
Slider_Add()
oLightness = oSlider
CS_AdjustSlider()
' draw color rectangle
CS_GetColor()
CS_ShowColor()
x = LEFTX
y = TOPY + DELTAY * 4
width = 100
height = 100
CS_DrawColorRect()
' add text box
GraphicsWindow.BrushColor = CAPTIONCOLOR
top = y + height + 4
oNewColor = Shapes.AddText("")
Shapes.Move(oNewColor, LEFTX, top)
GraphicsWindow.MouseUp = Slider_OnMouseUp
GraphicsWindow.MouseDown = Slider_OnMouseDown
EndSub
Sub CS_OnButtonClicked
cont = "False"
If Controls.LastClickedButton = oCancel Then
cancel = "True"
Else
cancel = "False"
EndIf
EndSub
Sub CS_SetColor
' param color
sColor = color
Color_ColorToRGB()
oSlider = oRed
level = iR
Slider_SetLevel()
oSlider = oGreen
level = iG
Slider_SetLevel()
oSlider = oBlue
level = iB
Slider_SetLevel()
CS_AdjustSlider()
EndSub
Sub CS_ShowColor
' param oColor
' param color
Shapes.SetText(oNewColor, color)
EndSub
Sub File_Save
' param buf - program buffer
' define constant
Stack.PushValue("local", cont)
colorInit = color ' initial color
TOPY = 80 ' top y
LEFTX = 36 ' left x
DELTAY = 40 ' delta y
CAPTIONCOLOR = "White"
POPUPCOLOR = "Black"
TEXTCOLOR = "Black"
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = POPUPCOLOR
oPopup = Shapes.AddRectangle(570, 310)
Shapes.SetOpacity(oPopup, 64)
Shapes.Move(oPopup, LEFTX - 10, TOPY - 10)
oText = Controls.AddTextBox(LEFTX, TOPY)
Controls.SetSize(oText, 550, 240)
Controls.SetTextBoxText(oText, buf)
oOK = Controls.AddButton("OK", LEFTX + 500, TOPY + 260)
Controls.ButtonClicked = File_OnButtonClicked
cont = "True" ' continue
While cont
Program.Delay(200)
EndWhile
Controls.Remove(oText)
Controls.Remove(oOK)
Controls.Remove(oPopup)
cont = Stack.PopValue("local")
EndSub
Sub File_OnButtonClicked
cont = "False"
EndSub
Sub Math_CartesianToPolar
' 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
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 Math_Hex2Dec
' Math | Convert hexadecimal to decimal
' param sHex
' return iDec
iDec = 0
iLen = Text.GetLength(sHex)
For iPtr = 1 To iLen
iDec = iDec * 16 + Text.GetIndexOf("0123456789ABCDEF", Text.GetSubText(sHex, iPtr, 1)) - 1
EndFor
EndSub
Sub Shapes_Add
' param shape - array of shapes
' param 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 = 1 To nShapes
GraphicsWindow.PenWidth = shape[i]["pw"] * s
If shape[i]["pw"] > 0 Then
GraphicsWindow.PenColor = shape[i]["pc"]
EndIf
If shape[i]["func"] = "rect" Then
GraphicsWindow.BrushColor = shape[i]["bc"]
x = shape[i]["x"]
y = shape[i]["y"]
width = shape[i]["width"]
height = shape[i]["height"]
shape[i]["obj"] = Shapes.AddRectangle(width * s, height * s)
Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
ElseIf shape[i]["func"] = "ell" Then
GraphicsWindow.BrushColor = shape[i]["bc"]
x = shape[i]["x"]
y = shape[i]["y"]
width = shape[i]["width"]
height = shape[i]["height"]
shape[i]["obj"] = Shapes.AddEllipse(width * s, height * s)
Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
ElseIf shape[i]["func"] = "tri" Then
GraphicsWindow.BrushColor = shape[i]["bc"]
x = shape[i]["x"]
y = shape[i]["y"]
x1 = shape[i]["x1"]
y1 = shape[i]["y1"]
x2 = shape[i]["x2"]
y2 = shape[i]["y2"]
x3 = shape[i]["x3"]
y3 = shape[i]["y3"]
shape[i]["obj"] = Shapes.AddTriangle(x1 * s, y1 * s, x2 * s, y2 * s, x3 * s, y3 * s)
Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
ElseIf shape[i]["func"] = "line" Then
x = shape[i]["x"]
y = shape[i]["y"]
x1 = shape[i]["x1"]
y1 = shape[i]["y1"]
x2 = shape[i]["x2"]
y2 = shape[i]["y2"]
shape[i]["obj"] = Shapes.AddLine(x1 * s, y1 * s, x2 * s, y2 * s)
Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
EndIf
EndFor
shAngle = 0
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub
Sub Shapes_CalcWidthAndHeight
' return nShapes - number of shapes
' return shWidth, shHeight - total size of shapes
nShapes = Array.GetItemCount(shape)
For i = 1 To nShapes
If shape[i]["func"] = "tri" Or shape[i]["func"] = "line" Then
xmin = shape[i]["x1"]
xmax = shape[i]["x1"]
ymin = shape[i]["y1"]
ymax = shape[i]["y1"]
If shape[i]["x2"] < xmin Then
xmin = shape[i]["x2"]
EndIf
If xmax < shape[i]["x2"] Then
xmax = shape[i]["x2"]
EndIf
If shape[i]["y2"] < ymin Then
ymin = shape[i]["y2"]
EndIf
If ymax < shape[i]["y2"] Then
ymax = shape[i]["y2"]
EndIf
If shape[i]["func"] = "tri" Then
If shape[i]["x3"] < xmin Then
xmin = shape[i]["x3"]
EndIf
If xmax < shape[i]["x3"] Then
xmax = shape[i]["x3"]
EndIf
If shape[i]["y3"] < ymin Then
ymin = shape[i]["y3"]
EndIf
If ymax < shape[i]["y3"] Then
ymax = shape[i]["y3"]
EndIf
EndIf
shape[i]["width"] = xmax - xmin
shape[i]["height"] = ymax - ymin
EndIf
If i = 1 Then
shWidth = shape[i]["x"] + shape[i]["width"]
shHeight = shape[i]["y"] + shape[i]["height"]
Else
If shWidth < shape[i]["x"] + shape[i]["width"] Then
shWidth = shape[i]["x"] + shape[i]["width"]
EndIf
If shHeight < shape[i]["y"] + shape[i]["height"] Then
shHeight = shape[i]["y"] + shape[i]["height"]
EndIf
EndIf
EndFor
EndSub
Sub Shapes_CalcRotatePos
' param x, y - position of a shape
' param width, height - size of a shape
' param cx, cy - center of shapes
' param shAngle - rotate angle
' return x, y - rotated position of a shape
_cx = x + width / 2
_cy = y + height / 2
x = _cx - cx
y = _cy - cy
Math_CartesianToPolar()
a = a + shAngle
x = r * Math.Cos(a * Math.Pi / 180)
y = r * Math.Sin(a * Math.Pi / 180)
_cx = x + cx
_cy = y + cy
x = _cx - width / 2
y = _cy - height / 2
EndSub
Sub Shapes_Move
' param shape - array of shapes
' param scale
' param x, y - position to move
' return shX, shY - new position of shapes
Stack.PushValue("local", i)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
shX = x
shY = y
For i = 1 To nShapes
_x = shape[i]["x"]
_y = shape[i]["y"]
width = shape[i]["width"]
height = shape[i]["height"]
Shapes_CalcRotatePos()
Shapes.Move(shape[i]["obj"], shX + _x * s, shY + _y * s)
EndFor
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub
Sub Shapes_Remove
' param shape - array of shapes
Stack.PushValue("local", i)
For i = 1 To nShapes
Shapes.Remove(shape[i]["obj"])
EndFor
i = Stack.PopValue("local")
EndSub
Sub Shapes_Rotate
' param shape - array of shapes
' param scale
' param angle
Stack.PushValue("local", i)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
s = scale
shAngle = angle
cx = shWidth / 2
cy = shHeight / 2
For i = 1 To nShapes
x = shape[i]["x"]
y = shape[i]["y"]
width = shape[i]["width"]
height = shape[i]["height"]
Shapes_CalcRotatePos()
Shapes.Move(shape[i]["obj"], shX + x * s, shY + y * s)
Shapes.Rotate(shape[i]["obj"], shAngle)
EndFor
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub
Sub Slider_Add
' Slider | Add slider as shapes and property
' param width
' param caption
' param min, max
' param left, top
' return oSlider
numSlider = numSlider + 1
oSlider = "Slider" + numSlider
' add shapes for slider
GraphicsWindow.BrushColor = CAPTIONCOLOR
len = Text.GetLength(caption)
prop[oSlider + ".oCaption"] = Shapes.AddText(caption)
Shapes.Move(prop[oSlider + ".oCaption"], left - (len * 5 + 10), top + 1)
level = Math.Floor((min + max) / 2)
prop[oSlider + ".level"] = level ' property
prop[oSlider + ".min"] = min
prop[oSlider + ".max"] = max
GraphicsWindow.PenColor = BORDERCOLOR
mag = (level - min) / (max - min)
GraphicsWindow.BrushColor = SLITCOLOR
prop[oSlider + ".oSlit"] = Shapes.AddRectangle(width, 10)
GraphicsWindow.PenColor = BORDERCOLOR
GraphicsWindow.BrushColor = BOXCOLOR
prop[oSlider + ".oBox"] = Shapes.AddRectangle(10, 18)
GraphicsWindow.BrushColor = CAPTIONCOLOR
prop[oSlider + ".oLevel"] = Shapes.AddText(level)
prop[oSlider + ".x0"] = left
prop[oSlider + ".x1"] = left + width
prop[oSlider + ".y0"] = top
Shapes.Move(prop[oSlider + ".oLevel"], left + width + 5, top)
' move and zoom shapes for slider
Shapes.Move(prop[oSlider + ".oSlit"], left, top + 4)
Slider_SetLevel()
EndSub