-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.c
2018 lines (1894 loc) · 65.3 KB
/
ui.c
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
#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <netdb.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
#include <time.h>
#include <ctype.h>
#include "gfxlib.h"
#include "videoformats.h"
#include "ui.h"
#include "audio.h"
#include "config.h"
#include "kbjs.h"
#include "mainmenu.h"
#include "region.h"
#include "GFXDATA/gfxdata.h"
/* sounds disabled because it sucked
static AudioSampleInfo asiKbClick;
extern const signed char soundraw_data[];
extern const unsigned int soundraw_size;
*/
static VGImage bgImage = 0;
static VGImage tvImage = 0;
static VGImage upArrowImage = 0;
static VGImage downArrowImage = 0;
struct result_rec * first_rec = NULL;
struct result_rec * last_rec = NULL;
struct result_rec * selected_rec = NULL;
int numPointFontTiny;
int numPointFontSmall;
int numPointFontMed;
int numPointFontLarge;
int numThumbWidth;
int numRow;
int numCol;
int numResults;
int numFormat;
int numStart;
int numFontSpacing;
int numRectPenSize;
int numShadowOffset;
enum tSoundOutput soundOutput;
enum tVideoPlayer videoPlayer;
enum tJpegDecoder jpegDecoder = jdLibJpeg;
#define ERROR_POINT (numPointFontMed)
tColorDef colorScheme[] =
{
{5.0f, 5.0f, 5.0f, 1.0f},
{0.0f, 0.0f, 5.0f, 1.0f},
{0.0f, 0.0f, 0.0f, 1.0f},
{0.0f, 0.0f, 3.0f, 1.0f},
{2.0f, 5.0f, 2.0f, 1.0f},
{2.0f, 1.5f, 0.0f, 1.0f},
{0.0f, 0.0f, 0.0f, 1.0f},
{4.0f, 0.0f, 0.0f, 1.0f},
{0.0f, 0.5f, 0.0f, 1.0f},
};
tColorDef * textColor = &colorScheme[0];
tColorDef * rectColor = &colorScheme[1];
tColorDef * rectColor2 = &colorScheme[2];
tColorDef * outlineColor = &colorScheme[3];
tColorDef * outlineColor2 = &colorScheme[4];
tColorDef * selectedColor = &colorScheme[5];
tColorDef * bgColor = &colorScheme[6];
tColorDef * errorColor = &colorScheme[7];
tColorDef * rectColor3 = &colorScheme[8];
extern unsigned char *download_file(char * host, char * fileName, unsigned int * fileSize);
extern unsigned char *find_jpg_start(unsigned char * buf, unsigned int * bufSize);
extern VGImage OMXCreateImageFromBuf(unsigned char * buf, unsigned int bufLength, unsigned int outputWidth, unsigned int outputHeight);
tMenuState regionMenu;
tMenuState mainMenu;
tMenuState fontMenu;
tMenuState guiMenu;
tMenuState titleFontMenu;
tMenuState formatMenu;
tMenuState jskbMenu;
tMenuState categoryMenu;
extern const char tv_jpeg_raw_data[];
extern const unsigned int tv_jpeg_raw_size;
//------------------------------------------------------------------------------
void setBGImage()
{
if(bgImage != 0)
vgGetPixels(bgImage, 0,0, 0,0,state->screen_width, state->screen_height);
else
bgImage = createImageFromScreen();
}
//------------------------------------------------------------------------------
void drawBGImage()
{
if(bgImage != 0)
vgSetPixels(0,0, bgImage, 0, 0, state->screen_width, state->screen_height);
}
//------------------------------------------------------------------------------
struct result_rec * init_result_rec()
{
struct result_rec * new_rec = malloc(sizeof(struct result_rec));
if (new_rec != NULL)
{
new_rec->image = 0;
new_rec->largeImage = 0;
new_rec->id = NULL;
new_rec->title = NULL;
new_rec->date = NULL;
new_rec->category = NULL;
new_rec->user = NULL;
new_rec->description = NULL;
new_rec->url = NULL;
new_rec->thumbSmall = NULL;
new_rec->thumbLarge = NULL;
new_rec->tnSmallDLData = NULL;
new_rec->tnSmallImageData = NULL;
new_rec->tnSmallImageDataSize = 0;
new_rec->next = (struct result_rec *) NULL;
new_rec->prev = (struct result_rec *) NULL;
}
return new_rec;
}
//------------------------------------------------------------------------------
void free_result_rec(struct result_rec * rec)
{
if(rec != NULL)
{
if(rec->id != NULL)
free(rec->id);
if(rec->title != NULL)
free(rec->title);
if(rec->date != NULL)
free(rec->date);
if(rec->category != NULL)
free(rec->category);
if(rec->user != NULL)
free(rec->user);
if(rec->description != NULL)
free(rec->description);
if(rec->url != NULL)
free(rec->url);
if(rec->thumbSmall != NULL)
free(rec->thumbSmall);
if(rec->thumbLarge != NULL)
free(rec->thumbLarge);
if(rec->tnSmallDLData)
free(rec->tnSmallDLData);
if(rec->image > 0)
vgDestroyImage(rec->image);
if(rec->largeImage > 0)
vgDestroyImage(rec->largeImage);
free(rec);
}
}
//------------------------------------------------------------------------------
char ** get_lastrec_column(int iBracket, int iBrace, char * key)
{
if(last_rec != NULL)
{
if (iBracket == 3 && strcmp(key, "id") == 0)
return &last_rec->id;
else if (iBracket == 3 && strcmp(key, "title") == 0)
return &last_rec->title;
else if (iBracket == 3 && strcmp(key, "category") == 0)
return &last_rec->category;
else if (iBracket == 3 && strcmp(key, "uploader") == 0)
return &last_rec->user;
else if (iBracket == 3 && strcmp(key, "uploaded") == 0)
return &last_rec->date;
else if (iBracket == 3 && strcmp(key, "description") == 0)
return &last_rec->description;
else if (iBracket == 4 && strcmp(key, "sqDefault") == 0)
return &last_rec->thumbSmall;
else if (iBracket == 4 && strcmp(key, "hqDefault") == 0)
return &last_rec->thumbLarge;
else if (iBracket == 4 && strcmp(key, "default") == 0)
return &last_rec->url;
else
return NULL;
}
else
return NULL;
}
//------------------------------------------------------------------------------
VGImage create_image_from_buf(unsigned char *buf, size_t bufSize, size_t outputWidth, size_t outputHeight)
{
switch (jpegDecoder)
{
case jdOMXCPP:
return OMXCreateImageFromBuf((unsigned char *)
buf, bufSize, outputWidth, outputHeight);
break;
case jdOMXC:
return OpenMAXCreateImageFromBuf((unsigned char *)
buf, bufSize, outputWidth, outputHeight);
break;
case jdLibJpeg:
return createImageFromBuf((unsigned char *)
buf, bufSize, outputWidth, outputHeight);
break;
default:
show_message("ERROR:\n\nbad jped decoder enum", true, ERROR_POINT);
break;
}
return 0;
}
//------------------------------------------------------------------------------
inline void textXY(VGfloat x, VGfloat y, const char* s, int pointsize, tColorDef * fillcolor)
{
Text(&fontDefs[fontMenu.selectedItem], x, y, s, pointsize, fillcolor, VG_FILL_PATH);
}
//------------------------------------------------------------------------------
inline void textXY_Rollover (VGfloat x, VGfloat y,VGfloat brkLength, VGfloat maxLength, int maxLines, VGfloat yStep, const char* s, int pointsize, tColorDef * fillcolor)
{
Text_Rollover(&fontDefs[fontMenu.selectedItem], x, y, brkLength, maxLength, maxLines, yStep, s, pointsize, fillcolor, VG_FILL_PATH, false);
}
//------------------------------------------------------------------------------
void free_gui_images()
{
if (tvImage != 0)
vgDestroyImage(tvImage);
if (bgImage != 0)
vgDestroyImage(bgImage);
if(upArrowImage != 0)
vgDestroyImage(upArrowImage);
if(downArrowImage != 0)
vgDestroyImage(downArrowImage);
upArrowImage = 0;
downArrowImage = 0;
tvImage = 0;
bgImage = 0;
}
//------------------------------------------------------------------------------
void free_font_menus()
{
int i;
for(i=0; i < fontCount; i++)
unload_font(&fontDefs[i]);
if(fontMenu.menuItems!= NULL)
free(fontMenu.menuItems);
}
//------------------------------------------------------------------------------
void set_menu_value(tMenuState * menu, int value)
{
if(value > menu->maxItems)
{
menu->selectedIndex = value % menu->maxItems;
menu->scrollIndex = value / menu->maxItems;
}
else
{
menu->selectedIndex = value;
menu->scrollIndex = 0;
}
menu->selectedItem = value;
}
//------------------------------------------------------------------------------
void set_font(int font)
{
set_menu_value(&fontMenu, font);
}
//------------------------------------------------------------------------------
void set_title_font(int font)
{
set_menu_value(&titleFontMenu, font);
}
//------------------------------------------------------------------------------
int get_font()
{
return fontMenu.selectedIndex;
}
//------------------------------------------------------------------------------
int get_title_font()
{
return titleFontMenu.selectedItem;
}
//------------------------------------------------------------------------------
void init_font_menus()
{
init_small_menu(&fontMenu, "Font menu:");
init_small_menu(&titleFontMenu, "Title Font menu:");
int i;
fontMenu.menuItems = malloc(sizeof(tMenuItem) * (fontCount + 1));
for (i = 0; i < fontCount; i++)
{
load_font(&fontDefs[i]);
fontMenu.menuItems[i].key = fontDefs[i].name;
fontMenu.menuItems[i].description = fontDefs[i].name;
}
fontMenu.menuItems[i].key = NULL;
fontMenu.menuItems[i].description = NULL;
fontMenu.drawDetail = &font_menu_detail;
titleFontMenu.menuItems = fontMenu.menuItems;
titleFontMenu.drawDetail = fontMenu.drawDetail;
set_font(0);
set_title_font(4);
}
//------------------------------------------------------------------------------
static tPointXY arrowSize;
void load_gui_images()
{
if(tvImage == 0)
{
int w, h;
w = (state->screen_width * .35f);
h = (state->screen_height * .45f);
tvImage = create_image_from_buf((unsigned char *)
tv_jpeg_raw_data, tv_jpeg_raw_size, w, h);
}
if(upArrowImage == 0)
{
arrowSize.x = (state->screen_width * .05f);
arrowSize.y = (state->screen_height * .07f);
upArrowImage = create_image_from_buf((unsigned char *)
menu_arrow_up_raw_data, menu_arrow_up_raw_size, arrowSize.x, arrowSize.y);
downArrowImage = create_image_from_buf((unsigned char *)
menu_arrow_down_raw_data, menu_arrow_down_raw_size, arrowSize.x, arrowSize.y);
}
}
//------------------------------------------------------------------------------
//
char * parse_url(char * url, char ** server, char ** page)
{
const char sStr[] = "//";
char * buff = malloc(strlen(url) + 1);
strcpy(buff, url);
*page = 0x00;
*server = buff;
char * temp = strstr(buff, sStr);
if(temp != NULL)
*server = temp + strlen(sStr);
temp = strstr(*server, "/");
if(temp != NULL)
*page = temp + 1;
*temp = 0x00;
return buff;
}
//------------------------------------------------------------------------------
void draw_menu(tMenuState * menu)
{
Roundrect(menu->bCenterX?(state->screen_width - menu->winRect.w) / 2:menu->winRect.x,
menu->winRect.y,
menu->winRect.w,
menu->winRect.h,
30, 20, numRectPenSize, rectColor, selectedColor);
Roundrect(menu->selRect.x,
menu->selRect.y,
menu->selRect.w,
menu->selRect.h,
20, 20, numShadowOffset, rectColor, selectedColor);
int i;
for(i=0; i<2; i++) //shadow effect.
Text(&fontDefs[titleFontMenu.selectedItem],
menu->titlePos.x-i*numShadowOffset,
menu->titlePos.y-i*numShadowOffset,
menu->title,
//menu->numPointFontTitle,
numPointFontLarge,
&colorScheme[6-i], VG_FILL_PATH);
}
//------------------------------------------------------------------------------
void draw_txt_box_cen(char * message, float widthP, float heightP, float boxYp, float tXp, float tYp, int points)
{
int width = state->screen_width * widthP;
int height = state->screen_height * heightP;
int x = (state->screen_width - width) / 2;
int y = state->screen_height * boxYp;
int tx = state->screen_width * tXp;
int ty = state->screen_height * tYp;
int txtBrk = width + x - numRectPenSize;
Roundrect(x,y, width, height, 20, 20, numRectPenSize, rectColor, selectedColor);
int i;
for(i=0; i<2; i++)
Text_Rollover(&fontDefs[titleFontMenu.selectedItem],tx-numShadowOffset*i, ty-numShadowOffset*i,
txtBrk, txtBrk, 1, 0, message, points, &colorScheme[6-i], VG_FILL_PATH, false);
}
//------------------------------------------------------------------------------
void clear_screen(bool swap)
{
glClear( GL_COLOR_BUFFER_BIT );
vgSetfv(VG_CLEAR_COLOR, 4, (VGfloat *) bgColor);
vgClear(0, 0, state->screen_width, state->screen_height);
vgLoadIdentity();
if(swap)
eglSwapBuffers(state->display, state->surface);
}
//------------------------------------------------------------------------------
int show_selection_info(struct result_rec * rec)
{
int key = ESC_KEY;
tPointXY offsetXY;
offsetXY.y = (state->screen_height * .060f);
offsetXY.x = (state->screen_width * .035f);
tRectBounds tvRect;
tvRect.w = vgGetParameteri(tvImage, VG_IMAGE_WIDTH);
tvRect.h = vgGetParameteri(tvImage, VG_IMAGE_HEIGHT);
tvRect.x = (state->screen_width - tvRect.w) / 2;
tvRect.y = (state->screen_height - tvRect.h);
tRectBounds imageRect;
imageRect.h = tvRect.h - (offsetXY.y * 2);
imageRect.w = tvRect.w - (offsetXY.x * 2);
imageRect.x = (state->screen_width - imageRect.w) / 2;
imageRect.y = (state->screen_height - imageRect.h) - (tvRect.h - imageRect.h) / 2;
unsigned char * downloadData = NULL;
unsigned char * imageData = NULL;
unsigned int imageDataSize;
if(rec->description)
{
redraw_results(false);
show_big_message("Info: loading...", rec->description);
vgSetPixels(tvRect.x,
tvRect.y,
tvImage,
0, 0,
tvRect.w,
tvRect.h);
eglSwapBuffers(state->display, state->surface);
}
else //description not found.
show_message("OOPS! description == NULL", true, ERROR_POINT);
if(rec->thumbLarge != NULL)
{
if (rec->largeImage == 0)
rec->largeImage = load_jpeg2(rec->thumbLarge, imageRect.w, imageRect.h,
&downloadData, &imageData, &imageDataSize);
char * infoStr = NULL;
if(rec->date != NULL && rec->user != NULL && rec->id != NULL)
{
char * T = strchr(rec->date, 'T'); //remove after T - time unwanted
if (T != NULL) *T= 0x00;
char formatStr[] = "Info: #%s : %s : %s";
size_t size = strlen(rec->id) +
strlen(rec->date) +
strlen(rec->user) +
strlen(formatStr);
infoStr = malloc(size);
snprintf(infoStr, size, formatStr, rec->id, rec->user, rec->date);
if (T != NULL) *T= 'T';
}
else
{
if(rec->description)
show_big_message("Info: ???", rec->description);
}
do
{
redraw_results(false);
if(infoStr != NULL && rec->description != NULL)
show_big_message(infoStr, rec->description);
vgSetPixels(tvRect.x,
tvRect.y,
tvImage,
0, 0,
tvRect.w,
tvRect.h);
vgSetPixels(imageRect.x,
imageRect.y,
rec->largeImage,
0, 0,
imageRect.w,
imageRect.h);
key = readKb_mouse();
if (imageData != NULL)
{
switch (key)
{
case 'h':
case 'H':
vgDestroyImage(-rec->largeImage);
rec->largeImage = OMXCreateImageFromBuf((unsigned char *)
imageData, imageDataSize, imageRect.w, imageRect.h);
break;
case 's':
case 'S':
vgDestroyImage(rec->largeImage);
rec->largeImage = createImageFromBuf((unsigned char *)
imageData, imageDataSize, imageRect.w, imageRect.h);
break;
}
}
switch(key)
{
case MOUSE_1:
if(point_in_rect(&clickXY, &tvRect))
key = RTN_KEY;
else
key = ESC_KEY;
break;
case MOUSE_2:
key = ESC_KEY;
break;
}
}
while ( key != ESC_KEY &&
key != RTN_KEY &&
key != JOY_1 &&
key != CUR_L &&
key != CUR_R &&
key != CUR_UP &&
key != CUR_DWN &&
key != 'i' &&
key != 'I' &&
key != 'f' &&
key != 'F');
if(infoStr != NULL) free(infoStr);
//vgDestroyImage(image);
if(downloadData != NULL)
free(downloadData);
redraw_results(true);
}
else
show_message("OOPS! rec->thumbLarge == NULL", true, ERROR_POINT);
return key;
}
//------------------------------------------------------------------------------
#define COLOR_SELECTED selectedColor
#define COLOR_NORMAL bgColor
#define TEXT_SELECTED selectedColor
#define TEXT_NORMAL textColor
#define OSK_KEY 30
#define OSK_DEL 31
#define OSK_SPC 32
#define OSK_CLR 33
#define OSK_RTN 34
//------------------------------------------------------------------------------
static char * oskKeyMap[2][30] =
{
{
"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P",
"A", "S", "D", "F", "G", "H", "J", "K", "L", "\"",
"`", "Z", "X", "C", "V", "B", "N", "M", ",", "."
},
{
"!", "@", "#", "$", "%", "^", "&", "*", "(", ")",
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
"~", "<", ">", "?", "[", "]", "{", "}", "\\", "/"
}
};
//------------------------------------------------------------------------------
static int osk_key_index(int * page, int c)
{
int index;
for ((*page) = 0; (*page) < 2; (*page)++)
for(index = 0; index < 30; index++)
if (oskKeyMap[(*page)][index][0] == c ||
oskKeyMap[(*page)][index][0] == toupper(c))
return index;
return -1;
}
//------------------------------------------------------------------------------
bool input_string(char * prompt, char * buf, int max)
{
tRectBounds keyRect;
int std_key_width = state->screen_width / 14;
int std_key_w = std_key_width * .90f;
int large_key_width = std_key_width * 1.5f;
int large_key_w = large_key_width * .90f;
int key_height = state->screen_height / 10;
keyRect.h = key_height * .90f;
int space_width = std_key_width * 4;
int space_w = space_width * .97f;
tPointXY offsetXY;
int key = 0x00;
int x, y;
int sel = 0;
int old;
int result, page;
int keyMapIndex = 0;
offsetXY.x = std_key_width / 3;
offsetXY.y = key_height / 3;
int offsetX2 = std_key_width / 6;
char * save = malloc(max+1);
strcpy(save, buf);
do
{
if(key != MOUSE_1) clear_screen(false);
int endPos = strlen(buf);
keyRect.w = std_key_w;
int index = 0;
for(y = 0; y < 3; y++)
{
for (x = 0; x < 10; x++)
{
keyRect.x = (x + 2) * std_key_width;
keyRect.y = state->screen_height - ((y + 1) * key_height);
if (key == MOUSE_1)
{
if (point_in_rect(&clickXY, &keyRect))sel=index;
}
else
{
Roundrect(keyRect.x, keyRect.y, keyRect.w, keyRect.h, 20, 20, numRectPenSize, rectColor, (sel==index)?COLOR_SELECTED:COLOR_NORMAL);
textXY(keyRect.x + offsetXY.x, keyRect.y + offsetXY.y, oskKeyMap[keyMapIndex][index], numPointFontLarge, (sel==index)?TEXT_SELECTED:TEXT_NORMAL);
}
index++;
}
}
keyRect.x = (2) * std_key_width;
keyRect.y = state->screen_height - ((y + 1) * key_height);
keyRect.w = large_key_w;
if (key == MOUSE_1)
{
if (point_in_rect(&clickXY, &keyRect))sel=OSK_KEY;
keyRect.x += large_key_width;
if (point_in_rect(&clickXY, &keyRect))sel=OSK_DEL;
keyRect.x += large_key_width;
keyRect.w = space_w;
if (point_in_rect(&clickXY, &keyRect))sel=OSK_SPC;
keyRect.x += space_width;
keyRect.w = large_key_w;
if (point_in_rect(&clickXY, &keyRect))sel=OSK_CLR;
keyRect.x += large_key_width;
if (point_in_rect(&clickXY, &keyRect))sel=OSK_RTN;
if(sel == - 1)
{
sel = old;
key = 0x00;
}
else
key = JOY_1;
}
else
{
Roundrect(keyRect.x, keyRect.y, keyRect.w, keyRect.h, 20, 20, numRectPenSize, (keyMapIndex==0)?rectColor:rectColor3, (sel==OSK_KEY)?COLOR_SELECTED:COLOR_NORMAL);
textXY(keyRect.x + offsetX2, keyRect.y + offsetXY.y, "!@#", numPointFontLarge, (sel==OSK_KEY)?TEXT_SELECTED:TEXT_NORMAL);
keyRect.x += large_key_width;
Roundrect(keyRect.x, keyRect.y, keyRect.w, keyRect.h, 20, 20, numRectPenSize, rectColor, (sel==OSK_DEL)?COLOR_SELECTED:COLOR_NORMAL);
textXY(keyRect.x + offsetXY.x, keyRect.y + offsetXY.y, "DEL", numPointFontLarge, (sel==OSK_DEL)?TEXT_SELECTED:TEXT_NORMAL);
keyRect.x += large_key_width;
keyRect.w = space_w;
Roundrect(keyRect.x, keyRect.y, space_w, keyRect.h, 20, 20, numRectPenSize, rectColor, (sel==OSK_SPC)?COLOR_SELECTED:COLOR_NORMAL);
keyRect.x += space_width;
keyRect.w = large_key_w;
Roundrect(keyRect.x, keyRect.y, keyRect.w, keyRect.h, 20, 20, numRectPenSize, rectColor, (sel==OSK_CLR)?COLOR_SELECTED:COLOR_NORMAL);
textXY(keyRect.x + offsetX2, keyRect.y + offsetXY.y, "CLR", numPointFontLarge, (sel==OSK_CLR)?TEXT_SELECTED:TEXT_NORMAL);
keyRect.x += large_key_width;
Roundrect(keyRect.x, keyRect.y, keyRect.w, keyRect.h, 20, 20, numRectPenSize, rectColor, (sel==OSK_RTN)?COLOR_SELECTED:COLOR_NORMAL);
textXY(keyRect.x + offsetX2, keyRect.y + offsetXY.y, "RTN", numPointFontLarge, (sel==OSK_RTN)?TEXT_SELECTED:TEXT_NORMAL);
draw_txt_box_cen(prompt, .95f, .50f, .05, .10f, .48f, numPointFontLarge);
buf[endPos] = '_';
buf[endPos+1]= 0x00;
textXY_Rollover(state->screen_width * .10f,
state->screen_height * .30f,
state->screen_width * .80f,
state->screen_width * .90f,
2, state->screen_width * .05f,
buf, numPointFontLarge, textColor);
buf[endPos] = 0x00;
key = readKb_mouse();
}
switch(key)
{
case MOUSE_1:
old = sel;
sel = -1;
break;
case CUR_L:
if (sel > 0)
sel--;
else
sel = OSK_RTN;
break;
case CUR_R:
if(sel < OSK_RTN)
sel++;
else
sel = 0;
break;
case CUR_DWN:
if(sel < 20)
sel += 10;
else if (sel == 20 || sel == 21)
sel = OSK_KEY;
else if(sel == 22)
sel = OSK_DEL;
else if(sel >= 23 && sel <= 26)
sel = OSK_SPC;
else if(sel == 27)
sel = OSK_CLR;
else if(sel == 28 || sel == 29)
sel = OSK_RTN;
break;
case CUR_UP:
if(sel >= 10 && sel <= 30)
sel -= 10;
else if(sel == OSK_DEL)
sel = 22;
else if(sel == OSK_SPC)
sel = 23;
else if(sel == OSK_CLR)
sel = 27;
else if(sel == OSK_RTN)
sel = 29;
break;
case JOY_1:
if(sel == OSK_RTN)
{
key = RTN_KEY;
}
else if(sel == OSK_KEY)
{
keyMapIndex += 1;
if(keyMapIndex > 1)
keyMapIndex = 0;
}
else if(sel == OSK_DEL)
{
if(endPos > 0)
buf[endPos-1] = 0x00;
}
else if(sel == OSK_CLR)
{
buf[0] = 0x00;
}
else if ((strlen(buf) + 3) < max)
{
if(sel >= 0 && sel < OSK_KEY)
strcat(buf, oskKeyMap[keyMapIndex][sel]);
else if(sel == OSK_SPC)
strcat(buf, " ");
}
break;
case MOUSE_2:
key = ESC_KEY;
case ESC_KEY:
strcpy(buf, save);
break;
case DEL_KEY:
if(endPos > 0)
buf[endPos-1] = 0x00;
sel = OSK_DEL;
break;
default:
result = osk_key_index(&page,key);
if(result != -1)
{
keyMapIndex = page;
if(keyMapIndex == page)
sel = result;
}
if(result != -1 || key == ' ')
{
if ((strlen(buf) + 3) < max)
{
result = strlen(buf);
buf[result] = key;
buf[result+1] = 0x00;
}
if (key == ' ')
sel = OSK_SPC;
}
}
}
while (key != ESC_KEY && key != RTN_KEY);
free(save);
if(key == ESC_KEY)
return false;
else
return true;
}
//------------------------------------------------------------------------------
void show_big_message(char * title, char * message)
{
redraw_results(false);
draw_txt_box_cen(title, .95f, .47f, .04, .10f, .44f, numPointFontLarge);
textXY_Rollover(state->screen_width * .10f,
state->screen_height * .38f,
state->screen_width * .85f,
state->screen_width * .90f,
7, //max no of lines
state->screen_height * numFontSpacing / 1000.0f,
message, numPointFontMed, textColor);
}
//------------------------------------------------------------------------------
static tRectBounds imageRect;
void show_message(char * message, int error, int points)
{
tPointXY offsetXY;
//tRectBounds imageRect;
tRectBounds guruRect;
tRectBounds tvRect;
offsetXY.y = (state->screen_height * .060f);
offsetXY.x = (state->screen_width * .035f);
tvRect.w = vgGetParameteri(tvImage, VG_IMAGE_WIDTH);
tvRect.h = vgGetParameteri(tvImage, VG_IMAGE_HEIGHT);
tvRect.x = (state->screen_width - tvRect.w) / 2;
tvRect.y = (state->screen_height - tvRect.h) / 2;
imageRect.h = tvRect.h - (offsetXY.y * 2);
imageRect.w = tvRect.w - (offsetXY.x * 2);
imageRect.x = (state->screen_width - imageRect.w) / 2;
imageRect.y = (state->screen_height - imageRect.h) / 2;
int tx = imageRect.x + state->screen_width * .03f;
int ty = imageRect.y + imageRect.h - offsetXY.x;
guruRect.w = imageRect.w * .95f;
guruRect.h = imageRect.h * .25f;
guruRect.x = (state->screen_width - guruRect.w) / 2;
guruRect.y = imageRect.y + imageRect.h - guruRect.h - (state->screen_width * .007f);
bool showGuru = true;
char * errorStr = NULL;
int key = ESC_KEY;
if(error)
{
char formatStr[] = "~7GURU MEDITATION #%08X\n\n~0%s";
size_t sErrorStr = strlen(formatStr) + strlen(message) + 8;
errorStr = malloc(sErrorStr);
snprintf(errorStr, sErrorStr, formatStr, error, message);
printf("ERROR->%d\n", error);
numTimer = 50; // starts TIMER_M messages
redraw_results(false);
setBGImage();
}
do
{
if (error) drawBGImage();
//vgCopyPixels(0,0,0,0, state->screen_width, state->screen_height);
vgSetPixels(tvRect.x,
tvRect.y,
tvImage,
0, 0,
tvRect.w,
tvRect.h);
Roundrect(imageRect.x, imageRect.y, imageRect.w, imageRect.h, 20, 20, numRectPenSize, error?bgColor:rectColor, bgColor);
if(error && showGuru)
Rect(guruRect.x, guruRect.y, guruRect.w, guruRect.h, numRectPenSize, bgColor, errorColor);
Text_Rollover ( &fontDefs[1], //Topaz font
tx, // X
ty, // Y
state->screen_width * .80f,
state->screen_width * .90f,
6,
state->screen_height * .05f,
error?errorStr:message, points, &colorScheme[0], VG_FILL_PATH, true);
if(error)
{
key = readKb_mouse();
if(key == TIMER_M)
showGuru = !showGuru;
}
else
break;
}
while (key != ESC_KEY &&
key != RTN_KEY &&
key != JOY_1 &&
key != MOUSE_1 &&
key != MOUSE_2);
if(errorStr != NULL)
free(errorStr);
numTimer = -1; //turn timer off;
}
//------------------------------------------------------------------------------
void calc_rect_bounds(tRectPer * rectPer, tRectBounds * rectBounds)
{
rectBounds->x = rectPer->xPer * state->screen_width;
rectBounds->y = rectPer->yPer * state->screen_height;
rectBounds->w = rectPer->wPer * state->screen_width;
rectBounds->h = rectPer->hPer * state->screen_height;
}
//------------------------------------------------------------------------------
void calc_point_xy(tPointPer * pointPer, tPointXY * pointXY)
{
pointXY->x = pointPer->xPer * state->screen_width;
pointXY->y = pointPer->yPer * state->screen_height;
}
//------------------------------------------------------------------------------
void init_arrow(VGfloat * xy, tRectPer * rectPer, bool bFlip)
{
tPointXY p1;
tPointXY p2;
tPointXY p3;
int x1 = state->screen_width * rectPer->xPer;
int x2 = state->screen_width * (rectPer->xPer + rectPer->wPer);
int x3 = x1 + ((x2 - x1) / 2);
int y1 = state->screen_height * rectPer->yPer;
int y2 = state->screen_height * rectPer->yPer;
int yOffset = rectPer->hPer * state->screen_height;
if(bFlip)
y1 += yOffset;
else
y2 += yOffset;
p1.x = x3;
p1.y = y1;
p2.x = x1;
p2.y = y2;
p3.x = x2;
p3.y = y2;
xy[0] = p1.x;
xy[1] = p1.y;
xy[2] = p2.x;
xy[3] = p2.y;
xy[4] = p3.x;
xy[5] = p3.y;
xy[6] = p1.x;
xy[7] = p1.y;
}
//------------------------------------------------------------------------------
void init_big_menu(tMenuState * menu, char * title)
{
menu->title = title;
menu->titlePer.xPer = .10f;
menu->titlePer.yPer = .87f;
calc_point_xy(&menu->titlePer, &menu->titlePos);
menu->selectedIndex = 0;
menu->scrollIndex = 0;
menu->selectedItem = 0;
menu->maxItems = 18;
menu->txtOffset.x = state->screen_height * .20f;
menu->txtOffset.y = state->screen_width * .10f;
menu->winPer.xPer = .10f;
menu->winPer.yPer = .05f;
menu->winPer.wPer = .92f;
menu->winPer.hPer = .90f;
calc_rect_bounds(&menu->winPer, &menu->winRect);
menu->numPointFontTitle = numPointFontLarge;
menu->numPointFont = numPointFontMed;
menu->selPer.xPer = .085f;
menu->yStep = state->screen_height * .04f;
menu->selPer.wPer = .50f;
menu->selPer.hPer = .04f;
calc_rect_bounds(&menu->selPer, &menu->selRect);
tRectPer rectPer;
rectPer.xPer = .88f;
rectPer.yPer = .83f;
rectPer.wPer = .04f;
rectPer.hPer = .04f;
init_arrow(menu->upArrow, &rectPer, true);
rectPer.yPer = .10f;
init_arrow(menu->downArrow, &rectPer, false);
menu->upArrowPer.xPer = .88f;
menu->upArrowPer.yPer = .83f;
calc_rect_bounds(&menu->upArrowPer, &menu->upArrowRect);
menu->downArrowPer.xPer = .88f;
menu->downArrowPer.yPer = .10f;
calc_rect_bounds(&menu->downArrowPer, &menu->downArrowRect);
menu->drawHeader = NULL;
menu->drawDetail = NULL;
menu->drawFooter = NULL;
menu->keyPress = NULL;
menu->bCenterX = true;
menu->bCenterY = false;
}
//------------------------------------------------------------------------------
void init_small_menu(tMenuState * menu, char * title)
{
menu->title = title;