forked from sparkfun/SparkFun_HyperDisplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyperdisplay.cpp
1673 lines (1413 loc) · 64.7 KB
/
hyperdisplay.cpp
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
/*
hyperdisplay.cpp
header file: hyperdisplay.h
*/
#include "hyperdisplay.h" // Click here to get the library: http://librarymanager/SparkFun_HyperDisplay
wind_info_t hyperdisplayDefaultWindow; // This window is used by default so that the user does not have to worry about windows if they don't want to
char_info_t hyperdisplayCharacter; // The default character to use
#if HYPERDISPLAY_USE_PRINT
const unsigned char *hyperdisplay::fontsPointer[] = {
font5x7,
font8x16
};
#if HYPERDISPLAY_INCLUDE_SMALL_FONT
hd_font_extent_t hyperdisplayXloc[HYPERDISPLAY_SMALL_FONT_WIDTH*HYPERDISPLAY_SMALL_FONT_HEIGHT];
hd_font_extent_t hyperdisplayYloc[HYPERDISPLAY_SMALL_FONT_WIDTH*HYPERDISPLAY_SMALL_FONT_HEIGHT];
uint8_t FONT_TYPE = 0;
#endif
#if HYPERDISPLAY_INCLUDE_LARGE_FONT
hd_font_extent_t hyperdisplayXloc[HYPERDISPLAY_LARGE_FONT_WIDTH*HYPERDISPLAY_LARGE_FONT_HEIGHT];
hd_font_extent_t hyperdisplayYloc[HYPERDISPLAY_LARGE_FONT_WIDTH*HYPERDISPLAY_LARGE_FONT_HEIGHT];
uint8_t FONT_TYPE = 1;
#endif
#endif
/////////////////////////////////////////////
// Constructor
/////////////////////////////////////////////
hyperdisplay::hyperdisplay(uint16_t xSize, uint16_t ySize)
{
xExt = xSize;
yExt = ySize;
pCurrentWindow = &hyperdisplayDefaultWindow; // Sets the current window to the default window structure
setWindowDefaults(pCurrentWindow); // Sets reasonable (uninitialized) values for the current window structure.
}
/////////////////////////////////////////////
// Display APIs
/////////////////////////////////////////////
// void hyperdisplay::hwpixel(hd_hw_extent_t x0, hd_hw_extent_t y0, color_t data, uint16_t colorCycleLength, uint16_t startColorOffset)
// {
// TIP: When you implement hwpixel for a particular device x0 and y0 are already guaranteed to be valid for your display area
// (Subject to a few assumptions, of course, like that you're using a rectangular display and you've properly set xExt and yExt)
// }
void hyperdisplay::hwxline(hd_hw_extent_t x0, hd_hw_extent_t y0, hd_hw_extent_t len, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset, bool goLeft)
{
// Note: color_t data is always a void pointer. You need to make sure that it points at the correct color type with enough elements.
// In this case the correct number of elements is colorCycleLength
if(data == NULL){ return; }
if(colorCycleLength == 0){ return; }
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 0); // This line is needed to condition the user's input start color offset because it could be greater than the cycle length
color_t value = getOffsetColor(data, startColorOffset);
if(goLeft)
{
for(hd_hw_extent_t indi = 0; indi < len; indi++)
{
hwpixel(x0 - indi, y0, value, 1, 0);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 1);
value = getOffsetColor(data, startColorOffset);
}
}
else
{
for(hd_hw_extent_t indi = 0; indi < len; indi++)
{
hwpixel(x0 + indi, y0, value, 1, 0);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 1);
value = getOffsetColor(data, startColorOffset);
}
}
hyperdisplayXLineCallback(x0, y0, len, data, colorCycleLength, startColorOffset, goLeft);
}
void hyperdisplay::hwyline(hd_hw_extent_t x0, hd_hw_extent_t y0, hd_hw_extent_t len, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset, bool goUp)
{
// Note: color_t data is always a void pointer. You need to make sure that it points at the correct color type with enough elements.
// In this case the correct number of elements is colorCycleLength
if(data == NULL){ return; }
if(colorCycleLength == 0){ return; }
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 0); // This line is needed to condition the user's input start color offset because it could be greater than the cycle length
color_t value = getOffsetColor(data, startColorOffset);
if(goUp)
{
for(hd_hw_extent_t indi = 0; indi < len; indi++)
{
hwpixel(x0, y0 - indi, value, 1, 0);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 1);
value = getOffsetColor(data, startColorOffset);
}
}
else
{
for(hd_hw_extent_t indi = 0; indi < len; indi++)
{
hwpixel(x0, y0 + indi, value, 1, 0);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 1);
value = getOffsetColor(data, startColorOffset);
}
}
hyperdisplayYLineCallback(x0, y0, len, data, colorCycleLength, startColorOffset, goUp);
}
void hyperdisplay::hwrectangle(hd_hw_extent_t x0, hd_hw_extent_t y0, hd_hw_extent_t x1, hd_hw_extent_t y1, bool filled, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset, bool reverseGradient, bool gradientVertical)
{
if(data == NULL){ return; }
if(colorCycleLength == 0){ return; }
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 0); // This line is needed to condition the user's input start color offset because it could be greater than the cycle length
hd_hw_extent_t xlen = x1 - x0 + 1;
if(filled)
{
color_t value = getOffsetColor(data, startColorOffset);
if(gradientVertical)
{
if(reverseGradient)
{
for(uint16_t y = y1; y >= y0; y--)
{
hwxline(x1, y, xlen, value, 1, 0, reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 1);
value = getOffsetColor(data, startColorOffset);
}
}
else
{
for(uint16_t y = y0; y <= y1; y++)
{
hwxline(x0, y, xlen, value, 1, 0, reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 1);
value = getOffsetColor(data, startColorOffset);
}
}
}
else
{
if(reverseGradient)
{
for(uint16_t y = y1; y >= y0; y--)
{
hwxline(x1, y, xlen, data, colorCycleLength, startColorOffset, reverseGradient);
}
}
else
{
for(uint16_t y = y0; y <= y1; y++)
{
hwxline(x0, y, xlen, data, colorCycleLength, startColorOffset, reverseGradient);
}
}
}
}
else
{
hd_hw_extent_t ylen = y1 - y0 + 1;
if(reverseGradient)
{
hwyline(x0, y0+1, ylen-2, data, colorCycleLength, startColorOffset, !reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, ylen-2);
hwxline(x0, y1, xlen, data, colorCycleLength, startColorOffset, !reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, xlen);
hwyline(x1, y1-1, ylen-2, data, colorCycleLength, startColorOffset, reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, ylen-2);
hwxline(x1, y0, xlen, data, colorCycleLength, startColorOffset, reverseGradient);
}
else
{
hwxline(x0, y0, xlen, data, colorCycleLength, startColorOffset, reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, xlen);
hwyline(x1, y0+1, ylen-2, data, colorCycleLength, startColorOffset, reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, ylen-2);
hwxline(x1, y1, xlen, data, colorCycleLength, startColorOffset, !reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, xlen);
hwyline(x0, y1-1, ylen-2, data, colorCycleLength, startColorOffset, !reverseGradient);
}
}
hyperdisplayRectangleCallback(x0, y0, x1, y1, data, filled, colorCycleLength, startColorOffset, gradientVertical, reverseGradient);
}
void hyperdisplay::hwfillFromArray(hd_hw_extent_t x0, hd_hw_extent_t y0, hd_hw_extent_t x1, hd_hw_extent_t y1, color_t data, hd_pixels_t numPixels, bool Vh)
{
if(data == NULL){ return; }
hd_pixels_t startColorOffset = 0;
if( Vh )
{
// Vertical lines first format
for(hd_hw_extent_t x = x0; x <= x1; x++)
{
for(hd_hw_extent_t y = y0; y <= y1; y++)
{
color_t value = getOffsetColor(data, startColorOffset);
startColorOffset = getNewColorOffset(numPixels, startColorOffset, 1);
hwpixel(x, y, value, 1, 0 );
}
}
}
else
{
// Horizontal lines first format
for(hd_hw_extent_t y = y0; y <= y1; y++)
{
for(hd_hw_extent_t x = x0; x <= x1; x++)
{
color_t value = getOffsetColor(data, startColorOffset);
startColorOffset = getNewColorOffset(numPixels, startColorOffset, 1);
hwpixel(x, y, value, 1, 0 );
}
}
}
hyperdisplayFillFromArrayCallback(x0, y0, x1, y1, numPixels, data);
}
// Buffer writing functions - all buffers are read left-to-right and top to bottom. Width and height are specified in the associated window's settings. Coordinates are window coordinates
hd_pixels_t hyperdisplay::wToPix( wind_info_t* wind, hd_hw_extent_t x0, hd_hw_extent_t y0)
{
if(wind == NULL){ return 0; } // Ideally we would have a better solution here...
hd_hw_extent_t width = uabslen <hd_hw_extent_t> (wind->xMax, wind->xMin);
hd_pixels_t pixOffst = x0 + (y0 * width);
return pixOffst;
}
void hyperdisplay::swpixel( hd_extent_t x0, hd_extent_t y0, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset)
{
if(data == NULL){ return; }
if(colorCycleLength == 0){ return; }
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 0); // This line is needed to condition the user's input start color offset because it could be greater than the cycle length
color_t value = getOffsetColor(data, startColorOffset);
hd_hw_extent_t x0w = (hd_hw_extent_t)x0; // Cast to hw extent type to be sure of integer values
hd_hw_extent_t y0w = (hd_hw_extent_t)y0;
hd_pixels_t pixOffst = wToPix(pCurrentWindow, x0, y0); // It was already ensured that this will be in range
color_t dest = getOffsetColor(pCurrentWindow->data, pixOffst); // Rely on the user's definition of a pixel's width in memory
uint32_t len = (uint32_t)getOffsetColor(0x00, 1); // Getting the offset from zero for one pixel tells us how many bytes to copy
memcpy((void*)dest, (void*)value, (size_t)len); // Copy data into the window's buffer
}
void hyperdisplay::swxline( hd_extent_t x0, hd_extent_t y0, hd_extent_t len, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset, bool goLeft)
{
// if(data == NULL){ return; }
// if(colorCycleLength == 0){ return; }
// startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 0); // This line is needed to condition the user's input start color offset because it could be greater than the cycle length
// color_t value = getOffsetColor(data, startColorOffset);
// hd_hw_extent_t x0w = (hd_hw_extent_t)x0; // Cast to hw extent type to be sure of integer values
// hd_hw_extent_t y0w = (hd_hw_extent_t)y0;
// hd_hw_extent_t lenw = (hd_hw_extent_t)len;
// hd_pixels_t pixOffst = wToPix(pCurrentWindow, x0, y0); // It was already ensured that this will be in range
// color_t dest = getOffsetColor(pCurrentWindow->data, pixOffst); // Rely on the user's definition of a pixel's width in memory
// uint32_t bpp = (uint32_t)getOffsetColor(0x00, 1); // Getting the offset from zero for one pixel tells us how many bytes to copy
// while(lenw > 0){ // Because of the checks already performed we know that len will fit into this row
// hd_hw_extent_t num2copy = min( (colorCycleLength-startColorOffset), lenw); // Determine how many to copy this time
// memcpy((void*) dest, (void*)value, bpp*num2copy ); // Copy them
// startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, num2copy); // Figure out new start offset
// value = getOffsetColor(data, startColorOffset); // Change the pointer to the color cycle
// dest = (((uint8_t*)dest) + bpp*num2copy); // Increment the destination pointer
// lenw -= num2copy; // Decrement the reamining number of bytes
// }
if(data == NULL){ return; }
if(colorCycleLength == 0){ return; }
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 0); // This line is needed to condition the user's input start color offset because it could be greater than the cycle length
color_t value = getOffsetColor(data, startColorOffset);
if(goLeft)
{
for(hd_hw_extent_t indi = 0; indi < len; indi++)
{
swpixel(x0 - indi, y0, value, 1, 0);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 1);
value = getOffsetColor(data, startColorOffset);
}
}
else
{
for(hd_hw_extent_t indi = 0; indi < len; indi++)
{
swpixel(x0 + indi, y0, value, 1, 0);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 1);
value = getOffsetColor(data, startColorOffset);
}
}
}
void hyperdisplay::swyline( hd_extent_t x0, hd_extent_t y0, hd_extent_t len, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset, bool goUp)
{
// if(data == NULL){ return; }
// if(colorCycleLength == 0){ return; }
// startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 0); // This line is needed to condition the user's input start color offset because it could be greater than the cycle length
// color_t value = getOffsetColor(data, startColorOffset);
// hd_hw_extent_t x0w = (hd_hw_extent_t)x0; // Cast to hw extent type to be sure of integer values
// hd_hw_extent_t y0w = (hd_hw_extent_t)y0;
// hd_hw_extent_t lenw = (hd_hw_extent_t)len;
// while(lenw > 0){ // Because of the checks already performed we know that len will fit into this column
// swpixel( x0, y0, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset)
// startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, num2copy); // Figure out new start offset
// value = getOffsetColor(data, startColorOffset); // Change the pointer to the color cycle
// lenw--; // Decrement the reamining number of bytes
// }
if(data == NULL){ return; }
if(colorCycleLength == 0){ return; }
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 0); // This line is needed to condition the user's input start color offset because it could be greater than the cycle length
color_t value = getOffsetColor(data, startColorOffset);
if(goUp)
{
for(hd_hw_extent_t indi = 0; indi < len; indi++)
{
swpixel(x0, y0 - indi, value, 1, 0);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 1);
value = getOffsetColor(data, startColorOffset);
}
}
else
{
for(hd_hw_extent_t indi = 0; indi < len; indi++)
{
swpixel(x0, y0 + indi, value, 1, 0);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 1);
value = getOffsetColor(data, startColorOffset);
}
}
}
void hyperdisplay::swrectangle( hd_extent_t x0, hd_extent_t y0, hd_extent_t x1, hd_extent_t y1, bool filled, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset, bool reverseGradient, bool gradientVertical)
{
// if(data == NULL){ return; }
// if(colorCycleLength == 0){ return; }
if(data == NULL){ return; }
if(colorCycleLength == 0){ return; }
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 0); // This line is needed to condition the user's input start color offset because it could be greater than the cycle length
hd_hw_extent_t xlen = x1 - x0 + 1;
if(filled)
{
color_t value = getOffsetColor(data, startColorOffset);
if(gradientVertical)
{
if(reverseGradient)
{
for(uint16_t y = y1; y >= y0; y--)
{
swxline(x1, y, xlen, value, 1, 0, reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 1);
value = getOffsetColor(data, startColorOffset);
}
}
else
{
for(uint16_t y = y0; y <= y1; y++)
{
swxline(x0, y, xlen, value, 1, 0, reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 1);
value = getOffsetColor(data, startColorOffset);
}
}
}
else
{
if(reverseGradient)
{
for(uint16_t y = y1; y >= y0; y--)
{
swxline(x1, y, xlen, data, colorCycleLength, startColorOffset, reverseGradient);
}
}
else
{
for(uint16_t y = y0; y <= y1; y++)
{
swxline(x0, y, xlen, data, colorCycleLength, startColorOffset, reverseGradient);
}
}
}
}
else
{
hd_hw_extent_t ylen = y1 - y0 + 1;
if(reverseGradient)
{
swyline(x0, y0+1, ylen-2, data, colorCycleLength, startColorOffset, !reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, ylen-2);
swxline(x0, y1, xlen, data, colorCycleLength, startColorOffset, !reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, xlen);
swyline(x1, y1-1, ylen-2, data, colorCycleLength, startColorOffset, reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, ylen-2);
swxline(x1, y0, xlen, data, colorCycleLength, startColorOffset, reverseGradient);
}
else
{
swxline(x0, y0, xlen, data, colorCycleLength, startColorOffset, reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, xlen);
swyline(x1, y0+1, ylen-2, data, colorCycleLength, startColorOffset, reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, ylen-2);
swxline(x1, y1, xlen, data, colorCycleLength, startColorOffset, !reverseGradient);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, xlen);
swyline(x0, y1-1, ylen-2, data, colorCycleLength, startColorOffset, !reverseGradient);
}
}
}
void hyperdisplay::swfillFromArray( hd_extent_t x0, hd_extent_t y0, hd_extent_t x1, hd_extent_t y1, color_t data, hd_pixels_t numPixels, bool Vh )
{
if(data == NULL){ return; }
hd_pixels_t startColorOffset = 0;
if( Vh )
{
// Vertical lines first format
for(hd_hw_extent_t x = x0; x <= x1; x++)
{
for(hd_hw_extent_t y = y0; y <= y1; y++)
{
color_t value = getOffsetColor(data, startColorOffset);
startColorOffset = getNewColorOffset(numPixels, startColorOffset, 1);
swpixel(x, y, value, 1, 0 );
}
}
}
else
{
// Horizontal lines first format
for(hd_hw_extent_t y = y0; y <= y1; y++)
{
for(hd_hw_extent_t x = x0; x <= x1; x++)
{
color_t value = getOffsetColor(data, startColorOffset);
startColorOffset = getNewColorOffset(numPixels, startColorOffset, 1);
swpixel(x, y, value, 1, 0 );
}
}
}
}
/////////////////////////////////////////////
// Primitive Drawing Functions
/////////////////////////////////////////////
void hyperdisplay::pixel(hd_extent_t x0, hd_extent_t y0, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset)
{
if(pCurrentWindow->bufferMode){
if(wToPix(pCurrentWindow, x0, y0) >= (pCurrentWindow->numPixels)){ return; } // Since we will never reposition a single pixel we can bail out early if it is beyond the number of pixel types available in the window buffer
hyperdisplay_dim_check_t x0c = enforceSWLimits(&x0, false); // Check the x-dimension and convert to hardware coordintaes using the currently assigned window
hyperdisplay_dim_check_t y0c = enforceSWLimits(&y0, true); // Check the y-dimension and convert to hardware coordintaes using the currently assigned window
if((x0c != hyperdisplay_dim_ok) || (y0c != hyperdisplay_dim_ok)){ return; } // Do not print a single pixel at the wrong location ever
if(data == NULL){ swpixel( x0, y0, pCurrentWindow->currentSequenceData, pCurrentWindow->currentColorCycleLength, pCurrentWindow->currentColorOffset); }
else{ swpixel( x0, y0, data, colorCycleLength, startColorOffset); }
}else{
hd_hw_extent_t x0hw, y0hw;
hyperdisplay_dim_check_t x0c = enforceHWLimits(&x0, &x0hw, false); // Check the x-dimension and convert to hardware coordintaes using the currently assigned window
hyperdisplay_dim_check_t y0c = enforceHWLimits(&y0, &y0hw, true); // Check the y-dimension and convert to hardware coordintaes using the currently assigned window
if((x0c != hyperdisplay_dim_ok) || (y0c != hyperdisplay_dim_ok)){ return; } // Do not print a single pixel at the wrong location ever
// Check if we are to use the default color
if(data == NULL){ hwpixel(x0hw, y0hw, pCurrentWindow->currentSequenceData, pCurrentWindow->currentColorCycleLength, pCurrentWindow->currentColorOffset); }
else{ hwpixel(x0hw, y0hw, data, colorCycleLength, startColorOffset); }
}
}
void hyperdisplay::xline(hd_extent_t x0, hd_extent_t y0, hd_extent_t len, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset, bool goLeft)
{
hd_extent_t x1;
if(goLeft){ x1 = x0 - len; }else{ x1 = x0 + len; } // Calculate where x1 would be in window coordinates
if(pCurrentWindow->bufferMode){
if(pCurrentWindow->data == NULL){ return; }
hyperdisplay_dim_check_t x0c = enforceSWLimits(&x0, false); // 'enforceHWLimits()' converts windows coordinates to hardware coordinates and restricts the dimension to be in drawable area
hyperdisplay_dim_check_t x1c = enforceSWLimits(&x1, false); // When the resulting hardware coordinate is in-bounds the function returns "hyperdisplay_dim_ok," otherwise is returns an applicable error
hyperdisplay_dim_check_t y0c = enforceSWLimits(&y0, true); // Next use the 'enforceHWLimits()' results to make sure the desired object is within the active window
if(y0c != hyperdisplay_dim_ok){ return; } // Don't do it if y was wrong
if((x0c == hyperdisplay_dim_low) && (x1c == hyperdisplay_dim_low)){ return; } // Don't do it if x0 and x1 were both low (would cause phantom dot at xMin)
if((x0c == hyperdisplay_dim_high) && (x1c == hyperdisplay_dim_high)){ return; } // Don't do it if x0 and x1 were both high (would cause phantom dot at xMax)
if(wToPix(pCurrentWindow, x0, y0) >= (pCurrentWindow->numPixels)){ return; } // Now that start/stop points have had the chance to be adjusted we can make sure they fit in the current window buffer (and hence give them the seal of approval)
if(wToPix(pCurrentWindow, x1, y0) >= (pCurrentWindow->numPixels)){ return; } // Same thing for the other coordinate pair (jic)
hd_extent_t rken = uabslen <hd_extent_t> (x1, x0);
if(data == NULL){ swxline( x0, y0, len, pCurrentWindow->currentSequenceData, pCurrentWindow->currentColorCycleLength, pCurrentWindow->currentColorOffset, goLeft); } // Check if default color
else{ swxline( x0, y0, rken, data, colorCycleLength, startColorOffset, goLeft); }
}else{
hd_hw_extent_t x0hw, x1hw, y0hw;
hyperdisplay_dim_check_t x0c = enforceHWLimits(&x0, &x0hw, false); // 'enforceHWLimits()' converts windows coordinates to hardware coordinates and restricts the dimension to be in drawable area
hyperdisplay_dim_check_t x1c = enforceHWLimits(&x1, &x1hw, false); // When the resulting hardware coordinate is in-bounds the function returns "hyperdisplay_dim_ok," otherwise is returns an applicable error
hyperdisplay_dim_check_t y0c = enforceHWLimits(&y0, &y0hw, true); // Next use the 'enforceHWLimits()' results to make sure the desired object is within the active window
if(y0c != hyperdisplay_dim_ok){ return; } // Don't do it if y was wrong
if((x0c == hyperdisplay_dim_low) && (x1c == hyperdisplay_dim_low)){ return; } // Don't do it if x0 and x1 were both low (would cause phantom dot at xMin)
if((x0c == hyperdisplay_dim_high) && (x1c == hyperdisplay_dim_high)){ return; } // Don't do it if x0 and x1 were both high (would cause phantom dot at xMax)
// Check if default color
hd_hw_extent_t rken = uabslen <hd_hw_extent_t> (x1hw, x0hw);
if(data == NULL){ hwxline(x0hw, y0hw, rken, pCurrentWindow->currentSequenceData, pCurrentWindow->currentColorCycleLength, pCurrentWindow->currentColorOffset, goLeft); }
else{ hwxline(x0hw, y0hw, rken, data, colorCycleLength, startColorOffset, goLeft); }
}
}
void hyperdisplay::yline(hd_extent_t x0, hd_extent_t y0, hd_extent_t len, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset, bool goUp)
{
hd_extent_t y1;
if(goUp){ y1 = y0 - len; }else{ y1 = y0 + len; } // Calculate where y1 would be in window coordinates
if(pCurrentWindow->bufferMode){
if(pCurrentWindow->data == NULL){ return; }
hyperdisplay_dim_check_t y0c = enforceSWLimits(&y0, true); // 'enforceHWLimits()' converts windows coordinates to hardware coordinates and restricts the dimension to be in drawable area
hyperdisplay_dim_check_t y1c = enforceSWLimits(&y1, true); // When the resulting hardware coordinate is in-bounds the function returns "hyperdisplay_dim_ok," otherwise is returns an applicable error
hyperdisplay_dim_check_t x0c = enforceSWLimits(&x0, false); // Next use the 'enforceHWLimits()' results to make sure the desired object is within the active window
if(x0c != hyperdisplay_dim_ok){ return; } // Don't do it if x was wrong
if((y0c == hyperdisplay_dim_low) && (y1c == hyperdisplay_dim_low)){ return; } // Don't do it if y0 and y1 were both low (would cause phantom dot at yMin)
if((y0c == hyperdisplay_dim_high) && (y1c == hyperdisplay_dim_high)){ return; } // Don't do it if y0 and y1 were both high (would cause phantom dot at yMax)
if(wToPix(pCurrentWindow, x0, y0) >= (pCurrentWindow->numPixels)){ return; } // Now that start/stop points have had the chance to be adjusted we can make sure they fit in the current window buffer (and hence give them the seal of approval)
if(wToPix(pCurrentWindow, x0, y1) >= (pCurrentWindow->numPixels)){ return; } // Same thing for the other coordinate pair (jic)
hd_extent_t rken = uabslen <hd_extent_t> (y1, y0);
if(data == NULL){ swyline( x0, y0, len, pCurrentWindow->currentSequenceData, pCurrentWindow->currentColorCycleLength, pCurrentWindow->currentColorOffset, goUp); }
else{ swyline( x0, y0, rken, data, colorCycleLength, startColorOffset, goUp); }
}else{
hd_hw_extent_t y0hw, y1hw, x0hw;
hyperdisplay_dim_check_t y0c = enforceHWLimits(&y0, &y0hw, true); // 'enforceHWLimits()' converts windows coordinates to hardware coordinates and restricts the dimension to be in drawable area
hyperdisplay_dim_check_t y1c = enforceHWLimits(&y1, &y1hw, true); // When the resulting hardware coordinate is in-bounds the function returns "hyperdisplay_dim_ok," otherwise is returns an applicable error
hyperdisplay_dim_check_t x0c = enforceHWLimits(&x0, &x0hw, false); // Next use the 'enforceHWLimits()' results to make sure the desired object is within the active window
if(x0c != hyperdisplay_dim_ok){ return; } // Don't do it if x was wrong
if((y0c == hyperdisplay_dim_low) && (y1c == hyperdisplay_dim_low)){ return; } // Don't do it if y0 and y1 were both low (would cause phantom dot at yMin)
if((y0c == hyperdisplay_dim_high) && (y1c == hyperdisplay_dim_high)){ return; } // Don't do it if y0 and y1 were both high (would cause phantom dot at yMax)
hd_hw_extent_t rken = uabslen <hd_hw_extent_t> (y1hw, y0hw);
if(data == NULL){ hwyline(x0hw, y0hw, rken, pCurrentWindow->currentSequenceData, pCurrentWindow->currentColorCycleLength, pCurrentWindow->currentColorOffset, goUp); }
else{ hwyline(x0hw, y0hw, rken, data, colorCycleLength, startColorOffset, goUp); }
}
}
void hyperdisplay::rectangle(hd_extent_t x0, hd_extent_t y0, hd_extent_t x1, hd_extent_t y1, bool filled, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset, bool reverseGradient, bool gradientVertical)
{
if(x0 > x1){ swap <hd_extent_t> (&x0, &x1); }
if(y0 > y1){ swap <hd_extent_t> (&y0, &y1); }
if(pCurrentWindow->bufferMode){
if(pCurrentWindow->data == NULL){ return; }
hyperdisplay_dim_check_t y0c = enforceSWLimits(&y0, true); // if the dimension was off-window then it will now be on the edge. enforceHWLimits also applies the transformation into hw coordinates
hyperdisplay_dim_check_t y1c = enforceSWLimits(&y1, true);
hyperdisplay_dim_check_t x0c = enforceSWLimits(&x0, false);
hyperdisplay_dim_check_t x1c = enforceSWLimits(&x1, false); // Next use 'enforceHWLimits()' to make sure the desired object is within the active window, as well as to convert from window coordiantes to hw coordiantes for the upcoming call to hwrectangle()
if((y0c == hyperdisplay_dim_low) && (y1c == hyperdisplay_dim_low)){ return; } // Don't do it if y0 and y1 were both low (would cause phantom line at yMin)
if((y0c == hyperdisplay_dim_high) && (y1c == hyperdisplay_dim_high)){ return; } // Don't do it if y0 and y1 were both high (would cause phantom line at yMax)
if((x0c == hyperdisplay_dim_low) && (x1c == hyperdisplay_dim_low)){ return; } // Don't do it if x0 and x1 were both low (would cause phantom line at xMin)
if((x0c == hyperdisplay_dim_high) && (x1c == hyperdisplay_dim_high)){ return; } // Don't do it if x0 and x1 were both high (would cause phantom line at xMax)
if(wToPix(pCurrentWindow, x0, y0) >= (pCurrentWindow->numPixels)){ return; } // Now that start/stop points have had the chance to be adjusted we can make sure they fit in the current window buffer (and hence give them the seal of approval)
if(wToPix(pCurrentWindow, x1, y0) >= (pCurrentWindow->numPixels)){ return; } // Repeat for all coordinate pairs
if(wToPix(pCurrentWindow, x0, y1) >= (pCurrentWindow->numPixels)){ return; } // Repeat for all coordinate pairs
if(wToPix(pCurrentWindow, x1, y1) >= (pCurrentWindow->numPixels)){ return; } // Repeat for all coordinate pairs
if(data == NULL){ swrectangle( x0, y0, x1, y1, filled, pCurrentWindow->currentSequenceData, pCurrentWindow->currentColorCycleLength, pCurrentWindow->currentColorOffset, reverseGradient, gradientVertical); }
else{ swrectangle( x0, y0, x1, y1, filled, data, colorCycleLength, startColorOffset, reverseGradient, gradientVertical); }
}else{
hd_hw_extent_t x0hw, x1hw, y0hw, y1hw;
hyperdisplay_dim_check_t y0c = enforceHWLimits(&y0, &y0hw, true); // if the dimension was off-window then it will now be on the edge. enforceHWLimits also applies the transformation into hw coordinates
hyperdisplay_dim_check_t y1c = enforceHWLimits(&y1, &y1hw, true);
hyperdisplay_dim_check_t x0c = enforceHWLimits(&x0, &x0hw, false);
hyperdisplay_dim_check_t x1c = enforceHWLimits(&x1, &x1hw, false); // Next use 'enforceHWLimits()' to make sure the desired object is within the active window, as well as to convert from window coordiantes to hw coordiantes for the upcoming call to hwrectangle()
if((y0c == hyperdisplay_dim_low) && (y1c == hyperdisplay_dim_low)){ return; } // Don't do it if y0 and y1 were both low (would cause phantom line at yMin)
if((y0c == hyperdisplay_dim_high) && (y1c == hyperdisplay_dim_high)){ return; } // Don't do it if y0 and y1 were both high (would cause phantom line at yMax)
if((x0c == hyperdisplay_dim_low) && (x1c == hyperdisplay_dim_low)){ return; } // Don't do it if x0 and x1 were both low (would cause phantom line at xMin)
if((x0c == hyperdisplay_dim_high) && (x1c == hyperdisplay_dim_high)){ return; } // Don't do it if x0 and x1 were both high (would cause phantom line at xMax)
if(data == NULL){ hwrectangle(x0hw, y0hw, x1hw, y1hw, filled, pCurrentWindow->currentSequenceData, pCurrentWindow->currentColorCycleLength, pCurrentWindow->currentColorOffset, gradientVertical, reverseGradient); }
else{ hwrectangle(x0hw, y0hw, x1hw, y1hw, filled, data, colorCycleLength, startColorOffset, reverseGradient, gradientVertical); }
}
}
void hyperdisplay::fillFromArray(hd_extent_t x0, hd_extent_t y0, hd_extent_t x1, hd_extent_t y1, color_t data, hd_pixels_t numPixels, bool Vh)
{
if(data == NULL){ return; }
if(x0 > x1){ swap <hd_extent_t> (&x0, &x1); }
if(y0 > y1){ swap <hd_extent_t> (&y0, &y1); }
if(pCurrentWindow->bufferMode){
if(pCurrentWindow->data == NULL){ return; }
hyperdisplay_dim_check_t y0c = enforceSWLimits(&y0, true);
hyperdisplay_dim_check_t y1c = enforceSWLimits(&y1, true);
hyperdisplay_dim_check_t x0c = enforceSWLimits(&x0, false);
hyperdisplay_dim_check_t x1c = enforceSWLimits(&x1, false); // Next use 'enforceHWLimits()' to make sure the desired object is within the active window, as well as to convert from window coordiantes to hw coordiantes for the upcoming call to hwfillFromArray()
if((y0c == hyperdisplay_dim_low) && (y1c == hyperdisplay_dim_low)){ return; } // Don't do it if y0 and y1 were both low (would cause phantom line at yMin)
if((y0c == hyperdisplay_dim_high) && (y1c == hyperdisplay_dim_high)){ return; } // Don't do it if y0 and y1 were both high (would cause phantom line at yMax)
if((x0c == hyperdisplay_dim_low) && (x1c == hyperdisplay_dim_low)){ return; } // Don't do it if x0 and x1 were both low (would cause phantom line at xMin)
if((x0c == hyperdisplay_dim_high) && (x1c == hyperdisplay_dim_high)){ return; } // Don't do it if x0 and x1 were both high (would cause phantom line at xMax)
if(wToPix(pCurrentWindow, x0, y0) >= (pCurrentWindow->numPixels)){ return; } // Now that start/stop points have had the chance to be adjusted we can make sure they fit in the current window buffer (and hence give them the seal of approval)
if(wToPix(pCurrentWindow, x1, y0) >= (pCurrentWindow->numPixels)){ return; } // Repeat for all coordinate pairs
if(wToPix(pCurrentWindow, x0, y1) >= (pCurrentWindow->numPixels)){ return; } // Repeat for all coordinate pairs
if(wToPix(pCurrentWindow, x1, y1) >= (pCurrentWindow->numPixels)){ return; } // Repeat for all coordinate pairs
hd_extent_t xlen = uabslen <hd_extent_t> (x1, x0);
hd_extent_t ylen = uabslen <hd_extent_t> (y1, y0);
hd_pixels_t rNP = xlen*ylen;
swfillFromArray( x0, y0, x1, y1, data, rNP, Vh );
}else{
hd_hw_extent_t x0hw, x1hw, y0hw, y1hw;
hyperdisplay_dim_check_t y0c = enforceHWLimits(&y0, &y0hw, true);
hyperdisplay_dim_check_t y1c = enforceHWLimits(&y1, &y1hw, true);
hyperdisplay_dim_check_t x0c = enforceHWLimits(&x0, &x0hw, false);
hyperdisplay_dim_check_t x1c = enforceHWLimits(&x1, &x1hw, false); // Next use 'enforceHWLimits()' to make sure the desired object is within the active window, as well as to convert from window coordiantes to hw coordiantes for the upcoming call to hwfillFromArray()
if((y0c == hyperdisplay_dim_low) && (y1c == hyperdisplay_dim_low)){ return; } // Don't do it if y0 and y1 were both low (would cause phantom line at yMin)
if((y0c == hyperdisplay_dim_high) && (y1c == hyperdisplay_dim_high)){ return; } // Don't do it if y0 and y1 were both high (would cause phantom line at yMax)
if((x0c == hyperdisplay_dim_low) && (x1c == hyperdisplay_dim_low)){ return; } // Don't do it if x0 and x1 were both low (would cause phantom line at xMin)
if((x0c == hyperdisplay_dim_high) && (x1c == hyperdisplay_dim_high)){ return; } // Don't do it if x0 and x1 were both high (would cause phantom line at xMax)
hd_hw_extent_t xlen = uabslen <hd_hw_extent_t> (x1hw, x0hw);
hd_hw_extent_t ylen = uabslen <hd_hw_extent_t> (y1hw, y0hw);
hd_pixels_t rNP = xlen*ylen;
if(numPixels < rNP){ rNP = numPixels; }
hwfillFromArray(x0hw, y0hw, x1hw, y1hw, data, rNP, Vh);
}
}
void hyperdisplay::fillWindow(color_t color, hd_colors_t colorCycleLength, hd_colors_t startColorOffset)
{
// The rectangle function uses window coordinates, so to fill a window you go from (0,0) to (xWidth, yWidth)
rectangle( 0, 0, pCurrentWindow->xMax - pCurrentWindow->xMin, pCurrentWindow->yMax - pCurrentWindow->yMin, true, color, colorCycleLength, startColorOffset, false, false);
}
void hyperdisplay::setWindowColorSequence(wind_info_t * wind, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset)
{
if(wind == NULL){ return; }
wind->currentSequenceData = data;
wind->currentColorCycleLength = colorCycleLength;
wind->currentColorOffset = startColorOffset;
}
void hyperdisplay::setCurrentWindowColorSequence(color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset)
{
setWindowColorSequence(pCurrentWindow, data, colorCycleLength, startColorOffset);
}
int hyperdisplay::setWindowMemory(wind_info_t * wind, color_t data, hd_pixels_t numPixels, uint8_t bpp, bool allowDynamic)
{
if(wind == NULL){ return -1; }
if(wind->data != NULL){ // If there was a buffer previously associated you need to handle getting rid of it
if(wind->dynamic){ // If it was dynamically allocated then free the memory
free(wind->data); // Maybe should use delete?
}
wind->numPixels = 0;
wind->dynamic = false;
}
if(data == NULL){ // If the user does not supply a pointer then try dynamic allocation
if(allowDynamic){
color_t ptemp = NULL;
ptemp = (color_t)malloc(numPixels*bpp*sizeof(uint8_t));
if(ptemp == NULL){
return -1; // Could not allocate memory
}
wind->data = ptemp;
wind->dynamic = true;
}
else{
return -1;
}
}else{
wind->data = data;
wind->dynamic = false;
}
wind->numPixels = numPixels;
return 0; // Good!
}
int hyperdisplay::setCurrentWindowMemory( color_t data, hd_pixels_t numPixels, uint8_t bpp, bool allowDynamic)
{
setWindowMemory(pCurrentWindow, data, numPixels, bpp, allowDynamic);
}
// Buffer and Show
void hyperdisplay::buffer( wind_info_t * wind ){ // Puts the current window into buffer mode - drawing commands are performed on the current window's data buffer - if available
if(wind != NULL){
wind->bufferMode = true;
}else{
pCurrentWindow->bufferMode = true;
}
}
void hyperdisplay::direct( wind_info_t * wind ){ // Cancels buffer mode. Drawing commands will go straight to display memory. Buffered data will remain and can still be shown later
if(wind != NULL){
wind->bufferMode = false;
}else{
pCurrentWindow->bufferMode = false;
}
}
void hyperdisplay::show( wind_info_t * wind ){ // Outputs the current window's buffered data to the display
if(wind != NULL){
wind_info_t* pLastWindow = pCurrentWindow; // Since fillFromArray uses window coordinates we need to change the current window, temporarily
pCurrentWindow = wind;
bool lastBuffMode = wind->bufferMode; // Save the state of bufferMode
wind->bufferMode = false; // If we tried to output data while still in buffer mode it would be a mess!
fillFromArray(0, 0, wind->xMax - wind->xMin, wind->yMax - wind->yMin, wind->data, wind->numPixels, false); // Use horizontal mode
wind->bufferMode = lastBuffMode; // Put the window back into whatever buffer mode it had been in before.
pCurrentWindow = pLastWindow; // Switch back to the old window
}else{
bool lastBuffMode = pCurrentWindow->bufferMode; // Save the state of bufferMode
pCurrentWindow->bufferMode = false; // If we tried to output data while still in buffer mode it would be a mess!
fillFromArray(0, 0, pCurrentWindow->xMax - pCurrentWindow->xMin, pCurrentWindow->yMax - pCurrentWindow->yMin, pCurrentWindow->data, pCurrentWindow->numPixels, false); // Use horizontal mode
pCurrentWindow->bufferMode = lastBuffMode; // Put the window back into whatever buffer mode it had been in before.
}
}
#if HYPERDISPLAY_USE_PRINT
// FYI this virtual function can be overwritten. It is just the most basic default version
size_t hyperdisplay::write(uint8_t val)
{
size_t numWritten = 0;
getCharInfo(val, &hyperdisplayCharacter);
// Check to see if current cursor coordinates work for the requested character
if(((pCurrentWindow->xMax - pCurrentWindow->xMin) - hyperdisplayCharacter.xDim) < pCurrentWindow->cursorX)
{
if(((pCurrentWindow->yMax - pCurrentWindow->yMin) - hyperdisplayCharacter.yDim) < pCurrentWindow->cursorY)
{
return numWritten; // return because there is no more room in the x or y directions of the window
}
pCurrentWindow->cursorX = pCurrentWindow->xReset; // Put x cursor back to reset location
pCurrentWindow->cursorY += hyperdisplayCharacter.yDim; // Move the cursor down by the size of the character
}
// Now write the character
if(hyperdisplayCharacter.show)
{
// fillFromArray(pCurrentWindow->cursorX, pCurrentWindow->cursorY, pCurrentWindow->cursorX+hyperdisplayCharacter.xDim, pCurrentWindow->cursorY+hyperdisplayCharacter.yDim, hyperdisplayCharacter.numPixels, hyperdisplayCharacter.data);
for(uint32_t indi = 0; indi < hyperdisplayCharacter.numPixels; indi++)
{
pixel(((pCurrentWindow->cursorX)+*(hyperdisplayCharacter.xLoc + indi)), ((pCurrentWindow->cursorY)+*(hyperdisplayCharacter.yLoc + indi)), NULL, 1, 0);
}
numWritten = 1;
// Now advance the cursor in the x direction so that you don't overwrite the work you just did
pCurrentWindow->cursorX += hyperdisplayCharacter.xDim + 1;
}
pCurrentWindow->lastCharacter = hyperdisplayCharacter; // Set this character as the previous character - the info will persist because this is direct
return numWritten;
}
void hyperdisplay::getCharInfo(uint8_t character, char_info_t * character_info)
{
// Retrieve local constants from the font header
uint8_t FONT_HEADER_SIZE= 6;
uint8_t FONT_WIDTH = pgm_read_byte(fontsPointer[FONT_TYPE] + 0);
uint8_t FONT_HEIGHT = pgm_read_byte(fontsPointer[FONT_TYPE] + 1);
uint8_t FONT_START_CHAR = pgm_read_byte(fontsPointer[FONT_TYPE] + 2);
uint8_t FONT_TOTAL_CHAR = pgm_read_byte(fontsPointer[FONT_TYPE] + 3);
uint16_t FONT_MAP_WIDTH = (pgm_read_byte(fontsPointer[FONT_TYPE] + 4) * 100)
+ pgm_read_byte(fontsPointer[FONT_TYPE] + 5);
// Initialize the local variables
uint8_t indi, indj, row, currentByte, rowsToDraw, pixelLocationArrayIndex = 0;
rowsToDraw = FONT_HEIGHT / 8;
// Set the character structure to the selected font
character_info->data = NULL;
character_info->xLoc = hyperdisplayXloc;
character_info->yLoc = hyperdisplayYloc;
character_info->xDim = FONT_WIDTH;
character_info->yDim = FONT_HEIGHT;
character_info->numPixels = 0;
// Figure out if the character should cause a newline
if (character == '\r' || character == '\n')
{
character_info->causesNewline = true;
}
else
{
character_info->causesNewline = false;
}
// Figure out if you need to actually show the chracter
if ((character >= ' ') && (character <= '~'))
{
character_info->show = true;
}
else
{
character_info->show = false;
return; // No point in continuing;
}
// Figure out if the character is within the font range
if ((character < FONT_START_CHAR) || (character > (FONT_START_CHAR + FONT_TOTAL_CHAR - 1))) {
return;
}
// Figure out if the number of rows is one or more rows
if (rowsToDraw <= 1)
{
rowsToDraw = 1;
}
// Load up the character data and fill in coordinate data
if (rowsToDraw == 1)
{
for (indi = 0; indi < FONT_WIDTH; indi++)
{
// Retreive a single byte of data
currentByte = pgm_read_byte(fontsPointer[FONT_TYPE] + FONT_HEADER_SIZE + ((character - FONT_START_CHAR) * FONT_WIDTH) + indi);
for (indj = 0; indj < 8; indj++)
{
// Figure out which pixels should be on or off
if (currentByte & (0x01 << indj))
{
// Update the character stuct
character_info->numPixels++;
*(character_info->xLoc + pixelLocationArrayIndex) = (hd_font_extent_t)indi;
*(character_info->yLoc + pixelLocationArrayIndex) = (hd_font_extent_t)indj;
pixelLocationArrayIndex++;
}
}
}
return;
}
else
{
// Figure out the location of the lower half of the characters
uint16_t charactersPerBitmapRow = FONT_MAP_WIDTH / FONT_WIDTH;
uint16_t characterColumnPositionOnBitmap = (character - FONT_START_CHAR) % charactersPerBitmapRow;
uint16_t characterRowPositionOnBitmap = (character - FONT_START_CHAR) / charactersPerBitmapRow;
uint16_t characterBitmapStartPosition = (characterRowPositionOnBitmap * FONT_MAP_WIDTH * (FONT_HEIGHT / 8)) + (characterColumnPositionOnBitmap * FONT_WIDTH);
// Load up the character data and fill in coordinate data one row at a time
for (row = 0; row < rowsToDraw; row++)
{
for (indi = 0; indi < FONT_WIDTH; indi++)
{
// Retreive a single byte of data
currentByte = pgm_read_byte(fontsPointer[FONT_TYPE] + FONT_HEADER_SIZE + characterBitmapStartPosition + (row * FONT_MAP_WIDTH) + indi);
for (indj = 0; indj < 8; indj++)
{
if (currentByte & (0x01 << indj))
{
// Update the character stuct
character_info->numPixels++;
*(character_info->xLoc + pixelLocationArrayIndex) = (hd_font_extent_t)indi;
*(character_info->yLoc + pixelLocationArrayIndex) = (hd_font_extent_t)(indj + (row * 8));
pixelLocationArrayIndex++;
}
}
}
}
return;
}
}
#else /* HYPERDISPLAY_USE_PRINT */
// This is here in case you choose not to implement printing functions
size_t hyperdisplay::write(uint8_t val)
{
Serial.write(val);
}
#endif /* HYPERDISPLAY_USE_PRINT */
void hyperdisplay::setTextCursor(int32_t x0, int32_t y0, wind_info_t * window){
if(!window){ window = pCurrentWindow; } //default to current
if(!window){ return; } // Dont operate on null
window->cursorX = x0; // Where the cursor is currently in window-coordinates
window->cursorY = y0; // Where the cursor is currently in window-coordinates
}
void hyperdisplay::resetTextCursor(wind_info_t * window){
if(!window){ window = pCurrentWindow; } //default to current
if(!window){ return; } // Dont operate on null
setTextCursor(window->xReset, window->yReset, window);
}
/////////////////////////////////////////////
// Level 1 Drawing Functions
/////////////////////////////////////////////
#if HYPERDISPLAY_DRAWING_LEVEL > 0
uint16_t hyperdisplay::line(hd_extent_t x0, hd_extent_t y0, hd_extent_t x1, hd_extent_t y1, uint16_t width, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset, bool reverseGradient)
{
hd_extent_t absY = uabslen <hd_extent_t> (y1, y0);
hd_extent_t absX = uabslen <hd_extent_t> (x1, x0);
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 0); // This line is needed to condition the user's input start color offset
if( absY < absX )
{
if( x0 > x1 )
{
if(reverseGradient)
{
return lineLowReverse(x1, y1, x0, y0, width, data, colorCycleLength, startColorOffset);
}
else
{
return lineLowNorm(x1, y1, x0, y0, width, data, colorCycleLength, startColorOffset);
}
}
else
{
if(reverseGradient)
{
return lineLowReverse(x0, y0, x1, y1, width, data, colorCycleLength, startColorOffset);
}
else
{
return lineLowNorm(x0, y0, x1, y1, width, data, colorCycleLength, startColorOffset);
}
}
}
else
{