-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnuklear_quickdraw.h
More file actions
1524 lines (1148 loc) · 48.2 KB
/
Copy pathnuklear_quickdraw.h
File metadata and controls
1524 lines (1148 loc) · 48.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
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
/*
* Nuklear - 1.32.0 - public domain
* no warranty implied; use at your own risk.
* based on allegro5 version authored from 2015-2016 by Micha Mettke
* quickdraw version camhenlin 2021-2022
*
* v1 intent:
* - only default system font support
* - no graphics/images support - quickdraw has very limited support for this
*/
/*
* ==============================================================
*
* API
*
* ===============================================================
*/
#ifndef NK_QUICKDRAW_H_
#define NK_QUICKDRAW_H_
#include <MacTypes.h>
#include <Types.h>
#include <Quickdraw.h>
#include <Scrap.h>
#include <Serial.h>
#include "SerialHelper.h"
#include <stdlib.h>
#define ENABLED_DOUBLE_BUFFERING
#define COMMAND_CACHING
#include "nuklear.h"
// #define NK_QUICKDRAW_GRAPHICS_DEBUGGING
// #define DRAW_BLIT_LOCATION
Boolean lastInputWasBackspace;
typedef struct NkQuickDrawFont NkQuickDrawFont;
NK_API struct nk_context* nk_quickdraw_init(unsigned int width, unsigned int height);
NK_API int nk_quickdraw_handle_event(EventRecord *event, struct nk_context *nuklear_context);
NK_API void nk_quickdraw_shutdown(void);
NK_API void nk_quickdraw_render(WindowPtr window, struct nk_context *ctx);
NK_API struct nk_image* nk_quickdraw_create_image(const char* file_name);
NK_API void nk_quickdraw_del_image(struct nk_image* image);
NK_API NkQuickDrawFont* nk_quickdraw_font_create_from_file();
#endif
/*
* ==============================================================
*
* IMPLEMENTATION
*
* ===============================================================
*/
#define MAX_MEMORY_IN_KB 6
#ifdef NK_QUICKDRAW_IMPLEMENTATION
#ifndef NK_QUICKDRAW_TEXT_MAX
#define NK_QUICKDRAW_TEXT_MAX 256
#endif
#endif
struct NkQuickDrawFont {
struct nk_user_font nk;
char *font;
};
int lastEventWasKey = 0;
void *last;
void *buf;
// constant keyboard mappings for convenenience
// See Inside Macintosh: Text pg A-7, A-8
int homeKey = (int)0x01;
int enterKey = (int)0x03;
int endKey = (int)0x04;
int helpKey = (int)0x05;
int backspaceKey = (int)0x08;
int deleteKey = (int)0x7F;
int tabKey = (int)0x09;
int pageUpKey = (int)0x0B;
int pageDownKey = (int)0x0C;
int returnKey = (int)0x0D;
int rightArrowKey = (int)0x1D;
int leftArrowKey = (int)0x1C;
int downArrowKey = (int)0x1F;
int upArrowKey = (int)0x1E;
int eitherShiftKey = (int)0x0F;
int escapeKey = (int)0x1B;
// #define NK_QUICKDRAW_GRAPHICS_DEBUGGING
// #def#ifdef NK_QUICKDRAW_EVENTS_DEBUGG
typedef struct {
Ptr Address;
long RowBytes;
GrafPtr bits;
Rect bounds;
BitMap BWBits;
GrafPort BWPort;
Handle OrigBits;
} ShockBitmap;
void NewShockBitmap(ShockBitmap *theMap, short width, short height) {
theMap->bits = 0L;
SetRect(&theMap->bounds, 0, 0, width, height);
theMap->BWBits.bounds = theMap->bounds;
theMap->BWBits.rowBytes = ((width+15) >> 4)<<1; // round to even
theMap->BWBits.baseAddr = NewPtr(((long) height * (long) theMap->BWBits.rowBytes));
theMap->BWBits.baseAddr = StripAddress(theMap->BWBits.baseAddr);
OpenPort(&theMap->BWPort);
SetPort(&theMap->BWPort);
SetPortBits(&theMap->BWBits);
SetRectRgn(theMap->BWPort.visRgn, theMap->bounds.left, theMap->bounds.top, theMap->bounds.right, theMap->bounds.bottom);
SetRectRgn(theMap->BWPort.clipRgn, theMap->bounds.left, theMap->bounds.top, theMap->bounds.right, theMap->bounds.bottom);
EraseRect(&theMap->bounds);
theMap->Address = theMap->BWBits.baseAddr;
theMap->RowBytes = (long) theMap->BWBits.rowBytes;
theMap->bits = (GrafPtr) &theMap->BWPort;
}
ShockBitmap gMainOffScreen;
// bezier code is from http://preserve.mactech.com/articles/mactech/Vol.05/05.01/BezierCurve/index.html
// as it is not built in to quickdraw like other "modern" graphics environments
/*
The greater the number of curve segments, the smoother the curve,
and the longer it takes to generate and draw. The number below was pulled
out of a hat, and seems to work o.k.
*/
#define SEGMENTS 16
static Fixed weight1[SEGMENTS + 1];
static Fixed weight2[SEGMENTS + 1];
#define w1(s) weight1[s]
#define w2(s) weight2[s]
#define w3(s) weight2[SEGMENTS - s]
#define w4(s) weight1[SEGMENTS - s]
/*
* SetupBezier -- one-time setup code.
* Compute the weights for the Bezier function.
* For the those concerned with space, the tables can be precomputed.
Setup is done here for purposes of illustration.
*/
void setupBezier() {
Fixed t, zero, one;
int s;
zero = FixRatio(0, 1);
one = FixRatio(1, 1);
weight1[0] = one;
weight2[0] = zero;
for (s = 1; s < SEGMENTS; ++s) {
t = FixRatio(s, SEGMENTS);
weight1[s] = FixMul(one - t, FixMul(one - t, one - t));
weight2[s] = 3 * FixMul(t, FixMul(t - one, t - one));
}
weight1[SEGMENTS] = zero;
weight2[SEGMENTS] = zero;
}
/*
* computeSegments -- compute segments for the Bezier curve
* Compute the segments along the curve.
* The curve touches the endpoints, so don’t bother to compute them.
*/
static void computeSegments(p1, p2, p3, p4, segment) Point p1, p2, p3, p4; Point segment[]; {
int s;
segment[0] = p1;
for (s = 1; s < SEGMENTS; ++s) {
segment[s].v = FixRound(w1(s) * p1.v + w2(s) * p2.v + w3(s) * p3.v + w4(s) * p4.v);
segment[s].h = FixRound(w1(s) * p1.h + w2(s) * p2.h + w3(s) * p3.h + w4(s) * p4.h);
}
segment[SEGMENTS] = p4;
}
/*
* BezierCurve -- Draw a Bezier Curve
* Draw a curve with the given endpoints (p1, p4), and the given
* control points (p2, p3).
* Note that we make no assumptions about pen or pen mode.
*/
void BezierCurve(p1, p2, p3, p4) Point p1, p2, p3, p4; {
int s;
Point segment[SEGMENTS + 1];
computeSegments(p1, p2, p3, p4, segment);
MoveTo(segment[0].h, segment[0].v);
for (s = 1 ; s <= SEGMENTS ; ++s) {
if (segment[s].h != segment[s - 1].h || segment[s].v != segment[s - 1].v) {
LineTo(segment[s].h, segment[s].v);
}
}
}
// ex usage:
// Point control[4] = {{144,72}, {72,144}, {216,144}, {144,216}};
// BezierCurve(c[0], c[1], c[2], c[3]);
static struct nk_quickdraw {
unsigned int width;
unsigned int height;
struct nk_context nuklear_context;
struct nk_buffer cmds;
} quickdraw;
// TODO: maybe V2 - skipping images for first pass
NK_API struct nk_image* nk_quickdraw_create_image(const char* file_name) {
// TODO: just read the file to a char, we can draw it using quickdraw
// b&w bitmaps are pretty easy to draw...
// for us to do this, we need to figure out the format, then figure out if we can make it in to a quickdraw rect
// and set the buffer to the image handle pointer in the image struct
// i assume this gets consumed elsewhere in the code, thinking NK_COMMAND_IMAGE
char* bitmap = ""; //al_load_bitmap(file_name); // TODO: https://www.allegro.cc/manual/5/al_load_bitmap, loads file to in-memory buffer understood by allegro
if (bitmap == NULL) {
fprintf(stdout, "Unable to load image file: %s\n", file_name);
return NULL;
}
struct nk_image *image = (struct nk_image*)calloc(1, sizeof(struct nk_image));
image->handle.ptr = bitmap;
image->w = 0; // al_get_bitmap_width(bitmap); // TODO: this can be retrieved from a bmp file
image->h = 0; // al_get_bitmap_height(bitmap); // TODO: this can be retrieved from a bmp file
return image;
}
// TODO: maybe V2 - skipping images for first pass
NK_API void nk_quickdraw_del_image(struct nk_image* image) {
if (!image) {
return;
}
// al_destroy_bitmap(image->handle.ptr); // TODO: https://www.allegro.cc/manual/5/al_destroy_bitmap
//this is just de-allocating the memory from a loaded bitmap
free(image);
}
// NOTE: you will need to generate this yourself if you want to add additional font support!
short widthFor12ptFont[128] = {
0,
10,
10,
10,
10,
10,
10,
10,
10,
8,
10,
10,
10,
0,
10,
10,
10,
11,
11,
9,
11,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
10,
4,
6,
7,
10,
7,
11,
10,
3,
5,
5,
7,
7,
4,
7,
4,
7,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
4,
4,
6,
8,
6,
8,
11,
8,
8,
8,
8,
7,
7,
8,
8,
6,
7,
9,
7,
12,
9,
8,
8,
8,
8,
7,
6,
8,
8,
12,
8,
8,
8,
5,
7,
5,
8,
8,
6,
8,
8,
7,
8,
8,
6,
8,
8,
4,
6,
8,
4,
12,
8,
8,
8,
8,
6,
7,
6,
8,
8,
12,
8,
8,
8,
5,
5,
5,
8,
8
};
// doing this in a "fast" way by using a precomputed table for a 12pt font
static short nk_quickdraw_font_get_text_width(nk_handle handle, short height, const char *text, short len) {
// this is going to produce a lot of logging and not a lot of value:
// #ifdef DEBUG_FUNCTION_CALLS
// writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: nk_quickdraw_font_get_text_width");
// #endif
if (!text || len == 0) {
return 0;
}
short width = 0;
for (short i = 0; i < len; i++) {
width += widthFor12ptFont[(int)text[i]];
}
return width;
}
static int _get_text_width(const char *text, int len) {
#ifdef DEBUG_FUNCTION_CALLS
writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: _get_text_width");
#endif
if (!text || len == 0) {
return 0;
}
int width = 0;
for (int i = 0; i < len; i++) {
width += widthFor12ptFont[(int)text[i]];
}
return width;
}
/* Flags are identical to al_load_font() flags argument */
NK_API NkQuickDrawFont* nk_quickdraw_font_create_from_file() {
NkQuickDrawFont *font = (NkQuickDrawFont*)calloc(1, sizeof(NkQuickDrawFont));
font->font = calloc(1, 1024);
if (font->font == NULL) {
fprintf(stdout, "Unable to load font file\n");
return NULL;
}
font->nk.userdata = nk_handle_ptr(font);
font->nk.height = (int)12;
font->nk.width = nk_quickdraw_font_get_text_width;
return font;
}
// used for bounds checking
int mostLeft = WINDOW_WIDTH;
int mostBottom = 1;
int mostTop = WINDOW_HEIGHT;
int mostRight = 1;
void updateBounds(int top, int bottom, int left, int right) {
#ifdef DEBUG_FUNCTION_CALLS
writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: updateBounds");
#endif
if (left < mostLeft) {
mostLeft = left;
}
if (right > mostRight) {
mostRight = right;
}
if (top < mostTop) {
mostTop = top;
}
if (bottom > mostBottom) {
mostBottom = bottom;
}
}
#ifdef COMMAND_CACHING
void runDrawCommand(const struct nk_command *cmd, const struct nk_command *lastCmd) {
#else
void runDrawCommand(const struct nk_command *cmd) {
#endif
#ifdef DEBUG_FUNCTION_CALLS
writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: runDrawCommand");
#endif
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
char x[255];
sprintf(x, "cmd: %d", cmd->type);
writeSerialPortDebug(boutRefNum, x);
char y[255];
sprintf(y, "lastCmd: %d", lastCmd->type);
writeSerialPortDebug(boutRefNum, y);
#endif
switch (cmd->type) {
case NK_COMMAND_NOP:
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "NK_COMMAND_NOP");
#endif
break;
case NK_COMMAND_SCISSOR: {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "NK_COMMAND_SCISSOR");
#endif
const struct nk_command_scissor *s = (const struct nk_command_scissor*)cmd;
// there is no point in supressing scissor commands because they only affect
// where we can actually draw to:
// #ifdef COMMAND_CACHING
// if (memcmp(s, lastCmd, sizeof(struct nk_command_scissor)) == 0) {
// #ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
// writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_scissor");
// #endif
// break;
// }
// #endif
Rect quickDrawRectangle;
quickDrawRectangle.top = s->y;
quickDrawRectangle.left = s->x;
quickDrawRectangle.bottom = s->y + s->h;
quickDrawRectangle.right = s->x + s->w;
#ifdef ENABLED_DOUBLE_BUFFERING
// we use "-8192" here to filter out nuklear "nk_null_rect" which we do not want updating bounds
if (quickDrawRectangle.top != -8192) {
updateBounds(quickDrawRectangle.top, quickDrawRectangle.bottom, quickDrawRectangle.left, quickDrawRectangle.right);
}
#endif
ClipRect(&quickDrawRectangle);
}
break;
case NK_COMMAND_RECT: {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "NK_COMMAND_RECT");
#endif
// http://mirror.informatimago.com/next/developer.apple.com/documentation/mac/QuickDraw/QuickDraw-102.html#MARKER-9-372
// http://mirror.informatimago.com/next/developer.apple.com/documentation/mac/QuickDraw/QuickDraw-103.html#HEADING103-0
const struct nk_command_rect *r = (const struct nk_command_rect *)cmd;
#ifdef COMMAND_CACHING
if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(r, lastCmd, sizeof(struct nk_command_rect)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_rect");
#endif
break;
}
#endif
ForeColor(r->color);
PenSize(r->line_thickness, r->line_thickness);
Rect quickDrawRectangle;
quickDrawRectangle.top = r->y;
quickDrawRectangle.left = r->x;
quickDrawRectangle.bottom = r->y + r->h;
quickDrawRectangle.right = r->x + r->w;
#ifdef ENABLED_DOUBLE_BUFFERING
updateBounds(quickDrawRectangle.top, quickDrawRectangle.bottom, quickDrawRectangle.left, quickDrawRectangle.right);
#endif
FrameRoundRect(&quickDrawRectangle, r->rounding, r->rounding);
}
break;
case NK_COMMAND_RECT_FILLED: {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "NK_COMMAND_RECT_FILLED");
#endif
const struct nk_command_rect_filled *r = (const struct nk_command_rect_filled *)cmd;
if (r->allowCache == false) {
Rect quickDrawRectangle;
quickDrawRectangle.top = r->y;
quickDrawRectangle.left = r->x;
quickDrawRectangle.bottom = r->y + r->h;
quickDrawRectangle.right = r->x + r->w;
#ifdef ENABLED_DOUBLE_BUFFERING
updateBounds(quickDrawRectangle.top, quickDrawRectangle.bottom, quickDrawRectangle.left, quickDrawRectangle.right);
#endif
FillRoundRect(&quickDrawRectangle, r->rounding, r->rounding, &qd.white);
break;
}
#ifdef COMMAND_CACHING
if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(r, lastCmd, sizeof(struct nk_command_rect_filled)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_rect_filled");
#endif
break;
}
#endif
// TODO: to support coloring the lines, we need to map from qd Pattern types to integer colors
// color = nk_color_to_quickdraw_bw_color(r->color);
// ForeColor(color);
ForeColor(blackColor);
PenSize(1.0, 1.0);
Rect quickDrawRectangle;
quickDrawRectangle.top = r->y;
quickDrawRectangle.left = r->x;
quickDrawRectangle.bottom = r->y + r->h;
quickDrawRectangle.right = r->x + r->w;
#ifdef ENABLED_DOUBLE_BUFFERING
updateBounds(quickDrawRectangle.top, quickDrawRectangle.bottom, quickDrawRectangle.left, quickDrawRectangle.right);
#endif
FillRoundRect(&quickDrawRectangle, r->rounding, r->rounding, &r->color);
FrameRoundRect(&quickDrawRectangle, r->rounding, r->rounding); // http://mirror.informatimago.com/next/developer.apple.com/documentation/mac/QuickDraw/QuickDraw-105.html#HEADING105-0
}
break;
case NK_COMMAND_TEXT: {
const struct nk_command_text *t = (const struct nk_command_text*)cmd;
#ifdef COMMAND_CACHING
if (!lastInputWasBackspace && t->allowCache && cmd->type == lastCmd->type && memcmp(t, lastCmd, sizeof(struct nk_command_text)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
char log[255];
sprintf(log, "ALREADY DREW CMD nk_command_text string: \"%s\", height: %d, length: %d, x: %d, y: %d, allowCache: %d", t->string, t->height, t->length, t->x, t->y, t->allowCache);
writeSerialPortDebug(boutRefNum, log);
#endif
break;
}
#endif
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
char log[255];
sprintf(log, "NK_COMMAND_TEXT string: \"%s\", height: %d, length: %d, x: %d, y: %d, allowCache: %d", t->string, t->height, t->length, t->x, t->y, t->allowCache);
writeSerialPortDebug(boutRefNum, log);
#endif
Rect quickDrawRectangle;
quickDrawRectangle.top = t->y;
quickDrawRectangle.left = t->x;
quickDrawRectangle.bottom = t->y + 15;
quickDrawRectangle.right = t->x + _get_text_width((const char*)t->string, (int)t->length);
#ifdef ENABLED_DOUBLE_BUFFERING
updateBounds(quickDrawRectangle.top, quickDrawRectangle.bottom, quickDrawRectangle.left, quickDrawRectangle.right);
#endif
#ifdef COMMAND_CACHING
EraseRect(&quickDrawRectangle);
#endif
ForeColor(t->foreground);
MoveTo(t->x, t->y + t->height);
PenSize(1.0, 1.0);
DrawText((const char*)t->string, 0, t->length);
}
break;
case NK_COMMAND_LINE: {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "NK_COMMAND_LINE");
#endif
const struct nk_command_line *l = (const struct nk_command_line *)cmd;
#ifdef COMMAND_CACHING
if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(l, lastCmd, sizeof(struct nk_command_line)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_line");
#endif
break;
}
#endif
// great reference: http://mirror.informatimago.com/next/developer.apple.com/documentation/mac/QuickDraw/QuickDraw-60.html
ForeColor(l->color);
PenSize(l->line_thickness, l->line_thickness);
MoveTo(l->begin.x, l->begin.y);
LineTo(l->end.x, l->end.y);
}
break;
case NK_COMMAND_CIRCLE: {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "NK_COMMAND_CIRCLE");
#endif
const struct nk_command_circle *c = (const struct nk_command_circle *)cmd;
#ifdef COMMAND_CACHING
if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(c, lastCmd, sizeof(struct nk_command_circle)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_circle");
#endif
break;
}
#endif
ForeColor(c->color);
Rect quickDrawRectangle;
quickDrawRectangle.top = c->y;
quickDrawRectangle.left = c->x;
quickDrawRectangle.bottom = c->y + c->h;
quickDrawRectangle.right = c->x + c->w;
#ifdef ENABLED_DOUBLE_BUFFERING
updateBounds(quickDrawRectangle.top, quickDrawRectangle.bottom, quickDrawRectangle.left, quickDrawRectangle.right);
#endif
FrameOval(&quickDrawRectangle); // An oval is a circular or elliptical shape defined by the bounding rectangle that encloses it. inside macintosh: imaging with quickdraw 3-25
}
break;
case NK_COMMAND_CIRCLE_FILLED: {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "NK_COMMAND_CIRCLE_FILLED");
#endif
const struct nk_command_circle_filled *c = (const struct nk_command_circle_filled *)cmd;
#ifdef COMMAND_CACHING
if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(c, lastCmd, sizeof(struct nk_command_circle_filled)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_circle_filled");
#endif
break;
}
#endif
ForeColor(blackColor);
// BackPat(&colorPattern); // inside macintosh: imaging with quickdraw 3-48
PenSize(1.0, 1.0);
Rect quickDrawRectangle;
quickDrawRectangle.top = c->y;
quickDrawRectangle.left = c->x;
quickDrawRectangle.bottom = c->y + c->h;
quickDrawRectangle.right = c->x + c->w;
#ifdef ENABLED_DOUBLE_BUFFERING
updateBounds(quickDrawRectangle.top, quickDrawRectangle.bottom, quickDrawRectangle.left, quickDrawRectangle.right);
#endif
FillOval(&quickDrawRectangle, &c->color);
FrameOval(&quickDrawRectangle);// An oval is a circular or elliptical shape defined by the bounding rectangle that encloses it. inside macintosh: imaging with quickdraw 3-25
// http://mirror.informatimago.com/next/developer.apple.com/documentation/mac/QuickDraw/QuickDraw-111.html#HEADING111-0
}
break;
case NK_COMMAND_TRIANGLE: {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "NK_COMMAND_TRIANGLE");
#endif
const struct nk_command_triangle *t = (const struct nk_command_triangle*)cmd;
#ifdef COMMAND_CACHING
if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(t, lastCmd, sizeof(struct nk_command_triangle)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_triangle");
#endif
break;
}
#endif
ForeColor(t->color);
PenSize(t->line_thickness, t->line_thickness);
MoveTo(t->a.x, t->a.y);
LineTo(t->b.x, t->b.y);
LineTo(t->c.x, t->c.y);
LineTo(t->a.x, t->a.y);
}
break;
case NK_COMMAND_TRIANGLE_FILLED: {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "NK_COMMAND_TRIANGLE_FILLED");
#endif
const struct nk_command_triangle_filled *t = (const struct nk_command_triangle_filled *)cmd;
#ifdef COMMAND_CACHING
if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(t, lastCmd, sizeof(struct nk_command_triangle_filled)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_triangle_filled");
#endif
break;
}
#endif
PenSize(1.0, 1.0);
// BackPat(&colorPattern); // inside macintosh: imaging with quickdraw 3-48
ForeColor(blackColor);
PolyHandle trianglePolygon = OpenPoly();
MoveTo(t->a.x, t->a.y);
LineTo(t->b.x, t->b.y);
LineTo(t->c.x, t->c.y);
LineTo(t->a.x, t->a.y);
ClosePoly();
FillPoly(trianglePolygon, &t->color);
KillPoly(trianglePolygon);
}
break;
case NK_COMMAND_POLYGON: {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "NK_COMMAND_POLYGON");
#endif
const struct nk_command_polygon *p = (const struct nk_command_polygon*)cmd;
#ifdef COMMAND_CACHING
if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(p, lastCmd, sizeof(struct nk_command_polygon)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_polygon");
#endif
break;
}
#endif
ForeColor(p->color);
int i;
for (i = 0; i < p->point_count; i++) {
if (i == 0) {
MoveTo(p->points[i].x, p->points[i].y);
}
LineTo(p->points[i].x, p->points[i].y);
if (i == p->point_count - 1) {
LineTo(p->points[0].x, p->points[0].y);
}
}
}
break;
case NK_COMMAND_POLYGON_FILLED: {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "NK_COMMAND_POLYGON_FILLED");
#endif
const struct nk_command_polygon_filled *p = (const struct nk_command_polygon_filled*)cmd;
#ifdef COMMAND_CACHING
if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(p, lastCmd, sizeof(struct nk_command_polygon_filled)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_polygon_filled");
#endif
break;
}
#endif
// BackPat(&colorPattern); // inside macintosh: imaging with quickdraw 3-48 -- but might actually need PenPat -- look into this
ForeColor(blackColor);
int i;
PolyHandle trianglePolygon = OpenPoly();
for (i = 0; i < p->point_count; i++) {
if (i == 0) {
MoveTo(p->points[i].x, p->points[i].y);
}
LineTo(p->points[i].x, p->points[i].y);
if (i == p->point_count - 1) {
LineTo(p->points[0].x, p->points[0].y);
}
}
ClosePoly();
FillPoly(trianglePolygon, &p->color);
KillPoly(trianglePolygon);
}
break;
case NK_COMMAND_POLYLINE: {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "NK_COMMAND_POLYLINE");
#endif
// this is similar to polygons except the polygon does not get closed to the 0th point
// check out the slight difference in the for loop
const struct nk_command_polygon *p = (const struct nk_command_polygon*)cmd;
#ifdef COMMAND_CACHING
if (!lastInputWasBackspace && cmd->type == lastCmd->type && memcmp(p, lastCmd, sizeof(struct nk_command_polygon)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_polygon");
#endif
break;
}
#endif
ForeColor(p->color);
int i;
for (i = 0; i < p->point_count; i++) {
if (i == 0) {
MoveTo(p->points[i].x, p->points[i].y);
}
LineTo(p->points[i].x, p->points[i].y);
}
}
break;
case NK_COMMAND_CURVE: {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING