/
roadmap_ticker.c
404 lines (336 loc) · 12.2 KB
/
roadmap_ticker.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
/* roadmap_ticker.c
*
* LICENSE:
*
* Copyright 2008 Avi B.S
*
* 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 V2 as published by
* the Free Software Foundation.
*
* 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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include "roadmap.h"
#include "roadmap_main.h"
#include "roadmap_types.h"
#include "roadmap_gui.h"
#include "roadmap_lang.h"
#include "roadmap_math.h"
#include "roadmap_line.h"
#include "roadmap_street.h"
#include "roadmap_config.h"
#include "roadmap_canvas.h"
#include "roadmap_message.h"
#include "roadmap_sprite.h"
#include "roadmap_voice.h"
#include "roadmap_skin.h"
#include "roadmap_plugin.h"
#include "roadmap_square.h"
#include "roadmap_math.h"
#include "roadmap_res.h"
#include "roadmap_bar.h"
#include "roadmap_sound.h"
#include "roadmap_pointer.h"
#include "roadmap_ticker.h"
#include "roadmap_device.h"
#include "editor/editor_screen.h"
#include "editor/editor_points.h"
#include "Realtime/Realtime.h"
#include "roadmap_display.h"
#include "roadmap_device_events.h"
static RoadMapImage gImageOpen, gMiddleImage, gImageClose, gImageDivider;
static RoadMapPen RoadMapTickerPen;
static BOOL gTickerOn = FALSE;
static BOOL gTickerHide = FALSE;
static BOOL gTickerSupressHide = FALSE;
static int gLastUpdateEvent = default_event;
static BOOL gInitialized;
static RoadMapGuiRect OpenIconRct;
//static RoadMapGuiRect CloseIconRct;
static RoadMapConfigDescriptor ShowTickerCfg =
ROADMAP_CONFIG_ITEM("User", "Show points ticker");
#define TICKER_TOP_BAR_OFFSET 0
#define TICKER_TOP_BAR_DIVIDER_OFFSET 25
#define TICKER_TOP_BAR_TEXT_OFFSET 25
////////////////////////////////////////////////////////////////////////////////
static void show_close_icon(){
}
////////////////////////////////////////////////////////////////////////////////
int ticker_cfg_on (void) {
return (roadmap_config_match(&ShowTickerCfg, "yes"));
}
////////////////////////////////////////////////////////////////////////////////
void roadmap_ticker_display() {
char text[256];
char points[20];
char rank[20];
int text_width, ascent, descent;
RoadMapGuiPoint position;
RoadMapGuiPoint text_position;
int start,end, start_x;
int iMyTotalPoints;
int iMyRanking;
int text_offset_y = 25;
int point_start_x = 190;
int rank_start_x = 270;
int new_pnts_start_x = 50;
int allign;
const char * point_text = NULL;
#if (defined(__SYMBIAN32__) && defined(TOUCH_SCREEN))
text_offset_y = 22;
point_start_x = 200;
rank_start_x = 280;
new_pnts_start_x = 65;
#endif
int width = roadmap_canvas_width();
if (!gInitialized) return ;
if (!ticker_cfg_on() && !gTickerSupressHide){
gTickerOn = FALSE;
return;
}
if (gTickerHide && (!roadmap_message_format (text, sizeof(text), "%X"))){
gTickerOn = FALSE;
return;
}
if (!roadmap_message_format (text, sizeof(text), "%X|%*")) {
if (gTickerSupressHide){
roadmap_message_set('*', "%d", 0);
roadmap_message_format (text, sizeof(text), "%*");
}
else{
show_close_icon();
gTickerOn = FALSE;
return;
}
}
gTickerOn = TRUE;
roadmap_canvas_get_text_extents (text, 14, &text_width, &ascent, &descent, NULL);
roadmap_canvas_select_pen (RoadMapTickerPen);
end = roadmap_canvas_width();
start = 1;
start_x = roadmap_canvas_image_width(gImageOpen)+1;
while (start < end){
position.x = start;
position.y = roadmap_bar_top_height() + TICKER_TOP_BAR_OFFSET;
roadmap_canvas_draw_image (gMiddleImage, &position, 0, IMAGE_NORMAL);
start += roadmap_canvas_image_width(gMiddleImage);
}
position.x = 1;
if (ssd_widget_rtl(NULL)){
allign = ROADMAP_CANVAS_RIGHT;
text_position.x = roadmap_canvas_width() -4;
}
else{
allign = ROADMAP_CANVAS_LEFT;
text_position.x = 4;
}
text_position.y = roadmap_bar_top_height() + TICKER_TOP_BAR_OFFSET + 2;
roadmap_canvas_draw_string_size (&text_position,
allign |ROADMAP_CANVAS_TOP,
14,roadmap_lang_get("Your Points (updated once a day)"));
text_position.x = 4;
text_position.y = roadmap_bar_top_height() + TICKER_TOP_BAR_OFFSET + 2 +TICKER_TOP_BAR_TEXT_OFFSET;
switch( gLastUpdateEvent ) {
case default_event:
point_text = roadmap_lang_get("New points");
break;
case report_event:
point_text = roadmap_lang_get("Road report");
break;
case comment_event:
point_text = roadmap_lang_get("Event comment");
break;
case confirm_event:
point_text= roadmap_lang_get("Prompt response");
break;
case road_munching_event :
point_text= roadmap_lang_get("Road munching");
break;
case user_contribution_event :
point_text= roadmap_lang_get("Traffic detection");
break;
}
roadmap_canvas_draw_string_size (&text_position,
ROADMAP_CANVAS_LEFT|ROADMAP_CANVAS_TOP,
14,point_text);
position.y = roadmap_bar_top_height() + TICKER_TOP_BAR_DIVIDER_OFFSET;
position.x = width /3 +4 + 30;
roadmap_canvas_draw_image (gImageDivider, &position, 0, IMAGE_NORMAL);
position.y = roadmap_bar_top_height() + TICKER_TOP_BAR_DIVIDER_OFFSET;
position.x = 2*width/3+4 +15;
roadmap_canvas_draw_image (gImageDivider, &position, 0, IMAGE_NORMAL);
text_position.x = (width/3) + (width/3)/4 + 30;
text_position.y = roadmap_bar_top_height() + TICKER_TOP_BAR_OFFSET + 2 + TICKER_TOP_BAR_TEXT_OFFSET;
roadmap_canvas_draw_string_size (&text_position,
ROADMAP_CANVAS_LEFT|ROADMAP_CANVAS_TOP,
14,roadmap_lang_get("Total"));
text_position.x = (width/3) + (width/3)/4+ 30;
text_position.y = roadmap_bar_top_height() + TICKER_TOP_BAR_OFFSET + text_offset_y +TICKER_TOP_BAR_TEXT_OFFSET;
iMyTotalPoints = editor_points_get_total_points();
if (iMyTotalPoints != -1){
if (iMyTotalPoints < 10000){
sprintf(points,"%d", iMyTotalPoints);
}
else{
sprintf(points,"%dK", (int)iMyTotalPoints/1000);
}
}
else{
strcpy(points,"");
}
roadmap_canvas_draw_string_size (&text_position,
ROADMAP_CANVAS_LEFT|ROADMAP_CANVAS_TOP,
14,points);
text_position.x = width - (width/3) + (width/3)/4+ 15;
text_position.y = roadmap_bar_top_height() + TICKER_TOP_BAR_OFFSET + 2 +TICKER_TOP_BAR_TEXT_OFFSET;
iMyRanking = RealTime_GetMyRanking();
if (iMyRanking == -1)
strcpy(rank,"");
else
sprintf(rank, "%d", iMyRanking);
roadmap_canvas_draw_string_size (&text_position,
ROADMAP_CANVAS_LEFT|ROADMAP_CANVAS_TOP,
14,roadmap_lang_get("Rank"));
text_position.x = width - (width/3) + (width/3)/4+ 12;
text_position.y = roadmap_bar_top_height() + TICKER_TOP_BAR_OFFSET + text_offset_y +TICKER_TOP_BAR_TEXT_OFFSET;
roadmap_canvas_draw_string_size (&text_position,
ROADMAP_CANVAS_LEFT|ROADMAP_CANVAS_TOP,
14,rank);
if (strcmp(text,"0")){
text_position.x = new_pnts_start_x - start_x + 30;
text_position.y = roadmap_bar_top_height() + TICKER_TOP_BAR_OFFSET + text_offset_y +TICKER_TOP_BAR_TEXT_OFFSET;
roadmap_canvas_draw_string_size (&text_position,
ROADMAP_CANVAS_LEFT|ROADMAP_CANVAS_TOP,
14,"+");
text_position.x = new_pnts_start_x - start_x + 40;
text_position.y = roadmap_bar_top_height() + TICKER_TOP_BAR_OFFSET + text_offset_y +TICKER_TOP_BAR_TEXT_OFFSET;
roadmap_canvas_draw_string_size (&text_position,
ROADMAP_CANVAS_LEFT|ROADMAP_CANVAS_TOP,
14,text);
}
}
static void supress_hide(void){
gTickerSupressHide = FALSE;
if(!roadmap_screen_refresh())
roadmap_screen_redraw();
roadmap_main_remove_periodic (supress_hide);
}
static int roadmap_ticker_short_click(RoadMapGuiPoint *point) {
static RoadMapSoundList list;
if (!gInitialized) return 0 ;
if (!gTickerOn)
return 0;
if (!list) {
list = roadmap_sound_list_create (SOUND_LIST_NO_FREE);
roadmap_sound_list_add (list, "click");
roadmap_res_get (RES_SOUND, 0, "click");
}
if (gTickerOn)
if ((point->y >= (OpenIconRct.miny)) &&
(point->y <= (OpenIconRct.maxy))) {
roadmap_sound_play_list (list);
roadmap_ticker_hide();
return 1;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
static int roadmap_ticker_key_pressed (RoadMapGuiPoint *point) {
if (!gInitialized) return 0 ;
if (!gTickerOn)
return 0;
if (gTickerOn)
if (gTickerOn)
if ((point->y >= (OpenIconRct.miny)) &&
(point->y <= (OpenIconRct.maxy))) {
roadmap_pointer_cancel_dragging();
return 1;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
void roadmap_ticker_initialize(void){
gInitialized = FALSE;
roadmap_config_declare_enumeration ("user", &ShowTickerCfg, NULL, "yes", "no", NULL);
gImageOpen = (RoadMapImage) roadmap_res_get(RES_BITMAP, RES_SKIN, TICKER_OPEN_IMAGE);
if (gImageOpen == NULL){
roadmap_log (ROADMAP_ERROR, "roadmap_ticker - cannot load %s image ", TICKER_OPEN_IMAGE);
}
gImageClose = (RoadMapImage) roadmap_res_get(RES_BITMAP, RES_SKIN, TICKER_CLOSED_IMAGE);
if (gImageOpen == NULL){
roadmap_log (ROADMAP_ERROR, "roadmap_ticker - cannot load %s image ", TICKER_CLOSED_IMAGE);
return;
}
gMiddleImage = (RoadMapImage) roadmap_res_get(RES_BITMAP, RES_SKIN, TICKER_MIDDLE_IMAGE);
if (gMiddleImage == NULL){
roadmap_log (ROADMAP_ERROR, "roadmap_ticker - cannot load %s image ", TICKER_MIDDLE_IMAGE);
return;
}
gImageDivider = (RoadMapImage) roadmap_res_get(RES_BITMAP, RES_SKIN, TICKER_DIVIDER);
if (gImageDivider == NULL){
roadmap_log (ROADMAP_ERROR, "roadmap_ticker - cannot load %s image ", TICKER_DIVIDER);
}
OpenIconRct.miny = roadmap_bar_top_height() + TICKER_TOP_BAR_OFFSET;
OpenIconRct.maxy = roadmap_bar_top_height() + TICKER_TOP_BAR_OFFSET + roadmap_canvas_image_height(gMiddleImage);
RoadMapTickerPen = roadmap_canvas_create_pen ("Ticker_pen");
roadmap_canvas_set_foreground (TICKER_FOREGROUND);
show_close_icon();
roadmap_pointer_register_pressed
(roadmap_ticker_key_pressed, POINTER_HIGH);
roadmap_pointer_register_short_click(roadmap_ticker_short_click, POINTER_HIGH);
gInitialized = TRUE;
}
////////////////////////////////////////////////////////////////////////////////
int roadmap_ticker_height(){
if (!gTickerOn)
return 0;
else
return roadmap_canvas_image_height(gMiddleImage) + TICKER_TOP_BAR_OFFSET;
}
////////////////////////////////////////////////////////////////////////////////
void roadmap_ticker_hide(void){
gTickerHide = TRUE;
if (!roadmap_screen_refresh())
roadmap_screen_redraw();
}
////////////////////////////////////////////////////////////////////////////////
int roadmap_ticker_state(void){
if (gTickerOn)
return 1;
else
return 0;
}
////////////////////////////////////////////////////////////////////////////////
void roadmap_ticker_show(void){
char text[256];
gTickerHide = FALSE;
if (! roadmap_message_format (text, sizeof(text), "%*|%X")) {
roadmap_message_set('*', "%d", 0);
roadmap_ticker_set_last_event(default_event);
}
if (gTickerSupressHide)
roadmap_main_remove_periodic (supress_hide);
roadmap_main_set_periodic (15000, supress_hide);
gTickerSupressHide = TRUE;
if (!roadmap_screen_refresh())
roadmap_screen_redraw();
}
void roadmap_ticker_set_last_event(int event){
gLastUpdateEvent = event;
}