1 |
|
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*- */ |
2 |
|
/* vim:set et sw=4 ts=4 cino=t0,(0: */ |
3 |
/* |
/* |
4 |
* Copyright (C) Till Harbaum 2009 <till@harbaum.org> |
* Copyright (C) Till Harbaum 2009 <till@harbaum.org> |
5 |
* |
* |
17 |
* with this program. If not, see <http://www.gnu.org/licenses/>. |
* with this program. If not, see <http://www.gnu.org/licenses/>. |
18 |
*/ |
*/ |
19 |
|
|
20 |
#include "config.h" |
#include "config.h" |
21 |
|
#include <stdlib.h> // abs |
22 |
|
#include <math.h> // M_PI/cos() |
23 |
|
|
24 |
|
/* parameters that can be overwritten from the config file: */ |
25 |
|
/* OSD_DIAMETER */ |
26 |
|
/* OSD_X, OSD_Y */ |
27 |
|
|
28 |
#ifdef USE_CAIRO |
#ifndef USE_CAIRO |
29 |
#include <cairo.h> |
#error "OSD control display lacks a non-cairo implementation!" |
30 |
#endif |
#endif |
31 |
|
|
32 |
|
#include <cairo.h> |
33 |
|
|
34 |
|
#include "osm-gps-map.h" |
35 |
|
#include "converter.h" |
36 |
|
#include "osm-gps-map-osd-classic.h" |
37 |
|
|
38 |
//the osd controls |
//the osd controls |
39 |
typedef struct { |
typedef struct { |
40 |
GdkPixmap *backup; |
/* the offscreen representation of the OSD */ |
41 |
cairo_surface_t *overlay; |
struct { |
42 |
gint backup_x, backup_y; |
cairo_surface_t *surface; |
43 |
OsmGpsMapOsdGpsCallback cb; |
gboolean rendered; |
44 |
gpointer data; |
#ifdef OSD_GPS_BUTTON |
45 |
|
gboolean gps_enabled; |
46 |
|
#endif |
47 |
|
} controls; |
48 |
|
|
49 |
|
#ifdef OSD_BALLOON |
50 |
|
//a balloon with additional info |
51 |
|
struct { |
52 |
|
cairo_surface_t *surface; |
53 |
|
|
54 |
|
float lat, lon; |
55 |
|
gboolean valid; |
56 |
|
OsmGpsMapRect_t rect; |
57 |
|
|
58 |
|
/* function called to have the user app draw the contents */ |
59 |
|
OsmGpsMapBalloonCallback cb; |
60 |
|
gpointer data; |
61 |
|
} balloon; |
62 |
|
#endif |
63 |
|
|
64 |
|
#ifdef OSD_SCALE |
65 |
|
struct { |
66 |
|
cairo_surface_t *surface; |
67 |
|
int zoom; |
68 |
|
} scale; |
69 |
|
#endif |
70 |
|
|
71 |
|
#ifdef OSD_CROSSHAIR |
72 |
|
struct { |
73 |
|
cairo_surface_t *surface; |
74 |
|
gboolean rendered; |
75 |
|
} crosshair; |
76 |
|
#endif |
77 |
|
|
78 |
|
#ifdef OSD_COORDINATES |
79 |
|
struct { |
80 |
|
cairo_surface_t *surface; |
81 |
|
float lat, lon; |
82 |
|
} coordinates; |
83 |
|
#endif |
84 |
|
|
85 |
|
#ifdef OSD_SOURCE_SEL |
86 |
|
struct { |
87 |
|
/* values to handle the "source" menu */ |
88 |
|
cairo_surface_t *surface; |
89 |
|
gboolean expanded; |
90 |
|
gint shift, dir, count; |
91 |
|
gint handler_id; |
92 |
|
gint width, height; |
93 |
|
gboolean rendered; |
94 |
|
} source_sel; |
95 |
|
#endif |
96 |
|
|
97 |
} osd_priv_t; |
} osd_priv_t; |
98 |
|
|
99 |
typedef struct { |
#ifdef OSD_BALLOON |
100 |
|
/* most visual effects are hardcoded by now, but may be made */ |
101 |
|
/* available via properties later */ |
102 |
|
#ifndef BALLOON_AREA_WIDTH |
103 |
|
#define BALLOON_AREA_WIDTH 290 |
104 |
|
#endif |
105 |
|
#ifndef BALLOON_AREA_HEIGHT |
106 |
|
#define BALLOON_AREA_HEIGHT 75 |
107 |
|
#endif |
108 |
|
#ifndef BALLOON_CORNER_RADIUS |
109 |
|
#define BALLOON_CORNER_RADIUS 10 |
110 |
|
#endif |
111 |
|
|
112 |
|
#define BALLOON_BORDER (BALLOON_CORNER_RADIUS/2) |
113 |
|
#define BALLOON_WIDTH (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER) |
114 |
|
#define BALLOON_HEIGHT (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER) |
115 |
|
#define BALLOON_TRANSPARENCY 0.8 |
116 |
|
#define POINTER_HEIGHT 20 |
117 |
|
#define POINTER_FOOT_WIDTH 20 |
118 |
|
#define POINTER_OFFSET (BALLOON_CORNER_RADIUS*3/4) |
119 |
|
#define BALLOON_SHADOW (BALLOON_CORNER_RADIUS/2) |
120 |
|
#define BALLOON_SHADOW_TRANSPARENCY 0.2 |
121 |
|
|
122 |
|
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) |
123 |
|
|
124 |
|
|
125 |
|
/* draw the bubble shape. this is used twice, once for the shape and once */ |
126 |
|
/* for the shadow */ |
127 |
|
static void |
128 |
|
osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1, |
129 |
|
gboolean bottom, int px, int py, int px0, int px1) { |
130 |
|
|
131 |
|
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
132 |
|
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
133 |
|
BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2); |
134 |
|
if(!bottom) { |
135 |
|
/* insert top pointer */ |
136 |
|
cairo_line_to (cr, px1, y0); |
137 |
|
cairo_line_to (cr, px, py); |
138 |
|
cairo_line_to (cr, px0, y0); |
139 |
|
} |
140 |
|
|
141 |
|
cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0); |
142 |
|
cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
143 |
|
BALLOON_CORNER_RADIUS, -M_PI/2, 0); |
144 |
|
cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS); |
145 |
|
cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, |
146 |
|
BALLOON_CORNER_RADIUS, 0, M_PI/2); |
147 |
|
if(bottom) { |
148 |
|
/* insert bottom pointer */ |
149 |
|
cairo_line_to (cr, px0, y1); |
150 |
|
cairo_line_to (cr, px, py); |
151 |
|
cairo_line_to (cr, px1, y1); |
152 |
|
} |
153 |
|
|
154 |
|
cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1); |
155 |
|
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, |
156 |
|
BALLOON_CORNER_RADIUS, M_PI/2, M_PI); |
157 |
|
|
158 |
|
cairo_close_path (cr); |
159 |
|
} |
160 |
|
|
161 |
|
/* xyz */ |
162 |
|
|
163 |
|
static void |
164 |
|
osd_render_balloon(osm_gps_map_osd_t *osd) { |
165 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
166 |
|
|
167 |
|
/* get zoom */ |
168 |
|
gint zoom; |
169 |
|
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
170 |
|
|
171 |
|
/* ------- convert given coordinate into screen position --------- */ |
172 |
|
gint x0, y0; |
173 |
|
osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
174 |
|
priv->balloon.lat, priv->balloon.lon, |
175 |
|
&x0, &y0); |
176 |
|
|
177 |
|
/* check position of this relative to screen center to determine */ |
178 |
|
/* pointer direction ... */ |
179 |
|
int pointer_x = x0, pointer_x0, pointer_x1; |
180 |
|
int pointer_y = y0; |
181 |
|
|
182 |
|
/* ... and calculate position */ |
183 |
|
if(x0 > osd->widget->allocation.width/2) { |
184 |
|
x0 += POINTER_OFFSET; |
185 |
|
pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
186 |
|
pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH; |
187 |
|
} else { |
188 |
|
x0 -= POINTER_OFFSET; |
189 |
|
pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
190 |
|
pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH; |
191 |
|
} |
192 |
|
|
193 |
|
gboolean bottom = FALSE; |
194 |
|
if(y0 > osd->widget->allocation.height/2) { |
195 |
|
bottom = TRUE; |
196 |
|
y0 -= BALLOON_HEIGHT + POINTER_HEIGHT; |
197 |
|
} else |
198 |
|
y0 += POINTER_HEIGHT; |
199 |
|
|
200 |
|
/* calculate bottom/right of box */ |
201 |
|
int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT; |
202 |
|
|
203 |
|
/* save balloon screen coordinates for later use */ |
204 |
|
priv->balloon.rect.x = x0 + BALLOON_BORDER; |
205 |
|
priv->balloon.rect.y = y0 + BALLOON_BORDER; |
206 |
|
priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER; |
207 |
|
priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; |
208 |
|
|
209 |
|
cairo_t *cr = cairo_create(priv->balloon.surface); |
210 |
|
|
211 |
|
/* --------- draw shadow --------------- */ |
212 |
|
osm_gps_map_draw_balloon_shape (cr, |
213 |
|
x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW, |
214 |
|
x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW, |
215 |
|
bottom, pointer_x, pointer_y, |
216 |
|
pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW); |
217 |
|
|
218 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY); |
219 |
|
cairo_fill_preserve (cr); |
220 |
|
cairo_set_source_rgba (cr, 1, 0, 0, 1.0); |
221 |
|
cairo_set_line_width (cr, 0); |
222 |
|
cairo_stroke (cr); |
223 |
|
|
224 |
|
/* --------- draw main shape ----------- */ |
225 |
|
osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1, |
226 |
|
bottom, pointer_x, pointer_y, pointer_x0, pointer_x1); |
227 |
|
|
228 |
|
cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY); |
229 |
|
cairo_fill_preserve (cr); |
230 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY); |
231 |
|
cairo_set_line_width (cr, 1); |
232 |
|
cairo_stroke (cr); |
233 |
|
|
234 |
|
|
235 |
|
/* ---------- draw close button --------- */ |
236 |
|
|
237 |
|
int cx = x1 - BALLOON_BORDER - CLOSE_BUTTON_RADIUS; |
238 |
|
int cy = y0 + BALLOON_BORDER + CLOSE_BUTTON_RADIUS; |
239 |
|
int crad = CLOSE_BUTTON_RADIUS; |
240 |
|
|
241 |
|
cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI); |
242 |
|
cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0); |
243 |
|
cairo_fill_preserve (cr); |
244 |
|
cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0); |
245 |
|
cairo_set_line_width (cr, 2); |
246 |
|
cairo_stroke(cr); |
247 |
|
|
248 |
|
cairo_set_source_rgba (cr, 1, 1, 1, 1.0); |
249 |
|
cairo_set_line_width (cr, BALLOON_CORNER_RADIUS/3.3); |
250 |
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
251 |
|
cairo_move_to (cr, cx - crad/2, cy - crad/2); |
252 |
|
cairo_line_to (cr, cx + crad/2, cy + crad/2); |
253 |
|
cairo_stroke (cr); |
254 |
|
cairo_move_to (cr, cx + crad/2, cy - crad/2); |
255 |
|
cairo_line_to (cr, cx - crad/2, cy + crad/2); |
256 |
|
cairo_stroke (cr); |
257 |
|
|
258 |
|
if (priv->balloon.cb) { |
259 |
|
/* clip in case application tries to draw in */ |
260 |
|
/* exceed of the balloon */ |
261 |
|
cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y, |
262 |
|
priv->balloon.rect.w, priv->balloon.rect.h); |
263 |
|
cairo_clip (cr); |
264 |
|
cairo_new_path (cr); /* current path is not |
265 |
|
consumed by cairo_clip() */ |
266 |
|
|
267 |
|
priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data); |
268 |
|
} |
269 |
|
|
270 |
|
cairo_destroy(cr); |
271 |
|
} |
272 |
|
|
273 |
|
#if 0 |
274 |
|
/* the user clicked into the balloons main area. handle this */ |
275 |
|
static void |
276 |
|
osm_gps_map_handle_balloon_click(OsmGpsMap *map, gint x, gint y) |
277 |
|
{ |
278 |
|
OsmGpsMapPrivate *priv = map->priv; |
279 |
|
|
280 |
|
if (!priv->balloon.valid) |
281 |
|
return; |
282 |
|
|
283 |
|
/* check if the close button was clicked */ |
284 |
|
if ((x > priv->balloon.rect.w - 2*CLOSE_BUTTON_RADIUS) && |
285 |
|
(x < priv->balloon.rect.w) && |
286 |
|
(y > 0) && (y < 2*CLOSE_BUTTON_RADIUS)) { |
287 |
|
|
288 |
|
priv->balloon.valid = FALSE; |
289 |
|
osm_gps_map_map_redraw_idle(map); |
290 |
|
} |
291 |
|
} |
292 |
|
|
293 |
|
/* return true if balloon is being displayed and if */ |
294 |
|
/* the given coordinate is within this balloon */ |
295 |
|
static gboolean |
296 |
|
osm_gps_map_in_balloon(OsmGpsMapPrivate *priv, gint x, gint y) |
297 |
|
{ |
298 |
|
return (priv->balloon.valid && |
299 |
|
(x > priv->balloon.rect.x) && |
300 |
|
(x < priv->balloon.rect.x + priv->balloon.rect.w) && |
301 |
|
(y > priv->balloon.rect.y) && |
302 |
|
(y < priv->balloon.rect.y + priv->balloon.rect.h)); |
303 |
|
} |
304 |
|
|
305 |
|
#if 0 |
306 |
|
/* don't drag if the user clicked within the balloon */ |
307 |
|
if (osm_gps_map_in_balloon(priv, |
308 |
|
event->x + EXTRA_BORDER, |
309 |
|
event->y + EXTRA_BORDER)) |
310 |
|
{ |
311 |
|
priv->drag_counter = -1; |
312 |
|
return FALSE; |
313 |
|
} |
314 |
|
|
315 |
|
#ifdef ENABLE_BALLOON |
316 |
|
/* released inside the balloon? */ |
317 |
|
if (osm_gps_map_in_balloon(priv, |
318 |
|
event->x + EXTRA_BORDER, |
319 |
|
event->y + EXTRA_BORDER)) |
320 |
|
{ |
321 |
|
osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget), |
322 |
|
event->x - priv->balloon.rect.x + EXTRA_BORDER, |
323 |
|
event->y - priv->balloon.rect.y + EXTRA_BORDER); |
324 |
|
} |
325 |
|
#endif |
326 |
|
|
327 |
|
#endif |
328 |
|
|
329 |
|
void |
330 |
|
osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
331 |
|
OsmGpsMapBalloonCallback cb, gpointer data) |
332 |
|
{ |
333 |
|
OsmGpsMapPrivate *priv; |
334 |
|
|
335 |
|
/* remove and previously installed balloon */ |
336 |
|
osm_gps_map_clear_balloon (map); |
337 |
|
|
338 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
339 |
|
priv = map->priv; |
340 |
|
|
341 |
|
priv->balloon.lat = latitude; |
342 |
|
priv->balloon.lon = longitude; |
343 |
|
priv->balloon.valid = TRUE; |
344 |
|
|
345 |
|
priv->balloon.cb = cb; |
346 |
|
priv->balloon.data = data; |
347 |
|
|
348 |
|
// this redraws the map |
349 |
|
osm_gps_map_map_redraw_idle(map); |
350 |
|
} |
351 |
|
|
352 |
|
void |
353 |
|
osm_gps_map_clear_balloon (OsmGpsMap *map) |
354 |
|
{ |
355 |
|
OsmGpsMapPrivate *priv; |
356 |
|
|
357 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
358 |
|
priv = map->priv; |
359 |
|
|
360 |
|
priv->balloon.valid = FALSE; |
361 |
|
|
362 |
|
osm_gps_map_map_redraw_idle(map); |
363 |
|
} |
364 |
|
#endif |
365 |
|
|
366 |
|
void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) { |
367 |
|
printf("request to clear balloon\n"); |
368 |
|
} |
369 |
|
|
370 |
|
void |
371 |
|
osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
372 |
|
OsmGpsMapBalloonCallback cb, gpointer data) |
373 |
|
{ |
374 |
|
printf("request to draw balloon at %f %f\n", latitude, longitude); |
375 |
|
} |
376 |
|
|
377 |
gpointer priv; |
#endif // OSD_BALLOON |
|
} osm_gps_map_osd_t; |
|
378 |
|
|
379 |
/* position and extent of bounding box */ |
/* position and extent of bounding box */ |
380 |
|
#ifndef OSD_X |
381 |
#define OSD_X (10) |
#define OSD_X (10) |
382 |
#define OSD_Y (10) |
#endif |
383 |
|
|
384 |
#define OSD_COLOR 0.5, 0.5, 1 |
#ifndef OSD_Y |
385 |
#define OSD_COLOR_DISABLED 0.8, 0.8, 0.8 |
#define OSD_Y (10) |
386 |
|
#endif |
387 |
|
|
388 |
/* parameters of the direction shape */ |
/* parameters of the direction shape */ |
389 |
#ifndef OSM_GPS_MAP_OSD_DIAMETER |
#ifndef OSD_DIAMETER |
390 |
#define D_RAD (30) // diameter of dpad |
#define D_RAD (30) // diameter of dpad |
391 |
#else |
#else |
392 |
#define D_RAD (OSM_GPS_MAP_OSD_DIAMETER) |
#define D_RAD (OSD_DIAMETER) |
393 |
#endif |
#endif |
394 |
#define D_TIP (4*D_RAD/5) // distance of arrow tip from dpad center |
#define D_TIP (4*D_RAD/5) // distance of arrow tip from dpad center |
395 |
#define D_LEN (D_RAD/4) // length of arrow |
#define D_LEN (D_RAD/4) // length of arrow |
399 |
#define Z_STEP (D_RAD/4) // distance between dpad and zoom |
#define Z_STEP (D_RAD/4) // distance between dpad and zoom |
400 |
#define Z_RAD (D_RAD/2) // radius of "caps" of zoom bar |
#define Z_RAD (D_RAD/2) // radius of "caps" of zoom bar |
401 |
|
|
402 |
|
#ifdef OSD_SHADOW_ENABLE |
403 |
/* shadow also depends on control size */ |
/* shadow also depends on control size */ |
404 |
#define OSD_SHADOW (D_RAD/6) |
#define OSD_SHADOW (D_RAD/6) |
405 |
|
#else |
406 |
|
#define OSD_SHADOW (0) |
407 |
|
#endif |
408 |
|
|
409 |
|
/* normally the GPS button is in the center of the dpad. if there's */ |
410 |
|
/* no dpad it will go into the zoom area */ |
411 |
|
#if defined(OSD_GPS_BUTTON) && defined(OSD_NO_DPAD) |
412 |
|
#define Z_GPS 1 |
413 |
|
#else |
414 |
|
#define Z_GPS 0 |
415 |
|
#endif |
416 |
|
|
417 |
/* total width and height of controls incl. shadow */ |
/* total width and height of controls incl. shadow */ |
418 |
#define OSD_W (2*D_RAD + OSD_SHADOW) |
#define OSD_W (2*D_RAD + OSD_SHADOW + Z_GPS * 2 * Z_RAD) |
419 |
|
#if !Z_GPS |
420 |
#define OSD_H (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW) |
#define OSD_H (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW) |
421 |
|
#else |
422 |
|
#define OSD_H (2*Z_RAD + OSD_SHADOW) |
423 |
|
#endif |
424 |
|
|
425 |
|
#ifdef OSD_SHADOW_ENABLE |
426 |
#define OSD_LBL_SHADOW (OSD_SHADOW/2) |
#define OSD_LBL_SHADOW (OSD_SHADOW/2) |
427 |
|
#endif |
428 |
|
|
429 |
|
#define Z_TOP ((1-Z_GPS) * (2 * D_RAD + Z_STEP)) |
430 |
|
|
|
#define Z_TOP (2 * D_RAD + Z_STEP) |
|
431 |
#define Z_MID (Z_TOP + Z_RAD) |
#define Z_MID (Z_TOP + Z_RAD) |
432 |
#define Z_BOT (Z_MID + Z_RAD) |
#define Z_BOT (Z_MID + Z_RAD) |
433 |
#define Z_LEFT (Z_RAD) |
#define Z_LEFT (Z_RAD) |
434 |
#define Z_RIGHT (2 * D_RAD - Z_RAD) |
#define Z_RIGHT (2 * D_RAD - Z_RAD + Z_GPS * 2 * Z_RAD) |
435 |
|
#define Z_CENTER ((Z_RIGHT + Z_LEFT)/2) |
436 |
|
|
437 |
/* create the cairo shape used for the zoom buttons */ |
/* create the cairo shape used for the zoom buttons */ |
438 |
static void |
static void |
439 |
osm_gps_map_osd_zoom_shape(cairo_t *cr, gint x, gint y) { |
osd_zoom_shape(cairo_t *cr, gint x, gint y) |
440 |
|
{ |
441 |
cairo_move_to (cr, x+Z_LEFT, y+Z_TOP); |
cairo_move_to (cr, x+Z_LEFT, y+Z_TOP); |
442 |
cairo_line_to (cr, x+Z_RIGHT, y+Z_TOP); |
cairo_line_to (cr, x+Z_RIGHT, y+Z_TOP); |
443 |
cairo_arc (cr, x+Z_RIGHT, y+Z_MID, Z_RAD, -M_PI/2, M_PI/2); |
cairo_arc (cr, x+Z_RIGHT, y+Z_MID, Z_RAD, -M_PI/2, M_PI/2); |
445 |
cairo_arc (cr, x+Z_LEFT, y+Z_MID, Z_RAD, M_PI/2, -M_PI/2); |
cairo_arc (cr, x+Z_LEFT, y+Z_MID, Z_RAD, M_PI/2, -M_PI/2); |
446 |
} |
} |
447 |
|
|
448 |
|
/* ------------------- color/shadow functions ----------------- */ |
449 |
|
|
450 |
|
#ifndef OSD_COLOR |
451 |
|
/* if no color has been specified we just use the gdks default colors */ |
452 |
|
static void |
453 |
|
osd_labels(cairo_t *cr, gint width, gboolean enabled, |
454 |
|
GdkColor *fg, GdkColor *disabled) { |
455 |
|
if(enabled) gdk_cairo_set_source_color(cr, fg); |
456 |
|
else gdk_cairo_set_source_color(cr, disabled); |
457 |
|
cairo_set_line_width (cr, width); |
458 |
|
} |
459 |
|
#else |
460 |
|
static void |
461 |
|
osd_labels(cairo_t *cr, gint width, gboolean enabled) { |
462 |
|
if(enabled) cairo_set_source_rgb (cr, OSD_COLOR); |
463 |
|
else cairo_set_source_rgb (cr, OSD_COLOR_DISABLED); |
464 |
|
cairo_set_line_width (cr, width); |
465 |
|
} |
466 |
|
#endif |
467 |
|
|
468 |
|
#ifdef OSD_SHADOW_ENABLE |
469 |
|
static void |
470 |
|
osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) { |
471 |
|
cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15); |
472 |
|
cairo_set_line_width (cr, width); |
473 |
|
} |
474 |
|
#endif |
475 |
|
|
476 |
|
#ifndef OSD_NO_DPAD |
477 |
/* create the cairo shape used for the dpad */ |
/* create the cairo shape used for the dpad */ |
478 |
static void |
static void |
479 |
osm_gps_map_osd_dpad_shape(cairo_t *cr, gint x, gint y) { |
osd_dpad_shape(cairo_t *cr, gint x, gint y) |
480 |
|
{ |
481 |
cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI); |
cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI); |
482 |
} |
} |
483 |
|
#endif |
484 |
|
|
485 |
|
#ifdef OSD_SHADOW_ENABLE |
486 |
|
static void |
487 |
|
osd_shape_shadow(cairo_t *cr) { |
488 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 0.2); |
489 |
|
cairo_fill (cr); |
490 |
|
cairo_stroke (cr); |
491 |
|
} |
492 |
|
#endif |
493 |
|
|
494 |
|
#ifndef OSD_COLOR |
495 |
|
/* if no color has been specified we just use the gdks default colors */ |
496 |
|
static void |
497 |
|
osd_shape(cairo_t *cr, GdkColor *bg, GdkColor *fg) { |
498 |
|
gdk_cairo_set_source_color(cr, bg); |
499 |
|
cairo_fill_preserve (cr); |
500 |
|
gdk_cairo_set_source_color(cr, fg); |
501 |
|
cairo_set_line_width (cr, 1); |
502 |
|
cairo_stroke (cr); |
503 |
|
} |
504 |
|
#else |
505 |
|
static void |
506 |
|
osd_shape(cairo_t *cr) { |
507 |
|
cairo_set_source_rgb (cr, OSD_COLOR_BG); |
508 |
|
cairo_fill_preserve (cr); |
509 |
|
cairo_set_source_rgb (cr, OSD_COLOR); |
510 |
|
cairo_set_line_width (cr, 1); |
511 |
|
cairo_stroke (cr); |
512 |
|
} |
513 |
|
#endif |
514 |
|
|
|
typedef enum { |
|
|
OSD_NONE = 0, |
|
|
OSD_BG, |
|
|
OSD_UP, |
|
|
OSD_DOWN, |
|
|
OSD_LEFT, |
|
|
OSD_RIGHT, |
|
|
OSD_IN, |
|
|
OSD_OUT, |
|
|
OSD_GPS |
|
|
} osd_button_t; |
|
515 |
|
|
516 |
static gboolean |
static gboolean |
517 |
osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad) |
osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad) |
519 |
return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad); |
return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad); |
520 |
} |
} |
521 |
|
|
522 |
|
#ifndef OSD_NO_DPAD |
523 |
/* check whether x/y is within the dpad */ |
/* check whether x/y is within the dpad */ |
524 |
static osd_button_t |
static osd_button_t |
525 |
osm_gps_map_osd_check_dpad(gint x, gint y) |
osd_check_dpad(gint x, gint y) |
526 |
{ |
{ |
527 |
/* within entire dpad circle */ |
/* within entire dpad circle */ |
528 |
if( osm_gps_map_in_circle(x, y, OSD_X + D_RAD, OSD_Y + D_RAD, D_RAD)) |
if( osm_gps_map_in_circle(x, y, D_RAD, D_RAD, D_RAD)) |
529 |
{ |
{ |
530 |
/* convert into position relative to dpads centre */ |
/* convert into position relative to dpads centre */ |
531 |
x -= (OSD_X + D_RAD); |
x -= D_RAD; |
532 |
y -= (OSD_Y + D_RAD); |
y -= D_RAD; |
533 |
|
|
534 |
|
#ifdef OSD_GPS_BUTTON |
535 |
/* check for dpad center goes here! */ |
/* check for dpad center goes here! */ |
536 |
if( osm_gps_map_in_circle(x, y, 0, 0, D_RAD/3)) |
if( osm_gps_map_in_circle(x, y, 0, 0, D_RAD/3)) |
537 |
return OSD_GPS; |
return OSD_GPS; |
538 |
|
#endif |
539 |
|
|
540 |
if( y < 0 && abs(x) < abs(y)) |
if( y < 0 && abs(x) < abs(y)) |
541 |
return OSD_UP; |
return OSD_UP; |
553 |
} |
} |
554 |
return OSD_NONE; |
return OSD_NONE; |
555 |
} |
} |
556 |
|
#endif |
557 |
|
|
558 |
/* check whether x/y is within the zoom pads */ |
/* check whether x/y is within the zoom pads */ |
559 |
static osd_button_t |
static osd_button_t |
560 |
osm_gps_map_osd_check_zoom(gint x, gint y) { |
osd_check_zoom(gint x, gint y) { |
561 |
if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < (OSD_Y+Z_BOT)) { |
if( x > 0 && x < OSD_W && y > Z_TOP && y < Z_BOT) { |
562 |
|
|
563 |
/* within circle around (-) label */ |
/* within circle around (-) label */ |
564 |
if( osm_gps_map_in_circle(x, y, OSD_X + Z_LEFT, OSD_Y + Z_MID, Z_RAD)) |
if( osm_gps_map_in_circle(x, y, Z_LEFT, Z_MID, Z_RAD)) |
|
return OSD_OUT; |
|
|
|
|
|
/* between center of (-) button and center of entire zoom control area */ |
|
|
if(x > OSD_LEFT && x < OSD_X + D_RAD) |
|
565 |
return OSD_OUT; |
return OSD_OUT; |
566 |
|
|
567 |
/* within circle around (+) label */ |
/* within circle around (+) label */ |
568 |
if( osm_gps_map_in_circle(x, y, OSD_X + Z_RIGHT, OSD_Y + Z_MID, Z_RAD)) |
if( osm_gps_map_in_circle(x, y, Z_RIGHT, Z_MID, Z_RAD)) |
569 |
return OSD_IN; |
return OSD_IN; |
570 |
|
|
571 |
|
#if Z_GPS == 1 |
572 |
|
/* within square around center */ |
573 |
|
if( x > Z_CENTER - Z_RAD && x < Z_CENTER + Z_RAD) |
574 |
|
return OSD_GPS; |
575 |
|
#endif |
576 |
|
|
577 |
|
/* between center of (-) button and center of entire zoom control area */ |
578 |
|
if(x > OSD_LEFT && x < D_RAD) |
579 |
|
return OSD_OUT; |
580 |
|
|
581 |
/* between center of (+) button and center of entire zoom control area */ |
/* between center of (+) button and center of entire zoom control area */ |
582 |
if(x < OSD_RIGHT && x > OSD_X + D_RAD) |
if(x < OSD_RIGHT && x > D_RAD) |
583 |
return OSD_IN; |
return OSD_IN; |
584 |
} |
} |
585 |
|
|
586 |
return OSD_NONE; |
return OSD_NONE; |
587 |
} |
} |
588 |
|
|
589 |
static osd_button_t |
#ifdef OSD_SOURCE_SEL |
|
osm_gps_map_osd_check(gint x, gint y) { |
|
|
osd_button_t but = OSD_NONE; |
|
590 |
|
|
591 |
/* first do a rough test for the OSD area. */ |
/* place source selection at right border */ |
592 |
/* this is just to avoid an unnecessary detailed test */ |
#define OSD_S_RAD (Z_RAD) |
593 |
if(x > OSD_X && x < OSD_X + OSD_W && |
#define OSD_S_X (-OSD_X) |
594 |
y > OSD_Y && y < OSD_Y + OSD_H) { |
#define OSD_S_Y (OSD_Y) |
595 |
but = osm_gps_map_osd_check_dpad(x, y); |
#define OSD_S_PW (2 * Z_RAD) |
596 |
|
#define OSD_S_W (OSD_S_PW) |
597 |
|
#define OSD_S_PH (2 * Z_RAD) |
598 |
|
#define OSD_S_H (OSD_S_PH + OSD_SHADOW) |
599 |
|
|
600 |
|
/* size of usable area when expanded */ |
601 |
|
#define OSD_S_AREA_W (priv->source_sel.width) |
602 |
|
#define OSD_S_AREA_H (priv->source_sel.height) |
603 |
|
#define OSD_S_EXP_W (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW) |
604 |
|
#define OSD_S_EXP_H (OSD_S_AREA_H + OSD_SHADOW) |
605 |
|
|
606 |
|
/* internal value to draw the arrow on the "puller" */ |
607 |
|
#define OSD_S_D0 (OSD_S_RAD/2) |
608 |
|
#ifndef OSD_FONT_SIZE |
609 |
|
#define OSD_FONT_SIZE 16.0 |
610 |
|
#endif |
611 |
|
#define OSD_TEXT_BORDER (OSD_FONT_SIZE/2) |
612 |
|
#define OSD_TEXT_SKIP (OSD_FONT_SIZE/8) |
613 |
|
|
614 |
if(but == OSD_NONE) |
/* draw the shape of the source selection OSD, either only the puller (not expanded) */ |
615 |
but = osm_gps_map_osd_check_zoom(x, y); |
/* or the entire menu incl. the puller (expanded) */ |
616 |
|
static void |
617 |
|
osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) { |
618 |
|
if(!priv->source_sel.expanded) { |
619 |
|
/* just draw the puller */ |
620 |
|
cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH); |
621 |
|
cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); |
622 |
|
cairo_line_to (cr, x + OSD_S_PW, y); |
623 |
|
} else { |
624 |
|
/* draw the puller and the area itself */ |
625 |
|
cairo_move_to (cr, x + OSD_S_PW + OSD_S_AREA_W, y + OSD_S_AREA_H); |
626 |
|
cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_AREA_H); |
627 |
|
if(OSD_S_Y > 0) { |
628 |
|
cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_PH); |
629 |
|
cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); |
630 |
|
} else { |
631 |
|
cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_AREA_H-OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); |
632 |
|
cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_AREA_H - OSD_S_PH); |
633 |
|
cairo_line_to (cr, x + OSD_S_PW, y); |
634 |
|
} |
635 |
|
cairo_line_to (cr, x + OSD_S_PW + OSD_S_AREA_W, y); |
636 |
|
cairo_close_path (cr); |
637 |
} |
} |
|
|
|
|
return but; |
|
638 |
} |
} |
639 |
|
|
640 |
static void |
static void |
641 |
osm_gps_map_osd_shape_shadow(cairo_t *cr) { |
osd_source_content(osm_gps_map_osd_t *osd, cairo_t *cr, gint offset) { |
642 |
cairo_set_source_rgba (cr, 0, 0, 0, 0.2); |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
|
cairo_fill (cr); |
|
|
cairo_stroke (cr); |
|
|
} |
|
643 |
|
|
644 |
static void |
int py = offset + OSD_S_RAD - OSD_S_D0; |
|
osm_gps_map_osd_shape(cairo_t *cr) { |
|
|
cairo_set_source_rgb (cr, 1, 1, 1); |
|
|
cairo_fill_preserve (cr); |
|
|
cairo_set_source_rgb (cr, OSD_COLOR); |
|
|
cairo_set_line_width (cr, 1); |
|
|
cairo_stroke (cr); |
|
|
} |
|
645 |
|
|
646 |
static void |
if(!priv->source_sel.expanded) { |
647 |
osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) { |
/* draw the "puller" open (<) arrow */ |
648 |
/* move reference to dpad center */ |
cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py); |
649 |
x += D_RAD; |
cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); |
650 |
y += D_RAD; |
cairo_rel_line_to (cr, +OSD_S_D0, +OSD_S_D0); |
651 |
|
} else { |
652 |
|
if(OSD_S_Y < 0) |
653 |
|
py += OSD_S_AREA_H - OSD_S_PH; |
654 |
|
|
655 |
|
/* draw the "puller" close (>) arrow */ |
656 |
|
cairo_move_to (cr, offset + OSD_S_RAD - OSD_S_D0/2, py); |
657 |
|
cairo_rel_line_to (cr, +OSD_S_D0, +OSD_S_D0); |
658 |
|
cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); |
659 |
|
cairo_stroke(cr); |
660 |
|
|
661 |
|
/* don't draw a shadow for the text content */ |
662 |
|
if(offset == 1) { |
663 |
|
gint source; |
664 |
|
g_object_get(osd->widget, "map-source", &source, NULL); |
665 |
|
|
666 |
|
cairo_select_font_face (cr, "Sans", |
667 |
|
CAIRO_FONT_SLANT_NORMAL, |
668 |
|
CAIRO_FONT_WEIGHT_BOLD); |
669 |
|
cairo_set_font_size (cr, OSD_FONT_SIZE); |
670 |
|
|
671 |
|
int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) / |
672 |
|
OSM_GPS_MAP_SOURCE_LAST; |
673 |
|
for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) { |
674 |
|
cairo_text_extents_t extents; |
675 |
|
const char *src = osm_gps_map_source_get_friendly_name(i); |
676 |
|
cairo_text_extents (cr, src, &extents); |
677 |
|
|
678 |
|
int x = offset + OSD_S_PW + OSD_TEXT_BORDER; |
679 |
|
int y = offset + step * (i-1) + OSD_TEXT_BORDER; |
680 |
|
|
681 |
|
/* draw filled rectangle if selected */ |
682 |
|
if(source == i) { |
683 |
|
cairo_rectangle(cr, x - OSD_TEXT_BORDER/2, |
684 |
|
y - OSD_TEXT_SKIP, |
685 |
|
priv->source_sel.width - OSD_TEXT_BORDER, |
686 |
|
step + OSD_TEXT_SKIP); |
687 |
|
cairo_fill(cr); |
688 |
|
|
689 |
|
/* temprarily draw with background color */ |
690 |
|
#ifndef OSD_COLOR |
691 |
|
GdkColor bg = osd->widget->style->bg[GTK_STATE_NORMAL]; |
692 |
|
gdk_cairo_set_source_color(cr, &bg); |
693 |
|
#else |
694 |
|
cairo_set_source_rgb (cr, OSD_COLOR_BG); |
695 |
|
#endif |
696 |
|
} |
697 |
|
|
698 |
const static gint offset[][3][2] = { |
cairo_move_to (cr, x, y + OSD_TEXT_SKIP - extents.y_bearing); |
699 |
/* left arrow/triangle */ |
cairo_show_text (cr, src); |
|
{ { -D_TIP+D_LEN, -D_WID }, { -D_LEN, D_WID }, { +D_LEN, D_WID } }, |
|
|
/* right arrow/triangle */ |
|
|
{ { +D_TIP-D_LEN, -D_WID }, { +D_LEN, D_WID }, { -D_LEN, D_WID } }, |
|
|
/* top arrow/triangle */ |
|
|
{ { -D_WID, -D_TIP+D_LEN }, { D_WID, -D_LEN }, { D_WID, +D_LEN } }, |
|
|
/* bottom arrow/triangle */ |
|
|
{ { -D_WID, +D_TIP-D_LEN }, { D_WID, +D_LEN }, { D_WID, -D_LEN } } |
|
|
}; |
|
700 |
|
|
701 |
int i; |
/* restore color */ |
702 |
for(i=0;i<4;i++) { |
if(source == i) { |
703 |
cairo_move_to (cr, x + offset[i][0][0], y + offset[i][0][1]); |
#ifndef OSD_COLOR |
704 |
cairo_rel_line_to (cr, offset[i][1][0], offset[i][1][1]); |
GdkColor fg = osd->widget->style->fg[GTK_STATE_NORMAL]; |
705 |
cairo_rel_line_to (cr, offset[i][2][0], offset[i][2][1]); |
gdk_cairo_set_source_color(cr, &fg); |
706 |
|
#else |
707 |
|
cairo_set_source_rgb (cr, OSD_COLOR); |
708 |
|
#endif |
709 |
|
} |
710 |
|
} |
711 |
|
} |
712 |
} |
} |
713 |
} |
} |
714 |
|
|
|
/* draw the sattelite dish icon in the center of the dpad */ |
|
|
#define GPS_V0 (D_RAD/8) |
|
|
#define GPS_V1 (D_RAD/10) |
|
|
#define GPS_V2 (D_RAD/5) |
|
|
|
|
|
/* draw a satellite receiver dish */ |
|
715 |
static void |
static void |
716 |
osm_gps_map_osd_dpad_gps(cairo_t *cr, gint x, gint y) { |
osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) { |
717 |
/* move reference to dpad center */ |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
|
x += D_RAD; |
|
|
y += D_RAD + GPS_V0; |
|
718 |
|
|
719 |
cairo_move_to (cr, x-GPS_V0, y+GPS_V0); |
if(priv->source_sel.rendered && !force_rerender) |
720 |
cairo_rel_line_to (cr, +GPS_V0, -GPS_V0); |
return; |
|
cairo_rel_line_to (cr, +GPS_V0, +GPS_V0); |
|
|
cairo_close_path (cr); |
|
721 |
|
|
722 |
cairo_move_to (cr, x+GPS_V1-GPS_V2, y-2*GPS_V2); |
priv->source_sel.rendered = TRUE; |
|
cairo_curve_to (cr, x-GPS_V2, y, x+GPS_V1, y+GPS_V1, x+GPS_V1+GPS_V2, y); |
|
|
cairo_close_path (cr); |
|
723 |
|
|
724 |
x += GPS_V1; |
#ifndef OSD_COLOR |
725 |
cairo_move_to (cr, x, y-GPS_V2); |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
726 |
cairo_rel_line_to (cr, +GPS_V1, -GPS_V1); |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
727 |
} |
GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE]; |
728 |
|
#endif |
729 |
|
|
730 |
#define Z_LEN (2*Z_RAD/3) |
/* draw source selector */ |
731 |
|
cairo_t *cr = cairo_create(priv->source_sel.surface); |
732 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
733 |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
734 |
|
cairo_paint(cr); |
735 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
736 |
|
|
737 |
static void |
#ifdef OSD_SHADOW_ENABLE |
738 |
osm_gps_map_osd_zoom_labels(cairo_t *cr, gint x, gint y) { |
osd_source_shape(priv, cr, 1+OSD_SHADOW, 1+OSD_SHADOW); |
739 |
cairo_move_to (cr, x + Z_LEFT - Z_LEN, y + Z_MID); |
osd_shape_shadow(cr); |
740 |
cairo_line_to (cr, x + Z_LEFT + Z_LEN, y + Z_MID); |
#endif |
741 |
|
|
742 |
cairo_move_to (cr, x + Z_RIGHT, y + Z_MID - Z_LEN); |
osd_source_shape(priv, cr, 1, 1); |
743 |
cairo_line_to (cr, x + Z_RIGHT, y + Z_MID + Z_LEN); |
#ifndef OSD_COLOR |
744 |
cairo_move_to (cr, x + Z_RIGHT - Z_LEN, y + Z_MID); |
osd_shape(cr, &bg, &fg); |
745 |
cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); |
#else |
746 |
} |
osd_shape(cr); |
747 |
|
#endif |
748 |
|
|
749 |
static void |
#ifdef OSD_SHADOW_ENABLE |
750 |
osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) { |
osd_labels_shadow(cr, Z_RAD/3, TRUE); |
751 |
if(enabled) cairo_set_source_rgb (cr, OSD_COLOR); |
osd_source_content(osd, cr, 1+OSD_LBL_SHADOW); |
|
else cairo_set_source_rgb (cr, OSD_COLOR_DISABLED); |
|
|
cairo_set_line_width (cr, width); |
|
752 |
cairo_stroke (cr); |
cairo_stroke (cr); |
753 |
} |
#endif |
754 |
|
#ifndef OSD_COLOR |
755 |
static void |
osd_labels(cr, Z_RAD/3, TRUE, &fg, &da); |
756 |
osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) { |
#else |
757 |
cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15); |
osd_labels(cr, Z_RAD/3, TRUE); |
758 |
cairo_set_line_width (cr, width); |
#endif |
759 |
|
osd_source_content(osd, cr, 1); |
760 |
cairo_stroke (cr); |
cairo_stroke (cr); |
761 |
|
|
762 |
|
cairo_destroy(cr); |
763 |
} |
} |
764 |
|
|
765 |
|
/* re-allocate the buffer used to draw the menu. This is used */ |
766 |
|
/* to collapse/expand the buffer */ |
767 |
static void |
static void |
768 |
osm_gps_map_osd_render(OsmGpsMapPrivate *priv) { |
osd_source_reallocate(osm_gps_map_osd_t *osd) { |
769 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
770 |
|
|
771 |
/* first fill with transparency */ |
/* re-allocate offscreen bitmap */ |
772 |
cairo_t *cr = cairo_create(priv->osd.overlay); |
g_assert (priv->source_sel.surface); |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
|
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
|
|
cairo_paint(cr); |
|
773 |
|
|
774 |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
int w = OSD_S_W, h = OSD_S_H; |
775 |
|
if(priv->source_sel.expanded) { |
776 |
|
cairo_text_extents_t extents; |
777 |
|
|
778 |
|
/* determine content size */ |
779 |
|
cairo_t *cr = cairo_create(priv->source_sel.surface); |
780 |
|
cairo_select_font_face (cr, "Sans", |
781 |
|
CAIRO_FONT_SLANT_NORMAL, |
782 |
|
CAIRO_FONT_WEIGHT_BOLD); |
783 |
|
cairo_set_font_size (cr, OSD_FONT_SIZE); |
784 |
|
|
785 |
|
/* calculate menu size */ |
786 |
|
int i, max_h = 0, max_w = 0; |
787 |
|
for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) { |
788 |
|
const char *src = osm_gps_map_source_get_friendly_name(i); |
789 |
|
cairo_text_extents (cr, src, &extents); |
790 |
|
|
791 |
/* --------- draw zoom and dpad shape shadow ----------- */ |
if(extents.width > max_w) max_w = extents.width; |
792 |
gint x = 0, y = 0; |
if(extents.height > max_h) max_h = extents.height; |
793 |
|
} |
794 |
|
cairo_destroy(cr); |
795 |
|
|
796 |
|
priv->source_sel.width = max_w + 2*OSD_TEXT_BORDER; |
797 |
|
priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST * |
798 |
|
(max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER; |
799 |
|
|
800 |
|
w = OSD_S_EXP_W; |
801 |
|
h = OSD_S_EXP_H; |
802 |
|
} |
803 |
|
|
804 |
|
cairo_surface_destroy(priv->source_sel.surface); |
805 |
|
priv->source_sel.surface = |
806 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
807 |
|
|
808 |
|
osd_render_source_sel(osd, TRUE); |
809 |
|
} |
810 |
|
|
811 |
|
#define OSD_HZ 15 |
812 |
|
#define OSD_TIME 500 |
813 |
|
|
814 |
|
static gboolean osd_source_animate(gpointer data) { |
815 |
|
osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data; |
816 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
817 |
|
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
818 |
|
gboolean done = FALSE; |
819 |
|
priv->source_sel.count += priv->source_sel.dir; |
820 |
|
|
821 |
|
/* shifting in */ |
822 |
|
if(priv->source_sel.dir < 0) { |
823 |
|
if(priv->source_sel.count <= 0) { |
824 |
|
priv->source_sel.count = 0; |
825 |
|
done = TRUE; |
826 |
|
} |
827 |
|
} else { |
828 |
|
if(priv->source_sel.count >= 1000) { |
829 |
|
priv->source_sel.expanded = FALSE; |
830 |
|
osd_source_reallocate(osd); |
831 |
|
|
832 |
osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW); |
priv->source_sel.count = 1000; |
833 |
osm_gps_map_osd_shape_shadow(cr); |
done = TRUE; |
834 |
osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW); |
} |
835 |
osm_gps_map_osd_shape_shadow(cr); |
} |
836 |
|
|
|
/* --------- draw zoom and dpad shape ----------- */ |
|
837 |
|
|
838 |
osm_gps_map_osd_zoom_shape(cr, x, y); |
/* count runs linearly from 0 to 1000, map this nicely onto a position */ |
|
osm_gps_map_osd_shape(cr); |
|
|
osm_gps_map_osd_dpad_shape(cr, x, y); |
|
|
osm_gps_map_osd_shape(cr); |
|
839 |
|
|
840 |
/* --------- draw zoom and dpad labels --------- */ |
/* nice sinoid mapping */ |
841 |
|
float m = 0.5-cos(priv->source_sel.count * M_PI / 1000.0)/2; |
842 |
|
priv->source_sel.shift = |
843 |
|
(osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
844 |
|
m * diff; |
845 |
|
|
846 |
osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
/* make sure the screen is updated */ |
847 |
osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
848 |
osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE); |
|
849 |
osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
/* stop animation if done */ |
850 |
osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, priv->osd.cb != NULL); |
if(done) |
851 |
|
priv->source_sel.handler_id = 0; |
852 |
osm_gps_map_osd_zoom_labels(cr, x, y); |
|
853 |
osm_gps_map_osd_dpad_labels(cr, x, y); |
return !done; |
|
osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE); |
|
|
osm_gps_map_osd_dpad_gps(cr, x, y); |
|
|
osm_gps_map_osd_labels(cr, Z_RAD/6, priv->osd.cb != NULL); |
|
|
|
|
|
cairo_destroy(cr); |
|
854 |
} |
} |
855 |
|
|
856 |
|
/* switch between expand and collapse mode of source selection */ |
857 |
static void |
static void |
858 |
osm_gps_map_osd_draw_controls (OsmGpsMap *map, gint xoffset, gint yoffset) |
osd_source_toggle(osm_gps_map_osd_t *osd) |
859 |
{ |
{ |
860 |
OsmGpsMapPrivate *priv = map->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
|
|
|
|
/* backup previous contents */ |
|
|
if(!priv->osd.backup) |
|
|
priv->osd.backup = gdk_pixmap_new(priv->pixmap, OSD_W+2, OSD_H+2, -1); |
|
861 |
|
|
862 |
gint x = OSD_X + EXTRA_BORDER + xoffset; |
/* ignore clicks while animation is running */ |
863 |
gint y = OSD_Y + EXTRA_BORDER + yoffset; |
if(priv->source_sel.handler_id) |
864 |
|
return; |
865 |
|
|
866 |
/* create backup of background */ |
/* expand immediately, collapse is handle at the end of the */ |
867 |
gdk_draw_drawable(priv->osd.backup, |
/* collapse animation */ |
868 |
GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))], |
if(!priv->source_sel.expanded) { |
869 |
priv->pixmap, x-1, y-1, 0, 0, OSD_W+2, OSD_H+2); |
priv->source_sel.expanded = TRUE; |
870 |
|
osd_source_reallocate(osd); |
871 |
|
|
872 |
|
priv->source_sel.count = 1000; |
873 |
|
priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W; |
874 |
|
priv->source_sel.dir = -1000/OSD_HZ; |
875 |
|
} else { |
876 |
|
priv->source_sel.count = 0; |
877 |
|
priv->source_sel.shift = osd->widget->allocation.width - |
878 |
|
OSD_S_EXP_W + OSD_S_X; |
879 |
|
priv->source_sel.dir = +1000/OSD_HZ; |
880 |
|
} |
881 |
|
|
882 |
|
/* start timer to handle animation */ |
883 |
|
priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, |
884 |
|
osd_source_animate, osd); |
885 |
|
} |
886 |
|
|
887 |
priv->osd.backup_x = x-1; |
/* check if the user clicked inside the source selection area */ |
888 |
priv->osd.backup_y = y-1; |
static osd_button_t |
889 |
|
osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
890 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
891 |
|
|
892 |
|
if(!priv->source_sel.expanded) |
893 |
|
x -= osd->widget->allocation.width - OSD_S_W; |
894 |
|
else |
895 |
|
x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
896 |
|
|
897 |
#ifdef USE_CAIRO |
if(OSD_S_Y > 0) |
898 |
/* OSD itself uses some off-screen rendering, so check if the */ |
y -= OSD_S_Y; |
899 |
/* offscreen buffer is present and create it if not */ |
else |
900 |
if(!priv->osd.overlay) { |
y -= osd->widget->allocation.height - OSD_S_PH + OSD_S_Y; |
901 |
/* create overlay ... */ |
|
902 |
priv->osd.overlay = |
/* within square around puller? */ |
903 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H); |
if(y > 0 && y < OSD_S_PH && x > 0 && x < OSD_S_PW) { |
904 |
/* ... and render it */ |
/* really within puller shape? */ |
905 |
osm_gps_map_osd_render(priv); |
if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) { |
906 |
|
/* expand source selector */ |
907 |
|
osd_source_toggle(osd); |
908 |
|
|
909 |
|
/* tell upper layers that user clicked some background element */ |
910 |
|
/* of the OSD */ |
911 |
|
return OSD_BG; |
912 |
|
} |
913 |
} |
} |
914 |
|
|
915 |
// now draw this onto the original context |
/* check for clicks into data area */ |
916 |
cairo_t *cr = gdk_cairo_create(priv->pixmap); |
if(priv->source_sel.expanded && !priv->source_sel.handler_id) { |
917 |
cairo_set_source_surface(cr, priv->osd.overlay, x, y); |
/* re-adjust from puller top to content top */ |
918 |
cairo_paint(cr); |
if(OSD_S_Y < 0) |
919 |
cairo_destroy(cr); |
y += OSD_S_EXP_H - OSD_S_PH; |
920 |
|
|
921 |
#else |
if(x > OSD_S_PW && |
922 |
#warning "OSD control display lacks a non-cairo implementation!" |
x < OSD_S_PW + OSD_S_EXP_W && |
923 |
#endif |
y > 0 && |
924 |
} |
y < OSD_S_EXP_H) { |
925 |
|
|
926 |
static void |
int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) |
927 |
osm_gps_map_osd_restore (OsmGpsMap *map) |
/ OSM_GPS_MAP_SOURCE_LAST; |
928 |
{ |
|
929 |
OsmGpsMapPrivate *priv = map->priv; |
y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP; |
930 |
|
y /= step; |
931 |
|
y += 1; |
932 |
|
|
933 |
|
gint old = 0; |
934 |
|
g_object_get(osd->widget, "map-source", &old, NULL); |
935 |
|
|
936 |
|
if(y > OSM_GPS_MAP_SOURCE_NULL && |
937 |
|
y <= OSM_GPS_MAP_SOURCE_LAST && |
938 |
|
old != y) { |
939 |
|
g_object_set(osd->widget, "map-source", y, NULL); |
940 |
|
|
941 |
|
osd_render_source_sel(osd, TRUE); |
942 |
|
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
943 |
|
} |
944 |
|
|
945 |
/* restore backup of previous contents */ |
/* return "clicked in OSD background" to prevent further */ |
946 |
if(priv->osd.backup) { |
/* processing by application */ |
947 |
/* create backup of background */ |
return OSD_BG; |
948 |
gdk_draw_drawable(priv->pixmap, |
} |
|
GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))], |
|
|
priv->osd.backup, 0, 0, |
|
|
priv->osd.backup_x, priv->osd.backup_y, OSD_W+2, OSD_H+2); |
|
949 |
} |
} |
950 |
|
|
951 |
|
return OSD_NONE; |
952 |
} |
} |
953 |
|
#endif // OSD_SOURCE_SEL |
954 |
|
|
955 |
#endif |
static osd_button_t |
956 |
|
osd_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
957 |
|
osd_button_t but = OSD_NONE; |
958 |
|
|
959 |
static gboolean |
#ifdef OSD_SOURCE_SEL |
960 |
osm_gps_map_map_redraw (OsmGpsMap *map) |
/* the source selection area is handles internally */ |
961 |
{ |
but = osd_source_check(osd, x, y); |
962 |
OsmGpsMapPrivate *priv = map->priv; |
if(but != OSD_NONE) |
963 |
|
return but; |
964 |
|
#endif |
965 |
|
|
966 |
priv->idle_map_redraw = 0; |
x -= OSD_X; |
967 |
|
y -= OSD_Y; |
968 |
|
|
969 |
/* the motion_notify handler uses priv->pixmap to redraw the area; if we |
if(OSD_X < 0) |
970 |
* change it while we are dragging, we will end up showing it in the wrong |
x -= (osd->widget->allocation.width - OSD_W); |
|
* place. This could be fixed by carefully recompute the coordinates, but |
|
|
* for now it's easier just to disable redrawing the map while dragging */ |
|
|
if (priv->dragging) |
|
|
return FALSE; |
|
971 |
|
|
972 |
priv->redraw_cycle++; |
if(OSD_Y < 0) |
973 |
|
y -= (osd->widget->allocation.height - OSD_H); |
974 |
|
|
975 |
/* draw white background to initialise pixmap */ |
/* first do a rough test for the OSD area. */ |
976 |
gdk_draw_rectangle ( |
/* this is just to avoid an unnecessary detailed test */ |
977 |
priv->pixmap, |
if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) { |
978 |
GTK_WIDGET(map)->style->white_gc, |
#ifndef OSD_NO_DPAD |
979 |
TRUE, |
but = osd_check_dpad(x, y); |
|
0, 0, |
|
|
GTK_WIDGET(map)->allocation.width + EXTRA_BORDER * 2, |
|
|
GTK_WIDGET(map)->allocation.height + EXTRA_BORDER * 2); |
|
|
|
|
|
osm_gps_map_fill_tiles_pixel(map); |
|
|
|
|
|
osm_gps_map_print_tracks(map); |
|
|
osm_gps_map_draw_gps_point(map); |
|
|
osm_gps_map_print_images(map); |
|
|
#ifdef ENABLE_BALLOON |
|
|
osm_gps_map_draw_balloon_int(map); |
|
|
#endif |
|
|
#ifdef ENABLE_OSD |
|
|
osm_gps_map_osd_draw_controls(map, 0, 0); |
|
980 |
#endif |
#endif |
981 |
|
|
982 |
//osm_gps_map_osd_speed(map, 1.5); |
if(but == OSD_NONE) |
983 |
osm_gps_map_purge_cache(map); |
but = osd_check_zoom(x, y); |
984 |
gtk_widget_queue_draw (GTK_WIDGET (map)); |
} |
|
|
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
static void |
|
|
osm_gps_map_map_redraw_idle (OsmGpsMap *map) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv = map->priv; |
|
985 |
|
|
986 |
if (priv->idle_map_redraw == 0) |
return but; |
|
priv->idle_map_redraw = g_idle_add ((GSourceFunc)osm_gps_map_map_redraw, map); |
|
987 |
} |
} |
988 |
|
|
989 |
|
#ifndef OSD_NO_DPAD |
990 |
static void |
static void |
991 |
osm_gps_map_init (OsmGpsMap *object) |
osd_dpad_labels(cairo_t *cr, gint x, gint y) { |
992 |
{ |
/* move reference to dpad center */ |
993 |
OsmGpsMapPrivate *priv; |
x += D_RAD; |
994 |
|
y += D_RAD; |
|
priv = G_TYPE_INSTANCE_GET_PRIVATE (object, OSM_TYPE_GPS_MAP, OsmGpsMapPrivate); |
|
|
object->priv = priv; |
|
|
|
|
|
priv->pixmap = NULL; |
|
|
|
|
|
priv->trip_history = NULL; |
|
|
priv->gps = g_new0(coord_t, 1); |
|
|
priv->gps_valid = FALSE; |
|
995 |
|
|
996 |
#ifdef ENABLE_BALLOON |
const static gint offset[][3][2] = { |
997 |
priv->balloon.coo = g_new0(coord_t, 1); |
/* left arrow/triangle */ |
998 |
priv->balloon.valid = FALSE; |
{ { -D_TIP+D_LEN, -D_WID }, { -D_LEN, D_WID }, { +D_LEN, D_WID } }, |
999 |
priv->balloon.cb = NULL; |
/* right arrow/triangle */ |
1000 |
#endif |
{ { +D_TIP-D_LEN, -D_WID }, { +D_LEN, D_WID }, { -D_LEN, D_WID } }, |
1001 |
|
/* top arrow/triangle */ |
1002 |
|
{ { -D_WID, -D_TIP+D_LEN }, { D_WID, -D_LEN }, { D_WID, +D_LEN } }, |
1003 |
|
/* bottom arrow/triangle */ |
1004 |
|
{ { -D_WID, +D_TIP-D_LEN }, { D_WID, +D_LEN }, { D_WID, -D_LEN } } |
1005 |
|
}; |
1006 |
|
|
1007 |
#ifdef ENABLE_OSD |
int i; |
1008 |
priv->osd.backup = NULL; |
for(i=0;i<4;i++) { |
1009 |
priv->osd.overlay = NULL; |
cairo_move_to (cr, x + offset[i][0][0], y + offset[i][0][1]); |
1010 |
priv->osd.cb = NULL; |
cairo_rel_line_to (cr, offset[i][1][0], offset[i][1][1]); |
1011 |
|
cairo_rel_line_to (cr, offset[i][2][0], offset[i][2][1]); |
1012 |
|
} |
1013 |
|
} |
1014 |
#endif |
#endif |
1015 |
|
|
1016 |
priv->tracks = NULL; |
#ifdef OSD_GPS_BUTTON |
1017 |
priv->images = NULL; |
/* draw the satellite dish icon in the center of the dpad */ |
1018 |
|
#define GPS_V0 (D_RAD/7) |
1019 |
|
#define GPS_V1 (D_RAD/10) |
1020 |
|
#define GPS_V2 (D_RAD/5) |
1021 |
|
|
1022 |
priv->drag_counter = 0; |
/* draw a satellite receiver dish */ |
1023 |
priv->drag_mouse_dx = 0; |
/* this is either drawn in the center of the dpad (if present) */ |
1024 |
priv->drag_mouse_dy = 0; |
/* or in the middle of the zoom area */ |
1025 |
priv->drag_start_mouse_x = 0; |
static void |
1026 |
priv->drag_start_mouse_y = 0; |
osd_dpad_gps(cairo_t *cr, gint x, gint y) { |
1027 |
|
/* move reference to dpad center */ |
1028 |
|
x += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD * 3; |
1029 |
|
y += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD + GPS_V0; |
1030 |
|
|
1031 |
priv->uri_format = 0; |
cairo_move_to (cr, x-GPS_V0, y+GPS_V0); |
1032 |
priv->the_google = FALSE; |
cairo_rel_line_to (cr, +GPS_V0, -GPS_V0); |
1033 |
|
cairo_rel_line_to (cr, +GPS_V0, +GPS_V0); |
1034 |
|
cairo_close_path (cr); |
1035 |
|
|
1036 |
priv->map_source = -1; |
cairo_move_to (cr, x+GPS_V1-GPS_V2, y-2*GPS_V2); |
1037 |
|
cairo_curve_to (cr, x-GPS_V2, y, x+GPS_V1, y+GPS_V1, x+GPS_V1+GPS_V2, y); |
1038 |
|
cairo_close_path (cr); |
1039 |
|
|
1040 |
#ifndef LIBSOUP22 |
x += GPS_V1; |
1041 |
//Change naumber of concurrent connections option? |
cairo_move_to (cr, x, y-GPS_V2); |
1042 |
priv->soup_session = soup_session_async_new_with_options( |
cairo_rel_line_to (cr, +GPS_V1, -GPS_V1); |
1043 |
SOUP_SESSION_USER_AGENT, |
} |
|
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11", |
|
|
NULL); |
|
|
#else |
|
|
/* libsoup-2.2 seems not to be able to set the user agent */ |
|
|
priv->soup_session = soup_session_async_new(); |
|
1044 |
#endif |
#endif |
1045 |
|
|
1046 |
//Hash table which maps tile d/l URIs to SoupMessage requests |
#define Z_LEN (2*Z_RAD/3) |
|
priv->tile_queue = g_hash_table_new (g_str_hash, g_str_equal); |
|
|
|
|
|
//Some mapping providers (Google) have varying degrees of tiles at multiple |
|
|
//zoom levels |
|
|
priv->missing_tiles = g_hash_table_new (g_str_hash, g_str_equal); |
|
|
|
|
|
/* memory cache for most recently used tiles */ |
|
|
priv->tile_cache = g_hash_table_new_full (g_str_hash, g_str_equal, |
|
|
g_free, (GDestroyNotify)cached_tile_free); |
|
|
priv->max_tile_cache_size = 20; |
|
1047 |
|
|
1048 |
gtk_widget_add_events (GTK_WIDGET (object), |
static void |
1049 |
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | |
osd_zoom_labels(cairo_t *cr, gint x, gint y) { |
1050 |
GDK_POINTER_MOTION_MASK | |
cairo_move_to (cr, x + Z_LEFT - Z_LEN, y + Z_MID); |
1051 |
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK); |
cairo_line_to (cr, x + Z_LEFT + Z_LEN, y + Z_MID); |
|
GTK_WIDGET_SET_FLAGS (object, GTK_CAN_FOCUS); |
|
1052 |
|
|
1053 |
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK, my_log_handler, NULL); |
cairo_move_to (cr, x + Z_RIGHT, y + Z_MID - Z_LEN); |
1054 |
|
cairo_line_to (cr, x + Z_RIGHT, y + Z_MID + Z_LEN); |
1055 |
|
cairo_move_to (cr, x + Z_RIGHT - Z_LEN, y + Z_MID); |
1056 |
|
cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); |
1057 |
} |
} |
1058 |
|
|
1059 |
#ifndef G_CHECKSUM_MD5 |
#ifdef OSD_COORDINATES |
|
/* simple hash algorithm hack if md5 is not present */ |
|
|
static char *simple_hash(char *str) { |
|
|
union { |
|
|
char str[4]; |
|
|
gulong val; |
|
|
} hash = { .val = 0x55555555 }; |
|
1060 |
|
|
1061 |
while(*str) { |
#ifndef OSD_COORDINATES_FONT_SIZE |
1062 |
hash.str[(int)str & 3] ^= *str; |
#define OSD_COORDINATES_FONT_SIZE 12 |
|
str++; |
|
|
} |
|
|
return g_strdup_printf("%08lX", hash.val); |
|
|
} |
|
1063 |
#endif |
#endif |
1064 |
|
|
1065 |
static GObject * |
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
|
osm_gps_map_constructor (GType gtype, guint n_properties, GObjectConstructParam *properties) |
|
|
{ |
|
|
GObject *object; |
|
|
OsmGpsMapPrivate *priv; |
|
|
OsmGpsMap *map; |
|
|
const char *uri; |
|
1066 |
|
|
1067 |
//Always chain up to the parent constructor |
#define OSD_COORDINATES_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
1068 |
object = G_OBJECT_CLASS(osm_gps_map_parent_class)->constructor(gtype, n_properties, properties); |
#define OSD_COORDINATES_H (2*OSD_COORDINATES_FONT_SIZE+OSD_COORDINATES_OFFSET) |
|
map = OSM_GPS_MAP(object); |
|
|
priv = OSM_GPS_MAP_PRIVATE(object); |
|
|
|
|
|
//user can specify a map source ID, or a repo URI as the map source |
|
|
uri = osm_gps_map_source_get_repo_uri(OSM_GPS_MAP_SOURCE_NULL); |
|
|
if ( (priv->map_source == 0) || (strcmp(priv->repo_uri, uri) == 0) ) { |
|
|
g_debug("Using null source"); |
|
|
priv->map_source = OSM_GPS_MAP_SOURCE_NULL; |
|
|
|
|
|
priv->null_tile = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 256, 256); |
|
|
gdk_pixbuf_fill(priv->null_tile, 0xcccccc00); |
|
|
} |
|
|
else if (priv->map_source >= 0) { |
|
|
//check if the source given is valid |
|
|
uri = osm_gps_map_source_get_repo_uri(priv->map_source); |
|
|
if (uri) { |
|
|
g_debug("Setting map source from ID"); |
|
|
g_free(priv->repo_uri); |
|
|
|
|
|
priv->repo_uri = g_strdup(uri); |
|
|
priv->image_format = g_strdup( |
|
|
osm_gps_map_source_get_image_format(priv->map_source)); |
|
|
priv->max_zoom = osm_gps_map_source_get_max_zoom(priv->map_source); |
|
|
priv->min_zoom = osm_gps_map_source_get_min_zoom(priv->map_source); |
|
|
} |
|
|
} |
|
1069 |
|
|
1070 |
if (!priv->cache_dir_is_full_path) { |
/* these can be overwritten with versions that support */ |
1071 |
#ifdef G_CHECKSUM_MD5 |
/* localization */ |
1072 |
char *md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->repo_uri, -1); |
#ifndef OSD_COORDINATES_CHR_N |
1073 |
#else |
#define OSD_COORDINATES_CHR_N "N" |
1074 |
char *md5 = simple_hash(priv->repo_uri); |
#endif |
1075 |
|
#ifndef OSD_COORDINATES_CHR_S |
1076 |
|
#define OSD_COORDINATES_CHR_S "S" |
1077 |
|
#endif |
1078 |
|
#ifndef OSD_COORDINATES_CHR_E |
1079 |
|
#define OSD_COORDINATES_CHR_E "E" |
1080 |
|
#endif |
1081 |
|
#ifndef OSD_COORDINATES_CHR_W |
1082 |
|
#define OSD_COORDINATES_CHR_W "W" |
1083 |
#endif |
#endif |
1084 |
|
|
|
if (priv->cache_dir) { |
|
|
char *old = priv->cache_dir; |
|
|
//the new cachedir is the given cache dir + the md5 of the repo_uri |
|
|
priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, md5); |
|
|
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
|
|
g_free(old); |
|
|
} else { |
|
|
//the new cachedir is the current dir + the md5 of the repo_uri |
|
|
priv->cache_dir = g_strdup(md5); |
|
|
} |
|
1085 |
|
|
1086 |
g_free(md5); |
|
1087 |
|
/* this is the classic geocaching notation */ |
1088 |
|
static char |
1089 |
|
*osd_latitude_str(float latitude) { |
1090 |
|
char *c = OSD_COORDINATES_CHR_N; |
1091 |
|
float integral, fractional; |
1092 |
|
|
1093 |
|
if(isnan(latitude)) |
1094 |
|
return NULL; |
1095 |
|
|
1096 |
|
if(latitude < 0) { |
1097 |
|
latitude = fabs(latitude); |
1098 |
|
c = OSD_COORDINATES_CHR_S; |
1099 |
} |
} |
1100 |
|
|
1101 |
inspect_map_uri(map); |
fractional = modff(latitude, &integral); |
1102 |
|
|
1103 |
|
return g_strdup_printf("%s %02d° %06.3f'", |
1104 |
|
c, (int)integral, fractional*60.0); |
1105 |
|
} |
1106 |
|
|
1107 |
|
static char |
1108 |
|
*osd_longitude_str(float longitude) { |
1109 |
|
char *c = OSD_COORDINATES_CHR_E; |
1110 |
|
float integral, fractional; |
1111 |
|
|
1112 |
|
if(isnan(longitude)) |
1113 |
|
return NULL; |
1114 |
|
|
1115 |
|
if(longitude < 0) { |
1116 |
|
longitude = fabs(longitude); |
1117 |
|
c = OSD_COORDINATES_CHR_W; |
1118 |
|
} |
1119 |
|
|
1120 |
return object; |
fractional = modff(longitude, &integral); |
1121 |
|
|
1122 |
|
return g_strdup_printf("%s %03d° %06.3f'", |
1123 |
|
c, (int)integral, fractional*60.0); |
1124 |
} |
} |
1125 |
|
|
1126 |
static void |
static void |
1127 |
osm_gps_map_dispose (GObject *object) |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
1128 |
{ |
{ |
1129 |
OsmGpsMap *map = OSM_GPS_MAP(object); |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
|
OsmGpsMapPrivate *priv = map->priv; |
|
1130 |
|
|
1131 |
if (priv->is_disposed) |
/* get current map position */ |
1132 |
return; |
gfloat lat, lon; |
1133 |
|
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
1134 |
priv->is_disposed = TRUE; |
|
1135 |
|
/* check if position has changed enough to require redraw */ |
1136 |
|
if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon)) |
1137 |
|
/* 1/60000 == 1/1000 minute */ |
1138 |
|
if((fabsf(lat - priv->coordinates.lat) < 1/60000) && |
1139 |
|
(fabsf(lon - priv->coordinates.lon) < 1/60000)) |
1140 |
|
return; |
1141 |
|
|
1142 |
soup_session_abort(priv->soup_session); |
priv->coordinates.lat = lat; |
1143 |
g_object_unref(priv->soup_session); |
priv->coordinates.lon = lon; |
1144 |
|
|
1145 |
g_hash_table_destroy(priv->tile_queue); |
/* first fill with transparency */ |
1146 |
g_hash_table_destroy(priv->missing_tiles); |
cairo_t *cr = cairo_create(priv->coordinates.surface); |
1147 |
g_hash_table_destroy(priv->tile_cache); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1148 |
|
// cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); |
1149 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
1150 |
|
cairo_paint(cr); |
1151 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1152 |
|
|
1153 |
osm_gps_map_free_images(map); |
cairo_select_font_face (cr, "Sans", |
1154 |
|
CAIRO_FONT_SLANT_NORMAL, |
1155 |
|
CAIRO_FONT_WEIGHT_BOLD); |
1156 |
|
cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE); |
1157 |
|
|
1158 |
if(priv->pixmap) |
char *latitude = osd_latitude_str(lat); |
1159 |
g_object_unref (priv->pixmap); |
char *longitude = osd_longitude_str(lon); |
1160 |
|
|
1161 |
|
cairo_text_extents_t lat_extents, lon_extents; |
1162 |
|
cairo_text_extents (cr, latitude, &lat_extents); |
1163 |
|
cairo_text_extents (cr, longitude, &lon_extents); |
1164 |
|
|
1165 |
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
1166 |
|
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
1167 |
|
cairo_move_to (cr, |
1168 |
|
(OSD_COORDINATES_W - lat_extents.width)/2, |
1169 |
|
OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
1170 |
|
cairo_text_path (cr, latitude); |
1171 |
|
cairo_move_to (cr, |
1172 |
|
(OSD_COORDINATES_W - lon_extents.width)/2, |
1173 |
|
OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
1174 |
|
OSD_COORDINATES_FONT_SIZE); |
1175 |
|
cairo_text_path (cr, longitude); |
1176 |
|
cairo_stroke (cr); |
1177 |
|
|
1178 |
if (priv->null_tile) |
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
1179 |
g_object_unref (priv->null_tile); |
cairo_move_to (cr, |
1180 |
|
(OSD_COORDINATES_W - lat_extents.width)/2, |
1181 |
|
OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
1182 |
|
cairo_show_text (cr, latitude); |
1183 |
|
cairo_move_to (cr, |
1184 |
|
(OSD_COORDINATES_W - lon_extents.width)/2, |
1185 |
|
OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
1186 |
|
OSD_COORDINATES_FONT_SIZE); |
1187 |
|
cairo_show_text (cr, longitude); |
1188 |
|
|
1189 |
if(priv->gc_map) |
g_free(latitude); |
1190 |
g_object_unref(priv->gc_map); |
g_free(longitude); |
1191 |
|
|
1192 |
if (priv->idle_map_redraw != 0) |
cairo_destroy(cr); |
1193 |
g_source_remove (priv->idle_map_redraw); |
} |
1194 |
|
#endif // OSD_COORDINATES |
1195 |
|
|
1196 |
g_free(priv->gps); |
#ifdef OSD_CROSSHAIR |
1197 |
|
|
1198 |
#ifdef ENABLE_BALLOON |
#ifndef OSD_CROSSHAIR_RADIUS |
1199 |
g_free(priv->balloon.coo); |
#define OSD_CROSSHAIR_RADIUS 10 |
1200 |
#endif |
#endif |
1201 |
|
|
1202 |
#ifdef ENABLE_OSD |
#define OSD_CROSSHAIR_TICK (OSD_CROSSHAIR_RADIUS/2) |
1203 |
if (priv->osd.backup) |
#define OSD_CROSSHAIR_BORDER (OSD_CROSSHAIR_TICK + OSD_CROSSHAIR_RADIUS/4) |
1204 |
g_object_unref(priv->osd.backup); |
#define OSD_CROSSHAIR_W ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2) |
1205 |
|
#define OSD_CROSSHAIR_H ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2) |
1206 |
|
|
1207 |
if (priv->osd.overlay) |
static void |
1208 |
cairo_surface_destroy(priv->osd.overlay); |
osd_render_crosshair_shape(cairo_t *cr) { |
1209 |
#endif |
cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2, |
1210 |
|
OSD_CROSSHAIR_RADIUS, 0, 2*M_PI); |
1211 |
|
|
1212 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2 - OSD_CROSSHAIR_RADIUS, |
1213 |
|
OSD_CROSSHAIR_H/2); |
1214 |
|
cairo_rel_line_to (cr, -OSD_CROSSHAIR_TICK, 0); |
1215 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2 + OSD_CROSSHAIR_RADIUS, |
1216 |
|
OSD_CROSSHAIR_H/2); |
1217 |
|
cairo_rel_line_to (cr, OSD_CROSSHAIR_TICK, 0); |
1218 |
|
|
1219 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2, |
1220 |
|
OSD_CROSSHAIR_H/2 - OSD_CROSSHAIR_RADIUS); |
1221 |
|
cairo_rel_line_to (cr, 0, -OSD_CROSSHAIR_TICK); |
1222 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2, |
1223 |
|
OSD_CROSSHAIR_H/2 + OSD_CROSSHAIR_RADIUS); |
1224 |
|
cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK); |
1225 |
|
|
1226 |
G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object); |
cairo_stroke (cr); |
1227 |
} |
} |
1228 |
|
|
1229 |
static void |
static void |
1230 |
osm_gps_map_finalize (GObject *object) |
osd_render_crosshair(osm_gps_map_osd_t *osd) |
1231 |
{ |
{ |
1232 |
OsmGpsMap *map = OSM_GPS_MAP(object); |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
|
OsmGpsMapPrivate *priv = map->priv; |
|
1233 |
|
|
1234 |
g_free(priv->cache_dir); |
if(priv->crosshair.rendered) |
1235 |
g_free(priv->repo_uri); |
return; |
|
g_free(priv->image_format); |
|
1236 |
|
|
1237 |
osm_gps_map_free_trip(map); |
priv->crosshair.rendered = TRUE; |
|
osm_gps_map_free_tracks(map); |
|
1238 |
|
|
1239 |
G_OBJECT_CLASS (osm_gps_map_parent_class)->finalize (object); |
/* first fill with transparency */ |
1240 |
} |
cairo_t *cr = cairo_create(priv->crosshair.surface); |
1241 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1242 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
1243 |
|
cairo_paint(cr); |
1244 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1245 |
|
|
1246 |
static void |
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
1247 |
osm_gps_map_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) |
|
1248 |
{ |
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5); |
1249 |
g_return_if_fail (OSM_IS_GPS_MAP (object)); |
cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/2); |
1250 |
OsmGpsMap *map = OSM_GPS_MAP(object); |
osd_render_crosshair_shape(cr); |
1251 |
OsmGpsMapPrivate *priv = map->priv; |
|
1252 |
|
cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5); |
1253 |
|
cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/4); |
1254 |
|
osd_render_crosshair_shape(cr); |
1255 |
|
|
1256 |
switch (prop_id) |
cairo_destroy(cr); |
1257 |
{ |
} |
1258 |
case PROP_AUTO_CENTER: |
#endif |
|
priv->map_auto_center = g_value_get_boolean (value); |
|
|
break; |
|
|
case PROP_RECORD_TRIP_HISTORY: |
|
|
priv->record_trip_history = g_value_get_boolean (value); |
|
|
break; |
|
|
case PROP_SHOW_TRIP_HISTORY: |
|
|
priv->show_trip_history = g_value_get_boolean (value); |
|
|
break; |
|
|
case PROP_AUTO_DOWNLOAD: |
|
|
priv->map_auto_download = g_value_get_boolean (value); |
|
|
break; |
|
|
case PROP_REPO_URI: |
|
|
priv->repo_uri = g_value_dup_string (value); |
|
|
break; |
|
|
case PROP_PROXY_URI: |
|
|
if ( g_value_get_string(value) ) { |
|
|
priv->proxy_uri = g_value_dup_string (value); |
|
|
g_debug("Setting proxy server: %s", priv->proxy_uri); |
|
|
|
|
|
#ifndef LIBSOUP22 |
|
|
GValue val = {0}; |
|
|
|
|
|
SoupURI* uri = soup_uri_new(priv->proxy_uri); |
|
|
g_value_init(&val, SOUP_TYPE_URI); |
|
|
g_value_take_boxed(&val, uri); |
|
1259 |
|
|
1260 |
g_object_set_property(G_OBJECT(priv->soup_session),SOUP_SESSION_PROXY_URI,&val); |
#ifdef OSD_SCALE |
1261 |
#else |
|
1262 |
SoupUri* uri = soup_uri_new(priv->proxy_uri); |
#ifndef OSD_SCALE_FONT_SIZE |
1263 |
g_object_set(G_OBJECT(priv->soup_session), SOUP_SESSION_PROXY_URI, uri, NULL); |
#define OSD_SCALE_FONT_SIZE 12 |
1264 |
#endif |
#endif |
1265 |
} else |
#define OSD_SCALE_W (10*OSD_SCALE_FONT_SIZE) |
1266 |
priv->proxy_uri = NULL; |
#define OSD_SCALE_H (5*OSD_SCALE_FONT_SIZE/2) |
1267 |
|
|
1268 |
break; |
/* various parameters used to create the scale */ |
1269 |
case PROP_TILE_CACHE_DIR: |
#define OSD_SCALE_H2 (OSD_SCALE_H/2) |
1270 |
if ( g_value_get_string(value) ) |
#define OSD_SCALE_TICK (2*OSD_SCALE_FONT_SIZE/3) |
1271 |
priv->cache_dir = g_value_dup_string (value); |
#define OSD_SCALE_M (OSD_SCALE_H2 - OSD_SCALE_TICK) |
1272 |
break; |
#define OSD_SCALE_I (OSD_SCALE_H2 + OSD_SCALE_TICK) |
1273 |
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
#define OSD_SCALE_FD (OSD_SCALE_FONT_SIZE/4) |
|
priv->cache_dir_is_full_path = g_value_get_boolean (value); |
|
|
break; |
|
|
case PROP_ZOOM: |
|
|
priv->map_zoom = g_value_get_int (value); |
|
|
break; |
|
|
case PROP_MAX_ZOOM: |
|
|
priv->max_zoom = g_value_get_int (value); |
|
|
break; |
|
|
case PROP_MIN_ZOOM: |
|
|
priv->min_zoom = g_value_get_int (value); |
|
|
break; |
|
|
case PROP_MAP_X: |
|
|
priv->map_x = g_value_get_int (value); |
|
|
priv->center_coord_set = FALSE; |
|
|
break; |
|
|
case PROP_MAP_Y: |
|
|
priv->map_y = g_value_get_int (value); |
|
|
priv->center_coord_set = FALSE; |
|
|
break; |
|
|
case PROP_GPS_TRACK_WIDTH: |
|
|
priv->ui_gps_track_width = g_value_get_int (value); |
|
|
break; |
|
|
case PROP_GPS_POINT_R1: |
|
|
priv->ui_gps_point_inner_radius = g_value_get_int (value); |
|
|
break; |
|
|
case PROP_GPS_POINT_R2: |
|
|
priv->ui_gps_point_outer_radius = g_value_get_int (value); |
|
|
break; |
|
|
case PROP_MAP_SOURCE: |
|
|
priv->map_source = g_value_get_int (value); |
|
|
break; |
|
|
case PROP_IMAGE_FORMAT: |
|
|
priv->image_format = g_value_dup_string (value); |
|
|
break; |
|
|
default: |
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
|
|
break; |
|
|
} |
|
|
} |
|
1274 |
|
|
1275 |
static void |
static void |
1276 |
osm_gps_map_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) |
osd_render_scale(osm_gps_map_osd_t *osd) |
1277 |
{ |
{ |
1278 |
g_return_if_fail (OSM_IS_GPS_MAP (object)); |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
|
float lat,lon; |
|
|
OsmGpsMap *map = OSM_GPS_MAP(object); |
|
|
OsmGpsMapPrivate *priv = map->priv; |
|
1279 |
|
|
1280 |
switch (prop_id) |
/* this only needs to be rendered if the zoom has changed */ |
1281 |
{ |
gint zoom; |
1282 |
case PROP_AUTO_CENTER: |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
1283 |
g_value_set_boolean(value, priv->map_auto_center); |
if(zoom == priv->scale.zoom) |
1284 |
break; |
return; |
|
case PROP_RECORD_TRIP_HISTORY: |
|
|
g_value_set_boolean(value, priv->record_trip_history); |
|
|
break; |
|
|
case PROP_SHOW_TRIP_HISTORY: |
|
|
g_value_set_boolean(value, priv->show_trip_history); |
|
|
break; |
|
|
case PROP_AUTO_DOWNLOAD: |
|
|
g_value_set_boolean(value, priv->map_auto_download); |
|
|
break; |
|
|
case PROP_REPO_URI: |
|
|
g_value_set_string(value, priv->repo_uri); |
|
|
break; |
|
|
case PROP_PROXY_URI: |
|
|
g_value_set_string(value, priv->proxy_uri); |
|
|
break; |
|
|
case PROP_TILE_CACHE_DIR: |
|
|
g_value_set_string(value, priv->cache_dir); |
|
|
break; |
|
|
case PROP_TILE_CACHE_DIR_IS_FULL_PATH: |
|
|
g_value_set_boolean(value, priv->cache_dir_is_full_path); |
|
|
break; |
|
|
case PROP_ZOOM: |
|
|
g_value_set_int(value, priv->map_zoom); |
|
|
break; |
|
|
case PROP_MAX_ZOOM: |
|
|
g_value_set_int(value, priv->max_zoom); |
|
|
break; |
|
|
case PROP_MIN_ZOOM: |
|
|
g_value_set_int(value, priv->min_zoom); |
|
|
break; |
|
|
case PROP_LATITUDE: |
|
|
lat = pixel2lat(priv->map_zoom, |
|
|
priv->map_y + (GTK_WIDGET(map)->allocation.height / 2)); |
|
|
g_value_set_float(value, rad2deg(lat)); |
|
|
break; |
|
|
case PROP_LONGITUDE: |
|
|
lon = pixel2lon(priv->map_zoom, |
|
|
priv->map_x + (GTK_WIDGET(map)->allocation.width / 2)); |
|
|
g_value_set_float(value, rad2deg(lon)); |
|
|
break; |
|
|
case PROP_MAP_X: |
|
|
g_value_set_int(value, priv->map_x); |
|
|
break; |
|
|
case PROP_MAP_Y: |
|
|
g_value_set_int(value, priv->map_y); |
|
|
break; |
|
|
case PROP_TILES_QUEUED: |
|
|
g_value_set_int(value, g_hash_table_size(priv->tile_queue)); |
|
|
break; |
|
|
case PROP_GPS_TRACK_WIDTH: |
|
|
g_value_set_int(value, priv->ui_gps_track_width); |
|
|
break; |
|
|
case PROP_GPS_POINT_R1: |
|
|
g_value_set_int(value, priv->ui_gps_point_inner_radius); |
|
|
break; |
|
|
case PROP_GPS_POINT_R2: |
|
|
g_value_set_int(value, priv->ui_gps_point_outer_radius); |
|
|
break; |
|
|
case PROP_MAP_SOURCE: |
|
|
g_value_set_int(value, priv->map_source); |
|
|
break; |
|
|
case PROP_IMAGE_FORMAT: |
|
|
g_value_set_string(value, priv->image_format); |
|
|
break; |
|
|
default: |
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
|
|
break; |
|
|
} |
|
|
} |
|
1285 |
|
|
1286 |
static gboolean |
priv->scale.zoom = zoom; |
|
osm_gps_map_scroll_event (GtkWidget *widget, GdkEventScroll *event) |
|
|
{ |
|
|
OsmGpsMap *map = OSM_GPS_MAP(widget); |
|
|
OsmGpsMapPrivate *priv = map->priv; |
|
1287 |
|
|
1288 |
if (event->direction == GDK_SCROLL_UP) |
float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget)); |
1289 |
{ |
|
1290 |
osm_gps_map_set_zoom(map, priv->map_zoom+1); |
/* first fill with transparency */ |
1291 |
} |
cairo_t *cr = cairo_create(priv->scale.surface); |
1292 |
else |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1293 |
{ |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1294 |
osm_gps_map_set_zoom(map, priv->map_zoom-1); |
// pink for testing: cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
1295 |
|
cairo_paint(cr); |
1296 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1297 |
|
|
1298 |
|
/* determine the size of the scale width in meters */ |
1299 |
|
float width = (OSD_SCALE_W-OSD_SCALE_FONT_SIZE/6) * m_per_pix; |
1300 |
|
|
1301 |
|
/* scale this to useful values */ |
1302 |
|
int exp = logf(width)*M_LOG10E; |
1303 |
|
int mant = width/pow(10,exp); |
1304 |
|
int width_metric = mant * pow(10,exp); |
1305 |
|
char *dist_str = NULL; |
1306 |
|
if(width_metric<1000) |
1307 |
|
dist_str = g_strdup_printf("%u m", width_metric); |
1308 |
|
else |
1309 |
|
dist_str = g_strdup_printf("%u km", width_metric/1000); |
1310 |
|
width_metric /= m_per_pix; |
1311 |
|
|
1312 |
|
/* and now the hard part: scale for useful imperial values :-( */ |
1313 |
|
/* try to convert to feet, 1ft == 0.3048 m */ |
1314 |
|
width /= 0.3048; |
1315 |
|
float imp_scale = 0.3048; |
1316 |
|
char *dist_imp_unit = "ft"; |
1317 |
|
|
1318 |
|
if(width >= 100) { |
1319 |
|
/* 1yd == 3 feet */ |
1320 |
|
width /= 3.0; |
1321 |
|
imp_scale *= 3.0; |
1322 |
|
dist_imp_unit = "yd"; |
1323 |
|
|
1324 |
|
if(width >= 1760.0) { |
1325 |
|
/* 1mi == 1760 yd */ |
1326 |
|
width /= 1760.0; |
1327 |
|
imp_scale *= 1760.0; |
1328 |
|
dist_imp_unit = "mi"; |
1329 |
|
} |
1330 |
} |
} |
1331 |
|
|
1332 |
return FALSE; |
/* also convert this to full tens/hundreds */ |
1333 |
|
exp = logf(width)*M_LOG10E; |
1334 |
|
mant = width/pow(10,exp); |
1335 |
|
int width_imp = mant * pow(10,exp); |
1336 |
|
char *dist_str_imp = g_strdup_printf("%u %s", width_imp, dist_imp_unit); |
1337 |
|
|
1338 |
|
/* convert back to pixels */ |
1339 |
|
width_imp *= imp_scale; |
1340 |
|
width_imp /= m_per_pix; |
1341 |
|
|
1342 |
|
cairo_select_font_face (cr, "Sans", |
1343 |
|
CAIRO_FONT_SLANT_NORMAL, |
1344 |
|
CAIRO_FONT_WEIGHT_BOLD); |
1345 |
|
cairo_set_font_size (cr, OSD_SCALE_FONT_SIZE); |
1346 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); |
1347 |
|
|
1348 |
|
cairo_text_extents_t extents; |
1349 |
|
cairo_text_extents (cr, dist_str, &extents); |
1350 |
|
|
1351 |
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
1352 |
|
cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6); |
1353 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD); |
1354 |
|
cairo_text_path (cr, dist_str); |
1355 |
|
cairo_stroke (cr); |
1356 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, |
1357 |
|
OSD_SCALE_H2+OSD_SCALE_FD + extents.height); |
1358 |
|
cairo_text_path (cr, dist_str_imp); |
1359 |
|
cairo_stroke (cr); |
1360 |
|
|
1361 |
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
1362 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD); |
1363 |
|
cairo_show_text (cr, dist_str); |
1364 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, |
1365 |
|
OSD_SCALE_H2+OSD_SCALE_FD + extents.height); |
1366 |
|
cairo_show_text (cr, dist_str_imp); |
1367 |
|
|
1368 |
|
g_free(dist_str); |
1369 |
|
g_free(dist_str_imp); |
1370 |
|
|
1371 |
|
/* draw white line */ |
1372 |
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
1373 |
|
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); |
1374 |
|
cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/3); |
1375 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M); |
1376 |
|
cairo_rel_line_to (cr, 0, OSD_SCALE_TICK); |
1377 |
|
cairo_rel_line_to (cr, width_metric, 0); |
1378 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1379 |
|
cairo_stroke(cr); |
1380 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I); |
1381 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1382 |
|
cairo_rel_line_to (cr, width_imp, 0); |
1383 |
|
cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK); |
1384 |
|
cairo_stroke(cr); |
1385 |
|
|
1386 |
|
/* draw black line */ |
1387 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); |
1388 |
|
cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6); |
1389 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M); |
1390 |
|
cairo_rel_line_to (cr, 0, OSD_SCALE_TICK); |
1391 |
|
cairo_rel_line_to (cr, width_metric, 0); |
1392 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1393 |
|
cairo_stroke(cr); |
1394 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I); |
1395 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1396 |
|
cairo_rel_line_to (cr, width_imp, 0); |
1397 |
|
cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK); |
1398 |
|
cairo_stroke(cr); |
1399 |
|
|
1400 |
|
cairo_destroy(cr); |
1401 |
} |
} |
1402 |
|
#endif |
1403 |
|
|
1404 |
static gboolean |
static void |
1405 |
osm_gps_map_button_press (GtkWidget *widget, GdkEventButton *event) |
osd_render_controls(osm_gps_map_osd_t *osd) |
1406 |
{ |
{ |
1407 |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1408 |
|
|
1409 |
#ifdef ENABLE_BALLOON |
if(priv->controls.rendered |
1410 |
/* don't drag if the user clicked within the balloon */ |
#ifdef OSD_GPS_BUTTON |
1411 |
if (osm_gps_map_in_balloon(priv, |
&& (priv->controls.gps_enabled == (osd->cb != NULL)) |
|
event->x + EXTRA_BORDER, |
|
|
event->y + EXTRA_BORDER)) |
|
|
{ |
|
|
priv->drag_counter = -1; |
|
|
return FALSE; |
|
|
} |
|
1412 |
#endif |
#endif |
1413 |
|
) |
1414 |
|
return; |
1415 |
|
|
1416 |
#ifdef ENABLE_OSD |
#ifdef OSD_GPS_BUTTON |
1417 |
#define SCROLL_STEP 10 |
priv->controls.gps_enabled = (osd->cb != NULL); |
1418 |
|
#endif |
1419 |
|
priv->controls.rendered = TRUE; |
1420 |
|
|
1421 |
/* pressed inside OSD control? */ |
#ifndef OSD_COLOR |
1422 |
osd_button_t but = osm_gps_map_osd_check(event->x, event->y); |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
1423 |
if(but != OSD_NONE) |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
1424 |
{ |
GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE]; |
1425 |
priv->drag_counter = -1; |
#endif |
1426 |
|
|
1427 |
switch(but) { |
/* first fill with transparency */ |
1428 |
case OSD_GPS: |
cairo_t *cr = cairo_create(priv->controls.surface); |
1429 |
priv->osd.cb(priv->osd.data); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1430 |
break; |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1431 |
|
cairo_paint(cr); |
1432 |
case OSD_UP: |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
|
priv->map_y -= GTK_WIDGET(widget)->allocation.height/SCROLL_STEP; |
|
|
priv->center_coord_set = FALSE; |
|
|
break; |
|
|
|
|
|
case OSD_DOWN: |
|
|
priv->map_y += GTK_WIDGET(widget)->allocation.height/SCROLL_STEP; |
|
|
priv->center_coord_set = FALSE; |
|
|
break; |
|
|
|
|
|
case OSD_LEFT: |
|
|
priv->map_x -= GTK_WIDGET(widget)->allocation.width/SCROLL_STEP; |
|
|
priv->center_coord_set = FALSE; |
|
|
break; |
|
|
|
|
|
case OSD_RIGHT: |
|
|
priv->map_x += GTK_WIDGET(widget)->allocation.width/SCROLL_STEP; |
|
|
priv->center_coord_set = FALSE; |
|
|
break; |
|
|
|
|
|
case OSD_IN: |
|
|
osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom+1); |
|
|
break; |
|
|
|
|
|
case OSD_OUT: |
|
|
osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom-1); |
|
|
break; |
|
|
|
|
|
default: |
|
|
break; |
|
|
} |
|
1433 |
|
|
1434 |
osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); |
/* --------- draw zoom and dpad shape shadow ----------- */ |
1435 |
|
#ifdef OSD_SHADOW_ENABLE |
1436 |
return FALSE; |
osd_zoom_shape(cr, 1+OSD_SHADOW, 1+OSD_SHADOW); |
1437 |
} |
osd_shape_shadow(cr); |
1438 |
|
#ifndef OSD_NO_DPAD |
1439 |
|
osd_dpad_shape(cr, 1+OSD_SHADOW, 1+OSD_SHADOW); |
1440 |
|
osd_shape_shadow(cr); |
1441 |
#endif |
#endif |
|
|
|
|
priv->drag_counter = 0; |
|
|
priv->drag_start_mouse_x = (int) event->x; |
|
|
priv->drag_start_mouse_y = (int) event->y; |
|
|
priv->drag_start_map_x = priv->map_x; |
|
|
priv->drag_start_map_y = priv->map_y; |
|
|
|
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
static gboolean |
|
|
osm_gps_map_button_release (GtkWidget *widget, GdkEventButton *event) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
|
|
|
|
|
#ifdef ENABLE_BALLOON |
|
|
/* released inside the balloon? */ |
|
|
if (osm_gps_map_in_balloon(priv, |
|
|
event->x + EXTRA_BORDER, |
|
|
event->y + EXTRA_BORDER)) |
|
|
{ |
|
|
osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget), |
|
|
event->x - priv->balloon.rect.x + EXTRA_BORDER, |
|
|
event->y - priv->balloon.rect.y + EXTRA_BORDER); |
|
|
} |
|
1442 |
#endif |
#endif |
1443 |
|
|
1444 |
if (priv->dragging) |
/* --------- draw zoom and dpad shape ----------- */ |
|
{ |
|
|
priv->dragging = FALSE; |
|
|
|
|
|
priv->map_x = priv->drag_start_map_x; |
|
|
priv->map_y = priv->drag_start_map_y; |
|
|
|
|
|
priv->map_x += (priv->drag_start_mouse_x - (int) event->x); |
|
|
priv->map_y += (priv->drag_start_mouse_y - (int) event->y); |
|
|
|
|
|
priv->center_coord_set = FALSE; |
|
|
|
|
|
osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); |
|
|
} |
|
|
|
|
|
priv->drag_mouse_dx = 0; |
|
|
priv->drag_mouse_dy = 0; |
|
|
priv->drag_counter = -1; |
|
|
|
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
static gboolean |
|
|
osm_gps_map_expose (GtkWidget *widget, GdkEventExpose *event); |
|
|
|
|
|
static gboolean |
|
|
osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion *event) |
|
|
{ |
|
|
int x, y; |
|
|
GdkModifierType state; |
|
|
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
|
|
|
|
|
if (event->is_hint) |
|
|
gdk_window_get_pointer (event->window, &x, &y, &state); |
|
|
else |
|
|
{ |
|
|
x = event->x; |
|
|
y = event->y; |
|
|
state = event->state; |
|
|
} |
|
|
|
|
|
// are we being dragged |
|
|
if (!(state & GDK_BUTTON1_MASK)) |
|
|
return FALSE; |
|
|
|
|
|
if (priv->drag_counter < 0) |
|
|
return FALSE; |
|
|
|
|
|
priv->drag_counter++; |
|
|
|
|
|
// we havent dragged more than 6 pixels |
|
|
if (priv->drag_counter < 6) |
|
|
return FALSE; |
|
|
|
|
|
#ifdef USE_MAEMO |
|
|
/* reduce update frequency on maemo to keep screen update fluid */ |
|
|
static guint32 last_time = 0; |
|
1445 |
|
|
1446 |
if(event->time - last_time < 100) return FALSE; |
osd_zoom_shape(cr, 1, 1); |
1447 |
last_time = event->time; |
#ifndef OSD_COLOR |
1448 |
|
osd_shape(cr, &bg, &fg); |
1449 |
|
#else |
1450 |
|
osd_shape(cr); |
1451 |
|
#endif |
1452 |
|
#ifndef OSD_NO_DPAD |
1453 |
|
osd_dpad_shape(cr, 1, 1); |
1454 |
|
#ifndef OSD_COLOR |
1455 |
|
osd_shape(cr, &bg, &fg); |
1456 |
|
#else |
1457 |
|
osd_shape(cr); |
1458 |
|
#endif |
1459 |
#endif |
#endif |
1460 |
|
|
1461 |
priv->dragging = TRUE; |
/* --------- draw zoom and dpad labels --------- */ |
|
|
|
|
if (priv->map_auto_center) |
|
|
g_object_set(G_OBJECT(widget), "auto-center", FALSE, NULL); |
|
|
|
|
|
priv->drag_mouse_dx = x - priv->drag_start_mouse_x; |
|
|
priv->drag_mouse_dy = y - priv->drag_start_mouse_y; |
|
|
|
|
|
#ifdef ENABLE_OSD |
|
|
/* undo OSD */ |
|
|
osm_gps_map_osd_restore (OSM_GPS_MAP(widget)); |
|
1462 |
|
|
1463 |
/* draw new OSD */ |
#ifdef OSD_SHADOW_ENABLE |
1464 |
osm_gps_map_osd_draw_controls (OSM_GPS_MAP(widget), |
osd_labels_shadow(cr, Z_RAD/3, TRUE); |
1465 |
-priv->drag_mouse_dx, |
osd_zoom_labels(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW); |
1466 |
-priv->drag_mouse_dy); |
#ifndef OSD_NO_DPAD |
1467 |
|
osd_dpad_labels(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW); |
1468 |
|
#endif |
1469 |
|
cairo_stroke(cr); |
1470 |
|
#ifdef OSD_GPS_BUTTON |
1471 |
|
osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL); |
1472 |
|
osd_dpad_gps(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW); |
1473 |
|
cairo_stroke(cr); |
1474 |
|
#endif |
1475 |
#endif |
#endif |
1476 |
|
|
1477 |
osm_gps_map_expose (widget, NULL); |
#ifndef OSD_COLOR |
1478 |
|
osd_labels(cr, Z_RAD/3, TRUE, &fg, &da); |
1479 |
|
#else |
1480 |
|
osd_labels(cr, Z_RAD/3, TRUE); |
1481 |
|
#endif |
1482 |
|
osd_zoom_labels(cr, 1, 1); |
1483 |
|
#ifndef OSD_NO_DPAD |
1484 |
|
osd_dpad_labels(cr, 1, 1); |
1485 |
|
#endif |
1486 |
|
cairo_stroke(cr); |
1487 |
|
|
1488 |
return FALSE; |
#ifndef OSD_COLOR |
1489 |
|
osd_labels(cr, Z_RAD/6, osd->cb != NULL, &fg, &da); |
1490 |
|
#else |
1491 |
|
osd_labels(cr, Z_RAD/6, osd->cb != NULL); |
1492 |
|
#endif |
1493 |
|
#ifdef OSD_GPS_BUTTON |
1494 |
|
osd_dpad_gps(cr, 1, 1); |
1495 |
|
#endif |
1496 |
|
cairo_stroke(cr); |
1497 |
|
|
1498 |
|
cairo_destroy(cr); |
1499 |
} |
} |
1500 |
|
|
1501 |
static gboolean |
static void |
1502 |
osm_gps_map_configure (GtkWidget *widget, GdkEventConfigure *event) |
osd_render(osm_gps_map_osd_t *osd) |
1503 |
{ |
{ |
1504 |
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
/* this function is actually called pretty often since the */ |
1505 |
|
/* OSD contents may have changed (due to a coordinate/zoom change). */ |
1506 |
|
/* The different OSD parts have to make sure that they don't */ |
1507 |
|
/* render unneccessarily often and thus waste CPU power */ |
1508 |
|
|
1509 |
/* create pixmap */ |
osd_render_controls(osd); |
|
if (priv->pixmap) |
|
|
g_object_unref (priv->pixmap); |
|
1510 |
|
|
1511 |
priv->pixmap = gdk_pixmap_new ( |
#ifdef OSD_SOURCE_SEL |
1512 |
widget->window, |
osd_render_source_sel(osd, FALSE); |
1513 |
widget->allocation.width + EXTRA_BORDER * 2, |
#endif |
|
widget->allocation.height + EXTRA_BORDER * 2, |
|
|
-1); |
|
|
|
|
|
/* and gc, used for clipping (I think......) */ |
|
|
if(priv->gc_map) |
|
|
g_object_unref(priv->gc_map); |
|
|
|
|
|
priv->gc_map = gdk_gc_new(priv->pixmap); |
|
|
|
|
|
osm_gps_map_map_redraw(OSM_GPS_MAP(widget)); |
|
1514 |
|
|
1515 |
return FALSE; |
#ifdef OSD_SCALE |
1516 |
} |
osd_render_scale(osd); |
1517 |
|
#endif |
1518 |
|
|
1519 |
static gboolean |
#ifdef OSD_CROSSHAIR |
1520 |
osm_gps_map_expose (GtkWidget *widget, GdkEventExpose *event) |
osd_render_crosshair(osd); |
1521 |
{ |
#endif |
|
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
|
1522 |
|
|
1523 |
gdk_draw_drawable ( |
#ifdef OSD_COORDINATES |
1524 |
widget->window, |
osd_render_coordinates(osd); |
|
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
|
|
priv->pixmap, |
|
|
0,0, |
|
|
priv->drag_mouse_dx - EXTRA_BORDER, |
|
|
priv->drag_mouse_dy - EXTRA_BORDER, |
|
|
-1,-1); |
|
|
|
|
|
//Paint white outside of the map if dragging. Its less |
|
|
//ugly than painting the corrupted map |
|
|
if(priv->drag_mouse_dx>EXTRA_BORDER) { |
|
|
gdk_draw_rectangle ( |
|
|
widget->window, |
|
|
widget->style->white_gc, |
|
|
TRUE, |
|
|
0, 0, |
|
|
priv->drag_mouse_dx - EXTRA_BORDER, |
|
|
widget->allocation.height); |
|
|
} |
|
|
else if (-priv->drag_mouse_dx > EXTRA_BORDER) |
|
|
{ |
|
|
gdk_draw_rectangle ( |
|
|
widget->window, |
|
|
widget->style->white_gc, |
|
|
TRUE, |
|
|
priv->drag_mouse_dx + widget->allocation.width + EXTRA_BORDER, 0, |
|
|
-priv->drag_mouse_dx - EXTRA_BORDER, |
|
|
widget->allocation.height); |
|
|
} |
|
|
|
|
|
if (priv->drag_mouse_dy>EXTRA_BORDER) { |
|
|
gdk_draw_rectangle ( |
|
|
widget->window, |
|
|
widget->style->white_gc, |
|
|
TRUE, |
|
|
0, 0, |
|
|
widget->allocation.width, |
|
|
priv->drag_mouse_dy - EXTRA_BORDER); |
|
|
} |
|
|
else if (-priv->drag_mouse_dy > EXTRA_BORDER) |
|
|
{ |
|
|
gdk_draw_rectangle ( |
|
|
widget->window, |
|
|
widget->style->white_gc, |
|
|
TRUE, |
|
|
0, priv->drag_mouse_dy + widget->allocation.height + EXTRA_BORDER, |
|
|
widget->allocation.width, |
|
|
-priv->drag_mouse_dy - EXTRA_BORDER); |
|
|
} |
|
|
#if 0 |
|
|
if(!priv->dragging) |
|
|
gdk_draw_drawable ( |
|
|
widget->window, |
|
|
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
|
|
priv->pixmap, |
|
|
event->area.x + EXTRA_BORDER, |
|
|
event->area.y + EXTRA_BORDER, |
|
|
event->area.x, event->area.y, |
|
|
event->area.width, event->area.height); |
|
1525 |
#endif |
#endif |
|
return FALSE; |
|
1526 |
} |
} |
1527 |
|
|
1528 |
static void |
static void |
1529 |
osm_gps_map_class_init (OsmGpsMapClass *klass) |
osd_draw(osm_gps_map_osd_t *osd, GdkDrawable *drawable) |
1530 |
{ |
{ |
1531 |
GObjectClass* object_class = G_OBJECT_CLASS (klass); |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
|
|
|
|
|
g_type_class_add_private (klass, sizeof (OsmGpsMapPrivate)); |
|
1532 |
|
|
1533 |
object_class->dispose = osm_gps_map_dispose; |
/* OSD itself uses some off-screen rendering, so check if the */ |
1534 |
object_class->finalize = osm_gps_map_finalize; |
/* offscreen buffer is present and create it if not */ |
1535 |
object_class->constructor = osm_gps_map_constructor; |
if(!priv->controls.surface) { |
1536 |
object_class->set_property = osm_gps_map_set_property; |
/* create overlay ... */ |
1537 |
object_class->get_property = osm_gps_map_get_property; |
priv->controls.surface = |
1538 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2); |
|
widget_class->expose_event = osm_gps_map_expose; |
|
|
widget_class->configure_event = osm_gps_map_configure; |
|
|
widget_class->button_press_event = osm_gps_map_button_press; |
|
|
widget_class->button_release_event = osm_gps_map_button_release; |
|
|
widget_class->motion_notify_event = osm_gps_map_motion_notify; |
|
|
widget_class->scroll_event = osm_gps_map_scroll_event; |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_AUTO_CENTER, |
|
|
g_param_spec_boolean ("auto-center", |
|
|
"auto center", |
|
|
"map auto center", |
|
|
TRUE, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_RECORD_TRIP_HISTORY, |
|
|
g_param_spec_boolean ("record-trip-history", |
|
|
"record trip history", |
|
|
"should all gps points be recorded in a trip history", |
|
|
TRUE, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_SHOW_TRIP_HISTORY, |
|
|
g_param_spec_boolean ("show-trip-history", |
|
|
"show trip history", |
|
|
"should the recorded trip history be shown on the map", |
|
|
TRUE, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_AUTO_DOWNLOAD, |
|
|
g_param_spec_boolean ("auto-download", |
|
|
"auto download", |
|
|
"map auto download", |
|
|
TRUE, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_REPO_URI, |
|
|
g_param_spec_string ("repo-uri", |
|
|
"repo uri", |
|
|
"map source tile repository uri", |
|
|
OSM_REPO_URI, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_PROXY_URI, |
|
|
g_param_spec_string ("proxy-uri", |
|
|
"proxy uri", |
|
|
"http proxy uri on NULL", |
|
|
NULL, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_TILE_CACHE_DIR, |
|
|
g_param_spec_string ("tile-cache", |
|
|
"tile cache", |
|
|
"osm local tile cache dir", |
|
|
NULL, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_TILE_CACHE_DIR_IS_FULL_PATH, |
|
|
g_param_spec_boolean ("tile-cache-is-full-path", |
|
|
"tile cache is full path", |
|
|
"if true, the path passed to tile-cache is interpreted as the full cache path", |
|
|
FALSE, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_ZOOM, |
|
|
g_param_spec_int ("zoom", |
|
|
"zoom", |
|
|
"zoom level", |
|
|
MIN_ZOOM, /* minimum property value */ |
|
|
MAX_ZOOM, /* maximum property value */ |
|
|
3, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_MAX_ZOOM, |
|
|
g_param_spec_int ("max-zoom", |
|
|
"max zoom", |
|
|
"maximum zoom level", |
|
|
MIN_ZOOM, /* minimum property value */ |
|
|
MAX_ZOOM, /* maximum property value */ |
|
|
OSM_MAX_ZOOM, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_MIN_ZOOM, |
|
|
g_param_spec_int ("min-zoom", |
|
|
"min zoom", |
|
|
"minimum zoom level", |
|
|
MIN_ZOOM, /* minimum property value */ |
|
|
MAX_ZOOM, /* maximum property value */ |
|
|
OSM_MIN_ZOOM, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_LATITUDE, |
|
|
g_param_spec_float ("latitude", |
|
|
"latitude", |
|
|
"latitude in degrees", |
|
|
-90.0, /* minimum property value */ |
|
|
90.0, /* maximum property value */ |
|
|
0, |
|
|
G_PARAM_READABLE)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_LONGITUDE, |
|
|
g_param_spec_float ("longitude", |
|
|
"longitude", |
|
|
"longitude in degrees", |
|
|
-180.0, /* minimum property value */ |
|
|
180.0, /* maximum property value */ |
|
|
0, |
|
|
G_PARAM_READABLE)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_MAP_X, |
|
|
g_param_spec_int ("map-x", |
|
|
"map-x", |
|
|
"initial map x location", |
|
|
G_MININT, /* minimum property value */ |
|
|
G_MAXINT, /* maximum property value */ |
|
|
890, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_MAP_Y, |
|
|
g_param_spec_int ("map-y", |
|
|
"map-y", |
|
|
"initial map y location", |
|
|
G_MININT, /* minimum property value */ |
|
|
G_MAXINT, /* maximum property value */ |
|
|
515, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_TILES_QUEUED, |
|
|
g_param_spec_int ("tiles-queued", |
|
|
"tiles-queued", |
|
|
"number of tiles currently waiting to download", |
|
|
G_MININT, /* minimum property value */ |
|
|
G_MAXINT, /* maximum property value */ |
|
|
0, |
|
|
G_PARAM_READABLE)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_GPS_TRACK_WIDTH, |
|
|
g_param_spec_int ("gps-track-width", |
|
|
"gps-track-width", |
|
|
"width of the lines drawn for the gps track", |
|
|
1, /* minimum property value */ |
|
|
G_MAXINT, /* maximum property value */ |
|
|
4, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_GPS_POINT_R1, |
|
|
g_param_spec_int ("gps-track-point-radius", |
|
|
"gps-track-point-radius", |
|
|
"radius of the gps point inner circle", |
|
|
0, /* minimum property value */ |
|
|
G_MAXINT, /* maximum property value */ |
|
|
10, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_GPS_POINT_R2, |
|
|
g_param_spec_int ("gps-track-highlight-radius", |
|
|
"gps-track-highlight-radius", |
|
|
"radius of the gps point highlight circle", |
|
|
0, /* minimum property value */ |
|
|
G_MAXINT, /* maximum property value */ |
|
|
20, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_MAP_SOURCE, |
|
|
g_param_spec_int ("map-source", |
|
|
"map source", |
|
|
"map source ID", |
|
|
-1, /* minimum property value */ |
|
|
G_MAXINT, /* maximum property value */ |
|
|
-1, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
|
|
|
|
|
g_object_class_install_property (object_class, |
|
|
PROP_IMAGE_FORMAT, |
|
|
g_param_spec_string ("image-format", |
|
|
"image format", |
|
|
"map source tile repository image format (jpg, png)", |
|
|
OSM_IMAGE_FORMAT, |
|
|
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); |
|
|
} |
|
1539 |
|
|
1540 |
const char* |
priv->controls.rendered = FALSE; |
1541 |
osm_gps_map_source_get_friendly_name(OsmGpsMapSource_t source) |
#ifdef OSD_GPS_BUTTON |
1542 |
{ |
priv->controls.gps_enabled = FALSE; |
1543 |
switch(source) |
#endif |
|
{ |
|
|
case OSM_GPS_MAP_SOURCE_NULL: |
|
|
return "None"; |
|
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
|
|
return "OpenStreetMap"; |
|
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
|
|
return "OpenStreetMap Renderer"; |
|
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
|
|
return "OpenAerialMap"; |
|
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
|
|
return "Maps-For-Free"; |
|
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
|
|
return "Google Maps"; |
|
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
|
|
return "Google Satellite"; |
|
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
|
|
return "Google Hybrid"; |
|
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
|
|
return "Virtual Earth"; |
|
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
|
|
return "Virtual Earth Satellite"; |
|
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
|
|
return "Virtual Earth Hybrid"; |
|
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
|
|
return "Yahoo Maps"; |
|
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
|
|
return "Yahoo Satellite"; |
|
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
|
|
return "Yahoo Hybrid"; |
|
|
default: |
|
|
return NULL; |
|
|
} |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
//http://www.internettablettalk.com/forums/showthread.php?t=5209 |
|
|
//https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/src/maps.c?root=maemo-mapper&view=markup |
|
|
//http://www.ponies.me.uk/maps/GoogleTileUtils.java |
|
|
//http://www.mgmaps.com/cache/MapTileCacher.perl |
|
|
const char* |
|
|
osm_gps_map_source_get_repo_uri(OsmGpsMapSource_t source) |
|
|
{ |
|
|
switch(source) |
|
|
{ |
|
|
case OSM_GPS_MAP_SOURCE_NULL: |
|
|
return "none://"; |
|
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
|
|
return OSM_REPO_URI; |
|
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
|
|
return "http://tah.openstreetmap.org/Tiles/tile/#Z/#X/#Y.png"; |
|
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
|
|
return "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z/#X/#Y.jpg"; |
|
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
|
|
return "http://maps-for-free.com/layer/relief/z#Z/row#Y/#Z_#X-#Y.jpg"; |
|
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
|
|
return "http://mt#R.google.com/vt/v=w2.97&x=#X&y=#Y&z=#Z"; |
|
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
|
|
return "http://khm#R.google.com/kh?n=404&v=3&t=#Q"; |
|
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
|
|
return NULL; /* No longer working "http://mt#R.google.com/mt?n=404&v=w2t.99&x=#X&y=#Y&zoom=#S" */ |
|
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
|
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/r#W.jpeg?g=50"; |
|
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
|
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/a#W.jpeg?g=50"; |
|
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
|
|
return "http://a#R.ortho.tiles.virtualearth.net/tiles/h#W.jpeg?g=50"; |
|
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
|
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
|
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
|
|
/* TODO: Implement signed Y, aka U |
|
|
* http://us.maps3.yimg.com/aerial.maps.yimg.com/ximg?v=1.7&t=a&s=256&x=%d&y=%-d&z=%d |
|
|
* x = tilex, |
|
|
* y = (1 << (MAX_ZOOM - zoom)) - tiley - 1, |
|
|
* z = zoom - (MAX_ZOOM - 17)); |
|
|
*/ |
|
|
return NULL; |
|
|
default: |
|
|
return NULL; |
|
|
} |
|
|
return NULL; |
|
|
} |
|
1544 |
|
|
1545 |
const char * |
#ifdef OSD_SOURCE_SEL |
1546 |
osm_gps_map_source_get_image_format(OsmGpsMapSource_t source) |
/* the initial OSD state is alway not-expanded */ |
1547 |
{ |
priv->source_sel.surface = |
1548 |
switch(source) { |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1549 |
case OSM_GPS_MAP_SOURCE_NULL: |
OSD_S_W+2, OSD_S_H+2); |
1550 |
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
priv->source_sel.rendered = FALSE; |
1551 |
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
#endif |
|
return "png"; |
|
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
|
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
|
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
|
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
|
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
|
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
|
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
|
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
|
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
|
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
|
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
|
|
return "jpg"; |
|
|
default: |
|
|
return "bin"; |
|
|
} |
|
|
return "bin"; |
|
|
} |
|
1552 |
|
|
1553 |
|
#ifdef OSD_SCALE |
1554 |
|
priv->scale.surface = |
1555 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1556 |
|
OSD_SCALE_W, OSD_SCALE_H); |
1557 |
|
priv->scale.zoom = -1; |
1558 |
|
#endif |
1559 |
|
|
1560 |
int |
#ifdef OSD_CROSSHAIR |
1561 |
osm_gps_map_source_get_min_zoom(OsmGpsMapSource_t source) |
priv->crosshair.surface = |
1562 |
{ |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1563 |
return 1; |
OSD_CROSSHAIR_W, OSD_CROSSHAIR_H); |
1564 |
} |
priv->crosshair.rendered = FALSE; |
1565 |
|
#endif |
1566 |
|
|
1567 |
int |
#ifdef OSD_COORDINATES |
1568 |
osm_gps_map_source_get_max_zoom(OsmGpsMapSource_t source) |
priv->coordinates.surface = |
1569 |
{ |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1570 |
switch(source) { |
OSD_COORDINATES_W, OSD_COORDINATES_H); |
|
case OSM_GPS_MAP_SOURCE_NULL: |
|
|
return 18; |
|
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP: |
|
|
return OSM_MAX_ZOOM; |
|
|
case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER: |
|
|
case OSM_GPS_MAP_SOURCE_OPENAERIALMAP: |
|
|
case OSM_GPS_MAP_SOURCE_GOOGLE_STREET: |
|
|
case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID: |
|
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET: |
|
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE: |
|
|
case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID: |
|
|
case OSM_GPS_MAP_SOURCE_YAHOO_STREET: |
|
|
case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE: |
|
|
case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID: |
|
|
return 17; |
|
|
case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE: |
|
|
return 11; |
|
|
case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE: |
|
|
return 18; |
|
|
default: |
|
|
return 17; |
|
|
} |
|
|
return 17; |
|
|
} |
|
1571 |
|
|
1572 |
void |
priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID; |
1573 |
osm_gps_map_download_maps (OsmGpsMap *map, coord_t *pt1, coord_t *pt2, int zoom_start, int zoom_end) |
#endif |
|
{ |
|
|
int i,j,zoom,num_tiles; |
|
|
OsmGpsMapPrivate *priv = map->priv; |
|
1574 |
|
|
1575 |
if (pt1 && pt2) |
/* ... and render it */ |
1576 |
{ |
osd_render(osd); |
|
gchar *filename; |
|
|
num_tiles = 0; |
|
|
zoom_end = CLAMP(zoom_end, priv->min_zoom, priv->max_zoom); |
|
|
g_debug("Download maps: z:%d->%d",zoom_start, zoom_end); |
|
|
|
|
|
for(zoom=zoom_start; zoom<=zoom_end; zoom++) |
|
|
{ |
|
|
int x1,y1,x2,y2; |
|
|
|
|
|
x1 = (int)floor((float)lon2pixel(zoom, pt1->rlon) / (float)TILESIZE); |
|
|
y1 = (int)floor((float)lat2pixel(zoom, pt1->rlat) / (float)TILESIZE); |
|
|
|
|
|
x2 = (int)floor((float)lon2pixel(zoom, pt2->rlon) / (float)TILESIZE); |
|
|
y2 = (int)floor((float)lat2pixel(zoom, pt2->rlat) / (float)TILESIZE); |
|
|
|
|
|
// loop x1-x2 |
|
|
for(i=x1; i<=x2; i++) |
|
|
{ |
|
|
// loop y1 - y2 |
|
|
for(j=y1; j<=y2; j++) |
|
|
{ |
|
|
// x = i, y = j |
|
|
filename = g_strdup_printf("%s%c%d%c%d%c%d.%s", |
|
|
priv->cache_dir, G_DIR_SEPARATOR, |
|
|
zoom, G_DIR_SEPARATOR, |
|
|
i, G_DIR_SEPARATOR, |
|
|
j, |
|
|
priv->image_format); |
|
|
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) |
|
|
{ |
|
|
osm_gps_map_download_tile(map, zoom, i, j, FALSE); |
|
|
num_tiles++; |
|
|
} |
|
|
g_free(filename); |
|
|
} |
|
|
} |
|
|
g_debug("DL @Z:%d = %d tiles",zoom,num_tiles); |
|
|
} |
|
1577 |
} |
} |
|
} |
|
|
|
|
|
void |
|
|
osm_gps_map_get_bbox (OsmGpsMap *map, coord_t *pt1, coord_t *pt2) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv = map->priv; |
|
1578 |
|
|
1579 |
if (pt1 && pt2) { |
// now draw this onto the original context |
1580 |
pt1->rlat = pixel2lat(priv->map_zoom, priv->map_y); |
cairo_t *cr = gdk_cairo_create(drawable); |
|
pt1->rlon = pixel2lon(priv->map_zoom, priv->map_x); |
|
|
pt2->rlat = pixel2lat(priv->map_zoom, priv->map_y + GTK_WIDGET(map)->allocation.height); |
|
|
pt2->rlon = pixel2lon(priv->map_zoom, priv->map_x + GTK_WIDGET(map)->allocation.width); |
|
|
|
|
|
g_debug("BBOX: %f %f %f %f", pt1->rlat, pt1->rlon, pt2->rlat, pt2->rlon); |
|
|
} |
|
|
} |
|
1581 |
|
|
1582 |
void |
int x, y; |
|
osm_gps_map_set_mapcenter (OsmGpsMap *map, float latitude, float longitude, int zoom) |
|
|
{ |
|
|
osm_gps_map_set_center (map, latitude, longitude); |
|
|
osm_gps_map_set_zoom (map, zoom); |
|
|
} |
|
1583 |
|
|
1584 |
void |
#ifdef OSD_SCALE |
1585 |
osm_gps_map_set_center (OsmGpsMap *map, float latitude, float longitude) |
x = OSD_X; |
1586 |
{ |
y = -OSD_Y; |
1587 |
int pixel_x, pixel_y; |
if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W; |
1588 |
OsmGpsMapPrivate *priv; |
if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H; |
1589 |
|
|
1590 |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
cairo_set_source_surface(cr, priv->scale.surface, x, y); |
1591 |
priv = map->priv; |
cairo_paint(cr); |
1592 |
|
#endif |
1593 |
|
|
1594 |
priv->center_rlat = deg2rad(latitude); |
#ifdef OSD_CROSSHAIR |
1595 |
priv->center_rlon = deg2rad(longitude); |
x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2; |
1596 |
priv->center_coord_set = TRUE; |
y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2; |
|
|
|
|
// pixel_x,y, offsets |
|
|
pixel_x = lon2pixel(priv->map_zoom, priv->center_rlon); |
|
|
pixel_y = lat2pixel(priv->map_zoom, priv->center_rlat); |
|
1597 |
|
|
1598 |
priv->map_x = pixel_x - GTK_WIDGET(map)->allocation.width/2; |
cairo_set_source_surface(cr, priv->crosshair.surface, x, y); |
1599 |
priv->map_y = pixel_y - GTK_WIDGET(map)->allocation.height/2; |
cairo_paint(cr); |
1600 |
|
#endif |
1601 |
|
|
1602 |
osm_gps_map_map_redraw_idle(map); |
#ifdef OSD_COORDINATES |
1603 |
} |
x = -OSD_X; |
1604 |
|
y = -OSD_Y; |
1605 |
|
if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W; |
1606 |
|
if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H; |
1607 |
|
|
1608 |
int |
cairo_set_source_surface(cr, priv->coordinates.surface, x, y); |
1609 |
osm_gps_map_set_zoom (OsmGpsMap *map, int zoom) |
cairo_paint(cr); |
1610 |
{ |
#endif |
|
int zoom_old; |
|
|
double factor = 0.0; |
|
|
int width_center, height_center; |
|
|
OsmGpsMapPrivate *priv; |
|
1611 |
|
|
1612 |
g_return_val_if_fail (OSM_IS_GPS_MAP (map), 0); |
x = OSD_X; |
1613 |
priv = map->priv; |
if(x < 0) |
1614 |
|
x += osd->widget->allocation.width - OSD_W; |
1615 |
|
|
1616 |
|
y = OSD_Y; |
1617 |
|
if(y < 0) |
1618 |
|
y += osd->widget->allocation.height - OSD_H; |
1619 |
|
|
1620 |
if (zoom != priv->map_zoom) |
cairo_set_source_surface(cr, priv->controls.surface, x, y); |
1621 |
{ |
cairo_paint(cr); |
|
width_center = GTK_WIDGET(map)->allocation.width / 2; |
|
|
height_center = GTK_WIDGET(map)->allocation.height / 2; |
|
1622 |
|
|
1623 |
zoom_old = priv->map_zoom; |
#ifdef OSD_SOURCE_SEL |
1624 |
//constrain zoom min_zoom -> max_zoom |
if(!priv->source_sel.handler_id) { |
1625 |
priv->map_zoom = CLAMP(zoom, priv->min_zoom, priv->max_zoom); |
/* the OSD source selection is not being animated */ |
1626 |
|
if(!priv->source_sel.expanded) |
1627 |
if (priv->center_coord_set) |
x = osd->widget->allocation.width - OSD_S_W; |
|
{ |
|
|
priv->map_x = lon2pixel(priv->map_zoom, priv->center_rlon) - width_center; |
|
|
priv->map_y = lat2pixel(priv->map_zoom, priv->center_rlat) - height_center; |
|
|
} |
|
1628 |
else |
else |
1629 |
{ |
x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
1630 |
factor = exp(priv->map_zoom * M_LN2)/exp(zoom_old * M_LN2); |
} else |
1631 |
priv->map_x = ((priv->map_x + width_center) * factor) - width_center; |
x = priv->source_sel.shift; |
1632 |
priv->map_y = ((priv->map_y + height_center) * factor) - height_center; |
|
1633 |
} |
y = OSD_S_Y; |
1634 |
|
if(OSD_S_Y < 0) { |
1635 |
g_debug("Zoom changed from %d to %d factor:%f x:%d", |
if(!priv->source_sel.expanded) |
1636 |
zoom_old, priv->map_zoom, factor, priv->map_x); |
y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y; |
1637 |
|
else |
1638 |
osm_gps_map_map_redraw_idle(map); |
y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y; |
|
} |
|
|
return priv->map_zoom; |
|
|
} |
|
|
|
|
|
void |
|
|
osm_gps_map_add_track (OsmGpsMap *map, GSList *track) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv; |
|
|
|
|
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
|
|
priv = map->priv; |
|
|
|
|
|
if (track) { |
|
|
priv->tracks = g_slist_append(priv->tracks, track); |
|
|
osm_gps_map_map_redraw_idle(map); |
|
|
} |
|
|
} |
|
|
|
|
|
void |
|
|
osm_gps_map_clear_tracks (OsmGpsMap *map) |
|
|
{ |
|
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
|
|
|
|
|
osm_gps_map_free_tracks(map); |
|
|
osm_gps_map_map_redraw_idle(map); |
|
|
} |
|
|
|
|
|
void |
|
|
osm_gps_map_add_image (OsmGpsMap *map, float latitude, float longitude, GdkPixbuf *image) |
|
|
{ |
|
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
|
|
|
|
|
if (image) { |
|
|
OsmGpsMapPrivate *priv = map->priv; |
|
|
image_t *im; |
|
|
|
|
|
//cache w/h for speed, and add image to list |
|
|
im = g_new0(image_t,1); |
|
|
im->w = gdk_pixbuf_get_width(image); |
|
|
im->h = gdk_pixbuf_get_height(image); |
|
|
im->pt.rlat = deg2rad(latitude); |
|
|
im->pt.rlon = deg2rad(longitude); |
|
|
|
|
|
g_object_ref(image); |
|
|
im->image = image; |
|
|
|
|
|
priv->images = g_slist_append(priv->images, im); |
|
|
|
|
|
osm_gps_map_map_redraw_idle(map); |
|
|
} |
|
|
} |
|
|
|
|
|
gboolean |
|
|
osm_gps_map_remove_image (OsmGpsMap *map, GdkPixbuf *image) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv = map->priv; |
|
|
if (priv->images) { |
|
|
GSList *list; |
|
|
for(list = priv->images; list != NULL; list = list->next) |
|
|
{ |
|
|
image_t *im = list->data; |
|
|
if (im->image == image) |
|
|
{ |
|
|
priv->images = g_slist_remove_link(priv->images, list); |
|
|
g_object_unref(im->image); |
|
|
g_free(im); |
|
|
osm_gps_map_map_redraw_idle(map); |
|
|
return TRUE; |
|
|
} |
|
|
} |
|
1639 |
} |
} |
|
return FALSE; |
|
|
} |
|
1640 |
|
|
1641 |
void |
cairo_set_source_surface(cr, priv->source_sel.surface, x, y); |
1642 |
osm_gps_map_clear_images (OsmGpsMap *map) |
cairo_paint(cr); |
1643 |
{ |
#endif |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
|
1644 |
|
|
1645 |
osm_gps_map_free_images(map); |
cairo_destroy(cr); |
|
osm_gps_map_map_redraw_idle(map); |
|
1646 |
} |
} |
1647 |
|
|
1648 |
void |
static void |
1649 |
osm_gps_map_osd_speed (OsmGpsMap *map, float speed) |
osd_free(osm_gps_map_osd_t *osd) |
1650 |
{ |
{ |
1651 |
OsmGpsMapPrivate *priv; |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1652 |
|
|
1653 |
PangoContext *context = NULL; |
if (priv->controls.surface) |
1654 |
PangoLayout *layout = NULL; |
cairo_surface_destroy(priv->controls.surface); |
|
PangoFontDescription *desc = NULL; |
|
|
|
|
|
GdkColor color; |
|
|
GdkGC *gc; |
|
|
|
|
|
gchar *buffer; |
|
|
//static int x = 10, y = 10; |
|
|
static int width = 0, height = 0; |
|
1655 |
|
|
1656 |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
#ifdef OSD_SOURCE_SEL |
1657 |
priv = map->priv; |
if(priv->source_sel.handler_id) |
1658 |
|
gtk_timeout_remove(priv->source_sel.handler_id); |
|
buffer = g_strdup_printf("%.0f", speed); |
|
|
|
|
|
/* pango initialisation */ |
|
|
context = gtk_widget_get_pango_context (GTK_WIDGET(map)); |
|
|
layout = pango_layout_new (context); |
|
|
desc = pango_font_description_new(); |
|
|
|
|
|
pango_font_description_set_size (desc, 40 * PANGO_SCALE); |
|
|
pango_layout_set_font_description (layout, desc); |
|
|
pango_layout_set_text (layout, buffer, strlen(buffer)); |
|
|
|
|
|
gc = gdk_gc_new (GTK_WIDGET(map)->window); |
|
|
|
|
|
color.red = (0 > 50) ? 0xffff : 0; |
|
|
color.green = 0; |
|
|
color.blue = 0; |
|
|
|
|
|
gdk_gc_set_rgb_fg_color (gc, &color); |
|
|
|
|
|
/* faster / less flicker alternative:*/ |
|
|
gdk_draw_drawable ( |
|
|
GTK_WIDGET(map)->window, |
|
|
GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(map)], |
|
|
priv->pixmap, |
|
|
0,0, |
|
|
0,0, |
|
|
width+10,width+10); |
|
|
|
|
|
gdk_draw_layout(GTK_WIDGET(map)->window, |
|
|
gc, |
|
|
0, 0, |
|
|
layout); |
|
|
|
|
|
/* set width and height */ |
|
|
pango_layout_get_pixel_size(layout, &width, &height); |
|
|
|
|
|
g_free(buffer); |
|
|
pango_font_description_free (desc); |
|
|
g_object_unref (layout); |
|
|
g_object_unref (gc); |
|
|
} |
|
1659 |
|
|
1660 |
void |
if (priv->source_sel.surface) |
1661 |
osm_gps_map_draw_gps (OsmGpsMap *map, float latitude, float longitude, float heading) |
cairo_surface_destroy(priv->source_sel.surface); |
1662 |
{ |
#endif |
|
int pixel_x, pixel_y; |
|
|
OsmGpsMapPrivate *priv; |
|
|
|
|
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
|
|
priv = map->priv; |
|
|
|
|
|
priv->gps->rlat = deg2rad(latitude); |
|
|
priv->gps->rlon = deg2rad(longitude); |
|
|
priv->gps_valid = TRUE; |
|
|
|
|
|
// pixel_x,y, offsets |
|
|
pixel_x = lon2pixel(priv->map_zoom, priv->gps->rlon); |
|
|
pixel_y = lat2pixel(priv->map_zoom, priv->gps->rlat); |
|
|
|
|
|
//If trip marker add to list of gps points. |
|
|
if (priv->record_trip_history) { |
|
|
coord_t *tp = g_new0(coord_t,1); |
|
|
tp->rlat = priv->gps->rlat; |
|
|
tp->rlon = priv->gps->rlon; |
|
|
priv->trip_history = g_slist_append(priv->trip_history, tp); |
|
|
} |
|
|
|
|
|
// dont draw anything if we are dragging |
|
|
if (priv->dragging) { |
|
|
g_debug("Dragging"); |
|
|
return; |
|
|
} |
|
1663 |
|
|
1664 |
//Automatically center the map if the track approaches the edge |
#ifdef OSD_SCALE |
1665 |
if(priv->map_auto_center) { |
if (priv->scale.surface) |
1666 |
int x = pixel_x - priv->map_x; |
cairo_surface_destroy(priv->scale.surface); |
1667 |
int y = pixel_y - priv->map_y; |
#endif |
|
int width = GTK_WIDGET(map)->allocation.width; |
|
|
int height = GTK_WIDGET(map)->allocation.height; |
|
|
if( x < (width/2 - width/8) || x > (width/2 + width/8) || |
|
|
y < (height/2 - height/8) || y > (height/2 + height/8)) { |
|
|
|
|
|
priv->map_x = pixel_x - GTK_WIDGET(map)->allocation.width/2; |
|
|
priv->map_y = pixel_y - GTK_WIDGET(map)->allocation.height/2; |
|
|
priv->center_coord_set = FALSE; |
|
|
} |
|
|
} |
|
1668 |
|
|
1669 |
// this redraws the map (including the gps track, and adjusts the |
#ifdef OSD_CROSSHAIR |
1670 |
// map center if it was changed |
if (priv->crosshair.surface) |
1671 |
osm_gps_map_map_redraw_idle(map); |
cairo_surface_destroy(priv->crosshair.surface); |
1672 |
} |
#endif |
1673 |
|
|
1674 |
void |
#ifdef OSD_COORDINATES |
1675 |
osm_gps_map_clear_gps (OsmGpsMap *map) |
if (priv->coordinates.surface) |
1676 |
{ |
cairo_surface_destroy(priv->coordinates.surface); |
1677 |
osm_gps_map_free_trip(map); |
#endif |
|
osm_gps_map_map_redraw_idle(map); |
|
|
} |
|
1678 |
|
|
1679 |
coord_t |
#ifdef OSD_BALLOON |
1680 |
osm_gps_map_get_co_ordinates (OsmGpsMap *map, int pixel_x, int pixel_y) |
if (priv->balloon.surface) |
1681 |
{ |
cairo_surface_destroy(priv->balloon.surface); |
1682 |
coord_t coord; |
#endif |
|
OsmGpsMapPrivate *priv = map->priv; |
|
1683 |
|
|
1684 |
coord.rlat = pixel2lat(priv->map_zoom, priv->map_y + pixel_y); |
g_free(priv); |
|
coord.rlon = pixel2lon(priv->map_zoom, priv->map_x + pixel_x); |
|
|
return coord; |
|
1685 |
} |
} |
1686 |
|
|
1687 |
GtkWidget * |
static gboolean |
1688 |
osm_gps_map_new (void) |
osd_busy(osm_gps_map_osd_t *osd) |
1689 |
{ |
{ |
1690 |
return g_object_new (OSM_TYPE_GPS_MAP, NULL); |
#ifdef OSD_SOURCE_SEL |
1691 |
|
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1692 |
|
return (priv->source_sel.handler_id != 0); |
1693 |
|
#else |
1694 |
|
return FALSE; |
1695 |
|
#endif |
1696 |
} |
} |
1697 |
|
|
1698 |
void |
static osm_gps_map_osd_t osd_classic = { |
1699 |
osm_gps_map_screen_to_geographic (OsmGpsMap *map, gint pixel_x, gint pixel_y, |
.widget = NULL, |
|
gfloat *latitude, gfloat *longitude) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv; |
|
1700 |
|
|
1701 |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
.draw = osd_draw, |
1702 |
priv = map->priv; |
.check = osd_check, |
1703 |
|
.render = osd_render, |
1704 |
|
.free = osd_free, |
1705 |
|
.busy = osd_busy, |
1706 |
|
|
1707 |
if (latitude) |
.cb = NULL, |
1708 |
*latitude = rad2deg(pixel2lat(priv->map_zoom, priv->map_y + pixel_y)); |
.data = NULL, |
|
if (longitude) |
|
|
*longitude = rad2deg(pixel2lon(priv->map_zoom, priv->map_x + pixel_x)); |
|
|
} |
|
1709 |
|
|
1710 |
void |
.priv = NULL |
1711 |
osm_gps_map_geographic_to_screen (OsmGpsMap *map, |
}; |
|
gfloat latitude, gfloat longitude, |
|
|
gint *pixel_x, gint *pixel_y) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv; |
|
|
|
|
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
|
|
priv = map->priv; |
|
|
|
|
|
if (pixel_x) |
|
|
*pixel_x = lon2pixel(priv->map_zoom, deg2rad(longitude)) - priv->map_x; |
|
|
if (pixel_y) |
|
|
*pixel_y = lat2pixel(priv->map_zoom, deg2rad(latitude)) - priv->map_y; |
|
|
} |
|
1712 |
|
|
1713 |
|
/* this is the only function that's externally visible */ |
1714 |
void |
void |
1715 |
osm_gps_map_scroll (OsmGpsMap *map, gint dx, gint dy) |
osm_gps_map_osd_classic_init(OsmGpsMap *map) |
|
{ |
|
|
OsmGpsMapPrivate *priv; |
|
|
|
|
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
|
|
priv = map->priv; |
|
|
|
|
|
priv->center_coord_set = FALSE; |
|
|
priv->map_x += dx; |
|
|
priv->map_y += dy; |
|
|
|
|
|
osm_gps_map_map_redraw_idle (map); |
|
|
} |
|
|
|
|
|
float |
|
|
osm_gps_map_get_scale(OsmGpsMap *map) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv; |
|
|
|
|
|
g_return_val_if_fail (OSM_IS_GPS_MAP (map), OSM_NAN); |
|
|
priv = map->priv; |
|
|
|
|
|
return osm_gps_map_get_scale_at_point(priv->map_zoom, priv->center_rlat, priv->center_rlon); |
|
|
} |
|
|
|
|
|
#ifdef ENABLE_BALLOON |
|
|
void |
|
|
osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
|
|
OsmGpsMapBalloonCallback cb, gpointer data) |
|
1716 |
{ |
{ |
1717 |
OsmGpsMapPrivate *priv; |
osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1); |
|
|
|
|
/* remove and previously installed balloon */ |
|
|
osm_gps_map_clear_balloon (map); |
|
|
|
|
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
|
|
priv = map->priv; |
|
|
|
|
|
priv->balloon.coo->rlat = deg2rad(latitude); |
|
|
priv->balloon.coo->rlon = deg2rad(longitude); |
|
|
priv->balloon.valid = TRUE; |
|
|
|
|
|
priv->balloon.cb = cb; |
|
|
priv->balloon.data = data; |
|
|
|
|
|
// this redraws the map |
|
|
osm_gps_map_map_redraw_idle(map); |
|
|
} |
|
1718 |
|
|
1719 |
void |
#ifdef OSD_BALLOON |
1720 |
osm_gps_map_clear_balloon (OsmGpsMap *map) |
priv->balloon.lat = OSM_GPS_MAP_INVALID; |
1721 |
{ |
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
1722 |
OsmGpsMapPrivate *priv; |
#endif |
1723 |
|
|
1724 |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
osd_classic.priv = priv; |
|
priv = map->priv; |
|
1725 |
|
|
1726 |
priv->balloon.valid = FALSE; |
osm_gps_map_register_osd(map, &osd_classic); |
|
|
|
|
osm_gps_map_map_redraw_idle(map); |
|
1727 |
} |
} |
|
#endif |
|
|
|
|
|
#ifdef ENABLE_OSD |
|
|
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdGpsCallback cb, gpointer data) { |
|
|
OsmGpsMapPrivate *priv; |
|
1728 |
|
|
1729 |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
#ifdef OSD_GPS_BUTTON |
1730 |
priv = map->priv; |
/* below are osd specific functions which aren't used by osm-gps-map */ |
1731 |
|
/* but instead are to be used by the main application */ |
1732 |
|
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, |
1733 |
|
gpointer data) { |
1734 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1735 |
|
g_return_if_fail (osd); |
1736 |
|
|
1737 |
priv->osd.cb = cb; |
osd->cb = cb; |
1738 |
priv->osd.data = data; |
osd->data = data; |
1739 |
|
|
1740 |
/* this may have changed the state of the gps button */ |
/* this may have changed the state of the gps button */ |
1741 |
/* we thus re-render the overlay */ |
/* we thus re-render the overlay */ |
1742 |
osm_gps_map_osd_render(priv); |
osd->render(osd); |
1743 |
|
|
1744 |
osm_gps_map_map_redraw_idle(map); |
osm_gps_map_redraw(map); |
1745 |
} |
} |
1746 |
#endif |
#endif |
1747 |
|
|
1748 |
|
osd_button_t |
1749 |
|
osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) { |
1750 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1751 |
|
g_return_val_if_fail (osd, OSD_NONE); |
1752 |
|
|
1753 |
|
return osd_check(osd, x, y); |
1754 |
|
} |