-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnuklear_mre.h
1981 lines (1649 loc) · 55.4 KB
/
nuklear_mre.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
/*
Nuklear MRE Implementation: nuklear_mre.h
Author: Varuna Singh, UstadMobile
*/
#include "mre_components.h"
#include "nuklear.h"
/* ==============================================================
* API
* =============================================================*/
/* If Implementation Header file is set: If declaration done
Note: This will always be called at the start.
As you can see if NK_MRE_H_ will be defined only when not
set. So these functions will be declared only once.
*/
#ifndef NK_MRE_H_
#define NK_MRE_H_
/* Define Platform specific preprocessor directive (#define) macros.
eg: #define WIN32_LEAN_AND_MEAN
This "reduces the size of the Win32 header files by excluding
some of the less frequently used APIs" -is Windows GDI
specific. Ignoring.
Here you can also define some platform specific header files relevant.
*/
/* Nuklear Header File
In new version v1.05, the nuklear.h file is included in main.c
#include "nuklear.h"
*/
/* Font */
typedef struct MreFont MreFont; //Gotta do this for it to know it exists
NK_API MreFont* nk_mrefont_create(const char *name, int size);
NK_API void nk_mre_set_font();
NK_API void nk_mrefont_del();
/* Declare the implementation:*/
NK_API struct nk_context* nk_mre_init(MreFont *font,unsigned int width, unsigned int height);
NK_API void nk_mre_handle_sys_event(VMINT message, VMINT param);
NK_API void nk_mre_handle_key_event(VMINT message, VMINT keycode);
NK_API void nk_mre_render(struct nk_color clear);
NK_API void nk_mre_shutdown(void);
/*Platform specific*/
NK_API int nk_init_mre(struct nk_context *ctx, const struct nk_user_font *font);
NK_INTERN void* mre_malloc(nk_handle unused, void *old, nk_size size); //nk_handle: A pointer, an int id; nk_size: unsigned long
NK_INTERN void mre_free(nk_handle unused, void* old); //nk_handle: A pointer, an int id
#endif
/* ==============================================================
* MRE IMPLEMENTATION
* =============================================================*/
/*TODO: Remove*/
#define NK_MRE_IMPLEMENTATION
/*if set to use MRE implementation*/
#ifdef NK_MRE_IMPLEMENTATION
/*********************
MRE HEADER FILES
*********************/
#include "vmsys.h"
/*********************
STRUCTS
*********************/
/*
Font object
MRE Doesn't really have a Font object
*/
struct MreFont{
struct nk_user_font nk;
int size;
};
struct FocusableObjects{
int id;
struct nk_rect area;
};
/* Create the mre display object */
static struct {
//some sort of window object - most similar in mre is layers?
int window;
//int memory_mre;
unsigned int width;
unsigned int height;
struct nk_context ctx;
//Focusable Object Areas:
struct nk_rect fObjs[20];
} mre;
/*
MRE-Nuklear Components
Components used to draw
TODO: Moved to mre_components. Check, Test and Delete this.
*/
struct mre_nk_c_old {
int id;
char *type;
char *title;
int len;
struct nk_style style;
int hovering;
int is_hoverable;
/* For Video: */
char *url;
char *thumbnail;
};
/* MRE View Properties
TODO: Moved to mre_components. Check, Test and Delete this.
*/
struct mre_view_p_old{
int hoverable_counter;
int hoverable_items;
struct mre_nk_c **components;
//struct mre_nk_c * components;
int components_count;
}mre_view_old;
/*********************
FUNCTIONS
*********************/
/* MRE's malloc
*/
NK_INTERN void* mre_malloc(nk_handle unused, void *old, nk_size size){
/*So basically what malloc does is set some memory aside in the, well, memory
and pass it on to the pointer back. That way we know for sure that memory is
allocated and you can store whatever data you want in it (puppy pics).
Its important to allocate the right amount of memory needed. If an object
has multiple variables, we need to calculate it and allocate it. Its really
bad to allocate a riddiculous huge amount of size that will never get filled.
Not only that but in memory sensitive devices this will unneccesarily crash.
Malloc will NOT initialise the memory with some data. Thats what calloc does.
calloc will initialise with 0s. Malloc just keeps it ready. Some cases we
would want to have some data but not here (afaik).
This method gets in:
a. nk_handle unused : Has a pointer and an int id
b. void *old: Old
c. nk_size size: The size of memory allocation in unsigned long
Steps:
i. Cast void to both unused and old
ii. Malloc size and return it.
*/
void *malloc_pointer;
/* Not sure what this does. Ignoring for now*/
//NK_UNUSED(unused);
//NK_UNUSED(old);
//TODO: Check this for MRE phones
//malloc_pointer = (void *)vm_malloc(size);
malloc_pointer = (void *)vm_malloc(size);
return malloc_pointer;
}
/* MRE's free
*/
NK_INTERN void mre_free(nk_handle unused, void *ptr){
NK_UNUSED(unused);
vm_free(ptr);
}
/*
Initialises the context - MRE way
We have to call this instead of nk_init_default (which is part of nuklear..h)
because that method uses STL and we have to make our own implementation of it
*/
NK_API int
nk_init_mre(struct nk_context *ctx, const struct nk_user_font *font) //similar to nk_init_default
{
/*
nk_allocator:
a. nk_alloc Obj: userdata
i. A pointer
ii. An id
b. alloc ()
c. free ()
Steps:
1. Set the pointer to a value
2. Set alloc method
3. Set Free Method
4. Call nk_init(ctx, font) to begin process
*/
struct nk_allocator alloc;
alloc.userdata.ptr = 0;
/* Assign implementation's alloc and malloc
alloc(nk_handle, void *old, nk_size)
free(nk_handle, void*)
Make sure they work OK
*/
alloc.alloc = mre_malloc;
alloc.free = mre_free;
//NOT ALLOWING FONT TO BE SET HERE.
//return nk_init(ctx, &alloc, font);
return nk_init(ctx, &alloc, font);
/*Origi code:
struct nk_allocator alloc;
alloc.userdata.ptr = 0;
alloc.alloc = nk_malloc; //(nk_handle, void *old, nk_size);
alloc.free = nk_mfree; //(nk_handle, void*)
return nk_init(ctx, &alloc, font);*/
}
/*
Convert nuklear's color into implementation color!
Color being used for all that drawing we gotta do
Used internally, not an implementation
Can be called anything..
*/
static VMINT
convert_color(struct nk_color c){
//..convert nk_color c to MRE color..
//returning red for now..
//return VM_RGB32_ARGB(c.a, c.r, c.g, c.b);
return VM_RGB565_ARGB(c.a, c.r, c.g, c.b);
//return VM_COLOR_RED;
}
/***********************************************
IMPL FUNCTIONS
Stroke: is line drawing
Fill: is line drawing + the area under the
outline (usually color)
***********************************************/
/*
Scissor
Something to do with scissor ?
Called by this command: NK_COMMAND_SCISSOR
*/
static void
nk_mre_scissor(void){
vm_log_debug("Scissor-ing..");
}
/*
Stroke line
Draw a line as stroke (outline)
Called by command: NK_COMMAND_LINE
*/
static void
nk_mre_stroke_line(short x0, short y0, short x1, short y1,
unsigned int line_thickness, struct nk_color col)
{
VMUINT8 *buffer;
VMUINT16 color;
VMINT LINE_X1, LINE_X2, LINE_Y1, LINE_Y2;
//Have the layer handle ready.. layer_hdl
//Maybe as global or passed here..
/*
get the target buffer from the layer
*/
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
//No need to fill a rectangle here..
//vm_graphic_fill_rect(buffer, MRE_SET_SRC_LEFT_TOP_X, MRE_SET_SRC_LEFT_TOP_Y, vm_graphic_get_screen_width(),
// vm_graphic_get_screen_height(), VM_COLOR_WHITE, VM_COLOR_GREEN);
color = VM_COLOR_RED;
color = convert_color(col);
LINE_X1 = x0;
LINE_X2 = x1;
LINE_Y1 = y0;
LINE_Y2 = y1;
//line_thickness not implemented..
vm_graphic_line(buffer, LINE_X1, LINE_Y1, LINE_X2, LINE_Y2, color);
/*
Gotta flush
Flush updates the LCD
*/
//vm_graphic_flush_layer(layer_hdl, 1);
vm_log_debug("draw line fun ends");
}
/*
Stroke Rectangle
Draw a rectangle as a stroke (outline)
Called by: NK_COMMAND_RECT
*/
static void
nk_mre_stroke_rect(short x, short y, unsigned short w,
unsigned short h, unsigned short r, unsigned short line_thickness, struct nk_color col)
{
VMUINT8 *buffer;
VMUINT16 color;
VMINT REC_X, REC_Y, REC_W, REC_L;
color = convert_color(col);
REC_X = x;
REC_Y = y;
REC_W = w;
REC_L = h;
/*Get the target buffer */
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
//vm_graphic_fill_rect(buffer, MRE_SET_SRC_LEFT_TOP_X, MRE_SET_SRC_LEFT_TOP_Y, vm_graphic_get_screen_width(),
// vm_graphic_get_screen_height(), VM_COLOR_WHITE, VM_COLOR_BLUE);
vm_graphic_rect(buffer, REC_X, REC_Y, REC_W, REC_L, color);
/*
Gotta flush:
Flush updates the LCD
*/
//vm_graphic_flush_layer(layer_hdl, 1);
}
/*
Fill Rectangle
Draws a rectangle outline and color fills it
Called by command: NK_COMMAND_RECT_FILLED
*/
static void
nk_mre_fill_rect(short x, short y, unsigned short w,
unsigned short h, unsigned short r, struct nk_color col)
{
VMUINT8 *buffer;
VMUINT16 color;
VMINT REC_X, REC_Y, REC_W, REC_L;
color = convert_color(col);
REC_X = x;
REC_Y = y;
REC_W = w;
REC_L = h;
/*Get the target buffer */
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
//vm_graphic_fill_rect(buffer, MRE_SET_SRC_LEFT_TOP_X, MRE_SET_SRC_LEFT_TOP_Y, vm_graphic_get_screen_width(),
// vm_graphic_get_screen_height(), VM_COLOR_WHITE, VM_COLOR_BLUE);
//vm_graphic_rect(buffer, REC_X, REC_Y, REC_W, REC_L, color);
vm_graphic_fill_rect(buffer, REC_X, REC_Y, REC_W, REC_L, color, color);
//Ignoring filled one first
//vm_graphic_fill_rect(buffer, REC_X, REC_Y, REC_W, REC_L, color, color);
/*
Gotta flush:
Flush updates the LCD
*/
//vm_graphic_flush_layer(layer_hdl, 1);
}
/*
Fill Triangle
Draws a triangle and fills area in between with color
Called by command: NK_COMMAND_TRIANGLE_FILLED
*/
static void
nk_mre_fill_triangle(short x0, short y0, short x1, short y1,
short x2, short y2, struct nk_color colr)
{
VMUINT8 *buffer;
VMUINT16 color;
VMINT TRN_X1, TRN_X2, TRN_X3, TRN_Y1, TRN_Y2, TRN_Y3;
vm_graphic_color col;
//vm_graphic_color col;
vm_graphic_point points[3];
color = convert_color(colr);
TRN_X1 = x0;
TRN_X2 = x1;
TRN_X3 = x2;
TRN_Y1 = y0;
TRN_Y2 = y1;
TRN_Y3 = y2;
/* function body */
vm_log_debug("draw triangle starts");
points[0].x = TRN_X1;
points[0].y = TRN_Y1;
points[1].x = TRN_X2;
points[1].y = TRN_Y2;
points[2].x = TRN_X3;
points[2].y = TRN_Y3;
col.vm_color_565 = VM_COLOR_RED;
col.vm_color_888 = VM_COLOR_565_TO_888(VM_COLOR_RED);
/* sets global color */
vm_graphic_setcolor(&col);
/* get the target buffer*/
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
//vm_graphic_fill_rect(buffer, MRE_SET_SRC_LEFT_TOP_X, MRE_SET_SRC_LEFT_TOP_Y, vm_graphic_get_screen_width(),
// vm_graphic_get_screen_height(), VM_COLOR_WHITE, VM_COLOR_GREEN);
/* Draw 3 points from points on the layer */
vm_graphic_fill_polygon(layer_hdl[0], points, 3);
/* Gotta flush */
//vm_graphic_flush_layer(layer_hdl, 1);
}
/*
Stroke Triangle
Draws the outline of the triangle
Called by command: NK_COMMAND_TRIANGLE
*/
static void
nk_mre_stroke_triangle(short x0, short y0, short x1, short y1,
short x2, short y2, unsigned short line_thickness, struct nk_color colr)
{
VMUINT8 *buffer;
VMUINT16 color;
VMINT TRN_X1, TRN_X2, TRN_X3, TRN_Y1, TRN_Y2, TRN_Y3;
vm_graphic_color col;
vm_graphic_point points[3];
color = convert_color(colr);
TRN_X1 = x0;
TRN_X2 = x1;
TRN_X3 = x2;
TRN_Y1 = y0;
TRN_Y2 = y1;
TRN_Y3 = y2;
/* function body */
vm_log_debug("draw triangle starts");
points[0].x = TRN_X1;
points[0].y = TRN_Y1;
points[1].x = TRN_X2;
points[1].y = TRN_Y2;
points[2].x = TRN_X3;
points[2].y = TRN_Y3;
col.vm_color_565 = VM_COLOR_RED;
col.vm_color_888 = VM_COLOR_565_TO_888(VM_COLOR_RED);
/* sets global color */
//vm_graphic_setcolor(&col);
/* get the target buffer*/
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
//vm_graphic_fill_rect(buffer, MRE_SET_SRC_LEFT_TOP_X, MRE_SET_SRC_LEFT_TOP_Y, vm_graphic_get_screen_width(),
// vm_graphic_get_screen_height(), VM_COLOR_WHITE, VM_COLOR_GREEN);
/* Draw 3 points from points on the layer */
vm_graphic_fill_polygon(layer_hdl[0], points, 3);
/* Gotta flush */
//vm_graphic_flush_layer(layer_hdl, 1);
}
/*
Fill Polygon
Draws polygon with count number from points and fills color in
Called by command: NK_COMMAND_POLYGON_FILLED
*/
static void
nk_mre_fill_polygon(const struct nk_vec2i *pnts, int count, struct nk_color colr)
{
VMUINT8 *buffer;
VMUINT16 color;
/*int a=42;
const int b=a;
int ipoints[b]; //Wont work because C89
*/
//int *a = new int[count]; //Not C syntax. More like c++
//vm_graphic_point points[10]; //Works because number is known at the time of compilation
//The way dynamically loading works:
//char* utf8 = malloc(utf8size);
int pointsize = count * sizeof(vm_graphic_point);
vm_graphic_point* points = vm_malloc(pointsize);
//VMINT TRN_X1, TRN_X2, TRN_X3, TRN_Y1, TRN_Y2, TRN_Y3;
vm_graphic_color col;
color = convert_color(colr);
/*TRN_X1 = x0;
TRN_X2 = x1;
TRN_X3 = x2;
TRN_Y1 = y0;
TRN_Y2 = y1;
TRN_Y3 = y2;*/
/* function body */
vm_log_debug("draw polygon starts");
/*for every point in nk_vec2i pnts .. put value in points..*/
/*points[0].x = TRN_X1;
points[0].y = TRN_Y1;
points[1].x = TRN_X2;
points[1].y = TRN_Y2;
points[2].x = TRN_X3;
points[2].y = TRN_Y3;*/
col.vm_color_565 = VM_COLOR_RED;
col.vm_color_888 = VM_COLOR_565_TO_888(VM_COLOR_RED);
/* sets global color */
vm_graphic_setcolor(&col);
/* get the target buffer*/
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
//vm_graphic_fill_rect(buffer, MRE_SET_SRC_LEFT_TOP_X, MRE_SET_SRC_LEFT_TOP_Y, vm_graphic_get_screen_width(),
// vm_graphic_get_screen_height(), VM_COLOR_WHITE, VM_COLOR_GREEN);
/* Draw 3 points from points on the layer */
vm_graphic_fill_polygon(layer_hdl[0], points, 3);
/* Gotta flush */
//vm_graphic_flush_layer(layer_hdl, 1);
}
/*
Stroke Polygon
Draws polygon of count points from points as outline
Called by command: NK_COMMAND_POLYGON
*/
static void
nk_mre_stroke_polygon(const struct nk_vec2i *pnts, int count,
unsigned short line_thickness, struct nk_color colr)
{
VMUINT8 *buffer;
VMUINT16 color;
//VMINT TRN_X1, TRN_X2, TRN_X3, TRN_Y1, TRN_Y2, TRN_Y3;
vm_graphic_color col;
vm_graphic_point points[3];
color = convert_color(colr);
/*TRN_X1 = x0;
TRN_X2 = x1;
TRN_X3 = x2;
TRN_Y1 = y0;
TRN_Y2 = y1;
TRN_Y3 = y2;*/
/* function body */
vm_log_debug("draw triangle starts");
/* for every points in vec2i pts put value in points..*/
/*points[0].x = TRN_X1;
points[0].y = TRN_Y1;
points[1].x = TRN_X2;
points[1].y = TRN_Y2;
points[2].x = TRN_X3;
points[2].y = TRN_Y3;*/
col.vm_color_565 = VM_COLOR_RED;
col.vm_color_888 = VM_COLOR_565_TO_888(VM_COLOR_RED);
/* sets global color */
//vm_graphic_setcolor(&col);
/* get the target buffer*/
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
//vm_graphic_fill_rect(buffer, MRE_SET_SRC_LEFT_TOP_X, MRE_SET_SRC_LEFT_TOP_Y, vm_graphic_get_screen_width(),
// vm_graphic_get_screen_height(), VM_COLOR_WHITE, VM_COLOR_GREEN);
/* Draw 3 points from points on the layer */
vm_graphic_fill_polygon(layer_hdl[0], points, 3);
/* Gotta flush */
//vm_graphic_flush_layer(layer_hdl, 1);
}
/*
Stroke PolyLine
Draws a polyline as outline
Called by command: NK_COMMAND_POLYLINE
*/
static void
nk_mre_stroke_polyline(const struct nk_vec2i *pnts, int count,
unsigned short line_thickness, struct nk_color col)
{
//VMUINT8 *buffer;
VMUINT16 color;
color = convert_color(col);
if (count > 0) {
int i;
//MoveToEx(dc, pnts[0].x, pnts[0].y, NULL);
for (i = 1; i < count; ++i)
{
//LineTo(dc, pnts[i].x, pnts[i].y);
//Replace this with draw line
}
}
}
/*
Fill Circle
Draws a circle and fills the area inside of it
Called by command: NK_COMMAND_CIRCLE_FILLED
*/
static void
nk_mre_fill_circle(short x, short y, unsigned short w,
unsigned short h, struct nk_color col)
{
//VMUINT8 *buffer;
VMUINT16 color;
color = convert_color(col);
}
/*
Stroke Circle
Draws a circle's outline
Called by command: NK_COMMAND_CIRCLE
*/
static void
nk_mre_stroke_circle(short x, short y, unsigned short w,
unsigned short h, unsigned short line_thickness, struct nk_color col)
{
VMUINT8 *buffer;
VMUINT16 color;
VMINT REC_X, REC_Y, REC_W, REC_L;
color = convert_color(col);
REC_X = x;
REC_Y = y;
REC_W = w;
REC_L = h;
/*Get the target buffer */
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
//vm_graphic_fill_rect(buffer, MRE_SET_SRC_LEFT_TOP_X, MRE_SET_SRC_LEFT_TOP_Y, vm_graphic_get_screen_width(),
// vm_graphic_get_screen_height(), VM_COLOR_WHITE, VM_COLOR_BLUE);
//void vm_graphic_ellipse (VMUINT8 * buf, VMINT x, VMINT y, VMINT width, VMINT height, VMUINT16 color);
/*TODO: Figure this out */
//vm_graphic_ellipse(buffer,...);
/*
Gotta flush:
Flush updates the LCD
*/
//vm_graphic_flush_layer(layer_hdl, 1);
}
/*
Stroke Curve
Draws a curve outline
Called by command: NK_COMMAND_CURVE
*/
static void
nk_mre_stroke_curve(struct nk_vec2i p1, struct nk_vec2i p2,
struct nk_vec2i p3, struct nk_vec2i p4, unsigned short line_thickness,
struct nk_color col)
{
VMUINT8 *buffer;
VMUINT16 color;
//VMINT REC_X, REC_Y, REC_W, REC_L;
color = convert_color(col);
/*Get the target buffer */
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
//vm_graphic_fill_rect(buffer, MRE_SET_SRC_LEFT_TOP_X, MRE_SET_SRC_LEFT_TOP_Y, vm_graphic_get_screen_width(),
// vm_graphic_get_screen_height(), VM_COLOR_WHITE, VM_COLOR_BLUE);
//void vm_graphic_ellipse (VMUINT8 * buf, VMINT x, VMINT y, VMINT width, VMINT height, VMUINT16 color);
/*TODO: Figure this out*/
//vm_graphic_fill_ellipse(buffer,...);
/*
Gotta flush:
Flush updates the LCD
*/
//vm_graphic_flush_layer(layer_hdl, 1);
}
/*
Draw Text
Draws text
Called by command: NK_COMMAND_TEXT
*/
static void
nk_mre_draw_text(short x, short y, unsigned short w, unsigned short h,
const char *text, int len, struct nk_color cbg, struct nk_color col)
{
VMUINT8 *buffer;
VMUINT16 color;
VMWCHAR display_string[MRE_STR_SIZE_MAX];
color = convert_color(col);
/*Get the target buffer */
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
/*
Text it out
We need to convert strings to usc2 format that
MRE only suppports
Then we draw the text on the screen
*/
/* converts string into usc2 format to display on the screen */
vm_gb2312_to_ucs2(display_string, MRE_STR_SIZE_MAX, (VMSTR)text);
/*
Draw Text
* disp_buf : [IN] display buffer pointer
* x : [IN] x offset of start position
* y : [IN] y offset of start position
* s : [IN] string pointer
* length : [IN] string length
* color : [IN] string color
*/
vm_graphic_textout(buffer, x,
y, display_string,
wstrlen(display_string), VM_COLOR_WHITE);
/*
Gotta flush:
Flush updates the LCD
*/
//vm_graphic_flush_layer(layer_hdl, 1);
}
/*
Draw Default Image
Draws defaut image. Used in testing
Called by command: NK_COMMAND_IMAGE
*/
static void
nk_mre_draw_image_default(short x, short y, short w, short h)
{
//struct nk_image img, int x, int y, const char *text
VMUINT8 *buffer;
//VMUINT16 color;
//VMWSTR filename;
//VMWCHAR display_string[MRE_STR_SIZE_MAX];
//VMINT res;
int ret;
/* File name related variables */
VMWSTR wfilename;
VMINT wfilename_size;
VMSTR filename;
VMCHAR f_name[MRE_STR_SIZE_MAX + 1]; //Old usage for video filename string
VMWCHAR f_wname[MRE_STR_SIZE_MAX + 1]; //Old usage for video filename
VMSTR file_name = "tips.gif";
/*Get the target buffer */
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
/*
Gotta flush:
Flush updates the LCD
*/
//vm_graphic_flush_layer(layer_hdl, 1);
/* Draw the PIKCHAAA */
/* Notes:
VM_GDI_HANDlE is basically VMINT
*/
//VMINT vm_graphic_draw_image_from_file(VM_GDI_HANDLE dest_layer_handle,
// VMINT x, VMINT y, const VMWSTR filename);
//Testing:
/* Getting em strings ready */
//Gotta allocate VMSTR before we do anything to it!
filename = vm_malloc(MRE_STR_SIZE_MAX);
sprintf (filename, "%c:\\%s", vm_get_removable_driver(), file_name);
//Gotta allocate VMWSTR before we do anything to it!
wfilename_size = (strlen(filename) + 1) * 2;
wfilename = vm_malloc(wfilename_size);
sprintf(f_name, "%c:\\%s", vm_get_removable_driver(), file_name);
/* String format conversion */
vm_ascii_to_ucs2 (wfilename, MRE_STR_SIZE_MAX, filename);
vm_ascii_to_ucs2(f_wname, MRE_STR_SIZE_MAX, f_name);
ret = vm_graphic_draw_image_from_file(layer_handle[0],
//80, 80, "E:\\tips.gif");
80, 80, f_wname);
//80, 80, "E:\umicon.jpg");
if (ret == VM_GDI_SUCCEED){
printf("Drew image?"); //Not sure what happens in there.
mre_show_image(MRE_GRAPHIC_IMAGE_CURRENT, f_wname, file_name, layer_hdl, x, y);
}else{
printf("Couldn't draw image..");
}
}
/*
Draw Image
Draws image set in image object
Called by command: NK_COMMAND_IMAGE
*/
static void
nk_mre_draw_image(short x, short y, short w, short h, struct nk_image img)
{
//struct nk_image img, int x, int y, const char *text
VMUINT8 *buffer;
//VMUINT16 color;
//VMWSTR filename;
//VMWCHAR display_string[MRE_STR_SIZE_MAX];
//VMINT res;
int ret;
/* File name related variables */
//VMWSTR wfilename;
//VMINT wfilename_size;
//VMSTR filename;
//VMCHAR f_name[MRE_STR_SIZE_MAX + 1]; //Old usage for video filename string
//VMWCHAR f_wname[MRE_STR_SIZE_MAX + 1]; //Old usage for video filename
VMWCHAR image_wpath[MRE_STR_SIZE_MAX +1];
//VMSTR file_name = "tips.gif";
VMSTR file_name;
/* Play with nk_image object */
/*Get the target buffer */
buffer = vm_graphic_get_layer_buffer(layer_hdl[0]);
/*
Gotta flush:
Flush updates the LCD
*/
//vm_graphic_flush_layer(layer_hdl, 1);
/* Draw the PIKCHAAA */
/* Notes:
VM_GDI_HANDlE is basically VMINT
*/
//VMINT vm_graphic_draw_image_from_file(VM_GDI_HANDLE dest_layer_handle,
// VMINT x, VMINT y, const VMWSTR filename);
//Testing:
/* Getting em strings ready */
/*
//Gotta allocate VMSTR before we do anything to it!
filename = vm_malloc(MRE_STR_SIZE_MAX);
sprintf (filename, "%c:\\%s", vm_get_removable_driver(), file_name);
//Gotta allocate VMWSTR before we do anything to it!
wfilename_size = (strlen(filename) + 1) * 2;
wfilename = vm_malloc(wfilename_size);
sprintf(f_name, "%c:\\%s", vm_get_removable_driver(), file_name);
*/
/* String format conversion */
//vm_ascii_to_ucs2 (wfilename, MRE_STR_SIZE_MAX, filename);
//vm_ascii_to_ucs2(f_wname, MRE_STR_SIZE_MAX, f_name);
vm_ascii_to_ucs2(image_wpath, MRE_STR_SIZE_MAX, img.path);
/* Get filename from the path
TODO: This
*/
file_name = "tips.gif";
ret = vm_graphic_draw_image_from_file(layer_handle[0],
//80, 80, "E:\umicon.jpg");
//80, 80, "E:\\tips.gif");
//80, 80, f_wname);
10, 10, image_wpath); //Ideally it should be x,y //Update: doesnt do anything
if (ret == VM_GDI_SUCCEED){
printf("Drew image?"); //Not sure what happens in there.
mre_show_image(MRE_GRAPHIC_IMAGE_CURRENT, image_wpath, file_name, layer_hdl, x, y);
}else{
printf("Couldn't draw image..");
}
}
/*
Clear It all
No idea what this is doing
*/
static void
nk_mre_clear(struct nk_color col)
{
VMUINT16 color;
color = convert_color(col);
}
/*
Whats a blit?
No idea what this is doing
I have a feeling this copies something from memory to memory
In this case its copying the worked on device context
to the gdi's memory device contesxt
(Probably not needed in MRE. Most similar is: flushing)
*/
static void
nk_mre_blit(void)
{
//Do nothing
}
/********************************************************
FONT STUFF
********************************************************/
/*Create the Font*/
MreFont*
nk_mrefont_create(const char *name, int size)
{
MreFont *font;
int obj_size = 1;
//MreFont *font = (MreFont*)vm_calloc(1, sizeof(MreFont));
obj_size = sizeof(MreFont);
font = (MreFont*)vm_calloc(obj_size);
if (!font){
return NULL;
}
/*Create font params*/
font->size = size;
return font;
}
/*Get Text Width*/
static float
nk_mrefont_get_text_width()
{
//Do nothing
return (float)1;
}
/*
Set Font
Sets the font required in the platform
Called at the start of the implementation
*/
NK_API void
nk_mre_set_font(void)
{
vm_log_debug("Not setting font - MRE will default it");
}
/*
Delete the font
Deletes the font set
*/
void
nk_mrefont_del()
{
//Do nothing
}
/* Get font float
Needed in nk_mre_init method for initialising nk's global font object:
nk_user_font. We need to give it some value. Since MRE's font isn't
really complete, we just give it some random float value (1) for now
*/