-
Notifications
You must be signed in to change notification settings - Fork 1
/
CirLCAR.bas
488 lines (428 loc) · 20.4 KB
/
CirLCAR.bas
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
Attribute VB_Name = "CircularLCAR"
Option Explicit
Public Const cLCAR_Yellow As Long = 6750104 'rgb(152,255,102)
Public Const cLCAR_Green As Long = 231942 'rgb(6,138,3)
Public Const cLCAR_LightBlue As Long = 16764313 'rgb(153,205,255)
Public Const cLCAR_Blue As Long = 16646144 'rgb(0,0,254)
'Private Const Resolution As Long = 1
Private Const ColsPerQuadrant As Long = 10 'must be an even number ' * Resolution
Private Const Rows As Long = 10 '* Resolution
Private Const Width As Single = 360 / (ColsPerQuadrant * 4)
Private Const LineWidth As Single = Width / 8 '4 per grid with equal whitespace
Public Enum LineType
NoLine
Color1Line
Color2Line
End Enum
Public Enum GridType
Blank
aCircle 'O
aSquare '[]
SemiCircle '(c
Lines '=
Bar 'u
GridLine
End Enum
Public Type GridSegment
SegmentType As GridType
Top As Single
Bottom As Single
Left As Single
Right As Single
Color As Long
BlinkColor As Long
Blinking As Boolean
End Type
Public Type CirLCAR
Grid(1 To Rows, 1 To ColsPerQuadrant * 4) As GridSegment
End Type
Public CircleID As Long, CircleName As String, CircleRow As Long, CircleCol As Long, CircleTool As Long, isdown2 As Boolean
Public CircleMode As GridType, CircleDiameter As Single, CircleLeft As Single, CircleRight As Single, CircleTop As Single, CircleBottom As Single
Public CircleColor As Long, CircleBlinkColor As Long, CircleLines(0 To 3) As Long
Dim temp As CirLCAR
Public Sub ShutdownEngine()
Form1.TimerBlink.Enabled = False
Form1.TimerEffects.Enabled = False
Form1.Cls
End Sub
Public Function CircleColsPerQuadrant() As Long
CircleColsPerQuadrant = ColsPerQuadrant
End Function
Public Function CircleCols() As Long
CircleCols = ColsPerQuadrant * 4
End Function
Public Function CircleRows() As Long
CircleRows = Rows
End Function
Public Function CircleColWidth() As Single
CircleColWidth = Width
End Function
Public Sub DrawCirLCAR(Circ As CirLCAR, X As Long, Y As Long, Radius As Long, Optional Blink As Boolean)
Dim Row As Long, Col As Long, CurrAngle As Single, Height As Long, Color As Long, TempColor As Long
Dim cStart As Long, cFinish As Long, temp As Double, temp2 As Long, X2 As Long, Y2 As Long, Col2 As Long
Height = Radius / Rows
cFinish = Height
For Row = 1 To Rows
If isRotated Then CurrAngle = 180 Else CurrAngle = 90 '- Width
For Col = 1 To ColsPerQuadrant * 4
If isRotated Then
Col2 = (Col + ColsPerQuadrant) Mod ColsPerQuadrant * 4
Else
Col2 = Col
End If
With Circ.Grid(Row, Col2)
If Blink And .Blinking Then Color = .BlinkColor Else Color = .Color
If RedAlert And Color <> vbBlack Then If Blink Then Color = LCAR_White Else Color = LCAR_Red
Select Case .SegmentType
Case aCircle
temp = DegreesToRadians(CorrectAngle(CurrAngle + 90 - (Width / 2) - (.Left * Width))) '-
X2 = findXY(CSng(X), CSng(Y), cStart + (Height / 2) + (Height * .Bottom), temp, True)
Y2 = findXY(CSng(X), CSng(Y), cStart + (Height / 2) + (Height * .Bottom), temp, False)
DrawSemiCircle X2, Y2, .Top * (Height / 2), 0, 360, Color, Color, , , 0
Case aSquare 'size is relative to radius, not height/width
temp2 = -1
Select Case Col
Case 1, ColsPerQuadrant * 4: temp2 = 0 'Top
Case ColsPerQuadrant * 3, ColsPerQuadrant * 3 + 1: temp2 = 6 'left
Case ColsPerQuadrant, ColsPerQuadrant + 1: temp2 = 2 'Right
Case ColsPerQuadrant * 2, ColsPerQuadrant * 2 + 1: temp2 = 4 'Bottom
Case ColsPerQuadrant / 2, ColsPerQuadrant / 2 + 1: temp2 = 1 'top right
Case ColsPerQuadrant * 1.5, ColsPerQuadrant * 1.5 + 1: temp2 = 3
Case ColsPerQuadrant * 2.5, ColsPerQuadrant * 2.5 + 1: temp2 = 5
Case ColsPerQuadrant * 3.5, ColsPerQuadrant * 3.5 + 1: temp2 = 7
End Select
If temp2 > -1 Then CirLCAR_DrawSquare X, Y, Height * .Right, Height * .Left, temp2, Color, Height * (Row - 1)
Case SemiCircle
'DrawSemiCircle X, Y, cStart + (.Top * Height), CurrAngle + (.Left * Width), (.Right * Width) - (.Left * Width), Color, Color, 2, , cStart + (.Bottom * Height)
If .Left < 0 Then
DrawSemiCircle X, Y, cStart + (.Top * Height), CurrAngle - (.Right * Width), (.Right - .Left) * Width, Color, Color, 2, , cStart + (.Bottom * Height), , 1
'DrawSemiCircle X, Y, cStart + (.Top * Height), CurrAngle + (.Left * Width) - ((.Right - .Left) * (Width)), (.Right - .Left) * Width, Color, Color, 2, , cStart + (.Bottom * Height), , 1
Else
DrawSemiCircle X, Y, cStart + (.Top * Height), CurrAngle - ((.Right + .Left) * Width) + (.Left * Width), (.Right - .Left) * Width, Color, Color, 2, , cStart + (.Bottom * Height), , 1
End If
Case Lines 'yes I could compress this but I don't have the time
temp2 = CLng(CurrAngle) '+ Width
CirDrawLine X, Y, temp2, cStart, Height, .Top, .Color, .BlinkColor, 2
temp2 = temp2 - LineWidth * 2
CirDrawLine X, Y, temp2, cStart, Height, .Bottom, .Color, .BlinkColor, 2
temp2 = temp2 - LineWidth * 2
CirDrawLine X, Y, temp2, cStart, Height, .Left, .Color, .BlinkColor, 2
temp2 = temp2 - LineWidth * 2
CirDrawLine X, Y, temp2, cStart, Height, .Right, .Color, .BlinkColor, 2
Case Bar
temp2 = cStart + (Height * 0.5)
'DrawSemiCircle X, Y, temp2, CurrAngle + (((1 - .Top) / 2) * Width), Width * .Top, Color, Color, Height / 2, 1, temp2
DrawSemiCircle X, Y, temp2, CurrAngle - ((.Left + .Right) * Width), (.Right * Width) - (.Left * Width), Color, Color, Height / 2, , temp2
Case GridLine
'DrawSemiCircle X, Y, cStart, CurrAngle - Width, Width, Color, Color, 1, 1, cStart
CirDrawLine X, Y, CLng(CurrAngle), cStart, Height, 1, Color, Color, 1
'CirDrawLine X, Y, CLng(CurrAngle) - Width, cStart, Height, 1, Color, Color, 1
DrawSemiCircle X, Y, cStart + Height, CurrAngle - Width, Width, Color, Color, 1, 1, cStart + Height
End Select
End With
CurrAngle = CurrAngle - Width
If CurrAngle < 0 Then CurrAngle = CurrAngle + 360
Next
cStart = cStart + Height
cFinish = cStart + Height
Next
End Sub
Public Function CirDrawLine(X As Long, Y As Long, Angle As Long, Radius As Long, Length As Long, State As Single, Color As Long, BlickColor As Long, DrawWidth As Long)
Dim temp As Long, temp2 As Long, X1 As Long, X2 As Long, Y1 As Long, Y2 As Long, Radians As Double
If Angle < 0 Then Angle = Angle + 360
If State > 0 Then
If RedAlert Then
If State = 1 Then temp = LCAR_Red Else temp = LCAR_White
Else
If State = 1 Then temp = Color Else temp = BlickColor
End If
Radians = DegreesToRadians(CorrectAngle(Angle + 90))
X1 = findXY(CSng(X), CSng(Y), CSng(Radius), Radians, True)
Y1 = findXY(CSng(X), CSng(Y), CSng(Radius), Radians, False)
X2 = findXY(CSng(X), CSng(Y), CSng(Radius) + Length, Radians, True)
Y2 = findXY(CSng(X), CSng(Y), CSng(Radius) + Length, Radians, False)
temp2 = dest.DrawWidth
dest.DrawWidth = DrawWidth
dest.Line (X1, Y1)-(X2, Y2), temp
dest.DrawWidth = temp2
End If
End Function
Public Sub CirLCAR_DrawSquare(ByVal X As Long, ByVal Y As Long, ByVal Width As Long, Length As Long, ByVal Angle As Long, Color As OLE_COLOR, Optional Start As Long)
Dim temp As Long, temp2 As Long, X2 As Long, Y2 As Long, NewAngle As Long
temp = Width / 2
If Width Mod 1 = 0 Then Width = Width + 1
Select Case Angle
Case 0 ' | up
DrawSquare X - temp, Y - Length - Start, Width, Length, Color, Color
Case 6 '- left
DrawSquare X - Length - Start, Y - temp, Length, Width, Color, Color
Case 2 ' - right
DrawSquare X + Start, Y - temp, Length, Width, Color, Color
Case 4 ' | down
DrawSquare X - temp, Y + Start, Width, Length, Color, Color
Case Else
Select Case Angle
Case 1: NewAngle = 135 ' / up right
Case 3: NewAngle = 45 ' \ down right
Case 5: NewAngle = 315 '/ down left
Case 7: NewAngle = 225 '\ up left
End Select
If isRotated Then NewAngle = CLng(CorrectAngle(NewAngle + 90))
temp = Width / 3
For temp2 = 0 To Length - 1
X2 = findXY(CSng(X), CSng(Y), Start + temp2, DegreesToRadians(NewAngle), True)
Y2 = findXY(CSng(X), CSng(Y), Start + temp2, DegreesToRadians(NewAngle), False)
Select Case Angle
Case 1 ' / up right
dest.Line (X2 - temp, Y2 - temp)-(X2 + temp + 1, Y2 + temp + 1), Color
dest.Line (X2 - temp + 1, Y2 - temp)-(X2 + temp + 2, Y2 + temp + 1), Color
Case 3 'down right
dest.Line (X2 + temp - 1, Y2 - temp + 1)-(X2 - temp, Y2 + temp), Color
dest.Line (X2 + temp - 2, Y2 - temp + 1)-(X2 - temp - 1, Y2 + temp), Color
Case 5 'down left
dest.Line (X2 - temp, Y2 - temp)-(X2 + temp + 1, Y2 + temp + 1), Color
dest.Line (X2 - temp - 1, Y2 - temp)-(X2 + temp, Y2 + temp + 1), Color
Case 7 'up left
dest.Line (X2 + temp - 1, Y2 - temp - 1)-(X2 - temp - 2, Y2 + temp), Color
dest.Line (X2 + temp - 2, Y2 - temp - 1)-(X2 - temp - 3, Y2 + temp), Color
'dest.Line (X2 + temp, Y2 - temp + 1)-(X2 - temp + 1, Y2 + temp), Color
End Select
Next
End Select
End Sub
Public Function CirLCAR_SetBlank(Circ As CirLCAR, Row As Long, Col As Long) As Boolean
If Row < 1 Or Row > Rows Then Exit Function
If Col < 1 Or Col > ColsPerQuadrant * 4 Then Exit Function
With Circ.Grid(Row, Col)
.SegmentType = Blank
.BlinkColor = LCAR_Black
.Blinking = False
.Color = LCAR_Black
.Bottom = 0
.Left = 0
.Top = 0
.Right = 0
End With
CirLCAR_SetBlank = True
End Function
Public Function CirLCAR_SetBar(Circ As CirLCAR, Row As Long, Col As Long, Optional Left As Single = 0, Optional Right As Single = 1, Optional Color As Long = cLCAR_Yellow, Optional BlinkColor As Long = -1) As Boolean
If Row < 1 Or Row > Rows Then Exit Function
If Col < 1 Or Col > ColsPerQuadrant * 4 Then Exit Function
With Circ.Grid(Row, Col)
.SegmentType = Bar
.Color = Color
.Left = Left
.Right = Right
If BlinkColor = -1 Then
.Blinking = False
.BlinkColor = LCAR_Black
Else
.Blinking = True
.BlinkColor = BlinkColor
End If
End With
CirLCAR_SetBar = True
End Function
Public Function CirLCAR_SetSemiCircle(Circ As CirLCAR, Row As Long, Col As Long, Top As Single, Bottom As Single, Left As Single, Right As Single, Optional Color As Long = cLCAR_Yellow, Optional BlinkColor As Long = -1) As Boolean
If Row < 1 Or Row > Rows Then Exit Function
If Col < 1 Or Col > ColsPerQuadrant * 4 Then Exit Function
If Top < Bottom Or Left > Right Then Exit Function
With Circ.Grid(Row, Col)
.SegmentType = SemiCircle
.Top = Top
.Bottom = Bottom
.Left = Left
.Right = Right
.Color = Color
If BlinkColor = -1 Then
.Blinking = False
.BlinkColor = LCAR_Black
Else
.Blinking = True
.BlinkColor = BlinkColor
End If
End With
CirLCAR_SetSemiCircle = True
End Function
Public Function CirLCAR_SetCircle(Circ As CirLCAR, Row As Long, Col As Long, Diameter As Single, Optional Color As Long = cLCAR_Yellow, Optional BlinkColor As Long = -1, Optional Left As Single, Optional Bottom As Single) As Boolean
If Row < 1 Or Row > Rows Then Exit Function
If Col < 1 Or Col > ColsPerQuadrant * 4 Then Exit Function
With Circ.Grid(Row, Col)
.SegmentType = aCircle
.Top = Diameter
.Color = Color
.Left = Left
.Bottom = Bottom
If BlinkColor = -1 Then
.Blinking = False
.BlinkColor = LCAR_Black
Else
.Blinking = True
.BlinkColor = BlinkColor
End If
End With
CirLCAR_SetCircle = True
End Function
Public Function CirLCAR_SetLines(Circ As CirLCAR, Row As Long, Col As Long, Optional Color1 As Long = cLCAR_Yellow, Optional Color2 As Long = cLCAR_Green, Optional Bar1 As LineType, Optional Bar2 As LineType, Optional Bar3 As LineType, Optional Bar4 As LineType) As Boolean
If Row < 1 Or Row > Rows Then Exit Function
If Col < 1 Or Col > ColsPerQuadrant * 4 Then Exit Function
If Bar1 < 0 Or Bar1 > 2 Then Exit Function
If Bar2 < 0 Or Bar2 > 2 Then Exit Function
If Bar3 < 0 Or Bar3 > 2 Then Exit Function
If Bar4 < 0 Or Bar4 > 2 Then Exit Function
With Circ.Grid(Row, Col)
.SegmentType = Lines
.Top = Bar1
.Bottom = Bar2
.Left = Bar3
.Right = Bar4
.Blinking = False
.Color = Color1
.BlinkColor = Color2
End With
CirLCAR_SetLines = True
End Function
Public Function CirLCAR_SetGridline(Circ As CirLCAR, Row As Long, Col As Long, Optional Color As Long = cLCAR_Yellow, Optional BlinkColor As Long = -1) As Boolean
If Row < 1 Or Row > Rows Then Exit Function
If Col < 1 Or Col > ColsPerQuadrant * 4 Then Exit Function
With Circ.Grid(Row, Col)
.SegmentType = GridLine
.Color = Color
If BlinkColor = -1 Then
.Blinking = False
.BlinkColor = LCAR_Black
Else
.Blinking = True
.BlinkColor = BlinkColor
End If
End With
End Function
Public Function CirLCAR_SetSquare(Circ As CirLCAR, Row As Long, Col As Long, Width As Single, Length As Single, Optional Color As Long = cLCAR_Yellow, Optional BlinkColor As Long = -1) As Boolean
If Row < 1 Or Row > Rows Then Exit Function
If Col < 1 Or Col > ColsPerQuadrant * 4 Then Exit Function
With Circ.Grid(Row, Col)
.SegmentType = aSquare
.Color = Color
If BlinkColor = -1 Then
.Blinking = False
.BlinkColor = LCAR_Black
Else
.Blinking = True
.BlinkColor = BlinkColor
End If
.Left = Length
.Right = Width
End With
End Function
Public Function CirLCAR_SetAllGridlines(Circ As CirLCAR, Optional Color As Long = cLCAR_Yellow, Optional BlinkColor As Long = -1) As Boolean
Dim temp As Long, temp2 As Long
For temp = 1 To Rows
For temp2 = 1 To ColsPerQuadrant * 4
If Color = -1 Then
CirLCAR_SetBlank Circ, temp, temp2
Else
CirLCAR_SetGridline Circ, temp, temp2, Color, BlinkColor
End If
Next
Next
CirLCAR_SetAllGridlines = True
End Function
Public Sub TestCirLCAR()
Dim temp2 As Long
CirLCAR_SetAllGridlines temp, LCAR_Red
temp2 = LCAR_AddCircle("circGridlines", -205, 279, 200, True, 8) '305
LCARCircleList(temp2).Circ = temp
CirLCAR_SetAllGridlines temp, -1
If False Then
CirLCAR_SetSemiCircle temp, 4, 1, 1, 0, 0, 1
CirLCAR_SetSemiCircle temp, 4, 2, 0.75, 0.25, 0, 1, cLCAR_Blue
CirLCAR_SetSemiCircle temp, 4, 4, 1, 0, 0, 1
CirLCAR_SetSemiCircle temp, 4, 5, 0.75, 0.25, 0, 1, cLCAR_LightBlue
CirLCAR_SetCircle temp, 4, 6, 0.75
CirLCAR_SetCircle temp, 4, 7, 0.75, cLCAR_Blue
CirLCAR_SetCircle temp, 4, 8, 0.75, cLCAR_LightBlue
CirLCAR_SetBar temp, 4, 9, 0.5
CirLCAR_SetLines temp, 4, 10, , , Color1Line, Color2Line, Color1Line, Color2Line
CirLCAR_SetGridline temp, 4, 11
CirLCAR_SetSemiCircle temp, 6, 1, 1, 0, 0, 1
CirLCAR_SetSemiCircle temp, 6, 2, 0.75, 0.25, 0, 1, cLCAR_Blue
CirLCAR_SetSemiCircle temp, 6, 4, 1, 0, 0, 1
CirLCAR_SetSemiCircle temp, 6, 5, 0.75, 0.25, 0, 1, cLCAR_LightBlue
End If
'DrawCirLCAR temp, 200, 200, 200
temp2 = LCAR_AddCircle("circTest", -205, 279, 200, True, 8) '305
LCARCircleList(temp2).Circ = temp
CircleDiameter = 0.1
CircleRight = 1
CircleTop = 1
End Sub
Public Function SaveCirLCAR(Cir As CirLCAR) As String
Const D As String = " "
Dim Row As Long, Col As Long, tempstr As String, tempstr2 As String
For Row = 1 To Rows
tempstr2 = Empty
For Col = 1 To ColsPerQuadrant * 4
With Cir.Grid(Row, Col)
tempstr2 = tempstr2 & .SegmentType & D & LCAR_ColorIDfromColor(.Color) & D & LCAR_ColorIDfromColor(.BlinkColor) & D & .Top & D & .Bottom & D & .Left & D & .Right & D
End With
Next
tempstr = tempstr & tempstr2
Next
SaveCirLCAR = Left(tempstr, Len(tempstr) - 1)
End Function
Public Function LoadCirLCAR(Cir As CirLCAR, Text As String, Optional StartCol As Long = 1, Optional EndCol As Long = -1) As Boolean
Dim Row As Long, Col As Long, tempstr() As String, temp As Long, Required As Long
If EndCol < StartCol Then EndCol = ColsPerQuadrant * 4
Required = (7 * Rows * ColsPerQuadrant * 4) - 1
tempstr = Split(Text, " ")
Row = 1
Col = 1
If UBound(tempstr) <> Required Then Exit Function
For temp = 0 To UBound(tempstr) Step 7
If Col >= StartCol And Col <= EndCol Then
With Cir.Grid(Row, Col)
.SegmentType = Val(tempstr(temp))
.Color = ColorList(Val(tempstr(temp + 1))).Color
.BlinkColor = ColorList(Val(tempstr(temp + 2))).Color
.Top = Val(tempstr(temp + 3))
.Bottom = Val(tempstr(temp + 4))
.Left = Val(tempstr(temp + 5))
.Right = Val(tempstr(temp + 6))
End With
End If
Col = Col + 1
If Col > ColsPerQuadrant * 4 Then
Col = 1
Row = Row + 1
End If
Next
LoadCirLCAR = True
End Function
Public Function LoadFile(Filename As String) As String
On Error Resume Next
If FileLen(Filename) = 0 Then Exit Function
Dim temp As Long, tempstr As String, tempstr2 As String
temp = FreeFile
If Dir(Filename) <> Filename Then
Open Filename For Input As temp
Do Until EOF(temp)
Line Input #temp, tempstr
If tempstr2 <> Empty Then tempstr2 = tempstr2 & vbNewLine
tempstr2 = tempstr2 & tempstr
DoEvents
Loop
LoadFile = tempstr2
Close temp
End If
End Function
Public Function SaveFile(Filename As String, Contents As String) As Boolean
On Error Resume Next
Dim temp As Long
temp = FreeFile
If Filename Like "?:\*" Then
Open Filename For Output As temp
Print #temp, Contents
Close temp
End If
SaveFile = True
End Function