-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfrmPattern.vb
More file actions
155 lines (133 loc) · 5.11 KB
/
frmPattern.vb
File metadata and controls
155 lines (133 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
Imports System.ComponentModel
Public Class frmPattern
Public actions As List(Of clsAction)
Public Class patternData
Public _button As String
Public mask As Integer
Public _interval As Integer
Public _offset As Integer
Public _count As Integer
Public Sub New(__button As String, _mask As Integer)
_button = __button
mask = _mask
End Sub
Public Property Button As String
Get
Return _button
End Get
Set(value As String)
_button = value
End Set
End Property
Public Property Interval As String
Get
Return IIf(_interval > 0, _interval, vbNullString)
End Get
Set(value As String)
_interval = IIf(value = vbNullString, 0, value)
End Set
End Property
Public Property Offset As String
Get
Return IIf(_offset > 0, _offset, vbNullString)
End Get
Set(value As String)
_offset = IIf(value = vbNullString, 0, value)
End Set
End Property
Public Property Count As String
Get
Return IIf(_count > 0, _count, vbNullString)
End Get
Set(value As String)
_count = IIf(value = vbNullString, 0, value)
End Set
End Property
End Class
Private buttons As List(Of patternData)
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
buttons = New List(Of patternData)
buttons.Add(New patternData("A", &H10))
buttons.Add(New patternData("B", &H20))
buttons.Add(New patternData("X", &H40))
buttons.Add(New patternData("Y", &H80))
buttons.Add(New patternData("LB", &H1))
dgvPattern.DataSource = buttons
dgvPattern.AutoResizeColumns()
End Sub
Private Sub dgvPattern_CellValidating(sender As Object, e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgvPattern.CellValidating
Select Case e.ColumnIndex
Case 0
Case 1, 2
Dim a As Integer
If e.FormattedValue = vbNullString Then Exit Sub
e.Cancel = Not Integer.TryParse(e.FormattedValue, a)
If e.Cancel Then dgvPattern.CancelEdit()
End Select
End Sub
Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancel.Click
actions = Nothing
Me.Close()
End Sub
Private Class patternAction
Implements IComparable(Of patternAction)
Public time As Integer
Public mask As Integer
Public Sub New(_time As Integer, _mask As Integer)
time = _time
mask=_mask
End Sub
Function CompareTo(other As patternAction) As Integer Implements IComparable(Of patternAction).CompareTo
If time < other.time Then Return -1
If time > other.time Then Return 1
Return 0
End Function
End Class
Private Sub btnOK_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
actions = Nothing
Dim patternButtons As New List(Of patternData)
Dim period As Integer = 0
For Each pd In buttons
If pd.Interval > 0 Then
patternButtons.Add(pd)
If pd.Count > 0 Then
period = Math.Max(period, pd.Interval * pd.Count + pd.Offset)
End If
End If
Next
Dim pressDict As New Dictionary(Of Integer, Integer)
For Each pd In patternButtons
For i As Integer = pd.Offset To period - 1 Step pd.Interval
If pressDict.ContainsKey(i) Then
pressDict(i) = pressDict(i) Or pd.mask
Else
pressDict.Add(i, pd.mask)
End If
Next
Next
Dim pressList As New List(Of patternAction)
For Each p As KeyValuePair(Of Integer, Integer) In pressDict
pressList.Add(New patternAction(p.Key, p.Value))
Next
pressDict = Nothing
pressList.Sort()
If pressList(0).time > 0 Then actions.Add(New clsActionWait(pressList(0).time, Nothing))
actions = New List(Of clsAction)
For i = 0 To pressList.Count - 1
Dim delay As Integer
If i = pressList.Count - 1 Then
delay = period - pressList(i).time
Else
delay = pressList(i + 1).time - pressList(i).time
End If
actions.Add(New clsActionPress(1, pressList(i).mask, -1, -1, New Point(-32768, -32768), New Point(-32768, -32768), 100, delay, 1, Nothing))
actions(i).index = i
Next
Me.Close()
End Sub
Private Sub dgvPattern_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvPattern.CellContentClick
End Sub
End Class