202 lines
9.9 KiB
VB.net
202 lines
9.9 KiB
VB.net
Public Class GUI_Functions
|
|
Private Shared angleFunctionActive As Boolean = False
|
|
Private Shared squareFunctionActive As Boolean = False
|
|
|
|
Private Shared pointCounter As Integer
|
|
|
|
Public Shared pointsFunc As New Dictionary(Of String, Boolean)
|
|
|
|
|
|
Public Shared Sub AngleButton(sender As Object, e As EventArgs)
|
|
GUI.Controls("AngleButton").Enabled = False
|
|
GUI.Controls("Button_Square").Enabled = False
|
|
|
|
Dim buttonX As Integer = GUI.Controls("AngleButton").Location.X
|
|
Dim buttonY As Integer = GUI.Controls("AngleButton").Location.Y
|
|
|
|
GUI.Create_TextBox("X_TextBox", "", buttonX + 20, buttonY + 40, 60)
|
|
AddHandler GUI.Controls("X_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
GUI.Create_Label("X_Label", "1", buttonX, buttonY + 43)
|
|
|
|
GUI.Create_TextBox("Y_TextBox", "", buttonX + 130, buttonY + 40, 60)
|
|
AddHandler GUI.Controls("Y_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
GUI.Create_Label("Y_Label", "2", buttonX + 110, buttonY + 43)
|
|
|
|
angleFunctionActive = True
|
|
End Sub
|
|
|
|
Public Shared Sub SquareButtton(sender As Object, e As EventArgs)
|
|
GUI.Controls("AngleButton").Enabled = False
|
|
GUI.Controls("Button_Square").Enabled = False
|
|
|
|
Dim buttonX As Integer = GUI.Controls("Button_Square").Location.X
|
|
Dim buttonY As Integer = GUI.Controls("Button_Square").Location.Y
|
|
|
|
GUI.Create_TextBox("X_TextBox", "", buttonX + 20, buttonY + 40, 60)
|
|
AddHandler GUI.Controls("X_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
GUI.Create_Label("X_Label", "1", buttonX, buttonY + 43)
|
|
|
|
GUI.Create_TextBox("Y_TextBox", "", buttonX + 130, buttonY + 40, 60)
|
|
AddHandler GUI.Controls("Y_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
GUI.Create_Label("Y_Label", "2", buttonX + 110, buttonY + 43)
|
|
|
|
' Add option for corner or side
|
|
|
|
squareFunctionActive = True
|
|
End Sub
|
|
|
|
Private Shared Sub FunctionText_Changed(sender As TextBox, e As EventArgs)
|
|
If Not GUI.Controls("X_TextBox").Text = "" And Not GUI.Controls("Y_TextBox").Text = "" Then
|
|
If GUI.DrawingPanel.Controls.Count = 0 Then
|
|
' Create Buttons for all clickable points
|
|
For i = 0 To GUI_Drawing_Panel.pointsOrder.Count - 1
|
|
If pointsFunc(GUI_Drawing_Panel.pointsOrder(i)) Then
|
|
Dim pointButton As New Button
|
|
pointButton.Width = 30
|
|
pointButton.Height = 30
|
|
|
|
pointButton.Left = GUI_Drawing_Panel.points(GUI_Drawing_Panel.pointsOrder(i))(0) - pointButton.Width / 2
|
|
pointButton.Top = GUI_Drawing_Panel.points(GUI_Drawing_Panel.pointsOrder(i))(1) - pointButton.Height / 2
|
|
|
|
pointButton.Name = GUI_Drawing_Panel.pointsOrder(i) & "_Button"
|
|
pointButton.Text = ""
|
|
|
|
pointButton.BackColor = Color.FromArgb(50, Color.Red)
|
|
pointButton.FlatStyle = FlatStyle.Flat
|
|
pointButton.FlatAppearance.BorderSize = 0
|
|
pointButton.FlatAppearance.MouseOverBackColor = Color.Red
|
|
pointButton.FlatAppearance.MouseDownBackColor = Color.DarkRed
|
|
|
|
Dim gp As New Drawing.Drawing2D.GraphicsPath
|
|
gp.AddEllipse(New Rectangle(New Point(0, 0), New Size(30, 30)))
|
|
pointButton.Region = New Region(gp)
|
|
|
|
GUI.DrawingPanel.Controls.Add(pointButton)
|
|
|
|
AddHandler pointButton.Click, AddressOf PointButton_Click
|
|
End If
|
|
Next
|
|
pointCounter = pointCounter + 1
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
' --- When a function button is pressed ---
|
|
Private Shared Sub PointButton_Click(sender As Button, e As EventArgs)
|
|
'Determine which point is being pressed
|
|
Dim pointPressed As String = sender.Name.Split("_")(0)
|
|
Dim index As Integer = GUI_Drawing_Panel.pointsOrder.IndexOf(pointPressed)
|
|
|
|
' Remove point buttons
|
|
For i = 0 To GUI_Drawing_Panel.pointsOrder.Count - 1
|
|
If pointsFunc(GUI_Drawing_Panel.pointsOrder(i)) Then
|
|
RemoveHandler GUI.DrawingPanel.Controls(GUI_Drawing_Panel.pointsOrder(i) & "_Button").Click,
|
|
AddressOf PointButton_Click
|
|
GUI.DrawingPanel.Controls.RemoveByKey(GUI_Drawing_Panel.pointsOrder(i) & "_Button")
|
|
End If
|
|
Next
|
|
|
|
'Retrive that points coords
|
|
Dim pXP As Decimal = GUI_Drawing_Panel.points(pointPressed)(0)
|
|
Dim pYP As Decimal = GUI_Drawing_Panel.points(pointPressed)(1)
|
|
Dim pXSW As Decimal = GUI_Drawing_Panel.points(pointPressed)(2)
|
|
Dim pYSW As Decimal = GUI_Drawing_Panel.points(pointPressed)(3)
|
|
|
|
Dim d1P As Decimal = GUI.Controls("X_TextBox").Text / GUI_Drawing_Panel.scaleDiff ' BEHÖVS Cdec??
|
|
Dim d2P As Decimal = GUI.Controls("Y_TextBox").Text / GUI_Drawing_Panel.scaleDiff
|
|
Dim d1SW As Decimal = GUI.Controls("X_TextBox").Text / 1000
|
|
Dim d2SW As Decimal = GUI.Controls("Y_TextBox").Text / 1000
|
|
|
|
Dim numOfNewPoints As Integer
|
|
|
|
If angleFunctionActive Then
|
|
If pXP < GUI_Drawing_Panel.containerMidX Then
|
|
If pYP > GUI_Drawing_Panel.containerMidY Then
|
|
'Kvadrant 4
|
|
GUI_Drawing_Panel.points.Add("pA" & pointCounter * 2 - 1, {pXP + d1P, pYP, pXSW + d1SW, pYSW})
|
|
GUI_Drawing_Panel.points.Add("pA" & pointCounter * 2, {pXP, pYP - d2P, pXSW, pYSW + d2SW})
|
|
Else
|
|
'Kvadrant 1
|
|
GUI_Drawing_Panel.points.Add("pA" & pointCounter * 2 - 1, {pXP, pYP + d2P, pXSW, pYSW - d2SW})
|
|
GUI_Drawing_Panel.points.Add("pA" & pointCounter * 2, {pXP + d1P, pYP, pXSW + d1SW, pYSW})
|
|
End If
|
|
Else
|
|
If pYP > GUI_Drawing_Panel.containerMidY Then
|
|
'Kvadrant 3
|
|
GUI_Drawing_Panel.points.Add("pA" & pointCounter * 2 - 1, {pXP, pYP - d2P, pXSW, pYSW + d2SW})
|
|
GUI_Drawing_Panel.points.Add("pA" & pointCounter * 2, {pXP - d1P, pYP, pXSW - d1SW, pYSW})
|
|
Else
|
|
'Kvadrant 2
|
|
GUI_Drawing_Panel.points.Add("pA" & pointCounter * 2 - 1, {pXP - d1P, pYP, pXSW - d1SW, pYSW})
|
|
GUI_Drawing_Panel.points.Add("pA" & pointCounter * 2, {pXP, pYP + d2P, pXSW, pYSW - d2SW})
|
|
End If
|
|
End If
|
|
pointsFunc.Add("pA" & pointCounter * 2 - 1, False)
|
|
pointsFunc.Add("pA" & pointCounter * 2, False)
|
|
|
|
'Insert two new points
|
|
GUI_Drawing_Panel.pointsOrder.Insert(index + 1, "pA" & pointCounter * 2 - 1)
|
|
GUI_Drawing_Panel.pointsOrder.Insert(index + 2, "pA" & pointCounter * 2)
|
|
|
|
numOfNewPoints = 2
|
|
angleFunctionActive = False
|
|
|
|
Else
|
|
If pXP < GUI_Drawing_Panel.containerMidX Then
|
|
If pYP > GUI_Drawing_Panel.containerMidY Then
|
|
'Kvadrant 4
|
|
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3 - 2, {pXP + d1P, pYP, pXSW + d1SW, pYSW})
|
|
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3 - 1, {pXP + d1P, pYP - d2P, pXSW + d1SW, pYSW + d2SW})
|
|
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3, {pXP, pYP - d2P, pXSW, pYSW + d2SW})
|
|
Else
|
|
'Kvadrant 1
|
|
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3 - 2, {pXP, pYP + d2P, pXSW, pYSW - d2SW})
|
|
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3 - 1, {pXP + d1P, pYP + d2P, pXSW + d1SW, pYSW - d2SW})
|
|
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3, {pXP + d1P, pYP, pXSW + d1SW, pYSW})
|
|
End If
|
|
Else
|
|
If pYP > GUI_Drawing_Panel.containerMidY Then
|
|
'Kvadrant 3
|
|
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3 - 2, {pXP, pYP - d2P, pXSW, pYSW + d2SW})
|
|
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3 - 1, {pXP - d1P, pYP - d2P, pXSW - d1SW, pYSW + d2SW})
|
|
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3, {pXP - d1P, pYP, pXSW - d1SW, pYSW})
|
|
Else
|
|
'Kvadrant 2
|
|
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3 - 2, {pXP - d1P, pYP, pXSW - d1SW, pYSW})
|
|
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3 - 1, {pXP - d1P, pYP + d2P, pXSW - d1SW, pYSW - d2SW})
|
|
GUI_Drawing_Panel.points.Add("pS" & pointCounter * 3, {pXP, pYP + d2P, pXSW, pYSW - d2SW})
|
|
End If
|
|
End If
|
|
pointsFunc.Add("pS" & pointCounter * 3 - 2, True)
|
|
pointsFunc.Add("pS" & pointCounter * 3 - 1, False)
|
|
pointsFunc.Add("pS" & pointCounter * 3, True)
|
|
|
|
'Insert new points
|
|
GUI_Drawing_Panel.pointsOrder.Insert(index + 1, "pS" & pointCounter * 3 - 2)
|
|
GUI_Drawing_Panel.pointsOrder.Insert(index + 2, "pS" & pointCounter * 3 - 1)
|
|
GUI_Drawing_Panel.pointsOrder.Insert(index + 3, "pS" & pointCounter * 3)
|
|
|
|
numOfNewPoints = 3
|
|
|
|
squareFunctionActive = False
|
|
|
|
End If
|
|
GUI_Drawing_Panel.pointsOrder.RemoveAt(index)
|
|
|
|
'Redraw grating
|
|
GUI.Refresh()
|
|
|
|
RemoveHandler GUI.Controls("X_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
GUI.Controls.RemoveByKey("X_TextBox")
|
|
|
|
RemoveHandler GUI.Controls("Y_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
GUI.Controls.RemoveByKey("Y_TextBox")
|
|
|
|
GUI.Controls.RemoveByKey("X_Label")
|
|
GUI.Controls.RemoveByKey("Y_Label")
|
|
|
|
GUI.Controls("AngleButton").Enabled = True
|
|
GUI.Controls("Button_Square").Enabled = True
|
|
End Sub
|
|
End Class
|