-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEffectsAPI.bas
More file actions
392 lines (335 loc) · 12.4 KB
/
EffectsAPI.bas
File metadata and controls
392 lines (335 loc) · 12.4 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
Attribute VB_Name = "EffectsAPI"
Option Explicit
Public Const HighliteColor As Long = LCAR_LightBlue
Public Const btntxtbox As String = "btntxtbox"
'keyboard
Public Text As String, SelStart As Long, SelLength As Long, Symbols As Boolean, Shift As Boolean, Caps As Boolean, TextID As Long, DefaultText As String, OldText As String
Public Operation As String
'sensor grid
Public Cx As Double, Cy As Double, pX As Double, pY As Double
Public Function isShift() As Boolean
isShift = Shift
End Function
Public Function CursorIsVisible() As Boolean
Static oldPosition As Long, oldWidth As Long
CursorIsVisible = (Second(Now) Mod 2 = 0) Or (oldPosition <> SelStart) Or (oldWidth <> SelLength)
oldPosition = SelStart
oldWidth = SelLength
End Function
Private Sub Emergency()
TextID = LCAR_FindLCAR(btntxtbox)
End Sub
Public Function CursorPosition(Optional Position As Long = -1) As Long
Dim oldsize As Long, Start As Long
oldsize = dest.Font.Size
Emergency
With LCAR_ButtonList(TextID)
dest.Font.Size = .TextSize
If Position = -1 Then
Start = dest.TextWidth(GetSelText)
Else
Start = .X + 4
If Start < 0 Then Start = DestWidth - .X
If Position > 0 Then Start = Start + dest.TextWidth(Mid(Text, 1, Position)) ': Debug.Print Mid(Text, 1, Position)
End If
CursorPosition = Start
End With
dest.Font.Size = oldsize
End Function
Public Sub DrawCursor()
Dim X As Long, Width As Long, Y As Long
Emergency
X = CursorPosition(SelStart)
If SelLength <> 0 Then
Width = CursorPosition
If SelLength < 0 Then Width = -Width
End If
With LCAR_ButtonList(TextID)
If Width <> 0 Then
If Width > 0 Then
DrawSquare X, Y + 2, Width, .Height - 1, HighliteColor, HighliteColor
DrawText X - 1, Y + 2, GetSelText, LCAR_Orange, .TextSize
Else
DrawSquare X + Width, Y + 2, Abs(Width) + 1, .Height - 1, HighliteColor, HighliteColor
DrawText X + Width, Y + 2, GetSelText, LCAR_Orange, .TextSize
End If
End If
If CursorIsVisible Then
DrawSquare X - 1, Y + 2, 3, .Height - 1, LCAR_Orange, LCAR_Orange
'DrawLine X, .Y, 1, .Height, LCAR_Orange
Else
LCAR_ButtonList(TextID).IsClean = False
End If
End With
End Sub
Public Function KeyboardIsVisible() As Boolean
KeyboardIsVisible = LCARlists(2).Visible
End Function
Public Sub ShowKeyboard(Default As String, Optional Op As String)
Emergency
Operation = Op
HideAllGroups 5
HideAllLists 2
LCAR_ButtonList(preview).Visible = False
DefaultText = Default
Text = Default
SelStart = 0
SelLength = Len(Default)
LCAR_SetText "btntxtbox", Default, , , , , , , , False
End Sub
Public Function HideKeyboard() As String
HideAllGroups 3
HideAllLists 0
LCAR_ButtonList(preview).Visible = True
HideKeyboard = Text
End Function
Public Sub DrawEffects()
If KeyboardIsVisible Then
IncrementGrid 0.005 '1
DrawGridAuto
End If
End Sub
Public Function ProcessKey(Key As String)
Static LCARid As Long, SymbolID As Long
Emergency
If Len(Key) > 0 Then
If Len(Key) = 1 Then
SetSelText Key
If Shift Then
Shift = False
If LCARid = 0 Then LCARid = LCAR_FindLCAR("frmbottom", , 6)
LCAR_Blink LCARid, False
End If
If Symbols Then
Symbols = False
If SymbolID = 0 Then SymbolID = LCAR_FindLCAR("frmbottom", , 4)
LCAR_Blink SymbolID, False
End If
Else
Select Case LCase(Key)
Case "left"
If Shift Then
SelLength = SelLength - 1
If SelLength < 0 Then
If SelStart + SelLength < 0 Then SelLength = SelLength + 1
End If
Else
SelLength = 0
SelStart = SelStart - 1
If SelStart < 0 Then ProcessKey "end"
End If
Case "right"
If Shift Then
SelLength = SelLength + 1
If SelLength > 0 Then
If SelStart + SelLength > Len(Text) Then SelLength = SelLength - 1
End If
Else
SelLength = 0
SelStart = SelStart + 1
If SelStart > Len(Text) Then ProcessKey "home"
End If
Case "home"
If Shift Then SelLength = SelStart Else SelLength = 0
SelStart = 0
Case "end"
If Shift Then SelLength = -(Len(Text) - SelStart) Else SelLength = 0
SelStart = Len(Text)
Case "delete"
If Len(Text) > 0 Then
If SelLength = 0 Then
SelLength = 1
End If
SetSelText Empty
End If
Case "backspace"
If Len(Text) > 0 Then
If SelLength = 0 Then
If SelStart > 0 Then
SelStart = SelStart - 1
SelLength = 1
End If
End If
SetSelText Empty
End If
Case "space"
ProcessKey " "
Case "shift"
LCARid = LCAR_FindLCAR("frmbottom", , 6)
LCAR_Blink LCARid, Not LCAR_isBlinking(LCARid)
Shift = LCAR_isBlinking(LCARid)
End Select
End If
End If
LCAR_SetText LCAR_ButtonList(TextID).Name, Text, , , , , , , , False
End Function
Public Function GetSelText() As String
If Abs(SelLength) = Len(Text) Then
GetSelText = Text
Else
If SelLength > 0 Then
GetSelText = Mid(Text, SelStart + 1, SelLength)
ElseIf SelLength < 0 Then
GetSelText = Mid(Text, SelStart + SelLength + 1, Abs(SelLength))
End If
End If
End Function
Public Sub SetSelText(Key As String)
Dim LSide As Long, RSide As Long, L As String, R As String
If SelLength > 0 Then
LSide = SelStart
RSide = Len(Text) - SelStart - SelLength
SelStart = SelStart + Len(Key)
ElseIf SelLength < 0 Then
LSide = SelStart + SelLength
RSide = Len(Text) - SelStart
SelStart = LSide + Len(Key)
Else
LSide = SelStart
RSide = Len(Text) - SelStart
SelStart = SelStart + Len(Key)
End If
If LSide > 0 Then L = Left(Text, LSide)
If RSide > 0 Then R = Right(Text, RSide)
Text = L + Key + R
SelLength = 0
End Sub
Public Function GetKey(Index As Long) As String
Dim tempstr As String
If Symbols Then tempstr = LCARlists(2).ListItems(Index).Side
If Len(tempstr) = 0 Then
tempstr = LCARlists(2).ListItems(Index).Text
If (Shift And Caps) Or ((Not Shift) And (Not Caps)) Then
tempstr = LCase(tempstr)
'ElseIf (Shift And Not Caps) Or (Not Shift And Caps) Then
' tempstr = UCase(tempstr)
End If
End If
GetKey = tempstr
End Function
Public Function vKey2String(vKey As Long, Optional Default As String = "Press Any Key") As String
Select Case vKey
Case 8: vKey2String = "Backspace"
Case 13: vKey2String = "Enter"
Case 16: vKey2String = "Shift"
Case 17: vKey2String = "Ctrl"
Case 18: vKey2String = "Alt"
Case 19: vKey2String = "Pause"
Case 20: vKey2String = "Caps Lock"
Case 27: vKey2String = "Escape"
Case 32: vKey2String = "Space"
Case 33: vKey2String = "Page Up"
Case 34: vKey2String = "Page Down"
Case 35: vKey2String = "End"
Case 36: vKey2String = "Home"
Case 37: vKey2String = "Left"
Case 38: vKey2String = "Up"
Case 39: vKey2String = "Right"
Case 40: vKey2String = "Down"
Case 45: vKey2String = "Insert"
Case 46: vKey2String = "Delete"
Case 48 To 57: vKey2String = Chr(vKey) '0-9
Case 65 To 90: vKey2String = LCase(Chr(vKey)) 'a-z
Case 91: vKey2String = "Start"
Case 93: vKey2String = "Menu"
Case 96 To 105: vKey2String = Chr(vKey - 48)
Case 106: vKey2String = "*"
Case 107: vKey2String = "+"
Case 109, 189: vKey2String = "-" '
Case 110, 190: vKey2String = "."
Case 111, 191: vKey2String = "/"
Case 220: vKey2String = "\"
'Case 186: vKey2String = ";"
'Case 112 To 123: vKey2String = "F" & vKey - 111
Case 144: vKey2String = "Num Lock"
Case 145: vKey2String = "Scroll Lock"
Case 192: vKey2String = "`"
Case Else: vKey2String = Default: MsgBox vKey
End Select
End Function
Public Sub SetupEffects()
Cx = 0.5
Cy = 0.5
pX = 0.5
pY = 0.5
End Sub
Public Sub DrawGridAuto()
Dim Width As Long, Height As Long
Width = DestWidth - 223
Height = DestHeight - 338
DrawSensorGrid 110, 88, Width, Height, Width * Cx, Height * Cy
End Sub
Public Sub IncrementGrid(Optional Speed As Double = 0.05)
If Cx < pX Then
Cx = Cx + Speed
If Cx > pX Then Cx = pX
ElseIf Cx > pX Then
Cx = Cx - Speed
If Cx < pX Then Cx = pX
End If
If Cy < pY Then
Cy = Cy + Speed
If Cy > pY Then Cy = pY
ElseIf Cy > pY Then
Cy = Cy - Speed
If Cy < pY Then Cy = pY
End If
If Cx = pX And Cy = pY Then
Randomize Timer
pX = Rnd
pY = Rnd
End If
End Sub
Public Sub DrawSensorGrid(X As Long, Y As Long, Width As Long, Height As Long, oX As Long, oY As Long, Optional StartSize As Double = 0.1, Optional Factor As Double = 0.95, Optional Border As Long = 2)
Dim Cx As Double, cWidth As Double, temp As Long
Static WasVisible As Boolean
'Units = 2 ^ Lines
DrawSquare X, Y, Width, Height, vbBlack, vbBlack
DrawSquare X + Border, Y + Border, Width - Border * 2, Height - Border * 2, vbWhite, IIf(RedAlert, LCAR_Red, LCAR_DarkBlue)
cWidth = StartSize * oX
Cx = oX + X
dest.DrawWidth = 3
DrawLine Cx, Y + 1, 1, Height - 2, vbWhite
DrawLine X + 1, oY + Y, Width - 2, 1, vbWhite
dest.DrawWidth = 1
temp = X + Border
Do While Cx > temp
cWidth = cWidth * Factor
Cx = Cx - cWidth
If Cx > X Then DrawLine Cx, Y, 1, Height, vbWhite
If cWidth < 2 Then Cx = 0
Loop
cWidth = StartSize * (Width - oX)
Cx = oX + X
temp = X + Width - Border
Do While Cx < temp
cWidth = cWidth * Factor
Cx = Cx + cWidth
If Cx < temp Then DrawLine Cx, Y, 1, Height, vbWhite
If cWidth < 2 Then Cx = X + Width
Loop
cWidth = StartSize * oY
Cx = oY + Y
temp = Y + Border
Do While Cx > temp
cWidth = cWidth * Factor
Cx = Cx - cWidth
If Cx > temp Then DrawLine X, Cx, Width, 1, vbWhite
If cWidth < 2 Then Cx = 0
Loop
cWidth = StartSize * (Height - oY)
Cx = oY + Y
temp = Y + Height - Border
Do While Cx < temp
cWidth = cWidth * Factor
Cx = Cx + cWidth
If Cx < temp Then DrawLine X, Cx, Width, 1, vbWhite
If cWidth < 2 Then Cx = temp
Loop
'If Not CursorIsVisible Then
DrawCursor ' Else LCAR_ButtonList(TextID).IsClean = False
'If WasVisible <> CursorIsVisible Then
' WasVisible = Not WasVisible
' DrawCursor
'End If
End Sub