-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathroadmap_border.c
358 lines (298 loc) · 12.8 KB
/
roadmap_border.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
/* roadmap_border.c - Handle Drawing of borders
*
* 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 <math.h>
#include "roadmap.h"
#include "roadmap_types.h"
#include "roadmap_gui.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_border.h"
#include "roadmap_display.h"
#include "roadmap_device.h"
static border_image s_images[border_img__count];
static const char* get_img_filename( border_images image_id)
{
switch( image_id)
{
case border_heading_red_left: return "Header_Red_left";
case border_heading_red_right: return "Header_Red_right";
case border_heading_red_middle: return "Header_Red_Mid";
case border_heading_green_left: return "Header_Green_left";
case border_heading_green_right: return "Header_Green_right";
case border_heading_green_middle: return "Header_Green_Mid";
case border_heading_black_left: return "Header_Black_left";
case border_heading_black_right: return "Header_Black_right";
case border_heading_black_middle: return "Header_Black_Mid";
case border_heading_gray_left: return "Header_Gray_left";
case border_heading_gray_right: return "Header_Gray_right";
case border_heading_gray_middle: return "Header_Gray_Mid";
case border_image_top: return "Top";
case border_image_top_right: return "TopRight";
case border_image_top_left: return "TopLeft";
case border_image_bottom_no_frame: return "Bottom_NoFrame";
case border_image_bottom: return "Bottom";
case border_image_bottom_right: return "BottomRight";
case border_image_bottom_left: return "BottomLeft";
case border_image_left: return "Left";
case border_image_right: return "Right";
case border_white_top: return "border_white_top";
case border_white_top_right: return "border_white_top_right";
case border_white_top_left: return "border_white_top_left";
case border_white_bottom: return "border_white_bottom";
case border_white_bottom_right: return "border_white_bottom_right";
case border_white_bottom_left: return "border_white_bottom_left";
case border_white_left: return "border_white_left";
case border_white_right: return "border_white_right";
case border_black_top: return "border_black_top";
case border_black_top_right: return "border_black_top_right";
case border_black_top_left: return "border_black_top_left";
case border_black_bottom: return "border_black_bottom";
case border_black_bottom_right: return "border_black_bottom_right";
case border_black_bottom_left: return "border_black_bottom_left";
case border_black_left: return "border_black_left";
case border_black_right: return "border_black_right";
case border_pointer_comment: return "PointerComment";
case border_pointer_menu: return "PointerMenu";
// case border_pointer_balck: return "PointerBlack";
default:
break;
}
return NULL;
}
BOOL load_border_images()
{
static BOOL border_images_loaded = FALSE;
int i;
if( border_images_loaded)
return TRUE;
for( i=0; i<border_img__count; i++)
{
const char* image_filename = get_img_filename(i);
assert(NULL != image_filename);
s_images[i].image = (RoadMapImage)roadmap_res_get(
RES_BITMAP,
RES_SKIN|RES_LOCK,
image_filename);
if( !s_images[i].image)
{
roadmap_log(ROADMAP_ERROR,
"load_border_images::load_border_images() - Failed to load image file '%s.png'",
image_filename);
return FALSE;
}
s_images[i].height = roadmap_canvas_image_height(s_images[i].image);
s_images[i].width = roadmap_canvas_image_width(s_images[i].image);
}
border_images_loaded = TRUE;
return TRUE;
}
int roadmap_display_border(int style, int header, int pointer_type, RoadMapGuiPoint *bottom, RoadMapGuiPoint *top, const char* background, RoadMapPosition *position){
//static const char *fill_bg = "#f3f3f5";// "#e4f1f9";
RoadMapPen fill_pen;
int screen_width, screen_height, sign_width, sign_height;
RoadMapGuiPoint right_point, left_point, start_sides_point, point, new_point;
int i, num_items;
int count, start_pos_x, top_height;
RoadMapGuiPoint sign_bottom, sign_top;
RoadMapGuiPoint fill_points[4];
load_border_images();
screen_width = roadmap_canvas_width();
screen_height = roadmap_canvas_height();
if (top == NULL)
{
sign_top.x = 1;
sign_top.y = roadmap_bar_top_height();
}
else{
sign_top.x = top->x ;
sign_top.y = top->y ;
}
if (bottom == NULL)
{
sign_bottom.x = screen_width-1;
sign_bottom.y = screen_height - roadmap_bar_bottom_height();
}
else{
sign_bottom.x = bottom->x ;
sign_bottom.y = bottom->y ;
}
sign_width = sign_bottom.x - sign_top.x;
sign_height = sign_bottom.y - sign_top.y;
if (header != HEADER_NONE){
roadmap_canvas_draw_image (s_images[header].image, &sign_top, 0, IMAGE_NORMAL);
left_point.x = sign_top.x;
right_point.x = left_point.x + sign_width - s_images[header+2].width ;
num_items = (right_point.x - left_point.x - s_images[header].width)/s_images[header+1].width+1;
for (i = 0; i<num_items; i++){
point.x = left_point.x + s_images[header].width + i * s_images[header+1].width ;
point.y = sign_top.y;
roadmap_canvas_draw_image (s_images[header+1].image, &point, 0, IMAGE_NORMAL);
}
point.y = sign_top.y;
roadmap_canvas_draw_image (s_images[header+2].image, &point, 0, IMAGE_NORMAL);
start_sides_point.y = sign_top.y + s_images[header].height ;
top_height = s_images[header].height+7;
}
else{
#ifdef TOUCH_SCREEN
left_point.x = sign_top.x;
#else
left_point.x = sign_top.x-1;
#endif
right_point.x = sign_bottom.x - s_images[border_image_right+style].width;
start_sides_point.y = sign_top.y + s_images[border_image_top_right+style].height;
left_point.y = sign_top.y ;
roadmap_canvas_draw_image (s_images[border_image_top_left+style].image, &left_point, 0, IMAGE_NORMAL);
right_point.y = sign_top.y;
roadmap_canvas_draw_image (s_images[border_image_top_right+style].image, &right_point, 0, IMAGE_NORMAL);
num_items = (right_point.x - left_point.x - s_images[border_image_left+style].width)/s_images[border_image_top+style].width;
for (i = 0; i<num_items; i++){
point.x = left_point.x + s_images[border_image_top_left+style].width + i * s_images[border_image_top+style].width ;
point.y = left_point.y;
roadmap_canvas_draw_image (s_images[border_image_top+style].image, &point, 0, IMAGE_NORMAL);
}
top_height = s_images[border_image_top+style].height;
}
num_items = ( sign_height - start_sides_point.y +sign_top.y - s_images[border_image_bottom+style].height ) / s_images[border_image_right+style].height;
for (i = 0; i<num_items; i++){
point.x = right_point.x;
point.y = start_sides_point.y + i* s_images[border_image_right+style].height;
roadmap_canvas_draw_image (s_images[border_image_right+style].image, &point, 0, IMAGE_NORMAL);
point.x = left_point.x;
point.y = start_sides_point.y + i* s_images[border_image_left+style].height;
roadmap_canvas_draw_image (s_images[border_image_left+style].image, &point, 0, IMAGE_NORMAL);
}
left_point.y = point.y + s_images[border_image_left+style].height ;
roadmap_canvas_draw_image (s_images[border_image_bottom_left+style].image, &left_point, 0, IMAGE_NORMAL);
right_point.y = point.y + s_images[border_image_right+style].height;
roadmap_canvas_draw_image (s_images[border_image_bottom_right+style].image, &right_point, 0, IMAGE_NORMAL);
if (pointer_type == POINTER_NONE){
num_items = (right_point.x - s_images[border_image_bottom_left+style].width - left_point.x)/s_images[border_image_bottom+style].width ;
for (i = 0; i<num_items; i++){
point.x = left_point.x + s_images[border_image_bottom_left+style].width + i * s_images[border_image_bottom+style].width ;
point.y = left_point.y;
roadmap_canvas_draw_image (s_images[border_image_bottom+style].image, &point, 0, IMAGE_NORMAL);
}
}
else{
if (pointer_type == POINTER_MENU)
num_items = 1;
else if (pointer_type == POINTER_COMMNET)
num_items = ((right_point.x - left_point.x)/s_images[border_image_bottom+style].width)/4 -2;
else if (pointer_type == POINTER_POSITION)
num_items = (right_point.x - 100)/s_images[border_image_bottom+style].width;
else
num_items = ((right_point.x - left_point.x)/s_images[border_image_bottom+style].width)/2 -2;
for (i = 0; i<num_items; i++){
point.x = left_point.x + s_images[border_image_bottom_left+style].width + i * s_images[border_image_bottom+style].width ;
point.y = left_point.y;
roadmap_canvas_draw_image (s_images[border_image_bottom+style].image, &point, 0, IMAGE_NORMAL);
}
if (pointer_type == POINTER_POSITION){
int visible = roadmap_math_point_is_visible (position);
if (visible){
int count = 3;
RoadMapGuiPoint points[3];
RoadMapPen pointer_pen;
roadmap_math_coordinate (position, points);
roadmap_math_rotate_coordinates (1, points);
if (points[0].y > (point.y +10) ){
points[1].x = point.x;
points[1].y = point.y+s_images[border_image_bottom_no_frame+style].height-4;
points[2].x = point.x+40;
points[2].y = point.y+s_images[border_image_bottom_no_frame+style].height-4;
pointer_pen = roadmap_canvas_create_pen ("fill_pop_up_pen");
roadmap_canvas_set_foreground("#d2dfef");
roadmap_canvas_draw_multiple_polygons (1, &count, points, 1, 0);
roadmap_canvas_set_foreground("#ffffff");
roadmap_canvas_draw_multiple_polygons (1, &count, points, 0, 0);
point.x += 1;
for (i=0; i<39; i++){
point.x = point.x + s_images[border_image_bottom_no_frame+style].width ;
point.y = point.y;
roadmap_canvas_draw_image (s_images[border_image_bottom_no_frame+style].image, &point, 0, IMAGE_NORMAL);
}
}
}
start_pos_x = point.x+1;
}
else{
roadmap_canvas_draw_image (s_images[pointer_type].image, &point, 0, IMAGE_NORMAL);
start_pos_x = point.x + s_images[pointer_type].width;
}
num_items = (right_point.x - start_pos_x )/s_images[border_image_bottom+style].width ;
for (i = 0; i<num_items; i++){
new_point.x = start_pos_x + i * s_images[border_image_bottom+style].width ;
new_point.y = point.y;
roadmap_canvas_draw_image (s_images[border_image_bottom+style].image, &new_point, 0, IMAGE_NORMAL);
}
}
//Fill the
if (style == STYLE_NORMAL){
fill_points[0].x =right_point.x+7 ;
fill_points[0].y =point.y +7;
fill_points[1].x =right_point.x +7;
fill_points[1].y = top->y + top_height -7;
fill_points[2].x = left_point.x + s_images[border_image_left+style].width -7;
fill_points[2].y = top->y + top_height - 7;
fill_points[3].x =left_point.x + s_images[border_image_left+style].width -7;
fill_points[3].y = point.y +7;
count = 4;
}
else{
fill_points[0].x =right_point.x+2 ;
fill_points[0].y =point.y +2;
fill_points[1].x =right_point.x +2;
fill_points[1].y = top->y + top_height -2;
fill_points[2].x = left_point.x + s_images[border_image_left+style].width -2;
fill_points[2].y = top->y + top_height - 2;
fill_points[3].x =left_point.x + s_images[border_image_left+style].width -2;
fill_points[3].y = point.y +2;
count = 4;
}
fill_pen = roadmap_canvas_create_pen ("fill_pop_up_pen");
roadmap_canvas_set_foreground(background);
roadmap_canvas_draw_multiple_polygons (1, &count, fill_points, 1,0 );
return sign_width;
}
int get_heading_height(int header_type){
return s_images[header_type].height;
}
void roadmap_border_load_images(){
load_border_images();
}