-
Notifications
You must be signed in to change notification settings - Fork 0
/
LCARSeffects2.bas
1247 lines (1085 loc) · 40.7 KB
/
LCARSeffects2.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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=StaticCode
Version=6.77
@EndOfDesignText@
'1:28 autodestruct is offline
'cache xy speeds for angles
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
'Universal buffer stuff
Dim CenterPlatformID As Int, CenterPlatform As Bitmap ,WasInit As Boolean,UNIFILE As String
'graph stuff
Type Graph(ID As Int, Points As List, MaxPoints As Int, CurrentPoint As Int, IsClearing As Boolean,IsClean As Boolean, ExpandWhenFull As Int, BracketX As Int)
Dim GraphList As List
GraphList.Initialize
'Omegastuff
Dim CachedOmega As Rect ,TopTextWidth As Int, OmegaNeedsInit As Boolean
Dim StarshipFont As Typeface
'Random number stuff
Type NumLin(Lines As Int, RedAlert As Int, RandomizeFullList As Int )
Type NumCol(Digits As Int, Align As Int, ColorID As Int)
Type NumLis(Columns As List, Values As List, ColorID As Int, Age As Int, ID As Int, TotalWidth As Int)
Dim Numbers As List, LineList As List ,NumSection As Int ,LastSecond As Int,RandomizeFullList As Boolean
'Adv. Drawing stuff
'Dim mMatrix As ABMatrix, mPaint As ABPaint, mCamera As ABCamera,isAdvInit As Boolean
Dim AMBIENT_LIGHT As Int: AMBIENT_LIGHT = 55 'Ambient light intensity
Dim DIFFUSE_LIGHT As Int: DIFFUSE_LIGHT = 200 'Diffuse light intensity
Dim SPECULAR_LIGHT As Float: SPECULAR_LIGHT = 70 'Specular light intensity
Dim SHININESS As Float: SHININESS = 200 'Shininess constant
Dim MAX_INTENSITY As Int: MAX_INTENSITY = 255 'The Max intensity of the light'0xFF
End Sub
Sub TempCanvas As Canvas
Dim BG As Canvas
If Not(CenterPlatform.IsInitialized) Then CenterPlatform.InitializeMutable(1,1)
BG.Initialize2(CenterPlatform)
Return BG
End Sub
Sub InitUniversalBMP(Width As Int, Height As Int, ElementType As Int) As Canvas
Dim BG As Canvas, NeedsInit As Boolean
WasInit=False
If Not(CenterPlatform.IsInitialized ) Or CenterPlatformID <> ElementType Then
NeedsInit=True
Else If CenterPlatform.Height<>Height Or CenterPlatform.Width <> Width Then
NeedsInit=True
End If
If NeedsInit Then
CenterPlatform.InitializeMutable(Width,Height)
CenterPlatformID = ElementType
WasInit=True
UNIFILE=""
End If
BG.Initialize2(CenterPlatform)
Return BG
End Sub
Sub LoadUniversalBMP(Dir As String, Filename As String, ElementType As Int) As Boolean
Dim tempstr As String
If Filename.length >0 Then
tempstr=File.Combine(Dir,Filename)
If Not(CenterPlatform.IsInitialized ) OR CenterPlatformID <> ElementType OR tempstr <> UNIFILE Then
If File.Exists(Dir,Filename) Then
Try
'If CenterPlatform.IsInitialized then BitMap.recycle
CenterPlatform.Initialize(Dir,Filename)
CenterPlatformID = ElementType
WasInit=True
UNIFILE=tempstr
Return True
Catch
Return False
End Try
End If
End If
Return True
End If
End Sub
Sub ClearRandomNumbers
LineList.Initialize
NumSection=0
Numbers.Initialize
End Sub
Sub InitRandomNumbers(ElementType As Int, IncrementalUpdates As Boolean) As Boolean
If ElementType <> NumSection Then
ClearRandomNumbers
NumSection=ElementType
RandomizeFullList = IncrementalUpdates
LastSecond= DateTime.GetSecond( DateTime.Now )
Return True
End If
Return False
End Sub
Sub SetColRowColorID(Row As Int, Col As Int, ColorID As Int)
Dim Rows As NumLis, Cols As NumCol
Rows = Numbers.Get(Row)
Cols = Rows.Columns.Get(Col)
Cols.ColorID=ColorID
End Sub
'Digits (-number has no padding), align (1=left -1=right)
Sub AddRowsOfNumbers(ID As Int,Rows As Int, ColorID As Int, Data As List)
Dim temp As Int
For temp = 1 To Rows
AddRowOfNumbers(ID, ColorID,Data)
Next
End Sub
Sub FindFirstLine(ID As Int,Index As Int) As NumLis
Dim temp As Int , Row As NumLis, LineIndex As Int
For temp = 0 To Numbers.Size-1
Row= Numbers.Get(temp)
If Row.ID = ID Then
If Index=LineIndex Then
Return Row
Else
LineIndex=LineIndex+1
End If
End If
Next
End Sub
Sub DuplicateFirstLines(ID As Int, Count As Int)
Dim temp As Int, Row As NumLis
Row = FindFirstLine(ID,0)
For temp = 1 To Count
DuplicateFirstLine(Row)
Next
End Sub
Sub DuplicateFirstLine(Src As NumLis)
Dim Row As NumLis , temp As Int
Row.Initialize
Row.id = Src.ID
Row.Columns.Initialize
Row.ColorID = Src.ColorID
For temp = 0 To Src.Columns.Size-1
Row.Columns.Add( Src.Columns.Get(temp) )
Next
RandomizeRow(Row)
AddLine(Src.ID )
Numbers.Add(Row)
End Sub
Sub DrawNumberBlock(BG As Canvas, X As Int, Y As Int, Width As Int, Height As Int, ColorID As Int, ID As Int, ElementType As Int, Text As String )
Dim Font As Typeface , MaxSize As Int
Font = LCAR.LCARfont 'Else Font = StarshipFont
If InitRandomNumbers(ElementType, True) Then
MaxSize = Max(LCAR.ScaleHeight,LCAR.ScaleWidth)
MakeRowOfRandomNumbers(BG, Font, LCAR.Fontsize, MaxSize, ID, ColorID)
End If
LCAR.DrawRect(BG,X,Y,Width+1,Height,Colors.black, 0)
If DrawRandomNumbers(BG,X,Y, Font, LCAR.Fontsize, Width, Height, ID ) =0 Then ClearRandomNumbers
If Text.Length >0 Then LCAR.DrawText(BG, X+Width+1, Y+2, Text, ColorID, 3,False,255,-1)
End Sub
Sub MakeRowOfRandomNumbers(BG As Canvas, Font As Typeface, FontSize As Int, Width As Int, ID As Int, ColorID As Int)
Dim CharWidth As Int ,TotalWidth As Int, CurrentWidth As Int , Row As NumLis ,Col As NumCol ,Digits As Int, Align As Int
CharWidth = BG.MeasureStringWidth("0", Font,FontSize)
Row.Initialize
Row.ID = ID
Row.Columns.Initialize
Row.ColorID = ColorID
Row.TotalWidth=Width
Do Until TotalWidth>=Width
Digits = Rnd(1,8)
If Rnd(0,2)=0 Then Digits = -Digits
Align= Rnd(-1,1)
CurrentWidth=(Abs(Digits)+2)*CharWidth
Row.Columns.Add(AddColOfNumbers(Digits,Align))
TotalWidth=TotalWidth+CurrentWidth
Loop
RandomizeRow(Row)
AddLine(ID)
Numbers.Add(Row)
End Sub
'Digits (-number has no padding), align (1=left -1=right)
Sub AddRowOfNumbers(ID As Int, ColorID As Int, Data As List)As Int
Dim Row As NumLis,temp As Int '10^digits
Row.Initialize
Row.ID = ID
Row.Columns.Initialize
For temp = 0 To Data.Size-1 Step 2
Row.Columns.Add ( AddColOfNumbers(Data.Get(temp), Data.Get(temp+1) ) )
Next
Row.ColorID=ColorID
RandomizeRow(Row)
AddLine(ID)
Numbers.Add(Row)
Return Numbers.Size-1
End Sub
Sub AddColOfNumbers(Digits As Int, Align As Int)As NumCol
Dim temp As NumCol
temp.Initialize
temp.Digits=Digits
temp.Align=Align
Return temp
End Sub
Sub IncrementNumbers As Boolean
Dim temp As Int , Line As NumLin,Row As NumLin ,Cols As NumLis ,temp2 As Int
If Numbers.IsInitialized Then
'debug( DateTime.GetSecond( DateTime.Now ) & " " & LastSecond & " " & Numbers.Size )
If DateTime.GetSecond( DateTime.Now ) <> LastSecond OR Numbers.Size=0 Then
LastSecond= DateTime.GetSecond( DateTime.Now )
If Not(RandomizeFullList) Then
For temp = 0 To Numbers.Size-1
RandomizeRow( Numbers.Get(temp) )
Next
Else
For temp = 0 To LineList.Size-1
Row = LineList.Get(temp)
Cols = FindFirstLine(temp, Row.RandomizeFullList)
RandomizeRow(Cols)
For temp2 = 0 To Row.Lines-1
If temp2 <> Row.RandomizeFullList Then
Cols = FindFirstLine(temp, temp2)
AgeRow(Cols)
End If
Next
Row.RandomizeFullList = (Row.RandomizeFullList+1) Mod Row.Lines
Next
End If
If LCAR.RedAlert Then
For temp = 0 To LineList.Size-1
Line = LineList.Get(temp)
Line.RedAlert = (Line.RedAlert+1) Mod Line.Lines
Next
End If
Return True
End If
End If
Return False
End Sub
Sub RandomizeRow(Row As NumLis)
Dim temp As Int, Col As NumCol
If Not(Row = Null ) Then
Row.Values.Initialize
Row.Age=0
For temp = 0 To Row.Columns.Size-1
Col = Row.Columns.Get(temp)
Row.Values.Add(RandomNumber(Abs(Col.Digits),Col.Digits>0))
Next
End If
End Sub
Sub AgeRow(Row As NumLis)
Row.Age = Row.Age+1
End Sub
Sub DrawRandomNumbers(BG As Canvas, X As Int, Y As Int,Font As Typeface, FontSize As Int, MaxWidth As Int, MaxHeight As Int, ID As Int ) As Int
Dim temp As Int, LineSize As Int , CharWidth As Int ,Height As Int,FirstLine As Int, Src As NumLis, Curr As NumLis , Line As NumLin , CurrLin As Int, LineIndex As Int,RedAlert As Boolean , DoBG As Boolean,Drawn As Boolean
LineSize=BG.MeasureStringHeight("1234567890", Font, FontSize)+2
If ID<0 Then
DoBG=True
Y=Y+LineSize-1
ID=Abs(ID)
End If
CharWidth = BG.MeasureStringWidth("0", Font,FontSize)
CurrLin=-1
For temp = 0 To Numbers.Size-1
Curr = Numbers.Get(temp)
'debug("Checking row: " & temp & " for ID " & ID & ", it was " & Curr.ID)
If Curr.ID = ID Then
'debug("Drawing row " & temp)
If LCAR.RedAlert Then
If CurrLin<> ID Then Line = LineList.Get(ID)
RedAlert = Line.RedAlert = LineIndex
End If
DrawRow(BG, X,Y, Font,FontSize,CharWidth, Curr, ID ,MaxWidth, RedAlert,DoBG,LineSize)
Drawn=True
Y=Y+LineSize
If MaxHeight>0 Then
If Not(Src.IsInitialized ) Then Src =Numbers.Get(temp)
Height=Height+LineSize
If Height>MaxHeight Then Exit
End If
LineIndex=LineIndex+1
End If
Next
If MaxHeight>0 AND Height+LineSize<=MaxHeight AND Src.IsInitialized Then'add more
CharWidth=0
For temp = Height To MaxHeight Step LineSize
Height=Height+LineSize
If Height< MaxHeight Then
DuplicateFirstLine(Src)
CharWidth=CharWidth+1
End If
Next
End If
If Drawn Then
Return LineSize
Else
Return 0
End If
End Sub
Sub DrawRow(BG As Canvas, X As Int, Y As Int, Font As Typeface, FontSize As Int, CharWidth As Int, Row As NumLis, ID As Int, MaxWidth As Int ,RedAlert As Boolean ,DoBackGround As Boolean,LineHeight As Int )
Dim temp As Int , Col As NumCol,Text As String ,Color As Int ,Width As Int,State As Boolean
If Row.ID = ID Then
If MaxWidth>0 Then MaxWidth=MaxWidth+X
For temp = 0 To Row.Columns.size-1
Col = Row.Columns.Get(temp)
Text = Row.Values.Get(temp)
Width = Abs(Col.Digits) * (CharWidth+2)
If LCAR.RedAlert Then
Color = LCAR.LCAR_RedAlert
Else
Color = API.IIF(Col.ColorID =0, Row.ColorID,Col.ColorID)
End If
'debug("Col " & temp & " = " & Text & " - " & Color)
If RedAlert Then
State= True
Else
State= (Row.age<2) AND RandomizeFullList
End If
Color = LCAR.GetColor(Color, State, 255)
If DoBackGround Then LCAR.DrawRect(BG, X,Y-LineHeight ,Width-2,LineHeight+2, Colors.black , 0)
If Col.Align=-1 Then'right align
BG.DrawText(Text, X+Width,Y,Font, FontSize, Color, "RIGHT")
Else'left align
BG.DrawText(Text, X,Y,Font, FontSize, Color, "LEFT")
End If
X=X+Width+CharWidth
If X>= MaxWidth AND MaxWidth>0 Then temp=Row.Columns.size
Next
Return True
End If
Return False
End Sub
Sub AddLine(ID As Int)
Dim Line As NumLin
If ID< LineList.Size Then
Line = LineList.Get(ID)
Line.Lines = Line.Lines+1
Else
Line.Initialize
Line.Lines=1
LineList.Add(Line)
End If
'debug("ID: " & ID & " has " & Line.Lines )
End Sub
Sub InitAdvDrawingStuff
' If Not(isAdvInit) Then
' mMatrix.Initialize
' mPaint.Initialize
' mPaint.SetAntiAlias(LCAR.AntiAliasing)
' mPaint.SetFilterBitmap(LCAR.AntiAliasing)
' isAdvInit=True
' End If
End Sub
Sub DrawTrapezoid(myBG As Canvas, BMP As Bitmap ,SRC As Rect , X As Int, Y As Int, TopWidth As Int, BottomWidth As Int, Height As Int, Alpha As Int)
Dim BottomLeft As Int
'lcar.ExDraw.save2(BG, lcar.ExDraw.MATRIX_SAVE_FLAG)
' If TopWidth=0 Then TopWidth=BottomWidth
' If BottomWidth=0 Then BottomWidth=TopWidth
' If BottomWidth> TopWidth Then X = X + (BottomWidth-TopWidth)/2
' BottomLeft = X+ TopWidth/2 - BottomWidth/2
' If SRC=Null Then SRC.Initialize(0,0, BMP.Width, BMP.Height)
' 'mPaint.SetAlpha(Alpha)
' mMatrix.setPolyToPoly( Array As Float(SRC.Left,SRC.Top, SRC.Right,SRC.Top, SRC.Right, SRC.Bottom, SRC.Left,SRC.Bottom), 0, Array As Float( X,Y, X+TopWidth,Y, BottomLeft+BottomWidth, Y+Height, BottomLeft, Y+Height ), 0,4)
' LCAR.ExDraw.drawBitmap4(myBG, BMP, mMatrix, mPaint)
'call LCAR.ExDraw.restore(BG) before Activity.Invalidate
End Sub
'Sub DrawBMP(myBG As Canvas, BMP As Bitmap, SrcX As Int, SrcY As Int, SrcWidth As Int, SrcHeight As Int, X As Int, Y As Int, Width As Int, Height As Int, Alpha As Int, FlipX As Boolean, FlipY As Boolean)
' Dim Dest() As Float ,Right As Int, Bottom As Int
' LCAR.ExDraw.save2(myBG, LCAR.ExDraw.MATRIX_SAVE_FLAG)
' If SrcWidth=0 Then SrcWidth = BMP.Width
' If SrcHeight=0 Then SrcHeight=BMP.Height
' 'mPaint.SetAlpha(Alpha)
' Right=X+Width
' Bottom=Y+Height
' If FlipX AND FlipY Then
'
' Else If FlipX Then
'
' Else If FlipY Then
' Dest=Array As Float(X,Bottom, Right,Bottom, X,Y, Right,Y)
' Else
' Dest=Array As Float( X,Y, Right,Y, Right, Bottom, X,Bottom )
' End If
' mMatrix.setPolyToPoly( Array As Float(SrcX,SrcY, SrcX+SrcWidth, SrcY, SrcX+SrcWidth,SrcY+SrcHeight, SrcX,SrcY+SrcHeight), 0, Dest, 0,4)
' LCAR.ExDraw.drawBitmap4(myBG, BMP, mMatrix, mPaint)
' LCAR.ExDraw.restore(myBG)
'End Sub
Sub SetupShine(RotationX As Float)
Dim cosRotation As Double, intensity As Int, highlightIntensity As Int, light As Int, highlight As Int
cosRotation = Cos(Trig.PI * RotationX / 180)
intensity = Min(MAX_INTENSITY, AMBIENT_LIGHT + (DIFFUSE_LIGHT * cosRotation))
highlightIntensity = Min(MAX_INTENSITY, SPECULAR_LIGHT * Power(cosRotation,SHININESS))
light = Colors.rgb(intensity, intensity, intensity)
highlight = Colors.rgb(highlightIntensity, highlightIntensity, highlightIntensity)
' mPaint.SetLightingColorFilter(light, highlight)
End Sub
Sub IsWithin(X As Int, Y As Int, RCT As Rect) As Boolean
If X >= RCT.Left Then
If X <= RCT.Right Then
If Y >= RCT.Top Then
If Y <= RCT.Bottom Then
Return True
End If
End If
End If
End If
End Sub
Sub CopyPlistToPath(Plist As List, P As Path, BG As Canvas, Color As Int,Stroke As Int, DoDraw As Boolean, DoDrawAll As Boolean ) As Rect
Dim Count As Int, temp As Point, temp2 As Point , dest As Rect
Dim Left As Int, Right As Int, Top As Int, Bottom As Int
Left=-1
Top = -1
temp = Plist.Get(0)
P.Initialize(temp.X, temp.Y)
If DoDraw Then LCAR.ActivateAA(BG, True)
For Count = 1 To Plist.Size-1
temp2 = Plist.Get(Count)
If temp2.X< Left OR Left=-1 Then Left = temp2.X
If temp2.X> Right Then Right = temp2.X
If temp2.y< Top OR Top = -1 Then Top = temp2.y
If temp2.y> Bottom Then Bottom = temp2.y
P.LineTo(temp2.X, temp2.Y)
If DoDraw Then
If (temp.x <> temp2.X AND temp.Y <> temp2.Y) OR DoDrawAll Then
BG.DrawLine(temp.x,temp.y, temp2.X,temp2.Y, Color, Stroke)
End If
temp.x=temp2.X
temp.y=temp2.Y
End If
Next
If DoDraw Then BG.ClipPath(P)
dest.Initialize(Left,Top,Right,Bottom)
Return dest
End Sub
Sub MakePoint(P As List, X As Int, Y As Int)As Point
Dim temp As Point
If Not (P.IsInitialized ) Then P.Initialize
temp=Trig.SetPoint(X,Y)
P.Add( temp )
Return temp
End Sub
Sub RandomENT As String
Return RandomNumber(2,True) & "-" & RandomNumber(3,True)
End Sub
Sub DrawLegacyButton(BG As Canvas, X As Int, Y As Int, Width As Int, Height As Int, Color As Int, Text As String, Align As Int)
Dim temp As ColorDrawable ,CornerRadius As Int,UseOtherFont As Boolean ,WhiteSpace As Int
If Align<0 Then
CornerRadius=Abs(Align)
Else
CornerRadius=10
End If
If Width<0 Then
Width=Abs(Width)
UseOtherFont=True
CornerRadius=Height/2
End If
If Color <> Colors.Transparent Then
temp.Initialize(Color, CornerRadius)
'LCAR.ActivateAA(BG,True)
BG.DrawDrawable(temp, LCAR.SetRect(X,Y,Width,Height))
End If
'LCAR.DrawTextbox(BG, Text, LCAR.LCAR_Black, X+CornerRadius,Y+CornerRadius, Width-CornerRadius*2,Height-CornerRadius*2, Align)
If Text.Length>0 Then
WhiteSpace= API.IIF( Height < LCAR.Fontsize*2 + 30 , 5 ,15)
'If UseOtherFont Then
LCAR.DrawTextbox(BG, Text, LCAR.LCAR_Black, X+CornerRadius/2,Y+WhiteSpace, Width-CornerRadius,Height-(WhiteSpace*2), Align)
'Else
'LCAR.DrawLegacyText(BG, X+CornerRadius,Y+CornerRadius, Width-CornerRadius*2,Height-CornerRadius*2, Text, 15, Colors.Black, Align)
'End If
End If
'LCAR.ActivateAA(BG,False)
End Sub
Sub UnusedGraphID As Int
Dim temp As Int
Do While FindGraph(temp)>-1
temp=temp+1
Loop
Return temp
End Sub
Sub CountUnusedPoints(GraphID As Int) As Int
Dim temp As Graph ,temp2 As Int
temp = GraphList.Get(GraphID)
For temp2 = 0 To temp.Points.Size-1
If temp.Points.Get(temp2) >0 Then Return temp2-1
Next
End Sub
Sub AddBlankPoints(GraphID As Int, Points As Int)
Dim temp As Graph ,temp2 As Int
If Points>0 Then
temp = GraphList.Get(GraphID)
For temp2 = 1 To Points
AddPoint(GraphID,0)
Next
End If
End Sub
Sub RemovePoints(GraphID As Int, Points As Int)
Dim temp As Graph ,temp2 As Int
temp = GraphList.Get(GraphID)
For temp2 = Points-1 To 0 Step -1
temp.Points.RemoveAt(temp2)
Next
temp.IsClean=False
temp.CurrentPoint = Max(0 , temp.CurrentPoint - Points)
End Sub
Sub FindGraph(ID As Int) As Int
Dim temp As Graph ,temp2 As Int
For temp2 = 0 To GraphList.Size-1
temp= GraphList.Get(temp2)
If temp.ID = ID Then Return temp2
Next
Return -1
End Sub
Sub isGraphClean(GraphID As Int) As Boolean
Dim temp As Graph
temp = GraphList.Get(GraphID)
Return temp.IsClean
End Sub
Sub GetGraph(GraphID As Int) As Graph
Return GraphList.Get(GraphID)
End Sub
Sub ClearGraph(GraphID As Int)
Dim temp As Graph ,temp2 As Int
temp = GraphList.Get(GraphID)
temp.IsClean=False
temp.IsClearing =False
temp.CurrentPoint=0
temp.Points.Initialize
End Sub
Sub AddGraph(ID As Int, MaxPoints As Int, ExpandWhenFull As Boolean ) As Int
Dim temp As Graph
temp.Initialize
If ExpandWhenFull Then temp.ExpandWhenFull=MaxPoints
temp.MaxPoints=MaxPoints
temp.ID =ID
temp.Points.Initialize
GraphList.Add(temp)
Return GraphList.Size-1
End Sub
Sub AddPoints(GraphID As Int, RecData() As Byte) As Boolean
Dim temp As Graph ,temp2 As Int ,temp3 As Int,temp4 As Int
temp = GraphList.Get(GraphID)
If Not(temp.IsClearing) Then
temp.IsClearing=True
temp2= RecData.Length /2
temp4=0 'temp.CurrentPoint
If temp.IsClean OR temp.Points.Size <> temp2 Then'only update if it's been drawn already (vsync!)
temp.Points.Initialize
For temp2 = 0 To RecData.Length -1 Step 2'RemoveRepeatedPoints(RecData)
temp3 = API.Combine(RecData(temp2+1), RecData(temp2))
If Abs(temp3)> temp4 Then
temp4 = Abs(temp3)
temp.ExpandWhenFull= temp2'location of maximum point
'If temp4>temp.CurrentPoint Then temp.CurrentPoint=temp4 'highest point value
End If
temp.Points.Add(temp3)
'debug("Added: " & temp3 & " of " & temp.CurrentPoint)
Next
If temp4>temp.CurrentPoint Then
temp.CurrentPoint=temp4 'highest point value
'Else If temp4<temp.CurrentPoint Then
' temp.CurrentPoint = LCAR.Increment(temp.CurrentPoint, 1000, temp4)
End If
'debug("Max this cycle=" & temp4 & " all cycles=" & temp.CurrentPoint)
'temp.CurrentPoint=temp4 'highest point value
'temp.CurrentPoint= Max(temp4,temp.CurrentPoint)
temp.IsClean=False
End If
temp.IsClearing=False
Return True
End If
End Sub
Sub Get2toTheN(Value As Int) As Int
Dim temp As Int ,temp2 As Int
temp = 1
Do Until temp > Value
temp2=temp
temp=temp*2
Loop
Return temp2
End Sub
'Sub RemoveRepeatedPoints(RecData() As Byte) As Int'didnt work
' Dim temp As Int , Count As Int , Current As Int , First As Int
' First = API.Combine(RecData(1), RecData(0))
' For temp =2 To RecData.Length -1 Step 2
' Current = API.Combine(RecData(temp+1), RecData(temp))
' If Current = First Then
' Count=Count+1
' Else
' Return Count
' End If
' Next
'End Sub
Sub RemoveGraph(GraphID As Int)
If GraphID>-1 AND GraphID< GraphList.Size Then GraphList.RemoveAt(GraphID)
End Sub
Sub AddPoint(GraphID As Int, Value As Int)
Dim temp As Graph ,temp2 As Double
temp = GraphList.Get(GraphID)
If temp.CurrentPoint = temp.MaxPoints Then
If temp.ExpandWhenFull>0 Then
temp.MaxPoints = temp.MaxPoints+temp.ExpandWhenFull
temp.CurrentPoint=temp.CurrentPoint+1
Else
temp.CurrentPoint=0
End If
Else
temp.CurrentPoint=temp.CurrentPoint+1
End If
temp2=Value*0.01
If temp.CurrentPoint < temp.Points.Size Then
temp.Points.Set(temp.CurrentPoint, temp2)
Else
temp.Points.Add(temp2)
End If
temp.IsClean=False
End Sub
Sub IncrementGraph(GraphID As Int, Style As Int)
Dim temp As Graph
If Style = 4 Then
temp = GraphList.Get(GraphID)
If temp.BracketX <> temp.ExpandWhenFull Then
temp.BracketX = LCAR.Increment(temp.BracketX, 25, temp.ExpandWhenFull)
End If
End If
End Sub
Sub DrawGraph(GraphID As Int, BG As Canvas, X As Int, Y As Int, Width As Int, Height As Int, ColorID As Int, GraphColor As Int, Alpha As Int, Style As Int, Cols As Int, Rows As Int)
Dim tempGraph As Graph ,PointWidth As Int , PrevPoint As Double ,CurrPoint As Double , temp As Int, temp2 As Int, currX As Int, Color As Int,X2 As Int,X3 As Int, isclean As Boolean ',P As Path
tempGraph = GraphList.Get(GraphID)
'If Style=4 Then
' PointWidth= Width / tempGraph.Points.Size
'Else
PointWidth= Width / tempGraph.MaxPoints
'End If
LCAR.ActivateAA(BG,True)
isclean=True
currX=X
If ColorID>-1 Then Color=LCAR.GetColor(ColorID, False,Alpha)
LCARSeffects.MakeClipPath(BG,X-1,Y-1,Width+1,Height)
'P.Initialize(X-1,Y-1)
'P.LineTo(X+Width,Y-1)
'P.LineTo(X+Width,Y+Height)
'P.LineTo(X-1,Y+Height)
'BG.ClipPath(P)
Select Case Style
Case 0 '/\ relative to center, 1 up and 1 down
If tempGraph.Points.Size>0 Then
PrevPoint=tempGraph.Points.Get(0)
For temp = 1 To tempGraph.Points.Size-1
CurrPoint=tempGraph.Points.Get(temp)
DrawPoint(BG, currX,Y, PointWidth, Height,Style, GraphColor, 1, PrevPoint,CurrPoint)
currX=currX+PointWidth
PrevPoint=CurrPoint
Next
End If
Case 1,-1'/ relative to bottom
PrevPoint=0
'GraphColor=Colors.White
For temp = 0 To tempGraph.Points.Size-1
CurrPoint=tempGraph.Points.Get(temp)
DrawPoint(BG, currX,Y, PointWidth, Height,Style, GraphColor, 1, PrevPoint,CurrPoint)
currX=currX+PointWidth
PrevPoint=CurrPoint
Next
Case 2'| bars
For temp = 0 To tempGraph.Points.Size-1
CurrPoint=tempGraph.Points.Get(temp)
DrawPoint(BG, currX,Y, PointWidth, Height,Style, GraphColor, 1, PrevPoint,CurrPoint)
currX=currX+PointWidth
Next
Case 3'circular
DrawCircularGraph(BG, X+Width/2, Y+Width/2, Min(Width,Height)/2, tempGraph, GraphColor, Color, Cols, Rows)
Case 4,5'frequency and spectrograph
'.Currentpoint = max amplitude
'.ExpandWhenFull = position of max amplitude
'.IsClearing = locked. transferring data or drawing
'.MaxPoints = tweened position of the brackets
CurrPoint=2
LCAR.DrawRect(BG,X-1,Y-1,Width+1,Height+1,Colors.Black,0)
'If Style = 4 Then
temp = API.IIF(LCAR.SmallScreen , 50,100)
Width=Width-temp
currX=currX+temp
'Else
' GraphColor = LCAR.GetColor(LCAR.LCAR_Orange, False, Alpha)
'End If
If tempGraph.MaxPoints=0 Then
PointWidth = (tempGraph.Points.Size / Width) * CurrPoint
Else
PointWidth = tempGraph.Points.Size / tempGraph.MaxPoints
End If
'If (tempGraph.IsClearing) Then
' isclean=False
'Else
tempGraph.IsClearing=True
Try
If Style=4 Then tempGraph.BracketX = LCAR.Increment(tempGraph.BracketX, PointWidth*5, tempGraph.ExpandWhenFull)
For temp = 0 To tempGraph.Points.Size-1 Step PointWidth
PrevPoint=0
For temp2 = temp To temp+PointWidth
If temp2 < tempGraph.Points.Size Then
PrevPoint = PrevPoint + tempGraph.Points.Get(temp2)
Else
PointWidth=PointWidth-1
End If
If temp2 = tempGraph.BracketX Then X3 = X2
Next
'debug(currX & " = " & PrevPoint & " " & PointWidth & " " & tempGraph.CurrentPoint)
PrevPoint = (PrevPoint / PointWidth) / tempGraph.CurrentPoint
If PrevPoint > tempGraph.CurrentPoint Then
tempGraph.CurrentPoint= PrevPoint
PrevPoint=1
End If
'If Style=4 Then
If LCAR.RedAlert Then
GraphColor =GetRedColor(X2, Width)
Else
GraphColor = API.HSLtoRGB(X2/Width*239, 127,127,255)'currX/Width*239
End If
'End If
DrawPoint(BG,currX,Y,1, Height, Style, GraphColor, 1, 0, PrevPoint)
currX=currX+CurrPoint
X2=X2+CurrPoint
Next
Catch
isclean = False
End Try
tempGraph.IsClearing=False
'End If
'If Style=4 Then
temp = API.IIF(LCAR.SmallScreen , 50,100)
DrawBox2(BG, X, temp, Y, Width, Height, Color, 60, 40, 2, X3)
'End If
Case Else
LCAR.DrawUnknownElement(BG,X,Y,Width,Height, ColorID, False, Alpha, "UNKNOWN CHART TYPE")
End Select
LCAR.ActivateAA(BG,False)
If Style<3 AND ColorID>-1 Then
DrawCursor(BG,X,Y,Width,Height, Colors.White, PointWidth,2, tempGraph.MaxPoints *0.2,tempGraph.CurrentPoint)
DrawBox(BG,X,Y,Width,Height, Color, Cols,Rows,2,1)
End If
BG.RemoveClip
tempGraph.isclean=isclean
End Sub
Sub DrawCircularGraph(BG As Canvas, X As Int, Y As Int, Radius As Int, tempGraph As Graph, GraphColor As Int, BoxColor As Int, Cols As Int, Rows As Int)
Dim DegreeWidth As Double , temp As Int , CurrValue As Double, NextValue As Double ,Inc As Double, Angle As Double , CurrCoord As Point, CurrPoint As Int, PrevCoord As Point
If tempGraph.Points.Size >1 Then
DegreeWidth = 360 / tempGraph.Points.Size
CurrValue = Radius * tempGraph.Points.Get(0)
Angle = DegreeWidth
For temp = 0 To 359'curved method
If temp>= Angle AND CurrPoint+1<tempGraph.Points.Size Then
CurrPoint=CurrPoint+1
NextValue = Radius * tempGraph.Points.Get( CurrPoint )
Inc = (NextValue - CurrValue) / DegreeWidth
Angle = Angle+DegreeWidth
'debug(CurrPoint & "@" & temp & " up until " & Angle & " the desired radius will be " & NextValue & " incrementing from " & CurrValue & " by " & Inc)
End If
CurrCoord = Trig.FindAnglePoint(X,Y, CurrValue, temp)
If temp>0 Then BG.DrawLine(PrevCoord.X,PrevCoord.Y, CurrCoord.X,CurrCoord.Y, GraphColor, 1)
PrevCoord = Trig.SetPoint( CurrCoord.X, CurrCoord.Y)
'debug("Angle: " & temp & " Radius " & CurrValue)
CurrValue = CurrValue+Inc' LCAR.Increment(CurrValue, Inc, NextValue)
Next
' For temp = 0 To tempGraph.Points.Size - 1 'linear method
' CurrValue = Radius * tempGraph.Points.Get(temp)
' CurrCoord = Trig.FindAnglePoint(X,Y, CurrValue, Angle)
' If temp>0 Then
' BG.DrawLine(PrevCoord.X,PrevCoord.Y, CurrCoord.X,CurrCoord.Y, GraphColor, 1)
' End If
' PrevCoord = Trig.SetPoint( CurrCoord.X, CurrCoord.Y)
' Angle=Angle+ DegreeWidth
' Next
End If
DrawRadar(BG,X,Y,Radius,BoxColor,Cols,Rows)
End Sub
Sub DrawRadar(BG As Canvas, X As Int, Y As Int, Radius As Int, Color As Int, Cols As Int, Rows As Int)
Dim DegreeWidth As Double , temp As Int, CurrCoord As Point, Angle As Double
If Cols>1 Then
DegreeWidth = 360 / Cols
Angle=0
For temp = 1 To Cols
CurrCoord = Trig.FindAnglePoint(X,Y, Radius, Angle)
BG.DrawLine(X, Y, CurrCoord.X,CurrCoord.Y, Color, 1)
Angle=Angle+DegreeWidth
Next
End If
If Rows>1 Then
DegreeWidth= Radius/ Rows
Angle=0
For temp = 1 To Rows-1
Angle=Angle+DegreeWidth
BG.DrawCircle(X,Y,Angle,Color, False,1)
Next
End If
BG.DrawCircle(X,Y,Radius-1,Color, False,2)
End Sub
Sub GetRedColor(X As Int, Width As Int) As Int
Width=Width/2
If X< Width Then
Return Colors.RGB( 64 + X/Width*192 ,0,0)
Else
X=X-Width
X= X/Width*255
Return Colors.RGB(255, X,X)
End If
End Sub
Sub DrawPoint(BG As Canvas, X As Int, Y As Int, PointWidth As Int, Height As Int, Style As Int, Color As Int, Stroke As Int, PrevValue As Double, NewValue As Double )
Dim X2 As Int,X3 As Int, Y2 As Int, Y3 As Int, HalfHeight As Int
HalfHeight=Height*0.5
PointWidth=Max(2, PointWidth)
Select Case Style
Case 0'/\ relative to center, 1 up and 1 down
X2=X+PointWidth*0.5
Y2=GetPoint(Y,HalfHeight,Height,PrevValue, True,False) 'Y + HalfHeight + ( HalfHeight * (1-PrevValue))
Y3=GetPoint(Y,HalfHeight,Height,NewValue, True,True)' HalfHeight * (1-NewValue)
BG.DrawLine(X,Y2,X2,Y3, Color, Stroke)
X3=X+PointWidth
Y2=GetPoint(Y,HalfHeight,Height,NewValue, True,False)'Y+HalfHeight + Y3
BG.DrawLine(X2,Y3,X3, Y2 , Color, Stroke)
Case 1,-1'/ relative to bottom
X2=X+PointWidth
Y2=Y + Height*(1-PrevValue) 'Y + Height - Height*PrevValue
Y3=Y + Height*(1-NewValue) ' Y + Height - Height*NewValue
BG.DrawLine(X,Y2,X2,Y3, Color, Stroke)
Case 2'| bars
Y3= Height* NewValue*2
Y2= Y+ HalfHeight - (Y3*0.5)
BG.DrawRect( LCAR.SetRect(X, Y2, PointWidth-1, Y3), Color, True,0)
Case 4'lines, relative to center
Y3= Height* NewValue
If Y3>Height Then
Y3=Height
Else If Y3<-Height Then
Y3=-Height
End If
Y2= Y+ HalfHeight - (Y3*0.5)
BG.DrawLine(X, Y2, X, Y2+Y3, Color,2)
Case 5'lines relative to center
NewValue=NewValue*100
Y3= Height* Abs(NewValue)
If NewValue>0 Then
Y2= Y+ HalfHeight - (Y3*0.5)
Else
Y2= Y+ HalfHeight
End If
BG.DrawLine(X, Y2, X, Y2+Y3, Color,2)
'Y2= Y+ Height
'HalfHeight= Height* NewValue*50
'Y3= Y2 - HalfHeight
'BG.DrawLine(X, Y3, X, Y2, Color,2)
End Select
End Sub
Sub GetPoint(Y As Int, HalfHeight As Int, Height As Int, Value As Double , RelativeToCenter As Boolean , AboveCenter As Boolean ) As Int
Dim temp As Int
If RelativeToCenter Then
temp = Y+HalfHeight
If AboveCenter Then
Return temp - (HalfHeight*Value)
Else
Return temp + (HalfHeight*Value)
End If
Else
Return Y+ (Height*(1-Value))
End If
End Sub
Sub DrawCursor(BG As Canvas, X As Int, Y As Int, Width As Int, Height As Int, Color As Int, PointWidth As Int, PointsGradient As Int,PointsBlack As Int, StartPoint As Int)
Dim X2 As Int, Width2 As Int
X2=X+(StartPoint-PointsGradient)*PointWidth
Width2=PointWidth*PointsGradient
LCAR.DrawGradient(BG, Colors.ARGB(0,0,0,0), Color, 6, X2, Y, Width2,Height, 0,0)
X2=X2+Width2-2
Width2=PointWidth*PointsBlack
BG.DrawRect(LCAR.SetRect(X2,Y,Width2,Height), Colors.Black, True,0)
End Sub
Sub DrawBox(BG As Canvas, X As Int, Y As Int, Width As Int, Height As Int, Color As Int, Cols As Int, Rows As Int, OuterStroke As Int, InnerStroke As Int)
Dim temp As Int ,temp2 As Int
If OuterStroke>0 Then BG.DrawRect( LCAR.SetRect(X,Y,Width,Height), Color, False,OuterStroke)
If Rows>0 Then
temp2=Height/Rows
For temp = Y+temp2 To Y+Height-temp2 Step temp2
BG.DrawLine(X, temp, X+Width, temp, Color,InnerStroke)
Next
End If
If Cols>0 Then
temp2=Width/Cols
For temp = X+temp2 To X+Width-temp2 Step temp2
BG.DrawLine(temp, Y, temp, Y+Height, Color, InnerStroke)
Next
End If
End Sub
Sub DrawBox2(BG As Canvas, X As Int, BarWidth As Int, Y As Int, Width As Int, Height As Int, Color As Int, ColWidth As Int, RowHeight As Int, Stroke As Int, BracketX As Int)
Dim temp As Int ,temp2 As Int,temp3 As Int , Orange As Int, X2 As Int,BitWidth As Int, BitHeight As Int , Value As Int, Cols As Int , Purple As Int ,Rows As Int , Text As String, RowHeight2 As Int,TextHeight As Int