-
Notifications
You must be signed in to change notification settings - Fork 61
/
rawdraw_sf.h
8156 lines (6880 loc) · 250 KB
/
rawdraw_sf.h
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
//This file was automatically generated by Makefile at https://github.com/cntools/rawdraw
//Generated from files git hash 565787ec7c65e4f8289ce4b2e7fc5ba20ab3833a on Thu Oct 3 04:35:48 PM PDT 2024 (This is not the git hash of this file)
// Copyright 2010-2021 <>< CNLohr, et. al. (Several other authors, many but not all mentioned)
// Licensed under the MIT/x11 or NewBSD License you choose.
//
// CN Foundational Graphics Main Header File. This is the main header you
// should include. See README.md for more details.
#ifndef _CNFG_H
#define _CNFG_H
#ifdef __cplusplus
extern "C" {
#endif
/* Rawdraw flags:
CNFG3D -> Enable the weird 3D functionality that rawdraw has to allow you to
write apps which emit basic rawdraw primitives but look 3D!
CNFG_USE_DOUBLE_FUNCTIONS -> Use double-precision floating point for CNFG3D.
CNFGOGL -> Use an OpenGL Backend for all rawdraw functionality.
->Caveat->If using CNFG_HAS_XSHAPE, then, we do something realy wacky.
CNFGRASTERIZER -> Software-rasterize the rawdraw calls, and, use
CNFGUpdateScreenWithBitmap to send video to webpage.
CNFGCONTEXTONLY -> Don't add any drawing functions, only opening a window to
get an OpenGL context.
CNFG_IMPLEMENTATION -> #define this and it will make _this_ the file where the cnfg
functions actually live.
Usually tested combinations:
* TCC On Windows and X11 (Linux) with:
- CNFGOGL on or CNFGOGL off. If CNFGOGL is off you can use
CNFG_WINDOWS_DISABLE_BATCH to disable all batching.
-or-
- CNFGRASTERIZER
NOTE: Sometimes you can also use CNFGOGL + CNFGRASTERIZER
* WASM driver supports both: CNFGRASTERIZER and without CNFGRASTERIZER (Recommended turn rasterizer off)
* ANDROID (But this automatically sets CNFGRASTERIZER OFF and CNFGOGL ON)
Unusual compiler flags:
* CNFGHTTP - Enable the HTTP server-version of rawdraw, where it renders to a website.
* CNFGHTTPSERVERONLY - if you want to use the HTTP server w/o rawdraw. You will need to implement:
- CloseEvent, HTTPCustomCallback, HTTPCustomStart, NewWebSocket, WebSocketData, WebSocketTick
* CNFG_DISABLE_HTTP_FILES - disable the HTTP file server.
*/
#include <stdint.h>
//Some per-platform logic.
#if defined( ANDROID ) || defined( __android__ )
#define CNFGOGL
#endif
#if ( defined( CNFGOGL ) || defined( __wasm__ ) ) && !defined(CNFG_HAS_XSHAPE)
#define CNFG_BATCH 8192 //131,072 bytes.
#if defined( ANDROID ) || defined( __android__ ) || defined( __wasm__ ) || defined( EGL_LEAN_AND_MEAN )
#define CNFGEWGL //EGL or WebGL
#else
#define CNFGDESKTOPGL
#endif
#endif
typedef struct {
short x, y;
} RDPoint;
extern int CNFGPenX, CNFGPenY;
extern uint32_t CNFGBGColor;
extern uint32_t CNFGLastColor;
extern uint32_t CNFGDialogColor; //Only used for DrawBox
//Draws text at CNFGPenX, CNFGPenY, with scale of `scale`.
void CNFGDrawText( const char * text, short scale );
//Determine how large a given test would be to draw.
void CNFGGetTextExtents( const char * text, int * w, int * h, int textsize );
//Draws a box, outline as whatever the last CNFGColor was set to but also draws
//a rectangle as a background as whatever CNFGDialogColor is set to.
void CNFGDrawBox( short x1, short y1, short x2, short y2 );
//To be provided by driver. Rawdraw uses colors in the format 0xRRGGBBAA
//Note that some backends do not support alpha of any kind.
//Some platforms also support alpha blending. So, be sure to set alpha to 0xFF
uint32_t CNFGColor( uint32_t RGBA );
//This both updates the screen, and flips, all as a single operation.
void CNFGUpdateScreenWithBitmap( uint32_t * data, int w, int h );
//This is only supported on a FEW architectures, but allows arbitrary
//image blitting. Note that the alpha channel behavior is different
//on different systems.
void CNFGBlitImage( uint32_t * data, int x, int y, int w, int h );
// Only supported with CNFGOGL
#ifdef CNFGOGL
void CNFGDeleteTex( unsigned int tex );
unsigned int CNFGTexImage( uint32_t *data, int w, int h );
void CNFGBlitTex( unsigned int tex, int x, int y, int w, int h );
#endif
void CNFGTackPixel( short x1, short y1 );
void CNFGTackSegment( short x1, short y1, short x2, short y2 );
void CNFGTackRectangle( short x1, short y1, short x2, short y2 );
void CNFGTackPoly( RDPoint * points, int verts );
void CNFGClearFrame();
void CNFGSwapBuffers();
void CNFGGetDimensions( short * x, short * y );
//This will setup a window. Note that w and h have special meaning. On Windows
//and X11, for instance if you set w and h to be negative, then rawdraw will not
//show the window to the user. This is useful if you just need it for some
//off-screen-rendering purpose.
//
//Return value of 0 indicates success. Nonzero indicates error.
int CNFGSetup( const char * WindowName, int w, int h );
void CNFGSetupFullscreen( const char * WindowName, int screen_number );
int CNFGHandleInput();
//You must provide:
void HandleKey( int keycode, int bDown );
void HandleButton( int x, int y, int button, int bDown );
void HandleMotion( int x, int y, int mask );
int HandleDestroy(); // Return nonzero if you want to cancel destroy.
#ifdef ANDROID_WANT_WINDOW_TERMINATION
void HandleWindowTermination();
#endif
// Guaranteed to be for the current key inside HandleKey for drivers that support it
// If drivers don't support it, it is 0
extern int CNFGLastCharacter;
extern int CNFGLastScancode;
//Internal function for resizing rasterizer for rasterizer-mode.
void CNFGInternalResize( short x, short y ); //don't call this.
//Not available on all systems. Use The OGL portion with care.
#ifdef CNFGOGL
void CNFGSetVSync( int vson );
void * CNFGGetExtension( const char * extname );
#endif
//Also not available on all systems. Transparency.
void CNFGPrepareForTransparency();
void CNFGDrawToTransparencyMode( int transp );
void CNFGClearTransparencyLevel();
//Only available on systems that support it.
void CNFGSetLineWidth( short width );
void CNFGChangeWindowTitle( const char * windowtitle );
void CNFGSetWindowIconData( int w, int h, uint32_t * data );
int CNFGSetupWMClass( const char * WindowName, int w, int h , char * wm_res_name_ , char * wm_res_class_ );
// Mouse related functions on systems that support it.
// enum just in case we want more cursor shapes
typedef enum {
CNFG_CURSOR_HIDDEN, CNFG_CURSOR_ARROW, CNFG_CURSOR_LAST
} CNFGCursorShape;
// This may put a motion event into the queue, which will call HandleMotion
void CNFGSetMousePosition( int x, int y );
void CNFGConfineMouse( int confined );
void CNFGSetCursor( CNFGCursorShape shape );
//If you're using a batching renderer, for instance on Android or an OpenGL
//You will need to call this function inbetewen swtiching properties of drawing. This is usually
//only needed if you calling OpenGL / OGLES functions directly and outside of CNFG.
//
//Note that these are the functions that are used on the backends which support this
//sort of thing.
#ifdef CNFG_BATCH
//If you are not using the CNFGOGL driver, you will need to define these in your driver.
void CNFGEmitBackendTriangles( const float * vertices, const uint32_t * colors, int num_vertices );
void CNFGBlitImage( uint32_t * data, int x, int y, int w, int h );
//These need to be defined for the specific driver.
void CNFGClearFrame();
void CNFGSwapBuffers();
void CNFGFlushRender(); //Emit any geometry (lines, squares, polys) which are slated to be rendered.
void CNFGInternalResize( short x, short y ); //Driver calls this after resize happens.
void CNFGSetupBatchInternal(); //Driver calls this after setup is complete.
//Useful function for emitting a non-axis-aligned quad.
void CNFGEmitQuad( float cx0, float cy0, float cx1, float cy1, float cx2, float cy2, float cx3, float cy3 );
extern int CNFGVertPlace;
extern float CNFGVertDataV[CNFG_BATCH*3];
extern uint32_t CNFGVertDataC[CNFG_BATCH];
#endif
#define CNFG_KEY_FOCUS 0xf000
#if defined(WINDOWS) || defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN64)
#define CNFG_KEY_BACKSPACE 0x08
#define CNFG_KEY_TAB 0x09
#define CNFG_KEY_CLEAR 0x0C
#define CNFG_KEY_ENTER 0x0D
#define CNFG_KEY_SHIFT 0x10
#define CNFG_KEY_CTRL 0x11
#define CNFG_KEY_ALT 0x12
#define CNFG_KEY_PAUSE 0x13
#define CNFG_KEY_CAPS_LOCK 0x14
#define CNFG_KEY_ESCAPE 0x1B
#define CNFG_KEY_SPACE 0x20
#define CNFG_KEY_PAGE_UP 0x21
#define CNFG_KEY_PAGE_DOWN 0x22
#define CNFG_KEY_END 0x23
#define CNFG_KEY_HOME 0x24
#define CNFG_KEY_LEFT_ARROW 0x25
#define CNFG_KEY_TOP_ARROW 0x26
#define CNFG_KEY_RIGHT_ARROW 0x27
#define CNFG_KEY_BOTTOM_ARROW 0x28
#define CNFG_KEY_SELECT 0x29
#define CNFG_KEY_PRINT 0x2A
#define CNFG_KEY_EXECUTE 0x2B
#define CNFG_KEY_PRINT_SCREEN 0x2C
#define CNFG_KEY_INSERT 0x2D
#define CNFG_KEY_DELETE 0x2E
#define CNFG_KEY_HELP 0x2F
#define CNFG_KEY_LEFT_SUPER 0x5B
#define CNFG_KEY_RIGHT_SUPER 0x5C
#define CNFG_KEY_NUM_0 0x60
#define CNFG_KEY_NUM_1 0x61
#define CNFG_KEY_NUM_2 0x62
#define CNFG_KEY_NUM_3 0x63
#define CNFG_KEY_NUM_4 0x64
#define CNFG_KEY_NUM_5 0x65
#define CNFG_KEY_NUM_6 0x66
#define CNFG_KEY_NUM_7 0x67
#define CNFG_KEY_NUM_8 0x68
#define CNFG_KEY_NUM_9 0x69
#define CNFG_KEY_NUM_MULTIPLY 0x6A
#define CNFG_KEY_NUM_ADD 0x6B
#define CNFG_KEY_NUM_SEPARATOR 0x6C
#define CNFG_KEY_NUM_SUBTRACT 0x6D
#define CNFG_KEY_NUM_DECIMAL 0x6E
#define CNFG_KEY_NUM_DIVIDE 0x6F
#define CNFG_KEY_F1 0x70
#define CNFG_KEY_F2 0x71
#define CNFG_KEY_F3 0x72
#define CNFG_KEY_F4 0x73
#define CNFG_KEY_F5 0x74
#define CNFG_KEY_F6 0x75
#define CNFG_KEY_F7 0x76
#define CNFG_KEY_F8 0x77
#define CNFG_KEY_F9 0x78
#define CNFG_KEY_F10 0x79
#define CNFG_KEY_F11 0x7A
#define CNFG_KEY_F12 0x7B
#define CNFG_KEY_F13 0x7C
#define CNFG_KEY_F14 0x7D
#define CNFG_KEY_F15 0x7E
#define CNFG_KEY_F16 0x7F
#define CNFG_KEY_F17 0x80
#define CNFG_KEY_F18 0x81
#define CNFG_KEY_F19 0x82
#define CNFG_KEY_F20 0x83
#define CNFG_KEY_F21 0x84
#define CNFG_KEY_F22 0x85
#define CNFG_KEY_F23 0x86
#define CNFG_KEY_F24 0x87
#define CNFG_KEY_NUM_LOCK 0x90
#define CNFG_KEY_SCROLL_LOCK 0x91
#define CNFG_KEY_LEFT_SHIFT 0xA0
#define CNFG_KEY_RIGHT_SHIFT 0xA1
#define CNFG_KEY_LEFT_CONTROL 0xA2
#define CNFG_KEY_RIGHT_CONTROL 0xA3
#define CNFG_KEY_LEFT_ALT 0xA4
#define CNFG_KEY_RIGHT_ALT 0xA5
#elif defined( EGL_LEAN_AND_MEAN ) // doesn't have any keys
#elif defined( __android__ ) || defined( ANDROID ) // ^
#elif defined( __wasm__ )
#define CNFG_KEY_BACKSPACE 8
#define CNFG_KEY_TAB 9
#define CNFG_KEY_CLEAR 12
#define CNFG_KEY_ENTER 13
#define CNFG_KEY_SHIFT 16
#define CNFG_KEY_CTRL 17
#define CNFG_KEY_ALT 18
#define CNFG_KEY_PAUSE 19
#define CNFG_KEY_CAPS_LOCK 20
#define CNFG_KEY_ESCAPE 27
#define CNFG_KEY_SPACE 32
#define CNFG_KEY_PAGE_UP 33
#define CNFG_KEY_PAGE_DOWN 34
#define CNFG_KEY_END 35
#define CNFG_KEY_HOME 36
#define CNFG_KEY_LEFT_ARROW 37
#define CNFG_KEY_TOP_ARROW 38
#define CNFG_KEY_RIGHT_ARROW 39
#define CNFG_KEY_BOTTOM_ARROW 40
#define CNFG_KEY_SELECT 41
#define CNFG_KEY_PRINT 42
#define CNFG_KEY_EXECUTE 43
#define CNFG_KEY_PRINT_SCREEN 44
#define CNFG_KEY_INSERT 45
#define CNFG_KEY_DELETE 46
#define CNFG_KEY_HELP 47
#define CNFG_KEY_LEFT_SUPER 91
#define CNFG_KEY_RIGHT_SUPER 92
#define CNFG_KEY_NUM_0 96
#define CNFG_KEY_NUM_1 97
#define CNFG_KEY_NUM_2 98
#define CNFG_KEY_NUM_3 99
#define CNFG_KEY_NUM_4 100
#define CNFG_KEY_NUM_5 101
#define CNFG_KEY_NUM_6 102
#define CNFG_KEY_NUM_7 103
#define CNFG_KEY_NUM_8 104
#define CNFG_KEY_NUM_9 105
#define CNFG_KEY_NUM_MULTIPLY 106
#define CNFG_KEY_NUM_ADD 107
#define CNFG_KEY_NUM_SEPARATOR 108
#define CNFG_KEY_NUM_SUBTRACT 109
#define CNFG_KEY_NUM_DECIMAL 110
#define CNFG_KEY_NUM_DIVIDE 111
#define CNFG_KEY_F1 112
#define CNFG_KEY_F2 113
#define CNFG_KEY_F3 114
#define CNFG_KEY_F4 115
#define CNFG_KEY_F5 116
#define CNFG_KEY_F6 117
#define CNFG_KEY_F7 118
#define CNFG_KEY_F8 119
#define CNFG_KEY_F9 120
#define CNFG_KEY_F10 121
#define CNFG_KEY_F11 122
#define CNFG_KEY_F12 123
#define CNFG_KEY_F13 124
#define CNFG_KEY_F14 125
#define CNFG_KEY_F15 126
#define CNFG_KEY_F16 127
#define CNFG_KEY_F17 128
#define CNFG_KEY_F18 129
#define CNFG_KEY_F19 130
#define CNFG_KEY_F20 131
#define CNFG_KEY_F21 132
#define CNFG_KEY_F22 133
#define CNFG_KEY_F23 134
#define CNFG_KEY_F24 135
#define CNFG_KEY_NUM_LOCK 144
#define CNFG_KEY_SCROLL_LOCK 145
#define CNFG_KEY_LEFT_SHIFT 160
#define CNFG_KEY_RIGHT_SHIFT 161
#define CNFG_KEY_LEFT_CONTROL 162
#define CNFG_KEY_RIGHT_CONTROL 163
#define CNFG_KEY_LEFT_ALT 164
#define CNFG_KEY_RIGHT_ALT 165
#else // most likely x11
#define CNFG_KEY_BACKSPACE 65288
#define CNFG_KEY_TAB 65289
#define CNFG_KEY_CLEAR 65291
#define CNFG_KEY_ENTER 65293
#define CNFG_KEY_SHIFT 65505
#define CNFG_KEY_CTRL 65507
#define CNFG_KEY_ALT 65513
#define CNFG_KEY_PAUSE 65299
#define CNFG_KEY_CAPS_LOCK 65509
#define CNFG_KEY_ESCAPE 65505
#define CNFG_KEY_SPACE 32
#define CNFG_KEY_PAGE_UP 65365
#define CNFG_KEY_PAGE_DOWN 65366
#define CNFG_KEY_END 65367
#define CNFG_KEY_HOME 65360
#define CNFG_KEY_LEFT_ARROW 65361
#define CNFG_KEY_TOP_ARROW 65362
#define CNFG_KEY_RIGHT_ARROW 65363
#define CNFG_KEY_BOTTOM_ARROW 65364
#define CNFG_KEY_SELECT 65376
#define CNFG_KEY_PRINT 65377
#define CNFG_KEY_EXECUTE 65378
#define CNFG_KEY_PRINT_SCREEN 64797
#define CNFG_KEY_INSERT 65379
#define CNFG_KEY_DELETE 65535
#define CNFG_KEY_HELP 65386
#define CNFG_KEY_LEFT_SUPER 65515
#define CNFG_KEY_RIGHT_SUPER 65516
#define CNFG_KEY_NUM_0 65456
#define CNFG_KEY_NUM_1 65457
#define CNFG_KEY_NUM_2 65458
#define CNFG_KEY_NUM_3 65459
#define CNFG_KEY_NUM_4 65460
#define CNFG_KEY_NUM_5 65461
#define CNFG_KEY_NUM_6 65462
#define CNFG_KEY_NUM_7 65463
#define CNFG_KEY_NUM_8 65464
#define CNFG_KEY_NUM_9 65465
#define CNFG_KEY_NUM_MULTIPLY 65450
#define CNFG_KEY_NUM_ADD 65451
#define CNFG_KEY_NUM_SEPARATOR 65452
#define CNFG_KEY_NUM_SUBTRACT 65453
#define CNFG_KEY_NUM_DECIMAL 65454
#define CNFG_KEY_NUM_DIVIDE 65455
#define CNFG_KEY_F1 65470
#define CNFG_KEY_F2 65471
#define CNFG_KEY_F3 65472
#define CNFG_KEY_F4 65473
#define CNFG_KEY_F5 65474
#define CNFG_KEY_F6 65475
#define CNFG_KEY_F7 65476
#define CNFG_KEY_F8 65477
#define CNFG_KEY_F9 65478
#define CNFG_KEY_F10 65479
#define CNFG_KEY_F11 65480
#define CNFG_KEY_F12 65481
#define CNFG_KEY_F13 65482
#define CNFG_KEY_F14 65483
#define CNFG_KEY_F15 65484
#define CNFG_KEY_F16 65485
#define CNFG_KEY_F17 65486
#define CNFG_KEY_F18 65487
#define CNFG_KEY_F19 65488
#define CNFG_KEY_F20 65489
#define CNFG_KEY_F21 65490
#define CNFG_KEY_F22 65491
#define CNFG_KEY_F23 65492
#define CNFG_KEY_F24 65493
#define CNFG_KEY_NUM_LOCK 65407
#define CNFG_KEY_SCROLL_LOCK 65300
#define CNFG_KEY_LEFT_SHIFT 65505
#define CNFG_KEY_RIGHT_SHIFT 65506
#define CNFG_KEY_LEFT_CONTROL 65507
#define CNFG_KEY_RIGHT_CONTROL 65508
#define CNFG_KEY_LEFT_ALT 65513
#define CNFG_KEY_RIGHT_ALT 65514
#define CNFG_X11_EXPOSE 0xff00 //65280
#endif
#ifdef CNFG3D
#ifndef __wasm__
#include <math.h>
#endif
#ifdef CNFG_USE_DOUBLE_FUNCTIONS
#define tdCOS cos
#define tdSIN sin
#define tdTAN tan
#define tdSQRT sqrt
#else
#define tdCOS cosf
#define tdSIN sinf
#define tdTAN tanf
#define tdSQRT sqrtf
#endif
#ifdef __wasm__
void tdMATCOPY( float * x, const float * y ); //Copy y into x
#else
#define tdMATCOPY(x,y) memcpy( x, y, 16*sizeof(float))
#endif
#define tdQ_PI 3.141592653589
#define tdDEGRAD (tdQ_PI/180.)
#define tdRADDEG (180./tdQ_PI)
//General Matrix Functions
void tdIdentity( float * f );
void tdZero( float * f );
void tdTranslate( float * f, float x, float y, float z ); //Operates ON f
void tdScale( float * f, float x, float y, float z ); //Operates ON f
void tdRotateAA( float * f, float angle, float x, float y, float z ); //Operates ON f
void tdRotateQuat( float * f, float qw, float qx, float qy, float qz ); //Operates ON f
void tdRotateEA( float * f, float x, float y, float z ); //Operates ON f
void tdMultiply( float * fin1, float * fin2, float * fout ); //Operates ON f
void tdPrint( const float * f );
void tdTransposeSelf( float * f );
//Specialty Matrix Functions
void tdPerspective( float fovy, float aspect, float zNear, float zFar, float * out ); //Sets, NOT OPERATES. (FOVX=degrees)
void tdLookAt( float * m, float * eye, float * at, float * up ); //Operates ON m
//General point functions
#define tdPSet( f, x, y, z ) { f[0] = x; f[1] = y; f[2] = z; }
void tdPTransform( const float * pin, float * f, float * pout );
void tdVTransform( const float * vin, float * f, float * vout );
void td4Transform( float * kin, float * f, float * kout );
void td4RTransform( float * kin, float * f, float * kout );
void tdNormalizeSelf( float * vin );
void tdCross( float * va, float * vb, float * vout );
float tdDistance( float * va, float * vb );
float tdDot( float * va, float * vb );
#define tdPSub( x, y, z ) { (z)[0] = (x)[0] - (y)[0]; (z)[1] = (x)[1] - (y)[1]; (z)[2] = (x)[2] - (y)[2]; }
#define tdPAdd( x, y, z ) { (z)[0] = (x)[0] + (y)[0]; (z)[1] = (x)[1] + (y)[1]; (z)[2] = (x)[2] + (y)[2]; }
//Stack Functionality
#define tdMATRIXMAXDEPTH 32
extern float * gSMatrix;
void tdPush();
void tdPop();
void tdMode( int mode );
#define tdMODELVIEW 0
#define tdPROJECTION 1
//Final stage tools
void tdSetViewport( float leftx, float topy, float rightx, float bottomy, float pixx, float pixy );
void tdFinalPoint( float * pin, float * pout );
float tdNoiseAt( int x, int y );
float tdFLerp( float a, float b, float t );
float tdPerlin2D( float x, float y );
#endif
extern const unsigned char RawdrawFontCharData[1405];
extern const unsigned short RawdrawFontCharMap[256];
#ifdef __cplusplus
};
#endif
#if defined( ANDROID ) || defined( __android__ )
#ifndef _CNFG_ANDROID_H
#define _CNFG_ANDROID_H
//This file contains the additional functions that are available on the Android platform.
//In order to build rawdraw for Android, please compile CNFGEGLDriver.c with -DANDROID
// Tricky: Android headers are confused by c++ if linking statically.
#ifdef __cplusplus
extern "C" {
int __system_property_get(const char* __name, char* __value);
};
#endif
extern struct android_app * gapp;
void AndroidMakeFullscreen();
const char* AndroidGetExternalFilesDir();
int AndroidHasPermissions(const char* perm_name);
void AndroidRequestAppPermissions(const char * perm);
void AndroidDisplayKeyboard(int pShow);
int AndroidGetUnicodeChar( int keyCode, int metaState );
void AndroidSendToBack( int param );
extern int android_sdk_version; //Derived at start from property ro.build.version.sdk
extern int android_width, android_height;
extern int UpdateScreenWithBitmapOffsetX;
extern int UpdateScreenWithBitmapOffsetY;
extern void (*HandleCustomEventCallback)();
extern void (*HandleWindowTermination)();
// If you need them, these are the names of raw EGL symbols.
//extern EGLDisplay egl_display;
//extern EGLSurface egl_surface;
//extern EGLContext egl_context;
//extern EGLConfig egl_config;
//You must implement these.
void HandleResume();
void HandleSuspend();
//Departures:
// HandleMotion's "mask" parameter is actually just an index, not a mask
// CNFGSetup / CNFGSetupFullScreen only controls whether or not the navigation
// decoration is removed. Fullscreen means *full screen* To choose fullscreen
// or not fullscrene, modify, in your AndroidManifest.xml file, the application
// section to either contain or not contain:
// android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
// For debugging:
#if defined( ANDROID ) && !defined( __cplusplus )
#include <jni.h>
static inline void PrintClassOfObject( jobject bundle )
{
const struct JNINativeInterface * env = 0;
const struct JNINativeInterface ** envptr = &env;
const struct JNIInvokeInterface ** jniiptr = gapp->activity->vm;
const struct JNIInvokeInterface * jnii = *jniiptr;
jnii->AttachCurrentThread( jniiptr, &envptr, NULL);
env = (*envptr);
jclass myclass = env->GetObjectClass( envptr, bundle );
jmethodID mid = env->GetMethodID( envptr, myclass, "getClass", "()Ljava/lang/Class;");
jobject clsObj = env->CallObjectMethod( envptr, bundle, mid );
jclass clazzz = env->GetObjectClass( envptr, clsObj );
mid = env->GetMethodID(envptr, clazzz, "getName", "()Ljava/lang/String;");
jstring strObj = (jstring)env->CallObjectMethod( envptr, clsObj, mid);
const char * name = env->GetStringUTFChars( envptr, strObj, 0);
printf( "Class type: %s\n", name );
env->DeleteLocalRef( envptr, myclass );
env->DeleteLocalRef( envptr, clsObj );
env->DeleteLocalRef( envptr, clazzz );
env->ReleaseStringUTFChars(envptr, strObj, name);
env->DeleteLocalRef( envptr, strObj );
}
static inline void PrintObjectString( jobject bundle )
{
const struct JNINativeInterface * env = 0;
const struct JNINativeInterface ** envptr = &env;
const struct JNIInvokeInterface ** jniiptr = gapp->activity->vm;
const struct JNIInvokeInterface * jnii = *jniiptr;
jnii->AttachCurrentThread( jniiptr, &envptr, NULL);
env = (*envptr);
jclass myclass = env->GetObjectClass( envptr, bundle );
jmethodID toStringMethod = env->GetMethodID( envptr, myclass, "toString", "()Ljava/lang/String;");
jstring strObjDescr = (jstring)env->CallObjectMethod( envptr, bundle, toStringMethod);
const char *descr = env->GetStringUTFChars( envptr, strObjDescr, 0);
printf( "String: %s\n", descr );
env->DeleteLocalRef( envptr, myclass );
env->ReleaseStringUTFChars( envptr, strObjDescr, descr );
env->DeleteLocalRef( envptr, strObjDescr );
}
static inline void DumpObjectClassProperties( jobject objToDump )
{
const struct JNINativeInterface * env = 0;
const struct JNINativeInterface ** envptr = &env;
const struct JNIInvokeInterface ** jniiptr = gapp->activity->vm;
const struct JNIInvokeInterface * jnii = *jniiptr;
jnii->AttachCurrentThread( jniiptr, &envptr, NULL);
env = (*envptr);
jclass mpclass = env->GetObjectClass( envptr, objToDump );
jmethodID midGetClass = env->GetMethodID( envptr, mpclass, "getClass", "()Ljava/lang/Class;");
jclass ClassClass = env->FindClass(envptr, "java/lang/Class");
jobject clsObj = env->CallObjectMethod( envptr, objToDump, midGetClass);
jmethodID gnid = env->GetMethodID(envptr, ClassClass, "getName", "()Ljava/lang/String;");
jstring nameObj = (jstring)env->CallObjectMethod( envptr, clsObj, gnid);
const char *name = env->GetStringUTFChars( envptr, nameObj, 0);
printf( "Class Name: %s\n", name );
env->ReleaseStringUTFChars(envptr, nameObj, name);
env->DeleteLocalRef( envptr, nameObj );
jmethodID getMethodsMethod = env->GetMethodID( envptr, ClassClass, "getMethods","()[Ljava/lang/reflect/Method;");
jobject jobjArray = env->CallObjectMethod( envptr, clsObj, getMethodsMethod );
jclass MethodType = env->FindClass(envptr, "java/lang/reflect/Method");
jclass TypeType = env->FindClass(envptr, "java/lang/reflect/Type");
jmethodID tnamemid = env->GetMethodID( envptr, TypeType, "getTypeName", "()Ljava/lang/String;" );
jmethodID getFieldsMethod = env->GetMethodID( envptr, ClassClass, "getFields","()[Ljava/lang/reflect/Field;");
jobject jobjArrayFields = env->CallObjectMethod( envptr, clsObj, getFieldsMethod );
jsize len = env->GetArrayLength(envptr, jobjArray);
jsize i;
printf( "Methods:\n" );
for (i = 0 ; i < len ; i++) {
jobject _strMethod = env->GetObjectArrayElement( envptr, jobjArray, i ) ;
jclass _methodClazz = env->GetObjectClass(envptr, _strMethod) ;
jmethodID mid = env->GetMethodID(envptr, _methodClazz , "getName", "()Ljava/lang/String;" );
jmethodID getGenericParameterTypes = env->GetMethodID( envptr, _methodClazz, "getGenericParameterTypes","()[Ljava/lang/reflect/Type;");
jmethodID getReturnTypeMethod = env->GetMethodID( envptr, _methodClazz, "getGenericReturnType","()Ljava/lang/reflect/Type;");
jstring _name = (jstring)env->CallObjectMethod( envptr, _strMethod , mid ) ;
const char *str = env->GetStringUTFChars(envptr, _name, 0);
printf(" %s( ", str);
jobject types = env->CallObjectMethod( envptr, _strMethod, getGenericParameterTypes );
jsize mlen = env->GetArrayLength(envptr, types);
jsize mi;
for( mi = 0; mi < mlen; mi++ )
{
jobject typeo = env->GetObjectArrayElement( envptr, types, mi );
jstring _tn = (jstring)env->CallObjectMethod( envptr, typeo, tnamemid );
const char * str = env->GetStringUTFChars(envptr, _tn, 0);
printf("%s%s ", str, (mi == mlen-1)?"":"," );
env->ReleaseStringUTFChars(envptr, _tn, str);
env->DeleteLocalRef( envptr, _tn );
env->DeleteLocalRef( envptr, typeo );
}
jobject rtype = env->CallObjectMethod( envptr, _strMethod, getReturnTypeMethod );
jstring _tn = (jstring)env->CallObjectMethod( envptr, rtype, tnamemid );
const char * strret = env->GetStringUTFChars(envptr, _tn, 0);
printf(") -> %s\n", strret);
env->ReleaseStringUTFChars(envptr, _tn, strret);
env->DeleteLocalRef( envptr, _tn );
env->DeleteLocalRef( envptr, rtype );
env->DeleteLocalRef( envptr, types );
env->ReleaseStringUTFChars(envptr, _name, str);
env->DeleteLocalRef( envptr, _methodClazz );
env->DeleteLocalRef( envptr, _strMethod );
env->DeleteLocalRef( envptr, _name );
}
len = env->GetArrayLength(envptr, jobjArrayFields);
printf( "Fields:\n" );
for ( i = 0; i < len; i++) {
jobject _strField = env->GetObjectArrayElement( envptr, jobjArrayFields, i) ;
jclass _methodClazz = env->GetObjectClass(envptr, _strField );
jmethodID mid = env->GetMethodID(envptr, _methodClazz , "getName", "()Ljava/lang/String;") ;
jstring _name = (jstring)env->CallObjectMethod( envptr, _strField , mid ) ;
const char *str = env->GetStringUTFChars(envptr, _name, 0);
jmethodID getTypeMethod = env->GetMethodID( envptr, _methodClazz, "getGenericType","()Ljava/lang/reflect/Type;");
jobject rtype = env->CallObjectMethod( envptr, _strField, getTypeMethod );
jstring _tn = (jstring)env->CallObjectMethod( envptr, rtype, tnamemid );
const char * strret = env->GetStringUTFChars(envptr, _tn, 0);
printf(" %s -> %s\n", str, strret );
env->ReleaseStringUTFChars(envptr, _name, str);
env->ReleaseStringUTFChars(envptr, _tn, strret);
env->DeleteLocalRef( envptr, _methodClazz );
env->DeleteLocalRef( envptr, _strField );
env->DeleteLocalRef( envptr, _name );
env->DeleteLocalRef( envptr, _tn );
}
env->DeleteLocalRef( envptr, TypeType );
env->DeleteLocalRef( envptr, MethodType );
env->DeleteLocalRef( envptr, clsObj );
env->DeleteLocalRef( envptr, ClassClass );
env->DeleteLocalRef( envptr, jobjArrayFields );
env->DeleteLocalRef( envptr, jobjArray );
env->DeleteLocalRef( envptr, mpclass );
}
#endif
#endif
#endif
#ifdef CNFG_IMPLEMENTATION
//Include this file to get all of rawdraw. You usually will not
//want to include this in your build, but instead, #include "CNFG.h"
//after #define CNFG_IMPLEMENTATION in one of your C files.
// Defined here for universal definition
int CNFGLastCharacter = 0;
int CNFGLastScancode = 0;
#if defined( CNFGHTTP )
//Copyright 2015-2021 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or
// ColorChord License. You Choose. This file mostly based on `cnhttp` from cntools.
#ifdef CNFGHTTP
//Pull from a buffer
#ifndef CNFGHTTP_LIVE_FS
#define USE_RAM_MFS
#endif
//single_file_http.c base from https://github.com/cntools/httptest.
//scroll to bottom for implementation.
#ifndef CUSTOM_HTTPHEADER_CODE
#define CUSTOM_HTTPHEADER_CODE PushString("Access-Control-Allow-Origin: *\r\n");
#endif
/* public api for steve reid's public domain SHA-1 implementation */
/* this file is in the public domain */
#include <stdint.h>
typedef struct {
uint32_t state[5];
uint32_t count[2];
uint8_t buffer[64];
} RD_SHA1_CTX;
#define RD_SHA1_DIGEST_SIZE 20
void static RD_SHA1_Init(RD_SHA1_CTX* context);
void static RD_SHA1_Update(RD_SHA1_CTX* context, const uint8_t* data, const unsigned long len);
void static RD_SHA1_Final(uint8_t digest[RD_SHA1_DIGEST_SIZE],RD_SHA1_CTX* context); //WARNINGThe parameters are flipped here. (CNL)
//Not to be confused with MFS for the AVR.
#ifndef _MFS_H
#define _MFS_H
#ifndef USE_RAM_MFS
#include <stdio.h>
#endif
#define MFS_SECTOR 256
#define MFS_FILENAMELEN 32-8
#define MFS_FILE_COMPRESSED_MEMORY (-2)
//Format:
// [FILE NAME (24)] [Start (4)] [Len (4)]
// NOTE: Filename must be null-terminated within the 24.
struct MFSFileEntry
{
char name[MFS_FILENAMELEN];
uint32_t start; //From beginning of mfs thing.
uint32_t len;
};
struct MFSFileInfo
{
uint32_t filelen;
#ifdef USE_RAM_MFS
uint32_t offset;
#else
FILE * file;
#endif
};
//Returns 0 on succses.
//Returns size of file if non-empty
//If positive, populates mfi.
//Returns -1 if can't find file or reached end of file list.
int8_t MFSOpenFile( const char * fname, struct MFSFileInfo * mfi );
int32_t MFSReadSector( uint8_t* data, struct MFSFileInfo * mfi ); //returns # of bytes left in file.
void MFSClose( struct MFSFileInfo * mfi );
#endif
#ifndef _CNHTTP_H
#define _CNHTTP_H
#include <stdint.h>
extern struct HTTPConnection * curhttp;
extern uint8_t * curdata;
extern uint16_t curlen;
extern uint8_t wsmask[4];
extern uint8_t wsmaskplace;
uint8_t WSPOPMASK();
#define HTTPPOP (*curdata++)
//You must provide this.
void HTTPCustomStart( );
void HTTPCustomCallback( ); //called when we can send more data
void WebSocketData( int len );
void WebSocketTick( );
void WebSocketNew();
void HTTPHandleInternalCallback( );
uint8_t hex2byte( const char * c );
void NewWebSocket();
void et_espconn_disconnect( int socket );
//Internal Functions
void HTTPTick( uint8_t timedtick );
int URLDecode( char * decodeinto, int maxlen, const char * buf );
void WebSocketGotData( uint8_t c );
void WebSocketTickInternal();
void WebSocketSend( uint8_t * data, int size );
//Host-level functions
void my_base64_encode(const unsigned char *data, unsigned int input_length, uint8_t * encoded_data );
void Uint32To10Str( char * out, uint32_t dat );
void http_recvcb(int conn, char *pusrdata, unsigned short length);
void http_disconnetcb(int conn);
int httpserver_connectcb( int socket ); // return which HTTP it is. -1 for failure
void DataStartPacket();
extern uint8_t * databuff_ptr;
void PushString( const char * data );
void PushByte( uint8_t c );
void PushBlob( const uint8_t * datam, int len );
int TCPCanSend( int socket, int size );
int TCPDoneSend( int socket );
int EndTCPWrite( int socket );
#define HTTP_CONNECTIONS 50
#ifndef MAX_HTTP_PATHLEN
#define MAX_HTTP_PATHLEN 80
#endif
#define HTTP_SERVER_TIMEOUT 500
#define HTTP_STATE_NONE 0
#define HTTP_STATE_WAIT_METHOD 1
#define HTTP_STATE_WAIT_PATH 2
#define HTTP_STATE_WAIT_PROTO 3
#define HTTP_STATE_WAIT_FLAG 4
#define HTTP_STATE_WAIT_INFLAG 5
#define HTTP_STATE_DATA_XFER 7
#define HTTP_STATE_DATA_WEBSOCKET 8
#define HTTP_WAIT_CLOSE 15
struct HTTPConnection
{
uint8_t state:4;
uint8_t state_deets;
//Provides path, i.e. "/index.html" but, for websockets, the last
//32 bytes of the buffer are used for the websockets key.
uint8_t pathbuffer[MAX_HTTP_PATHLEN];
uint8_t is_dynamic:1;
uint16_t timeout;
union data_t
{
struct MFSFileInfo filedescriptor;
struct UserData { uint16_t a, b, c; } user;
struct UserDataPtr { void * v; } userptr;
} data;
void * rcb;
void * rcbDat; //For websockets primarily.
void * ccb; //Close callback (used for websockets, primarily)
uint32_t bytesleft;
uint32_t bytessofar;
uint8_t is404:1;
uint8_t isdone:1;
uint8_t isfirst:1;
uint8_t keep_alive:1;
uint8_t need_resend:1;
uint8_t send_pending:1; //If we can send data, we should?
uint8_t is_gzip:1;
int socket;
uint8_t corked_data[4096];
int corked_data_place;
};
extern struct HTTPConnection HTTPConnections[HTTP_CONNECTIONS];
#endif
#ifndef _HTTP_BSD_H
#define _HTTP_BSD_H
//Call this to start your webserver.
int RunHTTP( int port );
int TickHTTP(); //returns -1 if problem.
//For running on a BSD Sockets System
int htsend( int socket, uint8_t * data, int datact );
void et_espconn_disconnect( int socket );
void http_recvcb(int whichhttp, char *pusrdata, unsigned short length);
void http_disconnetcb(int whichhttp);
int httpserver_connectcb( int socket ); // return which HTTP it is. -1 for failure
void DataStartPacket();
extern uint8_t * databuff_ptr;
void PushBlob( const uint8_t * data, int len );
void PushByte( uint8_t c );
void PushString( const char * data );
int TCPCanSend( int socket, int size );
int TCPDoneSend( int socket );
int EndTCPWrite( int socket );
void TermHTTPServer();
extern int cork_binary_rx;
#endif
//Copyright 2012-2016 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or ColorChord License. You Choose.
#include <string.h>
#include <stdio.h>
struct HTTPConnection HTTPConnections[HTTP_CONNECTIONS];
#define HTDEBUG( x, ... ) printf( x, ##__VA_ARGS__ )
//#define HTDEBUG( x... )