194 lines
8.7 KiB
VB.net
194 lines
8.7 KiB
VB.net
Public Class GUI_Functions
|
|
Public Shared Sub AngleButton(sender As Object, e As EventArgs)
|
|
Me.Controls("AngleButton").Enabled = False
|
|
Me.Controls("Button_Square").Enabled = False
|
|
|
|
Dim buttonX As Integer = Me.Controls("AngleButton").Location.X
|
|
Dim buttonY As Integer = Me.Controls("AngleButton").Location.Y
|
|
|
|
Create_TextBox("X_TextBox", "", buttonX + 20, buttonY + 40, 60)
|
|
AddHandler Me.Controls("X_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
Create_Label("X_Label", "1", buttonX, buttonY + 43)
|
|
|
|
Create_TextBox("Y_TextBox", "", buttonX + 130, buttonY + 40, 60)
|
|
AddHandler Me.Controls("Y_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
Create_Label("Y_Label", "2", buttonX + 110, buttonY + 43)
|
|
|
|
angleFunctionActive = True
|
|
End Sub
|
|
|
|
Public Shared Sub SquareButtton(sender As Object, e As EventArgs)
|
|
Me.Controls("AngleButton").Enabled = False
|
|
Me.Controls("Button_Square").Enabled = False
|
|
|
|
Dim buttonX As Integer = Me.Controls("Button_Square").Location.X
|
|
Dim buttonY As Integer = Me.Controls("Button_Square").Location.Y
|
|
|
|
Create_TextBox("X_TextBox", "", buttonX + 20, buttonY + 40, 60)
|
|
AddHandler Me.Controls("X_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
Create_Label("X_Label", "1", buttonX, buttonY + 43)
|
|
|
|
Create_TextBox("Y_TextBox", "", buttonX + 130, buttonY + 40, 60)
|
|
AddHandler Me.Controls("Y_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
Create_Label("Y_Label", "2", buttonX + 110, buttonY + 43)
|
|
|
|
' Add option for corner or side
|
|
|
|
squareFunctionActive = True
|
|
|
|
End Sub
|
|
|
|
Private Sub FunctionText_Changed(sender As TextBox, e As EventArgs)
|
|
If Not Me.Controls("X_TextBox").Text = "" And Not Me.Controls("Y_TextBox").Text = "" Then
|
|
If containerPanel.Controls.Count = 0 Then
|
|
' Create Buttons for all clickable points
|
|
For i = 0 To pointsOrder.Count - 1
|
|
If pointsFunc(pointsOrder(i)) Then
|
|
Dim pointButton As New Button
|
|
pointButton.Width = 30
|
|
pointButton.Height = 30
|
|
|
|
pointButton.Left = points(pointsOrder(i))(0) - pointButton.Width / 2
|
|
pointButton.Top = points(pointsOrder(i))(1) - pointButton.Height / 2
|
|
|
|
pointButton.Name = 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)
|
|
|
|
containerPanel.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 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 = pointsOrder.IndexOf(pointPressed)
|
|
|
|
' Remove point buttons
|
|
For i = 0 To pointsOrder.Count - 1
|
|
If pointsFunc(pointsOrder(i)) Then
|
|
RemoveHandler containerPanel.Controls(pointsOrder(i) & "_Button").Click, AddressOf PointButton_Click
|
|
containerPanel.Controls.RemoveByKey(pointsOrder(i) & "_Button")
|
|
End If
|
|
Next
|
|
|
|
'Retrive that points coords
|
|
Dim pXP As Decimal = points(pointPressed)(0)
|
|
Dim pYP As Decimal = points(pointPressed)(1)
|
|
Dim pXSW As Decimal = points(pointPressed)(2)
|
|
Dim pYSW As Decimal = points(pointPressed)(3)
|
|
|
|
Dim d1P As Decimal = Me.Controls("X_TextBox").Text / scaleDiff ' BEHÖVS Cdec??
|
|
Dim d2P As Decimal = Me.Controls("Y_TextBox").Text / scaleDiff
|
|
Dim d1SW As Decimal = Me.Controls("X_TextBox").Text / 1000
|
|
Dim d2SW As Decimal = Me.Controls("Y_TextBox").Text / 1000
|
|
|
|
Dim numOfNewPoints As Integer
|
|
|
|
If angleFunctionActive Then
|
|
If pXP < containerMidX Then
|
|
If pYP > containerMidY Then
|
|
'Kvadrant 4
|
|
points.Add("pA" & pointCounter * 2 - 1, {pXP + d1P, pYP, pXSW + d1SW, pYSW})
|
|
points.Add("pA" & pointCounter * 2, {pXP, pYP - d2P, pXSW, pYSW + d2SW})
|
|
Else
|
|
'Kvadrant 1
|
|
points.Add("pA" & pointCounter * 2 - 1, {pXP, pYP + d2P, pXSW, pYSW - d2SW})
|
|
points.Add("pA" & pointCounter * 2, {pXP + d1P, pYP, pXSW + d1SW, pYSW})
|
|
End If
|
|
Else
|
|
If pYP > containerMidY Then
|
|
'Kvadrant 3
|
|
points.Add("pA" & pointCounter * 2 - 1, {pXP, pYP - d2P, pXSW, pYSW + d2SW})
|
|
points.Add("pA" & pointCounter * 2, {pXP - d1P, pYP, pXSW - d1SW, pYSW})
|
|
Else
|
|
'Kvadrant 2
|
|
points.Add("pA" & pointCounter * 2 - 1, {pXP - d1P, pYP, pXSW - d1SW, pYSW})
|
|
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
|
|
pointsOrder.Insert(index + 1, "pA" & pointCounter * 2 - 1)
|
|
pointsOrder.Insert(index + 2, "pA" & pointCounter * 2)
|
|
|
|
numOfNewPoints = 2
|
|
angleFunctionActive = False
|
|
|
|
Else
|
|
If pXP < containerMidX Then
|
|
If pYP > containerMidY Then
|
|
'Kvadrant 4
|
|
points.Add("pS" & pointCounter * 3 - 2, {pXP + d1P, pYP, pXSW + d1SW, pYSW})
|
|
points.Add("pS" & pointCounter * 3 - 1, {pXP + d1P, pYP - d2P, pXSW + d1SW, pYSW + d2SW})
|
|
points.Add("pS" & pointCounter * 3, {pXP, pYP - d2P, pXSW, pYSW + d2SW})
|
|
Else
|
|
'Kvadrant 1
|
|
points.Add("pS" & pointCounter * 3 - 2, {pXP, pYP + d2P, pXSW, pYSW - d2SW})
|
|
points.Add("pS" & pointCounter * 3 - 1, {pXP + d1P, pYP + d2P, pXSW + d1SW, pYSW - d2SW})
|
|
points.Add("pS" & pointCounter * 3, {pXP + d1P, pYP, pXSW + d1SW, pYSW})
|
|
End If
|
|
Else
|
|
If pYP > containerMidY Then
|
|
'Kvadrant 3
|
|
points.Add("pS" & pointCounter * 3 - 2, {pXP, pYP - d2P, pXSW, pYSW + d2SW})
|
|
points.Add("pS" & pointCounter * 3 - 1, {pXP - d1P, pYP - d2P, pXSW - d1SW, pYSW + d2SW})
|
|
points.Add("pS" & pointCounter * 3, {pXP - d1P, pYP, pXSW - d1SW, pYSW})
|
|
Else
|
|
'Kvadrant 2
|
|
points.Add("pS" & pointCounter * 3 - 2, {pXP - d1P, pYP, pXSW - d1SW, pYSW})
|
|
points.Add("pS" & pointCounter * 3 - 1, {pXP - d1P, pYP + d2P, pXSW - d1SW, pYSW - d2SW})
|
|
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
|
|
pointsOrder.Insert(index + 1, "pS" & pointCounter * 3 - 2)
|
|
pointsOrder.Insert(index + 2, "pS" & pointCounter * 3 - 1)
|
|
pointsOrder.Insert(index + 3, "pS" & pointCounter * 3)
|
|
|
|
numOfNewPoints = 3
|
|
|
|
squareFunctionActive = False
|
|
|
|
End If
|
|
pointsOrder.RemoveAt(index)
|
|
|
|
'Redraw grating
|
|
Me.Refresh()
|
|
|
|
RemoveHandler Me.Controls("X_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
Me.Controls.RemoveByKey("X_TextBox")
|
|
|
|
RemoveHandler Me.Controls("Y_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
Me.Controls.RemoveByKey("Y_TextBox")
|
|
|
|
Me.Controls.RemoveByKey("X_Label")
|
|
Me.Controls.RemoveByKey("Y_Label")
|
|
|
|
Me.Controls("AngleButton").Enabled = True
|
|
Me.Controls("Button_Square").Enabled = True
|
|
End Sub
|
|
End Class
|