Files
google-game-thing/GoogleGameThing/FrmCapture.vb
2022-09-27 14:58:48 +01:00

56 lines
3.5 KiB
VB.net

Public Class FrmCapture
Private _currentActionPointsList As New List(Of Tuple(Of Integer, Integer))() 'List array of x/y points for the current mouse action being created
Private _lastActionPoint As Tuple(Of Integer, Integer) 'The last x/y point that was taken
Private _penColor As New Pen(Color.Black, 2) 'Default pen color for the graphics drawing to use
Private _graphics As Drawing.Graphics 'Loading the graphics interface
Private _selectedKey As Char 'The selected key character for this command
Private _offsetX As Integer 'The mouse offset for X so that we can reset the actions x/y to 0 later
Private _offsetY As Integer 'The mouse offset for Y so that we can reset the actions x/y to 0 later
Private Sub FrmCapture_Load(sender As Object, e As EventArgs) Handles MyBase.Load
_graphics = Me.CreateGraphics()
_selectedKey = Nothing
_offsetX = 0
_offsetY = 0
End Sub
Private Sub FrmCapture_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown 'Method to clear the current action if the user tries to redraw it
_currentActionPointsList.Clear()
_graphics.Clear(FrmCapture.DefaultBackColor)
End Sub
Private Sub FrmCapture_Closed(sender As Object, e As EventArgs) Handles Me.Closed
If _selectedKey <> Nothing Then 'Check if the user has selected a key to use for the action otherwise just close the form with no save
Dim name As String = InputBox("Please give this action a name", "Name?", "No Name") 'Ask the user to select a name
If name.Trim = "" Then
name = "No Name"
End If
'Add the action to the actions list on the main form
FrmMain.ChkActions.Items.Add(name & " | " & _selectedKey)
FrmMain.mouseActionList.Add(_selectedKey, _currentActionPointsList)
End If
End Sub
Private Sub FrmCapture_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown 'Method to listen for a keypress to set the actions key value
If e.KeyCode = Keys.Escape Then 'If escape is hit then close the form
Me.Close()
ElseIf Char.IsLetter(Chr(e.KeyValue)) Or Char.IsNumber(Chr(e.KeyValue)) Then 'Check if its a letter or number input
_selectedKey = Chr(e.KeyValue)
LblKeySet.Text = Chr(e.KeyValue)
End If
End Sub
Private Sub FrmCapture_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove 'Method to listen for mouse movements and to draw the action when the left button is clicked
If e.Button = Windows.Forms.MouseButtons.Left Then 'Wait for the left button to be held down
If _currentActionPointsList.Count > 0 Then 'If the action has already started recording then draw the connecting line
_graphics.DrawLine(_penColor, (_lastActionPoint.Item1 - Me.Location.X), (_lastActionPoint.Item2 - Me.Location.Y), (Cursor.Position.X - Me.Location.X), (Cursor.Position.Y - Me.Location.Y))
Else 'Otherwise set the initial offset values so that we can reset them to 0 and make them relative
_offsetX = Cursor.Position.X
_offsetY = Cursor.Position.Y
End If
'Add the current X and Y to the list and set the "last" value
_currentActionPointsList.Add(Tuple.Create(Cursor.Position.X - _offsetX, Cursor.Position.Y - _offsetY))
_lastActionPoint = Tuple.Create(Cursor.Position.X, Cursor.Position.Y)
End If
End Sub
End Class