This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 148
/
roadmap_bar.c
1405 lines (1087 loc) · 36.1 KB
/
roadmap_bar.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
/* roadmap|_bar.c - Handle main bar
*
* LICENSE:
*
* Copyright 2008 Avi B.S
* Copyright 2008 Ehud Shabtai
*
* This file is part of RoadMap.
*
* RoadMap is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* RoadMap is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "roadmap.h"
#include "roadmap_canvas.h"
#include "roadmap_lang.h"
#include "roadmap_screen_obj.h"
#include "roadmap_screen.h"
#include "roadmap_file.h"
#include "roadmap_res.h"
#include "roadmap_math.h"
#include "roadmap_time.h"
#include "roadmap_state.h"
#include "roadmap_message.h"
#include "roadmap_bar.h"
#include "roadmap_factory.h"
#include "roadmap_start.h"
#include "roadmap_pointer.h"
#include "roadmap_softkeys.h"
#include "roadmap_skin.h"
#include "roadmap_mood.h"
#include "roadmap_groups.h"
#include "Realtime/RealtimeAlerts.h"
#define MAX_STATES 40
#define MAX_CONDITIONS 9
#define TOP_BAR_IMAGE "top_bar_background"
#define BOTTOM_BAR_IMAGE "bottom_bar_background"
#define TOP_BAR_SELECTED_BG_IMAGE "top_bar_s"
static RoadMapSize TopBarBgImageSize = {-1, -1};
static RoadMapSize BottomBarBgImageSize = {-1, -1};
static RoadMapImage TopBarSelectedBg = NULL;
static RoadMapImage TopBarFullBg = NULL;
static RoadMapImage BottomBarFullBg = NULL;
#ifdef ANDROID
static BOOL gHideBottomBar = TRUE;
#else
static BOOL gHideBottomBar = FALSE;
#endif
static BOOL gHideTopBar = FALSE;
void roadmap_bar_switch_skins(void);
static BOOL bar_initialized = FALSE;
#define TOPBAR_FLAG 0x10000
#define BOTTOM_BAR_FLAG 0x20000
#define IMAGE_STATE_NORMAL 0
#define IMAGE_STATE_SELECTED 1
const char * get_time_str(void);
const char * get_current_street(void);
const char * get_time_to_destination(void);
const char * get_dist_to_destination(void);
const char * get_current_num_comments(void);
#define MAX_OBJECTS 40
typedef struct {
const char *name;
RoadMapPen foreground;
const char *default_foreground;
RoadMapBarTextFn bar_text_fn;
} BarText;
typedef struct {
const char *name;
RoadMapBarTextFn bar_text_fn;
} BarDynamicImages;
#define ROADMAP_TEXT(p,w,t) \
{p, NULL, w, t}
#define ROADMAP_DYNAMIC_IMAGE(p,t) \
{p, t}
BarText RoadMapTexts[] = {
ROADMAP_TEXT("clock", "#ffffff", get_time_str),
ROADMAP_TEXT("num_alerts", "#ffffff",RTAlerts_Count_Str),
ROADMAP_TEXT("left_softkey", "#ffffff",roadmap_softkeys_get_left_soft_key_text),
ROADMAP_TEXT("right_softkey", "#ffffff",roadmap_softkeys_get_right_soft_key_text),
ROADMAP_TEXT("right_softkey", "#ffffff",get_current_street),
ROADMAP_TEXT("time_to_dest", "#ffffff",get_time_to_destination),
ROADMAP_TEXT("dist_to_dest", "#ffffff",get_dist_to_destination),
ROADMAP_TEXT("current_num_comments", "#ffffff",get_current_num_comments),
ROADMAP_TEXT("group_num_alerts", "#ffffff",RTAlerts_GroupCount_Str),
ROADMAP_TEXT(NULL, NULL, NULL)
};
BarDynamicImages RoadMapDynamicImages[] = {
ROADMAP_DYNAMIC_IMAGE("group_wazer", roadmap_groups_get_active_group_wazer_icon),
ROADMAP_DYNAMIC_IMAGE(NULL, NULL)
};
typedef struct {
char *name;
// const char *image_file[MAX_STATES];
int pos_x;
int pos_y;
char* images[MAX_STATES];
char* image_selected[MAX_STATES];
const char *state;
int states_count;
RoadMapStateFn state_fn;
BarText *bar_text;
int font_size;
int text_alling;
char *text_color;
const char *fixed_text;
RoadMapGuiRect bbox;
const RoadMapAction *action;
RoadMapStateFn condition_fn[MAX_CONDITIONS];
int condition_value[MAX_CONDITIONS];
int num_conditions;
int image_state;
BarDynamicImages *bar_image_fn;
} BarObject;
typedef struct {
BarObject *object[MAX_OBJECTS];
int draw_bg;
int count;
} BarObjectTable_s;
static BarObjectTable_s TopBarObjectTable;
static BarObjectTable_s BottomBarObjectTable;
static BarObject* SelectedBarObject = NULL;
extern void roadmap_androidmenu_initialize();
static RoadMapImage roadmap_bar_load_image( const char* obj_name, const char* img_name );
static BarText * roadmap_bar_text_find(const char *name){
BarText *text;
for (text = RoadMapTexts; text->name != NULL; ++text) {
if (strcmp (text->name, name) == 0) {
return text;
}
}
roadmap_log (ROADMAP_ERROR, "unknown bar text '%s'", name);
return NULL;
}
static BarDynamicImages * roadmap_bar_dynamic_image_find(const char *name){
BarDynamicImages *d_image;
for (d_image = RoadMapDynamicImages; d_image->name != NULL; ++d_image) {
if (strcmp (d_image->name, name) == 0) {
return d_image;
}
}
roadmap_log (ROADMAP_ERROR, "unknown bar dynamic image '%s'", name);
return NULL;
}
static void roadmap_bar_pos (BarObject *object,
RoadMapGuiPoint *pos) {
pos->x = object->pos_x;
pos->y = object->pos_y;
if (pos->x < 0)
pos->x += roadmap_canvas_width ();
if (pos->y < 0)
pos->y += roadmap_canvas_height ();
}
static char *roadmap_bar_object_string (const char *data, int length) {
char *p = malloc (length+1);
roadmap_check_allocated(p);
strncpy (p, data, length);
p[length] = 0;
return p;
}
static void roadmap_bar_decode_arg (char *output, int o_size,
const char *input, int i_size) {
int size;
o_size -= 1;
size = i_size < o_size ? i_size : o_size;
strncpy (output, input, size);
output[size] = '\0';
}
static void roadmap_bar_decode_integer (int *value, int argc,
const char **argv, int *argl) {
char arg[255];
argc -= 1;
if (argc != 1) {
roadmap_log (ROADMAP_ERROR, "roadmap bar: illegal integer value - %s",
argv[0]);
return;
}
roadmap_bar_decode_arg (arg, sizeof(arg), argv[1], argl[1]);
*value = atoi(arg);
}
static void roadmap_bar_decode_position
(BarObject *object,
int argc, const char **argv, int *argl) {
char arg[255];
int pos;
argc -= 1;
if (argc != 2) {
roadmap_log (ROADMAP_ERROR, "roadmap bar:'%s' illegal position.",
object->name);
return;
}
roadmap_bar_decode_arg (arg, sizeof(arg), argv[1], argl[1]);
pos = atoi(arg);
object->pos_x = pos;
roadmap_bar_decode_arg (arg, sizeof(arg), argv[2], argl[2]);
pos = atoi(arg);
object->pos_y = pos;
}
static void roadmap_bar_decode_icon
(BarObject *object,
int argc, const char **argv, int *argl) {
int i;
argc -= 1;
if (object->states_count > MAX_STATES) {
roadmap_log (ROADMAP_ERROR, "roadmap bar:'%s' has too many states.",
object->name);
return;
}
for (i = 1; i <= argc; ++i) {
// RoadMapImage image = NULL;
char arg[256];
roadmap_bar_decode_arg (arg, sizeof(arg), argv[i], argl[i]);
if (i == 1)
object->images[object->states_count] = strdup( arg );
else
object->image_selected[object->states_count] = strdup( arg );
}
object->image_state = IMAGE_STATE_NORMAL;
object->states_count++;
}
static void roadmap_bar_decode_state
(BarObject *object,
int argc, const char **argv, int *argl) {
char arg[255];
argc -= 1;
if (argc != 1) {
roadmap_log (ROADMAP_ERROR, "roadmap bar:'%s' illegal state indicator.",
object->name);
return;
}
roadmap_bar_decode_arg (arg, sizeof(arg), argv[1], argl[1]);
object->state_fn = roadmap_state_find (arg);
if (!object->state_fn) {
roadmap_log (ROADMAP_ERROR,
"roadmap bar:'%s' can't find state indicator.",
object->name);
}
}
static void roadmap_bar_decode_text_color
(BarObject *object,
int argc, const char **argv, int *argl) {
char arg[255];
argc -= 1;
if (argc != 1) {
roadmap_log (ROADMAP_ERROR, "roadmap bar:'%s' illegal text color.",
object->name);
return;
}
roadmap_bar_decode_arg (arg, sizeof(arg), argv[1], argl[1]);
object->text_color = roadmap_bar_object_string (argv[1], argl[1]);
}
static void roadmap_bar_decode_condition
(BarObject *object,
int argc, const char **argv, int *argl) {
char arg[255];
argc -= 1;
if (argc != 2) {
roadmap_log (ROADMAP_ERROR, "roadmap bar:'%s' illegal condition indicator.",
object->name);
return;
}
if (object->num_conditions >= MAX_CONDITIONS){
roadmap_log (ROADMAP_ERROR, "roadmap bar:'%s' Too many conditions.",
object->name);
return;
}
roadmap_bar_decode_arg (arg, sizeof(arg), argv[1], argl[1]);
object->condition_fn[object->num_conditions] = roadmap_state_find (arg);
if (!object->condition_fn) {
roadmap_log (ROADMAP_ERROR,
"roadmap bar:'%s' can't find condition indicator.",
object->name);
return;
}
roadmap_bar_decode_arg (arg, sizeof(arg), argv[2], argl[2]);
object->condition_value[object->num_conditions] = atoi(arg);
object->num_conditions++;
}
static void roadmap_bar_decode_text
(BarObject *object,
int argc, const char **argv, int *argl) {
char arg[255];
argc -= 1;
if (argc != 1) {
roadmap_log (ROADMAP_ERROR, "roadmap bar:'%s' illegal condition indicator.",
object->name);
return;
}
roadmap_bar_decode_arg (arg, sizeof(arg), argv[1], argl[1]);
object->bar_text = roadmap_bar_text_find (arg);
}
static void roadmap_bar_decode_dynamic_image
(BarObject *object,
int argc, const char **argv, int *argl) {
char arg[255];
argc -= 1;
if (argc != 1) {
roadmap_log (ROADMAP_ERROR, "roadmap bar:'%s' illegal dynamic image indicator.",
object->name);
return;
}
roadmap_bar_decode_arg (arg, sizeof(arg), argv[1], argl[1]);
object->bar_image_fn = roadmap_bar_dynamic_image_find (arg);
}
static void roadmap_bar_decode_fixed_text
(BarObject *object,
int argc, const char **argv, int *argl) {
char arg[255];
char temp[255];
int i;
// argc -= 1;
arg[0] = 0;
for (i=1; i< argc; i++){
roadmap_bar_decode_arg (temp, sizeof(arg), argv[i], argl[i]);
strcat(arg, temp);
if (i != argc-1)
strcat(arg, " ");
}
object->fixed_text = strdup(roadmap_lang_get(arg));
}
static BarObject *roadmap_bar_new
(int argc, const char **argv, int *argl) {
BarObject *object = calloc(sizeof(*object), 1);
roadmap_check_allocated(object);
object->name = roadmap_bar_object_string (argv[1], argl[1]);
object->text_alling = -1;
object->text_color = NULL;
return object;
}
static void roadmap_bar_decode_bbox
(BarObject *object,
int argc, const char **argv, int *argl) {
char arg[255];
argc -= 1;
if (argc != 4) {
roadmap_log (ROADMAP_ERROR, "roadmap bar:'%s' illegal bbox.",
object->name);
return;
}
roadmap_bar_decode_arg (arg, sizeof(arg), argv[1], argl[1]);
object->bbox.minx = atoi(arg);
roadmap_bar_decode_arg (arg, sizeof(arg), argv[2], argl[2]);
object->bbox.miny = atoi(arg);
roadmap_bar_decode_arg (arg, sizeof(arg), argv[3], argl[3]);
object->bbox.maxx = atoi(arg);
roadmap_bar_decode_arg (arg, sizeof(arg), argv[4], argl[4]);
object->bbox.maxy = atoi(arg);
}
static void roadmap_bar_decode_action
(BarObject *object,
int argc, const char **argv, int *argl) {
char arg[255];
argc -= 1;
if (argc < 1) {
roadmap_log (ROADMAP_ERROR, "roadmap bar:'%s' illegal action.",
object->name);
return;
}
roadmap_bar_decode_arg (arg, sizeof(arg), argv[1], argl[1]);
object->action = roadmap_start_find_action (arg);
if (!object->action) {
roadmap_log (ROADMAP_ERROR, "roadmap bar:'%s' can't find action.",
object->name);
}
}
static BarObject *roadmap_bar_by_pos (RoadMapGuiPoint *point, BarObjectTable_s *table) {
int i;
int condition;
for (i = 0; i < table->count; i++) {
RoadMapGuiPoint pos;
roadmap_bar_pos(table->object[i], &pos);
if ((point->x >= (pos.x + table->object[i]->bbox.minx)) &&
(point->x <= (pos.x + table->object[i]->bbox.maxx)) &&
(point->y >= (pos.y + table->object[i]->bbox.miny)) &&
(point->y <= (pos.y + table->object[i]->bbox.maxy))) {
if (table->object[i]->condition_fn[0]){
int j;
BOOL cond = TRUE;
for (j=0; j< table->object[i]->num_conditions;j++){
condition = (*table->object[i]->condition_fn[j]) ();
if (condition != table->object[i]->condition_value[j])
cond = FALSE;
}
if (!cond)
continue;
}
return table->object[i];
}
}
return NULL;
}
static void roadmap_bar_load (const char *data, int size, BarObjectTable_s *BarObjectTable) {
int argc;
int argl[256];
const char *argv[256];
const char *p;
const char *end;
BarObject *object = NULL;
end = data + size;
while (data < end) {
while (data[0] == '#' || data[0] < ' ') {
if (*(data++) == '#') {
while ((data < end) && (data[0] >= ' ')) data += 1;
}
while (data < end && data[0] == '\n' && data[0] != '\r') data += 1;
}
argc = 1;
argv[0] = data;
for (p = data; p < end; ++p) {
if (*p == ' ') {
argl[argc-1] = p - argv[argc-1];
argv[argc] = p+1;
argc += 1;
if (argc >= 255) break;
}
if (p >= end || *p < ' ') break;
}
argl[argc-1] = p - argv[argc-1];
while (p < end && *p < ' ' && *p > 0) ++p;
data = p;
if (object == NULL) {
if (argv[0][0] != 'N') {
roadmap_log (ROADMAP_ERROR, "roadmap bar name is missing");
break;
}
}
switch (argv[0][0]) {
case 'P':
roadmap_bar_decode_position (object, argc, argv, argl);
break;
case 'I':
roadmap_bar_decode_icon (object, argc, argv, argl);
break;
case 'A':
roadmap_bar_decode_action (object, argc, argv, argl);
break;
case 'B':
roadmap_bar_decode_bbox (object, argc, argv, argl);
break;
case 'S':
roadmap_bar_decode_state (object, argc, argv, argl);
break;
case 'N':
object = roadmap_bar_new (argc, argv, argl);
BarObjectTable->object[BarObjectTable->count] = object;
BarObjectTable->count++;
break;
case 'C':
roadmap_bar_decode_condition (object, argc, argv, argl);
break;
case 'T':
roadmap_bar_decode_text (object, argc, argv, argl);
break;
case 'G':
roadmap_bar_decode_dynamic_image(object, argc, argv, argl);
break;
case 'F':
roadmap_bar_decode_integer (&object->font_size, argc, argv,
argl);
break;
case 'E':
roadmap_bar_decode_fixed_text (object, argc, argv, argl);
break;
case 'L':
roadmap_bar_decode_integer(&object->text_alling, argc, argv,
argl);
break;
case 'D':
roadmap_bar_decode_text_color (object, argc, argv, argl);
break;
case 'Y':
roadmap_bar_decode_integer (&BarObjectTable->draw_bg, argc, argv,
argl);
break;
}
while (p < end && *p < ' ') p++;
data = p;
}
}
const char * get_time_str(void){
time_t now;
now = time(NULL);
return roadmap_time_get_hours_minutes(now);
}
const char * get_current_street(void){
static char text[256];
roadmap_message_format (text, sizeof(text), "%Y");
return &text[0];
}
const char * get_current_num_comments(void){
static char text[20];
int has_comments = RTAlerts_CurrentAlert_Has_Comments();
if (has_comments){
int num_comments = RTAlerts_Get_Number_of_Comments(RTAlerts_Get_Current_Alert_Id());
sprintf(text,"%d",num_comments);
return &text[0];
}
else
return "";
}
const char *get_time_to_destination(void){
static char text[256];
if (roadmap_message_format (text, sizeof(text), "%T|%@"))
return &text[0];
return "";
}
const char *get_dist_to_destination(void){
static char text[256];
if (roadmap_message_format (text, sizeof(text), "%D (%W)|%D"))
return &text[0];
return "";
}
static void drawBarBGImage( const char* res, const RoadMapGuiPoint* pos ) {
int width = roadmap_canvas_width ();
int num_images;
int image_width, image_height;
int i;
RoadMapGuiPoint bottom_right_pos, BarLocation;
RoadMapImage bgImage = (RoadMapImage) roadmap_res_get( RES_BITMAP, RES_SKIN, res );
image_width = roadmap_canvas_image_width( bgImage );
image_height = roadmap_canvas_image_height( bgImage );
bottom_right_pos.x = roadmap_canvas_width ();
bottom_right_pos.y = pos->y + image_height;
#ifdef OPENGL
roadmap_canvas_draw_image_scaled( bgImage, pos, &bottom_right_pos, 0, IMAGE_NORMAL );
#else
num_images = width / image_width ;
BarLocation.y = pos->y;
for ( i = 0; i < num_images; i++ )
{
BarLocation.x = pos->x + i * image_width;
roadmap_canvas_draw_image( bgImage, &BarLocation, 0, IMAGE_NORMAL);
}
#endif
}
void draw_objects(BarObjectTable_s *table){
int font_size;
int i;
int state, condition;
RoadMapGuiPoint TextLocation;
RoadMapImage image;
int text_flag = ROADMAP_CANVAS_LEFT|ROADMAP_CANVAS_TOP ;
for (i=0; i < table->count; i++) {
RoadMapGuiPoint ObjectLocation;
RoadMapGuiPoint BgFocusLocation;
if (table->object[i] == NULL)
continue;
if (table->object[i]->condition_fn[0]){
int j;
BOOL cond = TRUE;
for (j=0; j< table->object[i]->num_conditions;j++){
condition = (*table->object[i]->condition_fn[j]) ();
if (condition != table->object[i]->condition_value[j])
cond = FALSE;
}
if (!cond)
continue;
}
roadmap_bar_pos(table->object[i], &ObjectLocation);
if (table->object[i]->state_fn) {
state = (*table->object[i]->state_fn) ();
if ((state < 0) || (state >= MAX_STATES)){
}
else{
if (table->object[i]->images[state] != NULL){
if (table->object[i]->image_state == IMAGE_STATE_SELECTED){
if (table->object[i]->image_selected[state] != NULL){
image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->image_selected[state] );
roadmap_canvas_draw_image ( image, &ObjectLocation, 0,IMAGE_NORMAL);
}
else{
if (TopBarSelectedBg){
image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[state] );
BgFocusLocation.x = ObjectLocation.x - (roadmap_canvas_image_width(TopBarSelectedBg) -roadmap_canvas_image_width( image ))/2;
BgFocusLocation.y = ObjectLocation.y - (roadmap_canvas_image_height(TopBarSelectedBg) -roadmap_canvas_image_height( image ))/4*3;
roadmap_canvas_draw_image ( TopBarSelectedBg, &BgFocusLocation, 0,IMAGE_NORMAL );
}
image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[state] );
roadmap_canvas_draw_image ( image, &ObjectLocation, 0,IMAGE_NORMAL);
}
}
else{
image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[state] );
roadmap_canvas_draw_image ( image, &ObjectLocation, 0,IMAGE_NORMAL);
}
}
}
}
else{
if (table->object[i]->image_state == IMAGE_STATE_SELECTED){
if (table->object[i]->image_selected[0] != NULL){
image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->image_selected[0] );
roadmap_canvas_draw_image ( image, &ObjectLocation, 0,IMAGE_NORMAL);
}
else{
if (TopBarSelectedBg){
image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[0] );
BgFocusLocation.x = ObjectLocation.x - (roadmap_canvas_image_width(TopBarSelectedBg) -roadmap_canvas_image_width( image ))/2;
BgFocusLocation.y = ObjectLocation.y - (roadmap_canvas_image_height(TopBarSelectedBg) -roadmap_canvas_image_height( image ))/4*3;
roadmap_canvas_draw_image ( TopBarSelectedBg, &BgFocusLocation, 0,IMAGE_NORMAL );
}
image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[0] );
roadmap_canvas_draw_image (image, &ObjectLocation, 0,IMAGE_NORMAL);
}
}
else if (table->object[i]->images[0] )
{
image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[0] );
roadmap_canvas_draw_image ( image , &ObjectLocation, 0,IMAGE_NORMAL);
}
}
if (table->object[i]->bar_image_fn){
const char *image_name = NULL;
image_name = table->object[i]->bar_image_fn->bar_text_fn();
if (image_name && *image_name){
image = roadmap_res_get (RES_BITMAP, RES_SKIN, image_name );
if (image){
roadmap_canvas_draw_image ( image , &ObjectLocation, 0,IMAGE_NORMAL);
}
}
}
if (table->object[i]->bar_text){
if (table->object[i]->font_size != 0)
font_size = table->object[i]->font_size;
else
font_size = 10;
if (table->object[i]->text_alling != -1){
text_flag = table->object[i]->text_alling;
}
else if (table->object[i]->pos_x < 0){
text_flag = ROADMAP_CANVAS_RIGHT|ROADMAP_CANVAS_TOP;
}
roadmap_canvas_create_pen (table->object[i]->bar_text->name);
if (table->object[i]->text_color){
roadmap_canvas_set_foreground (table->object[i]->text_color);
}
else{
roadmap_canvas_set_foreground (table->object[i]->bar_text->default_foreground);
}
if (table->object[i]->state_fn) {
state = (*table->object[i]->state_fn) ();
if (state >0){
if (table->object[i]->images[state])
{
image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[state] );
TextLocation.x = ObjectLocation.x + roadmap_canvas_image_width( image )/2;
TextLocation.y = ObjectLocation.y + roadmap_canvas_image_height( image )/2;
}
else
roadmap_bar_pos(table->object[i], &TextLocation);
roadmap_canvas_draw_string_size (&TextLocation,
text_flag,
font_size,(*table->object[i]->bar_text->bar_text_fn)());
}
}
else{
if (table->object[i]->images[0]){
image = roadmap_bar_load_image( table->object[i]->name, table->object[i]->images[0] );
TextLocation.x = ObjectLocation.x + roadmap_canvas_image_width( image )/2;
TextLocation.y = ObjectLocation.y + roadmap_canvas_image_height( image )/2 -2;
}
else
roadmap_bar_pos(table->object[i], &TextLocation);
roadmap_canvas_draw_string_size (&TextLocation,
text_flag,
font_size,(*table->object[i]->bar_text->bar_text_fn)());
}
}
if (table->object[i]->fixed_text){
if (table->object[i]->font_size != 0)
font_size = table->object[i]->font_size;
else
font_size = 10;
if (table->object[i]->text_alling != -1){
text_flag = table->object[i]->text_alling;
}
else if (table->object[i]->pos_x < 0){
text_flag = ROADMAP_CANVAS_RIGHT|ROADMAP_CANVAS_TOP;
}
roadmap_canvas_create_pen (table->object[i]->name);
if (table->object[i]->text_color){
roadmap_canvas_set_foreground (table->object[i]->text_color);
}
else{
if (roadmap_skin_state())
roadmap_canvas_set_foreground ("#ffffff");
else
roadmap_canvas_set_foreground ("#000000");
}
if (table->object[i]->state_fn) {
state = (*table->object[i]->state_fn) ();
if (state >0){
roadmap_bar_pos(table->object[i], &TextLocation);
roadmap_canvas_draw_string_size (&TextLocation,
text_flag,
font_size,table->object[i]->fixed_text);
}
}
else{
roadmap_bar_pos(table->object[i], &TextLocation);
roadmap_canvas_draw_string_size (&TextLocation,
text_flag,
font_size,table->object[i]->fixed_text);
}
}
}
}
void roadmap_bar_draw_top_bar (BOOL draw_bg) {
int width;
if (!bar_initialized)
return;
if ( gHideTopBar )
return;
width = roadmap_canvas_width ();
if (TopBarObjectTable.draw_bg && draw_bg){
RoadMapGuiPoint BarLocation;
BarLocation.y = 0;
BarLocation.x = 0;
if ( TopBarFullBg )
{
roadmap_canvas_draw_image (TopBarFullBg, &BarLocation, 0, 2 );
}
else
{
drawBarBGImage( TOP_BAR_IMAGE, &BarLocation );
}
}
draw_objects(&TopBarObjectTable);
}
int roadmap_bar_short_click (RoadMapGuiPoint *point)
{
if ( !SelectedBarObject )
return 0;
else
return 1;
}
int roadmap_bar_long_click (RoadMapGuiPoint *point) {
if ( !SelectedBarObject )
return 0;
else
return 1;
}
int roadmap_bar_drag_start(RoadMapGuiPoint *point)
{
if (!SelectedBarObject )
return 0;
else
return 1;
}
int roadmap_bar_drag_motion (RoadMapGuiPoint *point)
{
BarObject *new_bar_object = NULL;
if (SelectedBarObject == NULL)
return 0;
if ( !gHideTopBar )
new_bar_object = roadmap_bar_by_pos(point, &TopBarObjectTable);
if (!new_bar_object) {
if ( !gHideBottomBar )
new_bar_object = roadmap_bar_by_pos(point, &BottomBarObjectTable);
if (!new_bar_object){
SelectedBarObject->image_state = IMAGE_STATE_NORMAL;
roadmap_screen_redraw();
return 1;
}
}