Sub WaitToClick
param = "down=True;move=False;up=False;" ' wait to click
Mouse_SetHandler()
While clicked = "False"
Program.Delay(100)
EndWhile
EndSub
Sub WaitToRelease ' for sizing a shape
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "Black"
GraphicsWindow.BrushColor = "White"
param = "down=False;move=True;up=True;" ' for sizing a shape / wait to release
Mouse_SetHandler()
While released = "False"
If moved Then
param = "move=False;" ' while sizing a shape
Mouse_SetHandler()
If func = "rect" Then
If oRect <> "" Then
Shapes.Remove(oRect)
EndIf
xmin = Math.Min(mxD, mxM)
ymin = Math.Min(myD, myM)
xmax = Math.Max(mxD, mxM)
ymax = Math.Max(myD, myM)
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(mxD, mxM)
ymin = Math.Min(myD, myM)
xmax = Math.Max(mxD, mxM)
ymax = Math.Max(myD, myM)
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((mxM - mxD) / 2, 0, 0, myM - myD, mxM - mxD, myM - myD)
Shapes.Move(oTri, mxD, myD)
Shapes.SetOpacity(oTri, 50)
ElseIf func = "line" Then
If oLine <> "" Then
Shapes.Remove(oLine)
EndIf
oLine = Shapes.AddLine(mxD, myD, mxM, myM)
Shapes.SetOpacity(oLine, 50)
EndIf
param = "move=True;" ' for next sizing a shape
Mouse_SetHandler()
Else
Program.Delay(100)
EndIf
EndWhile
param = "move=False;up=False;" ' mouse released
Mouse_SetHandler()
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 WaitToRelease2 ' for moving a shape
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "Black"
GraphicsWindow.BrushColor = "White"
param = "down=False;move=True;up=True;" ' for moving a shape / wait to release
Mouse_SetHandler()
_x = shape[i]["x"]
_y = shape[i]["y"]
While released = "False"
If moved Then
param = "move=False;" ' while moving a shape
Mouse_SetHandler()
_x = shape[i]["x"] + mxM - mxD
_y = shape[i]["y"] + myM - myD
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
param = "move=True;" ' for next moving a shape
Mouse_SetHandler()
Else
Program.Delay(100)
EndIf
EndWhile
param = "move=False;up=False;" ' mouse released
Mouse_SetHandler()
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 SearchClickedObject
' return obj
Stack.PushValue("local", i)
obj = ""
For i = 1 To nMenu
If menu[i]["x0"] <= mxD And mxD <= menu[i]["x1"] And menu[i]["y0"] <= myD And myD <= 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 <= mxD And mxD <= _x1 And _y0 <= myD And myD <= _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 = (mxD - (_x0 + width / 2)) / width * 2
y = (myD - (_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 = (mxD - (_x0 + width / 2)) / width * 2
If shape[i]["y1"] = 0 Then
y = (myD - _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 = (myD - _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 - mxD, 2) + Math.Power(_y1 - myD, 2))
r2 = Math.SquareRoot(Math.Power(_x2 - mxD, 2) + Math.Power(_y2 - myD, 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 Color_Value
' Color | Function value
' param rN1, rN2
' param rH - [-120, 480)
' return iValue - 0..255
If rH >= 360 Then
rH = rH - 360
EndIF
If rH < 0 Then
rH = rH + 360
EndIF
If rH < 60 Then
rV = rN1 + (rN2 - rN1) * rH / 60
ElseIf rH < 180 Then
rV = rN2
ElseIf rH < 240 Then
rV = rN1 + (rN2 - rN1) * (240 - rH) / 60
Else
rV = rN1
EndIf
iValue = Math.Round(rV * 255)
EndSub
Sub CS_AddColorToPalette
' Color Selector | Add color to palette
' param color - color to set
' param maxPalette
' param nPalette
' param palette
' param tPalette - target palette
Stack.PushValue("local", i)
For i = 1 To nPalette
If color = palette[i]["color"] Then
Goto csactp_not_new_color
EndIf
EndFor
palette[tPalette]["color"] = color
If nPalette < maxPalette Then
nPalette = nPalette + 1
EndIf
tPalette = tPalette + 1
If maxPalette < tPalette Then
tPalette = 1
EndIf
csactp_not_new_color:
i = Stack.PopValue("local")
EndSub
Sub CS_AdjustSlider
' Color Selector | Adjust slider
' param iSlider - moved slider
Stack.PushValue("local", iSlider)
If iSlider = iHue Or iSlider = iLightness Or iSlider = iSaturation Then
If iSlider = iHue Then
Slider_GetLevel()
rHue = level
ElseIf iSlider = iLightness Then
Slider_GetLevel()
rLightness = level / 100
Else
Slider_GetLevel()
rSaturation = level / 100
EndIf
Color_HSLtoRGB()
iSlider = iRed
level = iR
Slider_SetLevel()
iSlider = iGreen
level = iG
Slider_SetLevel()
iSlider = iBlue
level = iB
Slider_SetLevel()
Else
CS_GetColorFromSlider()
sColor = GraphicsWindow.GetColorFromRGB(red, green, blue)
Color_RGBtoHSL()
If rHue = UNDEFINED Then
rHue = 0
EndIf
level = Math.Floor(rHue)
iSlider = iHue
Slider_SetLevel()
level = Math.Floor(rSaturation * 100)
iSlider = iSaturation
Slider_SetLevel()
level = Math.Floor(rLightness * 100)
iSlider = iLightness
Slider_SetLevel()
EndIf
iSlider = Stack.PopValue("local")
EndSub
Sub CS_DoObject
' Color Selector | Do object
' param - obj
While obj <> ""
CS_DoSlider()
If obj <> "" Then
CS_DoPalette()
EndIf
EndWhile
EndSub
Sub CS_DoSlider
' Color Selector | Do slider
' param obj - clicked object
' param iSlider - index of slider
If Text.StartsWith(obj, "slider") Then
Slider_WaitToRelease()
obj = ""
param = "down=True;move=False;up=False;" ' wait to click
Mouse_SetHandler()
EndIf
EndSub
Sub CS_DoPalette
' Color Selector | Do palette
' param obj - clicked object
If Text.StartsWith(obj, "palette") Then
iPalette = Text.GetSubTextToEnd(obj, 8)
color = palette[iPalette]["color"]
CS_SetColorToSlider() ' set color to slider
CS_ShowNewColor() ' show new color name
CS_DrawColorRect() ' draw new color rectangle
obj = ""
param = "down=True;move=False;up=False;" ' wait to click
Mouse_SetHandler()
EndIf
EndSub
Sub CS_DrawColorRect
' Color Selector | Draw color rectangle
' 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_DrawPalette
' Color Selector | Draw palette
' param palette[] - color palette
' param nPalette - number of color in palette
' param x, y - position of rectangle
' param width, height - size of rectangle
' return oPalette[] - palette object array
Stack.PushValue("local", i)
GraphicsWindow.PenColor = BORDERCOLOR
For i = 1 To nPalette
GraphicsWindow.BrushColor = palette[i]["color"]
palette[i]["oCell"] = Shapes.AddRectangle(width, height)
dx = Math.Remainder((i - 1), 8) * (width + 4)
dy = Math.Floor((i - 1) / 8) * (height + 4)
Shapes.Move(palette[i]["oCell"], x + dx, y + dy)
palette[i]["x"] = x + dx
palette[i]["y"] = y + dy
palette[i]["width"] = width
palette[i]["height"] = height
EndFor
i = Stack.PopValue("local")
EndSub
Sub CS_GetColorFromSlider
' Color Selector | get color from slider
' return color
Stack.PushValue("local", iSlider)
iSlider = iRed ' slider index
Slider_GetLevel()
red = level
iSlider = iGreen ' slider index
Slider_GetLevel()
green = level
iSlider = iBlue ' slider index
Slider_GetLevel()
blue = level
color = GraphicsWindow.GetColorFromRGB(red, green, blue)
iSlider = Stack.PopValue("local")
EndSub
Sub CS_Init
' Initialize sliders
width = 256
min = 0
max = 255
left = 190
' add red slider
top = TOPY
caption = "R"
Slider_Add()
iRed = iSlider ' index of slider
' add green slider
top = top + DELTAY
caption = "G"
Slider_Add()
iGreen = iSlider ' index of slider
' add blue slider
top = top + DELTAY
caption = "B"
Slider_Add()
iBlue = iSlider ' index of slider
' add hue slider
width = 360
top = top + DELTAY
max = 360
caption = "H"
Slider_Add()
iHue = iSlider ' index of slider
' add saturation slider
width = 100
top = top + DELTAY
max = 100
caption = "S"
Slider_Add()
iSaturation = iSlider ' index of slider
' add lightness slider
width = 100
top = top + DELTAY
max = 100
caption = "L"
Slider_Add()
iLightness = iSlider ' index of slider
' draw color rectangle
CS_GetColorFromSlider()
CS_ShowNewColor()
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)
EndSub
Sub CS_DumpSlider
For i = 1 To numSlider
TextWindow.WriteLine("slider" + i)
TextWindow.WriteLine(slider[i])
EndFor
EndSub
Sub CS_InitPalette
' Color Selector | Initialize palette
' This subroutine should be called before CS_ShowPopup().
maxPalette = 16 ' max cell number of palette
nPalette = 2 ' number of palette in use
tPalette = 3 ' index of update target cell
palette[1]["color"] = pcolor
palette[2]["color"] = bcolor
EndSub
Sub CS_RemovePalette
' Color Selector | Remove palette
' param nPalette - number of color in palette
' return oPalette[] - palette object array
Stack.PushValue("local", i)
For i = 1 To nPalette
oPalette = "Palette" + i
Shapes.Remove(palette[i]["oCell"])
EndFor
i = Stack.PopValue("local")
EndSub
Sub CS_RemoveSliders
' Color Selector | Remove sliders
For iSlider = 1 To numSlider
Slider_Remove()
EndFor
numSlider = 0
EndSub
Sub CS_SearchClickedObject
' Color Selector | Check slider clicked
' param mxD, myD - clicked point
' return obj - clicked slider or palette
' return iSlider - index if obj is slider
' return iPalette - index if obj is palette
Stack.PushValue("local", i)
For iSlider = 1 To numSlider
obj = "slider" + iSlider
x2 = slider[iSlider]["x2"]
y2 = slider[iSlider]["y2"]
x3 = slider[iSlider]["x3"]
y3 = slider[iSlider]["y3"]
If x2 <= mxD And mxD <= x3 And y2 <= myD And myD <= y3 Then
Goto scco_obj_found
EndIf
EndFor
For iPalette = 1 To nPalette
obj = "palette" + iPalette
x2 = palette[iPalette]["x"]
y2 = palette[iPalette]["y"]
x3 = palette[iPalette]["x"] + palette[iPalette]["width"]
y3 = palette[iPalette]["y"] + palette[iPalette]["height"]
If x2 <= mxD And mxD <= x3 And y2 <= myD And myD <= y3 Then
Goto scco_obj_found
EndIf
EndFor
obj = ""
scco_obj_found:
i = Stack.PopValue("local")
EndSub
Sub CS_SetColorToSlider
' Color Selector | Set color to slider
' param color
Stack.PushValue("local", iSlider)
sColor = color
Color_ColorToRGB()
iSlider = iRed
level = iR
Slider_SetLevel()
iSlider = iGreen
level = iG
Slider_SetLevel()
iSlider = iBlue
level = iB
Slider_SetLevel()
CS_AdjustSlider()
iSlider = Stack.PopValue("local")
EndSub
Sub CS_ShowNewColor
' Color Selector | Show new color
' param oColor
' param color
Shapes.SetText(oNewColor, color)
EndSub
Sub CS_ShowPopup
' Color Selector | Show popup
' param color - current color
' return color - new color
' define constant
Stack.PushValue("local", cont)
colorInit = color ' initial color
TOPY = 80 ' top y
LEFTX = 36 ' left x
BORDERCOLOR = "#666666"
BOXCOLOR = "LightGray"
CAPTIONCOLOR = "White"
DELTAY = 36 ' delta y
SLITCOLOR = "#555555"
TEXTCOLOR = "Black"
UNDEFINED = "N/A"
POPUPCOLOR = "Black"
GraphicsWindow.PenWidth = 2
GraphicsWindow.PenColor = POPUPCOLOR
GraphicsWindow.BrushColor = POPUPCOLOR
oPopup = Shapes.AddRectangle(570, 310)
Shapes.SetOpacity(oPopup, 64)
Shapes.Move(oPopup, LEFTX - 10, TOPY - 10)
oOK = Controls.AddButton("OK", LEFTX + 440, TOPY + 260)
oCancel = Controls.AddButton("Cancel", LEFTX + 480, TOPY + 260)
Controls.ButtonClicked = CS_OnButtonClicked
CS_Init()
Stack.PushValue("local", y)
y = TOPY
color = colorInit
CS_DrawColorRect() ' original color
oRectCurrent = oRect
oRect = "" ' keep current color
GraphicsWindow.SetPixel(0, 0, colorInit)
color = GraphicsWindow.GetPixel(0, 0)
GraphicsWindow.SetPixel(0, 0, "LightGray")
GraphicsWindow.BrushColor = CAPTIONCOLOR
oColor = Shapes.AddText(colorInit)
Shapes.Move(oColor, x, y + height + 2)
If color <> colorInit Then
oColor2 = Shapes.AddText(color)
Shapes.Move(oColor2, x, y + height + 14)
EndIf
y = Stack.PopValue("local")
CS_SetColorToSlider()
CS_DrawColorRect() ' draw new color rectangle
CS_ShowNewColor() ' show new color name
Stack.PushValue("local", x)
Stack.PushValue("local", y)
Stack.PushValue("local", width)
Stack.PushValue("local", height)
x = x + width + 30
y = TOPY + height * 2 + 24
width = 30
height = 30
CS_DrawPalette()
height = Stack.PopValue("local")
width = Stack.PopValue("local")
y = Stack.PopValue("local")
x = Stack.PopValue("local")
cont = "True" ' continue
param = "down=True;move=False;up=False;" ' wait click
Mouse_SetHandler()
While cont
If clicked Then
CS_SearchClickedObject()
CS_DoObject()
Else
Program.Delay(100)
EndIf
EndWhile
If cancel Then
color = colorInit
Else
CS_AddColorToPalette()
EndIf
CS_RemovePalette()
CS_RemoveSliders()
Shapes.Remove(oColor)
Shapes.Remove(oColor2)
Shapes.Remove(oNewColor)
Shapes.Remove(oRectCurrent)
Shapes.Remove(oRect)
Controls.Remove(oOK)
Controls.Remove(oCancel)
Shapes.Remove(oPopup)
cont = Stack.PopValue("local")
EndSub
Sub CS_OnButtonClicked
' Color Selector | Event handler on button clicked
cont = "False"
If Controls.LastClickedButton = oCancel Then
cancel = "True"
Else
cancel = "False"
EndIf
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 Scissors_Init
' Scissors | Initialize shapes data
' 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 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 iSlider
numSlider = numSlider + 1
iSlider = numSlider
' add shapes for slider
GraphicsWindow.BrushColor = CAPTIONCOLOR
len = Text.GetLength(caption)
slider[iSlider]["oCaption"] = Shapes.AddText(caption)
Shapes.Move(slider[iSlider]["oCaption"], left - (len * 5 + 10), top + 1)
level = Math.Floor((min + max) / 2)
slider[iSlider]["level"] = level ' property
slider[iSlider]["min"] = min
slider[iSlider]["max"] = max
GraphicsWindow.PenColor = BORDERCOLOR
mag = (level - min) / (max - min)
GraphicsWindow.BrushColor = SLITCOLOR
slider[iSlider]["oSlit"] = Shapes.AddRectangle(width, 10)
GraphicsWindow.PenColor = BORDERCOLOR
GraphicsWindow.BrushColor = BOXCOLOR
slider[iSlider]["oBox"] = Shapes.AddRectangle(10, 18)
GraphicsWindow.BrushColor = CAPTIONCOLOR
slider[iSlider]["oLevel"] = Shapes.AddText(level)
slider[iSlider]["x0"] = left
slider[iSlider]["x1"] = left + width
slider[iSlider]["y0"] = top
Shapes.Move(slider[iSlider]["oLevel"], left + width + 5, top)
' move and zoom shapes for slider
Shapes.Move(slider[iSlider]["oSlit"], left, top + 4)
Slider_SetLevel()
EndSub
Sub Slider_CallBack
' Slider | Call back
' param iSlider - changed slider
CS_AdjustSlider()
CS_GetColorFromSlider()
CS_ShowNewColor() ' show new color name
CS_DrawColorRect() ' draw new color rectangle
EndSub
Sub Slider_GetLevel
' Slider | Get latest level of slider
' param iSlider
' return level
level = slider[iSlider]["level"]
EndSub
Sub Slider_GetMouseLevel
' Slider | Get mouse level of slider
' param iSlider
' return level
x0 = slider[iSlider]["x0"]
x1 = slider[iSlider]["x1"]
max = slider[iSlider]["max"]
min = slider[iSlider]["min"]
level = min + Math.Floor((max - min) * (mxM - x0) / (x1 - x0))
EndSub
Sub Slider_WaitToRelease
' Slider | Get released point for slider moving
' param iSlider
param = "down=False;move=True;up=True;" ' for slider moving / wait to release
Mouse_SetHandler()
While released = "False"
If moved Then
param = "move=False;" ' while slider moving
Mouse_SetHandler()
x0_ = slider[iSlider]["x0"]
x1_ = slider[iSlider]["x1"]
If mxM < x0_ Then
mxM = x0_
EndIf
If x1_ < mxM Then
mxM = x1_
EndIf
Slider_GetMouseLevel() ' get mouse level of slider
Slider_SetLevel() ' set slider level and move slider box
Slider_CallBack()
param = "move=True;" ' for next slider moving
Mouse_SetHandler()
Else
Program.Delay(100)
EndIf
EndWhile
param = "move=False;up=False;" ' mouse released
Mouse_SetHandler()
EndSub
Sub Slider_Remove
' Slider | Remove a slider
' param iSlider
Shapes.Remove(slider[iSlider]["oCaption"])
Shapes.Remove(slider[iSlider]["oSlit"])
Shapes.Remove(slider[iSlider]["oBox"])
Shapes.Remove(slider[iSlider]["oLevel"])
EndSub
Sub Mouse_SetHandler
' Mouse | Common event handler setting
' param["down"] - "True" if set, "False" if reset mouse event handler
' param["move"] - "True" if set, "False" if reset mouse event handler
' param["up"] - - "True" if set, "False" if reset mouse event handler
' return clicked - "False" if set MouseDown
' return moved - "False" if set MouseMove
' return released - "False" if set MouseUp
' return dmu - which handlers are set for debug
If param["down"] Then
clicked = "False"
GraphicsWindow.MouseDown = Mouse_OnDown
handler["down"] = "D"
ElseIf param["down"] = "False" Then
GraphicsWindow.MouseDown = Mouse_DoNothing
handler["down"] = ""
EndIf
If param["move"] Then
moved = "False"
GraphicsWindow.MouseMove = Mouse_OnMove
handler["move"] = "M"
ElseIf param["move"] = "False" Then
GraphicsWindow.MouseMove = Mouse_DoNothing
handler["move"] = ""
EndIf
If param["up"] Then
released = "False"
GraphicsWindow.MouseUp = Mouse_OnUp
handler["up"] = "U"
ElseIf param["up"] = "False" Then
GraphicsWindow.MouseUp = Mouse_DoNothing
handler["up"] = ""
EndIf
dmu = handler["down"] + handler["move"] + handler["up"]
If debug Then
GraphicsWindow.Title = title + " set " + dmu
EndIf
EndSub
Sub Mouse_OnDown
' Mouse | Common event handler on mouse down
' return mxD, myD - position on mouse down
mxD = GraphicsWindow.MouseX
myD = GraphicsWindow.MouseY
clicked = "True"
If debug Then
GraphicsWindow.Title = title + " clicked " + mxD + "," + myD + " " + dmu
EndIf
EndSub
Sub Mouse_DoNothing
' Mouse | Common event handler to do nothing
EndSub
Sub Mouse_OnMove
' Mouse | Common event handler on mouse move
' return mxM, myM - position on mouse move
mxM = GraphicsWindow.MouseX
myM = GraphicsWindow.MouseY
moved = "True"
If debug Then
GraphicsWindow.Title = title + " moved " + mxM + "," + myM + " " + dmu
EndIf
EndSub
Sub Mouse_OnUp
' Mouse | Common event handler on mouse up
' return mxU, myU - position on mouse up
mxU = GraphicsWindow.MouseX
myU = GraphicsWindow.MouseY
released = "True"
If debug Then
GraphicsWindow.Title = title + " released " + mxU + "," + myU + " " + dmu
EndIf
EndSub