Parent Directory | Revision Log
Map handles overwritten coordinates
1 | harbaum | 71 | /* -*- 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 | harbaum | 70 | /* |
4 | * Copyright (C) Till Harbaum 2009 <till@harbaum.org> | ||
5 | * | ||
6 | * osm-gps-map is free software: you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation, either version 3 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * osm-gps-map is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
14 | * See the GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along | ||
17 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | harbaum | 73 | #include "config.h" |
21 | #include <stdlib.h> // abs | ||
22 | harbaum | 87 | #include <math.h> // M_PI/cos() |
23 | harbaum | 70 | |
24 | harbaum | 71 | /* parameters that can be overwritten from the config file: */ |
25 | harbaum | 77 | /* OSD_DIAMETER */ |
26 | /* OSD_X, OSD_Y */ | ||
27 | harbaum | 71 | |
28 | #ifndef USE_CAIRO | ||
29 | #error "OSD control display lacks a non-cairo implementation!" | ||
30 | harbaum | 70 | #endif |
31 | |||
32 | harbaum | 71 | #include <cairo.h> |
33 | |||
34 | #include "osm-gps-map.h" | ||
35 | harbaum | 112 | #include "converter.h" |
36 | harbaum | 73 | #include "osm-gps-map-osd-classic.h" |
37 | harbaum | 71 | |
38 | harbaum | 70 | //the osd controls |
39 | typedef struct { | ||
40 | harbaum | 74 | /* the offscreen representation of the OSD */ |
41 | harbaum | 108 | struct { |
42 | cairo_surface_t *surface; | ||
43 | gboolean rendered; | ||
44 | #ifdef OSD_GPS_BUTTON | ||
45 | gboolean gps_enabled; | ||
46 | #endif | ||
47 | } controls; | ||
48 | harbaum | 86 | |
49 | harbaum | 112 | #ifdef OSD_BALLOON |
50 | //a balloon with additional info | ||
51 | struct { | ||
52 | cairo_surface_t *surface; | ||
53 | harbaum | 113 | int orientation, offset_x, offset_y; |
54 | harbaum | 112 | |
55 | harbaum | 114 | gboolean just_created; |
56 | harbaum | 112 | float lat, lon; |
57 | OsmGpsMapRect_t rect; | ||
58 | |||
59 | /* function called to have the user app draw the contents */ | ||
60 | OsmGpsMapBalloonCallback cb; | ||
61 | gpointer data; | ||
62 | } balloon; | ||
63 | #endif | ||
64 | |||
65 | harbaum | 98 | #ifdef OSD_SCALE |
66 | harbaum | 110 | struct { |
67 | cairo_surface_t *surface; | ||
68 | int zoom; | ||
69 | } scale; | ||
70 | harbaum | 98 | #endif |
71 | harbaum | 110 | |
72 | harbaum | 105 | #ifdef OSD_CROSSHAIR |
73 | harbaum | 110 | struct { |
74 | cairo_surface_t *surface; | ||
75 | gboolean rendered; | ||
76 | } crosshair; | ||
77 | harbaum | 105 | #endif |
78 | |||
79 | harbaum | 106 | #ifdef OSD_COORDINATES |
80 | harbaum | 110 | struct { |
81 | cairo_surface_t *surface; | ||
82 | float lat, lon; | ||
83 | } coordinates; | ||
84 | harbaum | 106 | #endif |
85 | |||
86 | harbaum | 88 | #ifdef OSD_SOURCE_SEL |
87 | harbaum | 110 | struct { |
88 | /* values to handle the "source" menu */ | ||
89 | cairo_surface_t *surface; | ||
90 | gboolean expanded; | ||
91 | gint shift, dir, count; | ||
92 | gint handler_id; | ||
93 | gint width, height; | ||
94 | harbaum | 111 | gboolean rendered; |
95 | harbaum | 110 | } source_sel; |
96 | harbaum | 88 | #endif |
97 | harbaum | 87 | |
98 | harbaum | 70 | } osd_priv_t; |
99 | |||
100 | harbaum | 112 | #ifdef OSD_BALLOON |
101 | /* most visual effects are hardcoded by now, but may be made */ | ||
102 | /* available via properties later */ | ||
103 | #ifndef BALLOON_AREA_WIDTH | ||
104 | #define BALLOON_AREA_WIDTH 290 | ||
105 | #endif | ||
106 | #ifndef BALLOON_AREA_HEIGHT | ||
107 | #define BALLOON_AREA_HEIGHT 75 | ||
108 | #endif | ||
109 | #ifndef BALLOON_CORNER_RADIUS | ||
110 | #define BALLOON_CORNER_RADIUS 10 | ||
111 | #endif | ||
112 | |||
113 | #define BALLOON_BORDER (BALLOON_CORNER_RADIUS/2) | ||
114 | #define BALLOON_WIDTH (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER) | ||
115 | #define BALLOON_HEIGHT (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER) | ||
116 | #define BALLOON_TRANSPARENCY 0.8 | ||
117 | #define POINTER_HEIGHT 20 | ||
118 | #define POINTER_FOOT_WIDTH 20 | ||
119 | #define POINTER_OFFSET (BALLOON_CORNER_RADIUS*3/4) | ||
120 | #define BALLOON_SHADOW (BALLOON_CORNER_RADIUS/2) | ||
121 | #define BALLOON_SHADOW_TRANSPARENCY 0.2 | ||
122 | |||
123 | harbaum | 113 | #define BALLOON_W (BALLOON_WIDTH + BALLOON_SHADOW) |
124 | #define BALLOON_H (BALLOON_HEIGHT + POINTER_HEIGHT + BALLOON_SHADOW) | ||
125 | |||
126 | harbaum | 112 | #define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) |
127 | |||
128 | |||
129 | /* draw the bubble shape. this is used twice, once for the shape and once */ | ||
130 | /* for the shadow */ | ||
131 | static void | ||
132 | osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1, | ||
133 | gboolean bottom, int px, int py, int px0, int px1) { | ||
134 | |||
135 | cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); | ||
136 | cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, | ||
137 | BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2); | ||
138 | if(!bottom) { | ||
139 | /* insert top pointer */ | ||
140 | cairo_line_to (cr, px1, y0); | ||
141 | cairo_line_to (cr, px, py); | ||
142 | cairo_line_to (cr, px0, y0); | ||
143 | } | ||
144 | |||
145 | cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0); | ||
146 | cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, | ||
147 | BALLOON_CORNER_RADIUS, -M_PI/2, 0); | ||
148 | cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS); | ||
149 | cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, | ||
150 | BALLOON_CORNER_RADIUS, 0, M_PI/2); | ||
151 | if(bottom) { | ||
152 | /* insert bottom pointer */ | ||
153 | cairo_line_to (cr, px0, y1); | ||
154 | cairo_line_to (cr, px, py); | ||
155 | cairo_line_to (cr, px1, y1); | ||
156 | } | ||
157 | |||
158 | cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1); | ||
159 | cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, | ||
160 | BALLOON_CORNER_RADIUS, M_PI/2, M_PI); | ||
161 | |||
162 | cairo_close_path (cr); | ||
163 | } | ||
164 | |||
165 | static void | ||
166 | osd_render_balloon(osm_gps_map_osd_t *osd) { | ||
167 | osd_priv_t *priv = (osd_priv_t*)osd->priv; | ||
168 | |||
169 | /* get zoom */ | ||
170 | gint zoom; | ||
171 | g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); | ||
172 | |||
173 | /* ------- convert given coordinate into screen position --------- */ | ||
174 | harbaum | 113 | gint xs, ys; |
175 | harbaum | 112 | osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
176 | priv->balloon.lat, priv->balloon.lon, | ||
177 | harbaum | 113 | &xs, &ys); |
178 | harbaum | 112 | |
179 | harbaum | 113 | gint x0 = 1, y0 = 1; |
180 | |||
181 | harbaum | 112 | /* check position of this relative to screen center to determine */ |
182 | /* pointer direction ... */ | ||
183 | harbaum | 113 | int pointer_x, pointer_x0, pointer_x1; |
184 | int pointer_y; | ||
185 | harbaum | 112 | |
186 | /* ... and calculate position */ | ||
187 | harbaum | 113 | int orientation = 0; |
188 | if(xs > osd->widget->allocation.width/2) { | ||
189 | priv->balloon.offset_x = -BALLOON_WIDTH + POINTER_OFFSET; | ||
190 | pointer_x = x0 - priv->balloon.offset_x; | ||
191 | harbaum | 112 | pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
192 | pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH; | ||
193 | harbaum | 113 | orientation |= 1; |
194 | harbaum | 112 | } else { |
195 | harbaum | 113 | priv->balloon.offset_x = -POINTER_OFFSET; |
196 | pointer_x = x0 - priv->balloon.offset_x; | ||
197 | harbaum | 112 | pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
198 | pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH; | ||
199 | } | ||
200 | |||
201 | gboolean bottom = FALSE; | ||
202 | harbaum | 113 | if(ys > osd->widget->allocation.height/2) { |
203 | priv->balloon.offset_y = -BALLOON_HEIGHT - POINTER_HEIGHT; | ||
204 | pointer_y = y0 - priv->balloon.offset_y; | ||
205 | harbaum | 112 | bottom = TRUE; |
206 | harbaum | 113 | orientation |= 2; |
207 | } else { | ||
208 | priv->balloon.offset_y = 0; | ||
209 | pointer_y = y0 - priv->balloon.offset_y; | ||
210 | harbaum | 112 | y0 += POINTER_HEIGHT; |
211 | harbaum | 113 | } |
212 | harbaum | 112 | |
213 | harbaum | 113 | /* if required orientation equals current one, then don't render */ |
214 | /* anything */ | ||
215 | if(orientation == priv->balloon.orientation) | ||
216 | return; | ||
217 | |||
218 | priv->balloon.orientation = orientation; | ||
219 | |||
220 | harbaum | 112 | /* calculate bottom/right of box */ |
221 | int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT; | ||
222 | |||
223 | /* save balloon screen coordinates for later use */ | ||
224 | priv->balloon.rect.x = x0 + BALLOON_BORDER; | ||
225 | priv->balloon.rect.y = y0 + BALLOON_BORDER; | ||
226 | priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER; | ||
227 | priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; | ||
228 | |||
229 | cairo_t *cr = cairo_create(priv->balloon.surface); | ||
230 | harbaum | 113 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
231 | cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); | ||
232 | cairo_paint(cr); | ||
233 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | ||
234 | harbaum | 112 | |
235 | /* --------- draw shadow --------------- */ | ||
236 | osm_gps_map_draw_balloon_shape (cr, | ||
237 | x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW, | ||
238 | x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW, | ||
239 | bottom, pointer_x, pointer_y, | ||
240 | pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW); | ||
241 | |||
242 | cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY); | ||
243 | cairo_fill_preserve (cr); | ||
244 | cairo_set_source_rgba (cr, 1, 0, 0, 1.0); | ||
245 | cairo_set_line_width (cr, 0); | ||
246 | cairo_stroke (cr); | ||
247 | |||
248 | /* --------- draw main shape ----------- */ | ||
249 | osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1, | ||
250 | bottom, pointer_x, pointer_y, pointer_x0, pointer_x1); | ||
251 | |||
252 | cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY); | ||
253 | cairo_fill_preserve (cr); | ||
254 | cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY); | ||
255 | cairo_set_line_width (cr, 1); | ||
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 | harbaum | 113 | |
270 | harbaum | 112 | cairo_destroy(cr); |
271 | } | ||
272 | |||
273 | /* return true if balloon is being displayed and if */ | ||
274 | /* the given coordinate is within this balloon */ | ||
275 | static gboolean | ||
276 | harbaum | 114 | osd_balloon_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) |
277 | harbaum | 112 | { |
278 | harbaum | 113 | osd_priv_t *priv = (osd_priv_t*)osd->priv; |
279 | harbaum | 112 | |
280 | harbaum | 113 | if(!priv->balloon.surface) |
281 | harbaum | 112 | return FALSE; |
282 | |||
283 | harbaum | 113 | gint xs, ys; |
284 | osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), | ||
285 | priv->balloon.lat, priv->balloon.lon, | ||
286 | &xs, &ys); | ||
287 | harbaum | 112 | |
288 | harbaum | 120 | printf("click at %d/%d\n", x, y); |
289 | |||
290 | harbaum | 113 | xs += priv->balloon.rect.x + priv->balloon.offset_x; |
291 | ys += priv->balloon.rect.y + priv->balloon.offset_y; | ||
292 | harbaum | 112 | |
293 | harbaum | 120 | printf("balloon at %d/%d/%d/%d\n", |
294 | xs, ys, | ||
295 | xs + priv->balloon.rect.w, | ||
296 | ys + priv->balloon.rect.h); | ||
297 | harbaum | 114 | |
298 | gboolean is_in = | ||
299 | (x > xs) && (x < xs + priv->balloon.rect.w) && | ||
300 | (y > ys) && (y < ys + priv->balloon.rect.h); | ||
301 | |||
302 | harbaum | 120 | /* handle the fact that the balloon may have been created by the */ |
303 | /* button down event */ | ||
304 | harbaum | 114 | if(!is_in && !down && !priv->balloon.just_created) { |
305 | /* the user actually clicked outside the balloon */ | ||
306 | |||
307 | /* close the balloon! */ | ||
308 | osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget)); | ||
309 | } | ||
310 | |||
311 | return is_in; | ||
312 | harbaum | 113 | } |
313 | harbaum | 112 | |
314 | harbaum | 113 | void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) { |
315 | harbaum | 112 | g_return_if_fail (OSM_IS_GPS_MAP (map)); |
316 | |||
317 | harbaum | 113 | osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
318 | g_return_if_fail (osd); | ||
319 | harbaum | 112 | |
320 | harbaum | 113 | osd_priv_t *priv = (osd_priv_t*)osd->priv; |
321 | g_return_if_fail (priv); | ||
322 | harbaum | 112 | |
323 | harbaum | 113 | if(priv->balloon.surface) { |
324 | cairo_surface_destroy(priv->balloon.surface); | ||
325 | priv->balloon.surface = NULL; | ||
326 | priv->balloon.lat = OSM_GPS_MAP_INVALID; | ||
327 | priv->balloon.lon = OSM_GPS_MAP_INVALID; | ||
328 | } | ||
329 | osm_gps_map_redraw(map); | ||
330 | harbaum | 112 | } |
331 | |||
332 | void | ||
333 | harbaum | 113 | osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
334 | OsmGpsMapBalloonCallback cb, gpointer data) { | ||
335 | harbaum | 112 | g_return_if_fail (OSM_IS_GPS_MAP (map)); |
336 | |||
337 | harbaum | 113 | osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
338 | g_return_if_fail (osd); | ||
339 | harbaum | 112 | |
340 | harbaum | 113 | osd_priv_t *priv = (osd_priv_t*)osd->priv; |
341 | g_return_if_fail (priv); | ||
342 | harbaum | 112 | |
343 | harbaum | 113 | osm_gps_map_osd_clear_balloon (map); |
344 | |||
345 | /* allocate balloon surface */ | ||
346 | priv->balloon.surface = | ||
347 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, | ||
348 | BALLOON_W+2, BALLOON_H+2); | ||
349 | |||
350 | priv->balloon.lat = latitude; | ||
351 | priv->balloon.lon = longitude; | ||
352 | priv->balloon.cb = cb; | ||
353 | priv->balloon.data = data; | ||
354 | harbaum | 114 | priv->balloon.just_created = TRUE; |
355 | harbaum | 113 | |
356 | priv->balloon.orientation = -1; | ||
357 | |||
358 | osd_render_balloon(osd); | ||
359 | |||
360 | osm_gps_map_redraw(map); | ||
361 | harbaum | 112 | } |
362 | |||
363 | #endif // OSD_BALLOON | ||
364 | |||
365 | harbaum | 70 | /* position and extent of bounding box */ |
366 | harbaum | 77 | #ifndef OSD_X |
367 | harbaum | 70 | #define OSD_X (10) |
368 | harbaum | 77 | #endif |
369 | |||
370 | #ifndef OSD_Y | ||
371 | harbaum | 70 | #define OSD_Y (10) |
372 | harbaum | 77 | #endif |
373 | harbaum | 70 | |
374 | /* parameters of the direction shape */ | ||
375 | harbaum | 77 | #ifndef OSD_DIAMETER |
376 | harbaum | 70 | #define D_RAD (30) // diameter of dpad |
377 | #else | ||
378 | harbaum | 77 | #define D_RAD (OSD_DIAMETER) |
379 | harbaum | 70 | #endif |
380 | #define D_TIP (4*D_RAD/5) // distance of arrow tip from dpad center | ||
381 | #define D_LEN (D_RAD/4) // length of arrow | ||
382 | #define D_WID (D_LEN) // width of arrow | ||
383 | |||
384 | /* parameters of the "zoom" pad */ | ||
385 | #define Z_STEP (D_RAD/4) // distance between dpad and zoom | ||
386 | #define Z_RAD (D_RAD/2) // radius of "caps" of zoom bar | ||
387 | |||
388 | harbaum | 74 | #ifdef OSD_SHADOW_ENABLE |
389 | harbaum | 70 | /* shadow also depends on control size */ |
390 | #define OSD_SHADOW (D_RAD/6) | ||
391 | harbaum | 74 | #else |
392 | #define OSD_SHADOW (0) | ||
393 | #endif | ||
394 | harbaum | 70 | |
395 | harbaum | 77 | /* normally the GPS button is in the center of the dpad. if there's */ |
396 | /* no dpad it will go into the zoom area */ | ||
397 | #if defined(OSD_GPS_BUTTON) && defined(OSD_NO_DPAD) | ||
398 | #define Z_GPS 1 | ||
399 | #else | ||
400 | #define Z_GPS 0 | ||
401 | #endif | ||
402 | |||
403 | harbaum | 70 | /* total width and height of controls incl. shadow */ |
404 | harbaum | 77 | #define OSD_W (2*D_RAD + OSD_SHADOW + Z_GPS * 2 * Z_RAD) |
405 | #if !Z_GPS | ||
406 | harbaum | 70 | #define OSD_H (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW) |
407 | harbaum | 77 | #else |
408 | #define OSD_H (2*Z_RAD + OSD_SHADOW) | ||
409 | #endif | ||
410 | harbaum | 70 | |
411 | harbaum | 74 | #ifdef OSD_SHADOW_ENABLE |
412 | harbaum | 70 | #define OSD_LBL_SHADOW (OSD_SHADOW/2) |
413 | harbaum | 74 | #endif |
414 | harbaum | 70 | |
415 | harbaum | 77 | #define Z_TOP ((1-Z_GPS) * (2 * D_RAD + Z_STEP)) |
416 | |||
417 | harbaum | 70 | #define Z_MID (Z_TOP + Z_RAD) |
418 | #define Z_BOT (Z_MID + Z_RAD) | ||
419 | #define Z_LEFT (Z_RAD) | ||
420 | harbaum | 77 | #define Z_RIGHT (2 * D_RAD - Z_RAD + Z_GPS * 2 * Z_RAD) |
421 | #define Z_CENTER ((Z_RIGHT + Z_LEFT)/2) | ||
422 | harbaum | 70 | |
423 | /* create the cairo shape used for the zoom buttons */ | ||
424 | static void | ||
425 | harbaum | 86 | osd_zoom_shape(cairo_t *cr, gint x, gint y) |
426 | harbaum | 71 | { |
427 | harbaum | 70 | cairo_move_to (cr, x+Z_LEFT, y+Z_TOP); |
428 | cairo_line_to (cr, x+Z_RIGHT, y+Z_TOP); | ||
429 | cairo_arc (cr, x+Z_RIGHT, y+Z_MID, Z_RAD, -M_PI/2, M_PI/2); | ||
430 | cairo_line_to (cr, x+Z_LEFT, y+Z_BOT); | ||
431 | cairo_arc (cr, x+Z_LEFT, y+Z_MID, Z_RAD, M_PI/2, -M_PI/2); | ||
432 | } | ||
433 | |||
434 | harbaum | 86 | /* ------------------- color/shadow functions ----------------- */ |
435 | |||
436 | #ifndef OSD_COLOR | ||
437 | /* if no color has been specified we just use the gdks default colors */ | ||
438 | static void | ||
439 | osd_labels(cairo_t *cr, gint width, gboolean enabled, | ||
440 | GdkColor *fg, GdkColor *disabled) { | ||
441 | if(enabled) gdk_cairo_set_source_color(cr, fg); | ||
442 | else gdk_cairo_set_source_color(cr, disabled); | ||
443 | cairo_set_line_width (cr, width); | ||
444 | } | ||
445 | #else | ||
446 | static void | ||
447 | osd_labels(cairo_t *cr, gint width, gboolean enabled) { | ||
448 | if(enabled) cairo_set_source_rgb (cr, OSD_COLOR); | ||
449 | else cairo_set_source_rgb (cr, OSD_COLOR_DISABLED); | ||
450 | cairo_set_line_width (cr, width); | ||
451 | } | ||
452 | #endif | ||
453 | |||
454 | #ifdef OSD_SHADOW_ENABLE | ||
455 | static void | ||
456 | osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) { | ||
457 | cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15); | ||
458 | cairo_set_line_width (cr, width); | ||
459 | } | ||
460 | #endif | ||
461 | |||
462 | harbaum | 76 | #ifndef OSD_NO_DPAD |
463 | harbaum | 70 | /* create the cairo shape used for the dpad */ |
464 | static void | ||
465 | harbaum | 86 | osd_dpad_shape(cairo_t *cr, gint x, gint y) |
466 | harbaum | 71 | { |
467 | harbaum | 70 | cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI); |
468 | } | ||
469 | harbaum | 76 | #endif |
470 | harbaum | 70 | |
471 | harbaum | 86 | #ifdef OSD_SHADOW_ENABLE |
472 | static void | ||
473 | osd_shape_shadow(cairo_t *cr) { | ||
474 | cairo_set_source_rgba (cr, 0, 0, 0, 0.2); | ||
475 | cairo_fill (cr); | ||
476 | cairo_stroke (cr); | ||
477 | } | ||
478 | #endif | ||
479 | |||
480 | #ifndef OSD_COLOR | ||
481 | /* if no color has been specified we just use the gdks default colors */ | ||
482 | static void | ||
483 | osd_shape(cairo_t *cr, GdkColor *bg, GdkColor *fg) { | ||
484 | gdk_cairo_set_source_color(cr, bg); | ||
485 | cairo_fill_preserve (cr); | ||
486 | gdk_cairo_set_source_color(cr, fg); | ||
487 | cairo_set_line_width (cr, 1); | ||
488 | cairo_stroke (cr); | ||
489 | } | ||
490 | #else | ||
491 | static void | ||
492 | osd_shape(cairo_t *cr) { | ||
493 | cairo_set_source_rgb (cr, OSD_COLOR_BG); | ||
494 | cairo_fill_preserve (cr); | ||
495 | cairo_set_source_rgb (cr, OSD_COLOR); | ||
496 | cairo_set_line_width (cr, 1); | ||
497 | cairo_stroke (cr); | ||
498 | } | ||
499 | #endif | ||
500 | |||
501 | |||
502 | harbaum | 70 | static gboolean |
503 | osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad) | ||
504 | { | ||
505 | return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad); | ||
506 | } | ||
507 | |||
508 | harbaum | 76 | #ifndef OSD_NO_DPAD |
509 | harbaum | 70 | /* check whether x/y is within the dpad */ |
510 | static osd_button_t | ||
511 | harbaum | 86 | osd_check_dpad(gint x, gint y) |
512 | harbaum | 70 | { |
513 | /* within entire dpad circle */ | ||
514 | harbaum | 77 | if( osm_gps_map_in_circle(x, y, D_RAD, D_RAD, D_RAD)) |
515 | harbaum | 70 | { |
516 | /* convert into position relative to dpads centre */ | ||
517 | harbaum | 77 | x -= D_RAD; |
518 | y -= D_RAD; | ||
519 | harbaum | 70 | |
520 | harbaum | 76 | #ifdef OSD_GPS_BUTTON |
521 | harbaum | 70 | /* check for dpad center goes here! */ |
522 | if( osm_gps_map_in_circle(x, y, 0, 0, D_RAD/3)) | ||
523 | return OSD_GPS; | ||
524 | harbaum | 76 | #endif |
525 | harbaum | 70 | |
526 | if( y < 0 && abs(x) < abs(y)) | ||
527 | return OSD_UP; | ||
528 | |||
529 | if( y > 0 && abs(x) < abs(y)) | ||
530 | return OSD_DOWN; | ||
531 | |||
532 | if( x < 0 && abs(y) < abs(x)) | ||
533 | return OSD_LEFT; | ||
534 | |||
535 | if( x > 0 && abs(y) < abs(x)) | ||
536 | return OSD_RIGHT; | ||
537 | |||
538 | return OSD_BG; | ||
539 | } | ||
540 | return OSD_NONE; | ||
541 | } | ||
542 | harbaum | 76 | #endif |
543 | harbaum | 70 | |
544 | /* check whether x/y is within the zoom pads */ | ||
545 | static osd_button_t | ||
546 | harbaum | 86 | osd_check_zoom(gint x, gint y) { |
547 | harbaum | 77 | if( x > 0 && x < OSD_W && y > Z_TOP && y < Z_BOT) { |
548 | harbaum | 70 | |
549 | /* within circle around (-) label */ | ||
550 | harbaum | 77 | if( osm_gps_map_in_circle(x, y, Z_LEFT, Z_MID, Z_RAD)) |
551 | harbaum | 70 | return OSD_OUT; |
552 | |||
553 | harbaum | 77 | /* within circle around (+) label */ |
554 | if( osm_gps_map_in_circle(x, y, Z_RIGHT, Z_MID, Z_RAD)) | ||
555 | return OSD_IN; | ||
556 | |||
557 | #if Z_GPS == 1 | ||
558 | /* within square around center */ | ||
559 | if( x > Z_CENTER - Z_RAD && x < Z_CENTER + Z_RAD) | ||
560 | return OSD_GPS; | ||
561 | #endif | ||
562 | |||
563 | harbaum | 70 | /* between center of (-) button and center of entire zoom control area */ |
564 | harbaum | 77 | if(x > OSD_LEFT && x < D_RAD) |
565 | harbaum | 70 | return OSD_OUT; |
566 | |||
567 | /* between center of (+) button and center of entire zoom control area */ | ||
568 | harbaum | 77 | if(x < OSD_RIGHT && x > D_RAD) |
569 | harbaum | 70 | return OSD_IN; |
570 | } | ||
571 | |||
572 | return OSD_NONE; | ||
573 | } | ||
574 | |||
575 | harbaum | 88 | #ifdef OSD_SOURCE_SEL |
576 | |||
577 | harbaum | 86 | /* place source selection at right border */ |
578 | #define OSD_S_RAD (Z_RAD) | ||
579 | #define OSD_S_X (-OSD_X) | ||
580 | #define OSD_S_Y (OSD_Y) | ||
581 | #define OSD_S_PW (2 * Z_RAD) | ||
582 | #define OSD_S_W (OSD_S_PW) | ||
583 | #define OSD_S_PH (2 * Z_RAD) | ||
584 | #define OSD_S_H (OSD_S_PH + OSD_SHADOW) | ||
585 | |||
586 | harbaum | 87 | /* size of usable area when expanded */ |
587 | harbaum | 110 | #define OSD_S_AREA_W (priv->source_sel.width) |
588 | #define OSD_S_AREA_H (priv->source_sel.height) | ||
589 | harbaum | 86 | #define OSD_S_EXP_W (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW) |
590 | #define OSD_S_EXP_H (OSD_S_AREA_H + OSD_SHADOW) | ||
591 | |||
592 | /* internal value to draw the arrow on the "puller" */ | ||
593 | #define OSD_S_D0 (OSD_S_RAD/2) | ||
594 | harbaum | 87 | #ifndef OSD_FONT_SIZE |
595 | #define OSD_FONT_SIZE 16.0 | ||
596 | #endif | ||
597 | #define OSD_TEXT_BORDER (OSD_FONT_SIZE/2) | ||
598 | #define OSD_TEXT_SKIP (OSD_FONT_SIZE/8) | ||
599 | harbaum | 86 | |
600 | harbaum | 88 | /* draw the shape of the source selection OSD, either only the puller (not expanded) */ |
601 | /* or the entire menu incl. the puller (expanded) */ | ||
602 | harbaum | 86 | static void |
603 | osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) { | ||
604 | harbaum | 110 | if(!priv->source_sel.expanded) { |
605 | harbaum | 86 | /* just draw the puller */ |
606 | cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH); | ||
607 | cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); | ||
608 | cairo_line_to (cr, x + OSD_S_PW, y); | ||
609 | } else { | ||
610 | /* draw the puller and the area itself */ | ||
611 | cairo_move_to (cr, x + OSD_S_PW + OSD_S_AREA_W, y + OSD_S_AREA_H); | ||
612 | cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_AREA_H); | ||
613 | if(OSD_S_Y > 0) { | ||
614 | cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_PH); | ||
615 | cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); | ||
616 | } else { | ||
617 | cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_AREA_H-OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); | ||
618 | cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_AREA_H - OSD_S_PH); | ||
619 | cairo_line_to (cr, x + OSD_S_PW, y); | ||
620 | } | ||
621 | cairo_line_to (cr, x + OSD_S_PW + OSD_S_AREA_W, y); | ||
622 | cairo_close_path (cr); | ||
623 | } | ||
624 | } | ||
625 | |||
626 | static void | ||
627 | harbaum | 87 | osd_source_content(osm_gps_map_osd_t *osd, cairo_t *cr, gint offset) { |
628 | osd_priv_t *priv = (osd_priv_t*)osd->priv; | ||
629 | harbaum | 86 | |
630 | harbaum | 87 | int py = offset + OSD_S_RAD - OSD_S_D0; |
631 | |||
632 | harbaum | 110 | if(!priv->source_sel.expanded) { |
633 | harbaum | 86 | /* draw the "puller" open (<) arrow */ |
634 | harbaum | 87 | cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py); |
635 | harbaum | 86 | cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); |
636 | cairo_rel_line_to (cr, +OSD_S_D0, +OSD_S_D0); | ||
637 | } else { | ||
638 | if(OSD_S_Y < 0) | ||
639 | harbaum | 87 | py += OSD_S_AREA_H - OSD_S_PH; |
640 | harbaum | 86 | |
641 | /* draw the "puller" close (>) arrow */ | ||
642 | harbaum | 87 | cairo_move_to (cr, offset + OSD_S_RAD - OSD_S_D0/2, py); |
643 | harbaum | 86 | cairo_rel_line_to (cr, +OSD_S_D0, +OSD_S_D0); |
644 | cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); | ||
645 | harbaum | 87 | cairo_stroke(cr); |
646 | |||
647 | /* don't draw a shadow for the text content */ | ||
648 | if(offset == 1) { | ||
649 | gint source; | ||
650 | g_object_get(osd->widget, "map-source", &source, NULL); | ||
651 | |||
652 | cairo_select_font_face (cr, "Sans", | ||
653 | CAIRO_FONT_SLANT_NORMAL, | ||
654 | CAIRO_FONT_WEIGHT_BOLD); | ||
655 | cairo_set_font_size (cr, OSD_FONT_SIZE); | ||
656 | |||
657 | harbaum | 110 | int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) / |
658 | harbaum | 89 | OSM_GPS_MAP_SOURCE_LAST; |
659 | harbaum | 87 | for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) { |
660 | cairo_text_extents_t extents; | ||
661 | const char *src = osm_gps_map_source_get_friendly_name(i); | ||
662 | cairo_text_extents (cr, src, &extents); | ||
663 | |||
664 | int x = offset + OSD_S_PW + OSD_TEXT_BORDER; | ||
665 | int y = offset + step * (i-1) + OSD_TEXT_BORDER; | ||
666 | |||
667 | /* draw filled rectangle if selected */ | ||
668 | if(source == i) { | ||
669 | cairo_rectangle(cr, x - OSD_TEXT_BORDER/2, | ||
670 | y - OSD_TEXT_SKIP, | ||
671 | harbaum | 110 | priv->source_sel.width - OSD_TEXT_BORDER, |
672 | harbaum | 87 | step + OSD_TEXT_SKIP); |
673 | cairo_fill(cr); | ||
674 | |||
675 | /* temprarily draw with background color */ | ||
676 | #ifndef OSD_COLOR | ||
677 | GdkColor bg = osd->widget->style->bg[GTK_STATE_NORMAL]; | ||
678 | gdk_cairo_set_source_color(cr, &bg); | ||
679 | #else | ||
680 | cairo_set_source_rgb (cr, OSD_COLOR_BG); | ||
681 | #endif | ||
682 | } | ||
683 | |||
684 | cairo_move_to (cr, x, y + OSD_TEXT_SKIP - extents.y_bearing); | ||
685 | cairo_show_text (cr, src); | ||
686 | |||
687 | /* restore color */ | ||
688 | if(source == i) { | ||
689 | #ifndef OSD_COLOR | ||
690 | GdkColor fg = osd->widget->style->fg[GTK_STATE_NORMAL]; | ||
691 | gdk_cairo_set_source_color(cr, &fg); | ||
692 | #else | ||
693 | cairo_set_source_rgb (cr, OSD_COLOR); | ||
694 | #endif | ||
695 | } | ||
696 | } | ||
697 | } | ||
698 | harbaum | 86 | } |
699 | } | ||
700 | |||
701 | static void | ||
702 | harbaum | 111 | osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) { |
703 | harbaum | 86 | osd_priv_t *priv = (osd_priv_t*)osd->priv; |
704 | |||
705 | harbaum | 111 | if(priv->source_sel.rendered && !force_rerender) |
706 | return; | ||
707 | |||
708 | priv->source_sel.rendered = TRUE; | ||
709 | |||
710 | harbaum | 86 | #ifndef OSD_COLOR |
711 | GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; | ||
712 | GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; | ||
713 | GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE]; | ||
714 | #endif | ||
715 | |||
716 | /* draw source selector */ | ||
717 | harbaum | 110 | cairo_t *cr = cairo_create(priv->source_sel.surface); |
718 | harbaum | 86 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
719 | cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); | ||
720 | cairo_paint(cr); | ||
721 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | ||
722 | |||
723 | #ifdef OSD_SHADOW_ENABLE | ||
724 | osd_source_shape(priv, cr, 1+OSD_SHADOW, 1+OSD_SHADOW); | ||
725 | osd_shape_shadow(cr); | ||
726 | #endif | ||
727 | |||
728 | osd_source_shape(priv, cr, 1, 1); | ||
729 | #ifndef OSD_COLOR | ||
730 | osd_shape(cr, &bg, &fg); | ||
731 | #else | ||
732 | osd_shape(cr); | ||
733 | #endif | ||
734 | |||
735 | #ifdef OSD_SHADOW_ENABLE | ||
736 | osd_labels_shadow(cr, Z_RAD/3, TRUE); | ||
737 | harbaum | 87 | osd_source_content(osd, cr, 1+OSD_LBL_SHADOW); |
738 | cairo_stroke (cr); | ||
739 | harbaum | 86 | #endif |
740 | #ifndef OSD_COLOR | ||
741 | osd_labels(cr, Z_RAD/3, TRUE, &fg, &da); | ||
742 | #else | ||
743 | osd_labels(cr, Z_RAD/3, TRUE); | ||
744 | #endif | ||
745 | harbaum | 87 | osd_source_content(osd, cr, 1); |
746 | cairo_stroke (cr); | ||
747 | harbaum | 86 | |
748 | cairo_destroy(cr); | ||
749 | } | ||
750 | |||
751 | harbaum | 89 | /* re-allocate the buffer used to draw the menu. This is used */ |
752 | /* to collapse/expand the buffer */ | ||
753 | harbaum | 86 | static void |
754 | osd_source_reallocate(osm_gps_map_osd_t *osd) { | ||
755 | osd_priv_t *priv = (osd_priv_t*)osd->priv; | ||
756 | |||
757 | /* re-allocate offscreen bitmap */ | ||
758 | harbaum | 110 | g_assert (priv->source_sel.surface); |
759 | harbaum | 86 | |
760 | int w = OSD_S_W, h = OSD_S_H; | ||
761 | harbaum | 110 | if(priv->source_sel.expanded) { |
762 | harbaum | 87 | cairo_text_extents_t extents; |
763 | |||
764 | /* determine content size */ | ||
765 | harbaum | 110 | cairo_t *cr = cairo_create(priv->source_sel.surface); |
766 | harbaum | 87 | cairo_select_font_face (cr, "Sans", |
767 | CAIRO_FONT_SLANT_NORMAL, | ||
768 | CAIRO_FONT_WEIGHT_BOLD); | ||
769 | cairo_set_font_size (cr, OSD_FONT_SIZE); | ||
770 | |||
771 | /* calculate menu size */ | ||
772 | int i, max_h = 0, max_w = 0; | ||
773 | for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) { | ||
774 | const char *src = osm_gps_map_source_get_friendly_name(i); | ||
775 | cairo_text_extents (cr, src, &extents); | ||
776 | |||
777 | if(extents.width > max_w) max_w = extents.width; | ||
778 | if(extents.height > max_h) max_h = extents.height; | ||
779 | } | ||
780 | cairo_destroy(cr); | ||
781 | |||
782 | harbaum | 110 | priv->source_sel.width = max_w + 2*OSD_TEXT_BORDER; |
783 | priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST * | ||
784 | harbaum | 87 | (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER; |
785 | |||
786 | harbaum | 86 | w = OSD_S_EXP_W; |
787 | h = OSD_S_EXP_H; | ||
788 | } | ||
789 | |||
790 | harbaum | 110 | cairo_surface_destroy(priv->source_sel.surface); |
791 | priv->source_sel.surface = | ||
792 | harbaum | 86 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
793 | |||
794 | harbaum | 111 | osd_render_source_sel(osd, TRUE); |
795 | harbaum | 86 | } |
796 | |||
797 | #define OSD_HZ 15 | ||
798 | harbaum | 87 | #define OSD_TIME 500 |
799 | harbaum | 86 | |
800 | static gboolean osd_source_animate(gpointer data) { | ||
801 | osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data; | ||
802 | osd_priv_t *priv = (osd_priv_t*)osd->priv; | ||
803 | int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; | ||
804 | gboolean done = FALSE; | ||
805 | harbaum | 110 | priv->source_sel.count += priv->source_sel.dir; |
806 | harbaum | 86 | |
807 | /* shifting in */ | ||
808 | harbaum | 110 | if(priv->source_sel.dir < 0) { |
809 | if(priv->source_sel.count <= 0) { | ||
810 | priv->source_sel.count = 0; | ||
811 | harbaum | 86 | done = TRUE; |
812 | } | ||
813 | } else { | ||
814 | harbaum | 110 | if(priv->source_sel.count >= 1000) { |
815 | priv->source_sel.expanded = FALSE; | ||
816 | harbaum | 86 | osd_source_reallocate(osd); |
817 | |||
818 | harbaum | 110 | priv->source_sel.count = 1000; |
819 | harbaum | 86 | done = TRUE; |
820 | } | ||
821 | } | ||
822 | |||
823 | |||
824 | /* count runs linearly from 0 to 1000, map this nicely onto a position */ | ||
825 | |||
826 | harbaum | 111 | /* nice sinoid mapping */ |
827 | harbaum | 110 | float m = 0.5-cos(priv->source_sel.count * M_PI / 1000.0)/2; |
828 | harbaum | 111 | priv->source_sel.shift = |
829 | (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + | ||
830 | harbaum | 86 | m * diff; |
831 | |||
832 | harbaum | 111 | /* make sure the screen is updated */ |
833 | harbaum | 86 | osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
834 | |||
835 | harbaum | 111 | /* stop animation if done */ |
836 | harbaum | 86 | if(done) |
837 | harbaum | 110 | priv->source_sel.handler_id = 0; |
838 | harbaum | 86 | |
839 | return !done; | ||
840 | } | ||
841 | |||
842 | /* switch between expand and collapse mode of source selection */ | ||
843 | static void | ||
844 | osd_source_toggle(osm_gps_map_osd_t *osd) | ||
845 | { | ||
846 | osd_priv_t *priv = (osd_priv_t*)osd->priv; | ||
847 | |||
848 | /* ignore clicks while animation is running */ | ||
849 | harbaum | 110 | if(priv->source_sel.handler_id) |
850 | harbaum | 86 | return; |
851 | |||
852 | harbaum | 111 | /* expand immediately, collapse is handle at the end of the */ |
853 | /* collapse animation */ | ||
854 | harbaum | 110 | if(!priv->source_sel.expanded) { |
855 | priv->source_sel.expanded = TRUE; | ||
856 | harbaum | 86 | osd_source_reallocate(osd); |
857 | |||
858 | harbaum | 110 | priv->source_sel.count = 1000; |
859 | priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W; | ||
860 | priv->source_sel.dir = -1000/OSD_HZ; | ||
861 | harbaum | 86 | } else { |
862 | harbaum | 110 | priv->source_sel.count = 0; |
863 | harbaum | 111 | priv->source_sel.shift = osd->widget->allocation.width - |
864 | OSD_S_EXP_W + OSD_S_X; | ||
865 | harbaum | 110 | priv->source_sel.dir = +1000/OSD_HZ; |
866 | harbaum | 86 | } |
867 | |||
868 | harbaum | 111 | /* start timer to handle animation */ |
869 | priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, | ||
870 | osd_source_animate, osd); | ||
871 | harbaum | 86 | } |
872 | |||
873 | harbaum | 89 | /* check if the user clicked inside the source selection area */ |
874 | harbaum | 70 | static osd_button_t |
875 | harbaum | 114 | osd_source_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
876 | harbaum | 86 | osd_priv_t *priv = (osd_priv_t*)osd->priv; |
877 | |||
878 | harbaum | 110 | if(!priv->source_sel.expanded) |
879 | harbaum | 86 | x -= osd->widget->allocation.width - OSD_S_W; |
880 | else | ||
881 | x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; | ||
882 | |||
883 | if(OSD_S_Y > 0) | ||
884 | y -= OSD_S_Y; | ||
885 | else | ||
886 | y -= osd->widget->allocation.height - OSD_S_PH + OSD_S_Y; | ||
887 | |||
888 | /* within square around puller? */ | ||
889 | if(y > 0 && y < OSD_S_PH && x > 0 && x < OSD_S_PW) { | ||
890 | /* really within puller shape? */ | ||
891 | if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) { | ||
892 | /* expand source selector */ | ||
893 | harbaum | 114 | if(down) |
894 | osd_source_toggle(osd); | ||
895 | harbaum | 86 | |
896 | /* tell upper layers that user clicked some background element */ | ||
897 | /* of the OSD */ | ||
898 | return OSD_BG; | ||
899 | } | ||
900 | } | ||
901 | harbaum | 88 | |
902 | /* check for clicks into data area */ | ||
903 | harbaum | 110 | if(priv->source_sel.expanded && !priv->source_sel.handler_id) { |
904 | harbaum | 94 | /* re-adjust from puller top to content top */ |
905 | if(OSD_S_Y < 0) | ||
906 | y += OSD_S_EXP_H - OSD_S_PH; | ||
907 | |||
908 | harbaum | 88 | if(x > OSD_S_PW && |
909 | x < OSD_S_PW + OSD_S_EXP_W && | ||
910 | y > 0 && | ||
911 | y < OSD_S_EXP_H) { | ||
912 | harbaum | 94 | |
913 | harbaum | 110 | int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) |
914 | harbaum | 89 | / OSM_GPS_MAP_SOURCE_LAST; |
915 | harbaum | 88 | |
916 | harbaum | 89 | y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP; |
917 | y /= step; | ||
918 | y += 1; | ||
919 | |||
920 | harbaum | 114 | if(down) { |
921 | gint old = 0; | ||
922 | g_object_get(osd->widget, "map-source", &old, NULL); | ||
923 | harbaum | 89 | |
924 | harbaum | 114 | if(y > OSM_GPS_MAP_SOURCE_NULL && |
925 | y <= OSM_GPS_MAP_SOURCE_LAST && | ||
926 | old != y) { | ||
927 | g_object_set(osd->widget, "map-source", y, NULL); | ||
928 | |||
929 | osd_render_source_sel(osd, TRUE); | ||
930 | osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); | ||
931 | } | ||
932 | harbaum | 89 | } |
933 | |||
934 | /* return "clicked in OSD background" to prevent further */ | ||
935 | /* processing by application */ | ||
936 | harbaum | 88 | return OSD_BG; |
937 | } | ||
938 | } | ||
939 | |||
940 | harbaum | 86 | return OSD_NONE; |
941 | } | ||
942 | harbaum | 88 | #endif // OSD_SOURCE_SEL |
943 | harbaum | 86 | |
944 | static osd_button_t | ||
945 | harbaum | 114 | osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
946 | harbaum | 70 | osd_button_t but = OSD_NONE; |
947 | |||
948 | harbaum | 113 | #ifdef OSD_BALLOON |
949 | harbaum | 114 | if(down) { |
950 | /* needed to handle balloons that are created at click */ | ||
951 | osd_priv_t *priv = (osd_priv_t*)osd->priv; | ||
952 | priv->balloon.just_created = FALSE; | ||
953 | } | ||
954 | harbaum | 113 | #endif |
955 | |||
956 | harbaum | 86 | #ifdef OSD_SOURCE_SEL |
957 | /* the source selection area is handles internally */ | ||
958 | harbaum | 114 | but = osd_source_check(osd, down, x, y); |
959 | harbaum | 86 | #endif |
960 | harbaum | 114 | |
961 | if(but == OSD_NONE) { | ||
962 | harbaum | 120 | gint mx = x - OSD_X; |
963 | gint my = y - OSD_Y; | ||
964 | harbaum | 114 | |
965 | if(OSD_X < 0) | ||
966 | harbaum | 120 | mx -= (osd->widget->allocation.width - OSD_W); |
967 | harbaum | 114 | |
968 | if(OSD_Y < 0) | ||
969 | harbaum | 120 | my -= (osd->widget->allocation.height - OSD_H); |
970 | harbaum | 114 | |
971 | /* first do a rough test for the OSD area. */ | ||
972 | /* this is just to avoid an unnecessary detailed test */ | ||
973 | harbaum | 120 | if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) { |
974 | harbaum | 76 | #ifndef OSD_NO_DPAD |
975 | harbaum | 120 | but = osd_check_dpad(mx, my); |
976 | harbaum | 76 | #endif |
977 | harbaum | 114 | } |
978 | harbaum | 70 | |
979 | if(but == OSD_NONE) | ||
980 | harbaum | 120 | but = osd_check_zoom(mx, my); |
981 | harbaum | 70 | } |
982 | |||
983 | harbaum | 114 | #ifdef OSD_BALLOON |
984 | if(but == OSD_NONE) { | ||
985 | /* check if user clicked into balloon */ | ||
986 | if(osd_balloon_check(osd, down, x, y)) | ||
987 | but = OSD_BG; | ||
988 | } | ||
989 | #endif | ||
990 | |||
991 | harbaum | 70 | return but; |
992 | } | ||
993 | |||
994 | harbaum | 76 | #ifndef OSD_NO_DPAD |
995 | harbaum | 70 | static void |
996 | harbaum | 86 | osd_dpad_labels(cairo_t *cr, gint x, gint y) { |
997 | harbaum | 70 | /* move reference to dpad center */ |
998 | x += D_RAD; | ||
999 | y += D_RAD; | ||
1000 | |||
1001 | const static gint offset[][3][2] = { | ||
1002 | /* left arrow/triangle */ | ||
1003 | { { -D_TIP+D_LEN, -D_WID }, { -D_LEN, D_WID }, { +D_LEN, D_WID } }, | ||
1004 | /* right arrow/triangle */ | ||
1005 | { { +D_TIP-D_LEN, -D_WID }, { +D_LEN, D_WID }, { -D_LEN, D_WID } }, | ||
1006 | /* top arrow/triangle */ | ||
1007 | { { -D_WID, -D_TIP+D_LEN }, { D_WID, -D_LEN }, { D_WID, +D_LEN } }, | ||
1008 | /* bottom arrow/triangle */ | ||
1009 | { { -D_WID, +D_TIP-D_LEN }, { D_WID, +D_LEN }, { D_WID, -D_LEN } } | ||
1010 | }; | ||
1011 | |||
1012 | int i; | ||
1013 | for(i=0;i<4;i++) { | ||
1014 | cairo_move_to (cr, x + offset[i][0][0], y + offset[i][0][1]); | ||
1015 | cairo_rel_line_to (cr, offset[i][1][0], offset[i][1][1]); | ||
1016 | cairo_rel_line_to (cr, offset[i][2][0], offset[i][2][1]); | ||
1017 | } | ||
1018 | } | ||
1019 | harbaum | 76 | #endif |
1020 | harbaum | 70 | |
1021 | harbaum | 76 | #ifdef OSD_GPS_BUTTON |
1022 | /* draw the satellite dish icon in the center of the dpad */ | ||
1023 | harbaum | 77 | #define GPS_V0 (D_RAD/7) |
1024 | harbaum | 70 | #define GPS_V1 (D_RAD/10) |
1025 | #define GPS_V2 (D_RAD/5) | ||
1026 | |||
1027 | /* draw a satellite receiver dish */ | ||
1028 | harbaum | 77 | /* this is either drawn in the center of the dpad (if present) */ |
1029 | /* or in the middle of the zoom area */ | ||
1030 | harbaum | 70 | static void |
1031 | harbaum | 86 | osd_dpad_gps(cairo_t *cr, gint x, gint y) { |
1032 | harbaum | 70 | /* move reference to dpad center */ |
1033 | harbaum | 77 | x += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD * 3; |
1034 | y += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD + GPS_V0; | ||
1035 | harbaum | 70 | |
1036 | cairo_move_to (cr, x-GPS_V0, y+GPS_V0); | ||
1037 | cairo_rel_line_to (cr, +GPS_V0, -GPS_V0); | ||
1038 | cairo_rel_line_to (cr, +GPS_V0, +GPS_V0); | ||
1039 | cairo_close_path (cr); | ||
1040 | |||
1041 | cairo_move_to (cr, x+GPS_V1-GPS_V2, y-2*GPS_V2); | ||
1042 | cairo_curve_to (cr, x-GPS_V2, y, x+GPS_V1, y+GPS_V1, x+GPS_V1+GPS_V2, y); | ||
1043 | cairo_close_path (cr); | ||
1044 | |||
1045 | x += GPS_V1; | ||
1046 | cairo_move_to (cr, x, y-GPS_V2); | ||
1047 | cairo_rel_line_to (cr, +GPS_V1, -GPS_V1); | ||
1048 | } | ||
1049 | harbaum | 76 | #endif |
1050 | harbaum | 70 | |
1051 | #define Z_LEN (2*Z_RAD/3) | ||
1052 | |||
1053 | static void | ||
1054 | harbaum | 86 | osd_zoom_labels(cairo_t *cr, gint x, gint y) { |
1055 | harbaum | 70 | cairo_move_to (cr, x + Z_LEFT - Z_LEN, y + Z_MID); |
1056 | cairo_line_to (cr, x + Z_LEFT + Z_LEN, y + Z_MID); | ||
1057 | |||
1058 | cairo_move_to (cr, x + Z_RIGHT, y + Z_MID - Z_LEN); | ||
1059 | cairo_line_to (cr, x + Z_RIGHT, y + Z_MID + Z_LEN); | ||
1060 | cairo_move_to (cr, x + Z_RIGHT - Z_LEN, y + Z_MID); | ||
1061 | cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); | ||
1062 | } | ||
1063 | |||
1064 | harbaum | 106 | #ifdef OSD_COORDINATES |
1065 | |||
1066 | harbaum | 107 | #ifndef OSD_COORDINATES_FONT_SIZE |
1067 | #define OSD_COORDINATES_FONT_SIZE 12 | ||
1068 | #endif | ||
1069 | |||
1070 | harbaum | 108 | #define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
1071 | harbaum | 107 | |
1072 | harbaum | 108 | #define OSD_COORDINATES_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
1073 | #define OSD_COORDINATES_H (2*OSD_COORDINATES_FONT_SIZE+OSD_COORDINATES_OFFSET) | ||
1074 | |||
1075 | harbaum | 107 | /* these can be overwritten with versions that support */ |
1076 | /* localization */ | ||
1077 | #ifndef OSD_COORDINATES_CHR_N | ||
1078 | #define OSD_COORDINATES_CHR_N "N" | ||
1079 | #endif | ||
1080 | #ifndef OSD_COORDINATES_CHR_S | ||
1081 | #define OSD_COORDINATES_CHR_S "S" | ||
1082 | #endif | ||
1083 | #ifndef OSD_COORDINATES_CHR_E | ||
1084 | #define OSD_COORDINATES_CHR_E "E" | ||
1085 | #endif | ||
1086 | #ifndef OSD_COORDINATES_CHR_W | ||
1087 | #define OSD_COORDINATES_CHR_W "W" | ||
1088 | #endif | ||
1089 | |||
1090 | |||
1091 | |||
1092 | /* this is the classic geocaching notation */ | ||
1093 | static char | ||
1094 | *osd_latitude_str(float latitude) { | ||
1095 | char *c = OSD_COORDINATES_CHR_N; | ||
1096 | float integral, fractional; | ||
1097 | |||
1098 | if(isnan(latitude)) | ||
1099 | return NULL; | ||
1100 | |||
1101 | if(latitude < 0) { | ||
1102 | latitude = fabs(latitude); | ||
1103 | c = OSD_COORDINATES_CHR_S; | ||
1104 | } | ||
1105 | |||
1106 | fractional = modff(latitude, &integral); | ||
1107 | |||
1108 | return g_strdup_printf("%s %02d° %06.3f'", | ||
1109 | c, (int)integral, fractional*60.0); | ||
1110 | } | ||
1111 | |||
1112 | static char | ||
1113 | *osd_longitude_str(float longitude) { | ||
1114 | char *c = OSD_COORDINATES_CHR_E; | ||
1115 | float integral, fractional; | ||
1116 | |||
1117 | if(isnan(longitude)) | ||
1118 | return NULL; | ||
1119 | |||
1120 | if(longitude < 0) { | ||
1121 | longitude = fabs(longitude); | ||
1122 | c = OSD_COORDINATES_CHR_W; | ||
1123 | } | ||
1124 | |||
1125 | fractional = modff(longitude, &integral); | ||
1126 | |||
1127 | return g_strdup_printf("%s %03d° %06.3f'", | ||
1128 | c, (int)integral, fractional*60.0); | ||
1129 | } | ||
1130 | |||
1131 | harbaum | 106 | static void |
1132 | osd_render_coordinates(osm_gps_map_osd_t *osd) | ||
1133 | { | ||
1134 | osd_priv_t *priv = (osd_priv_t*)osd->priv; | ||
1135 | |||
1136 | harbaum | 107 | /* get current map position */ |
1137 | gfloat lat, lon; | ||
1138 | g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); | ||
1139 | |||
1140 | harbaum | 108 | /* check if position has changed enough to require redraw */ |
1141 | harbaum | 110 | if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon)) |
1142 | /* 1/60000 == 1/1000 minute */ | ||
1143 | if((fabsf(lat - priv->coordinates.lat) < 1/60000) && | ||
1144 | (fabsf(lon - priv->coordinates.lon) < 1/60000)) | ||
1145 | harbaum | 108 | return; |
1146 | |||
1147 | harbaum | 110 | priv->coordinates.lat = lat; |
1148 | priv->coordinates.lon = lon; | ||
1149 | harbaum | 108 | |
1150 | harbaum | 111 | /* first fill with transparency */ |
1151 | harbaum | 110 | cairo_t *cr = cairo_create(priv->coordinates.surface); |
1152 | harbaum | 106 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1153 | harbaum | 111 | // cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); |
1154 | cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); | ||
1155 | harbaum | 106 | cairo_paint(cr); |
1156 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | ||
1157 | |||
1158 | harbaum | 107 | cairo_select_font_face (cr, "Sans", |
1159 | CAIRO_FONT_SLANT_NORMAL, | ||
1160 | CAIRO_FONT_WEIGHT_BOLD); | ||
1161 | cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE); | ||
1162 | |||
1163 | char *latitude = osd_latitude_str(lat); | ||
1164 | char *longitude = osd_longitude_str(lon); | ||
1165 | |||
1166 | cairo_text_extents_t lat_extents, lon_extents; | ||
1167 | cairo_text_extents (cr, latitude, &lat_extents); | ||
1168 | cairo_text_extents (cr, longitude, &lon_extents); | ||
1169 | |||
1170 | cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); | ||
1171 | cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); | ||
1172 | harbaum | 108 | cairo_move_to (cr, |
1173 | (OSD_COORDINATES_W - lat_extents.width)/2, | ||
1174 | harbaum | 107 | OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
1175 | cairo_text_path (cr, latitude); | ||
1176 | cairo_move_to (cr, | ||
1177 | harbaum | 108 | (OSD_COORDINATES_W - lon_extents.width)/2, |
1178 | harbaum | 107 | OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
1179 | OSD_COORDINATES_FONT_SIZE); | ||
1180 | cairo_text_path (cr, longitude); | ||
1181 | cairo_stroke (cr); | ||
1182 | |||
1183 | cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); | ||
1184 | cairo_move_to (cr, | ||
1185 | harbaum | 108 | (OSD_COORDINATES_W - lat_extents.width)/2, |
1186 | harbaum | 107 | OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
1187 | cairo_show_text (cr, latitude); | ||
1188 | cairo_move_to (cr, | ||
1189 | harbaum | 108 | (OSD_COORDINATES_W - lon_extents.width)/2, |
1190 | harbaum | 107 | OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
1191 | OSD_COORDINATES_FONT_SIZE); | ||
1192 | cairo_show_text (cr, longitude); | ||
1193 | |||
1194 | g_free(latitude); | ||
1195 | g_free(longitude); | ||
1196 | |||
1197 | harbaum | 106 | cairo_destroy(cr); |
1198 | } | ||
1199 | #endif // OSD_COORDINATES | ||
1200 | |||
1201 | harbaum | 105 | #ifdef OSD_CROSSHAIR |
1202 | |||
1203 | #ifndef OSD_CROSSHAIR_RADIUS | ||
1204 | harbaum | 106 | #define OSD_CROSSHAIR_RADIUS 10 |
1205 | harbaum | 105 | #endif |
1206 | |||
1207 | harbaum | 106 | #define OSD_CROSSHAIR_TICK (OSD_CROSSHAIR_RADIUS/2) |
1208 | #define OSD_CROSSHAIR_BORDER (OSD_CROSSHAIR_TICK + OSD_CROSSHAIR_RADIUS/4) | ||
1209 | #define OSD_CROSSHAIR_W ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2) | ||
1210 | #define OSD_CROSSHAIR_H ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2) | ||
1211 | harbaum | 105 | |
1212 | static void | ||
1213 | harbaum | 106 | osd_render_crosshair_shape(cairo_t *cr) { |
1214 | cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2, | ||
1215 | OSD_CROSSHAIR_RADIUS, 0, 2*M_PI); | ||
1216 | |||
1217 | cairo_move_to (cr, OSD_CROSSHAIR_W/2 - OSD_CROSSHAIR_RADIUS, | ||
1218 | OSD_CROSSHAIR_H/2); | ||
1219 | cairo_rel_line_to (cr, -OSD_CROSSHAIR_TICK, 0); | ||
1220 | cairo_move_to (cr, OSD_CROSSHAIR_W/2 + OSD_CROSSHAIR_RADIUS, | ||
1221 | OSD_CROSSHAIR_H/2); | ||
1222 | cairo_rel_line_to (cr, OSD_CROSSHAIR_TICK, 0); | ||
1223 | |||
1224 | cairo_move_to (cr, OSD_CROSSHAIR_W/2, | ||
1225 | OSD_CROSSHAIR_H/2 - OSD_CROSSHAIR_RADIUS); | ||
1226 | cairo_rel_line_to (cr, 0, -OSD_CROSSHAIR_TICK); | ||
1227 | cairo_move_to (cr, OSD_CROSSHAIR_W/2, | ||
1228 | OSD_CROSSHAIR_H/2 + OSD_CROSSHAIR_RADIUS); | ||
1229 | cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK); | ||
1230 | |||
1231 | cairo_stroke (cr); | ||
1232 | } | ||
1233 | |||
1234 | static void | ||
1235 | harbaum | 105 | osd_render_crosshair(osm_gps_map_osd_t *osd) |
1236 | { | ||
1237 | osd_priv_t *priv = (osd_priv_t*)osd->priv; | ||
1238 | |||
1239 | harbaum | 110 | if(priv->crosshair.rendered) |
1240 | return; | ||
1241 | |||
1242 | priv->crosshair.rendered = TRUE; | ||
1243 | |||
1244 | harbaum | 105 | /* first fill with transparency */ |
1245 | harbaum | 110 | cairo_t *cr = cairo_create(priv->crosshair.surface); |
1246 | harbaum | 105 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1247 | harbaum | 106 | cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
1248 | harbaum | 105 | cairo_paint(cr); |
1249 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | ||
1250 | |||
1251 | harbaum | 106 | cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
1252 | |||
1253 | cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5); | ||
1254 | cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/2); | ||
1255 | osd_render_crosshair_shape(cr); | ||
1256 | |||
1257 | cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5); | ||
1258 | cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/4); | ||
1259 | osd_render_crosshair_shape(cr); | ||
1260 | |||
1261 | harbaum | 105 | cairo_destroy(cr); |
1262 | } | ||
1263 | #endif | ||
1264 | |||
1265 | #ifdef OSD_SCALE | ||
1266 | |||
1267 | #ifndef OSD_SCALE_FONT_SIZE | ||
1268 | #define OSD_SCALE_FONT_SIZE 12 | ||
1269 | #endif | ||
1270 | #define OSD_SCALE_W (10*OSD_SCALE_FONT_SIZE) | ||
1271 | #define OSD_SCALE_H (5*OSD_SCALE_FONT_SIZE/2) | ||
1272 | |||
1273 | harbaum | 103 | /* various parameters used to create the scale */ |
1274 | #define OSD_SCALE_H2 (OSD_SCALE_H/2) | ||
1275 | #define OSD_SCALE_TICK (2*OSD_SCALE_FONT_SIZE/3) | ||
1276 | #define OSD_SCALE_M (OSD_SCALE_H2 - OSD_SCALE_TICK) | ||
1277 | #define OSD_SCALE_I (OSD_SCALE_H2 + OSD_SCALE_TICK) | ||
1278 | #define OSD_SCALE_FD (OSD_SCALE_FONT_SIZE/4) | ||
1279 | harbaum | 99 | |
1280 | harbaum | 70 | static void |
1281 | harbaum | 98 | osd_render_scale(osm_gps_map_osd_t *osd) |
1282 | { | ||
1283 | harbaum | 86 | osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1284 | harbaum | 103 | |
1285 | /* this only needs to be rendered if the zoom has changed */ | ||
1286 | gint zoom; | ||
1287 | g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); | ||
1288 | harbaum | 110 | if(zoom == priv->scale.zoom) |
1289 | harbaum | 103 | return; |
1290 | |||
1291 | harbaum | 110 | priv->scale.zoom = zoom; |
1292 | harbaum | 103 | |
1293 | harbaum | 99 | float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget)); |
1294 | harbaum | 70 | |
1295 | harbaum | 98 | /* first fill with transparency */ |
1296 | harbaum | 110 | cairo_t *cr = cairo_create(priv->scale.surface); |
1297 | harbaum | 98 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1298 | harbaum | 100 | cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1299 | harbaum | 103 | // pink for testing: cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
1300 | harbaum | 98 | cairo_paint(cr); |
1301 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | ||
1302 | |||
1303 | /* determine the size of the scale width in meters */ | ||
1304 | harbaum | 103 | float width = (OSD_SCALE_W-OSD_SCALE_FONT_SIZE/6) * m_per_pix; |
1305 | harbaum | 102 | |
1306 | harbaum | 98 | /* scale this to useful values */ |
1307 | int exp = logf(width)*M_LOG10E; | ||
1308 | int mant = width/pow(10,exp); | ||
1309 | harbaum | 99 | int width_metric = mant * pow(10,exp); |
1310 | harbaum | 103 | char *dist_str = NULL; |
1311 | if(width_metric<1000) | ||
1312 | dist_str = g_strdup_printf("%u m", width_metric); | ||
1313 | else | ||
1314 | dist_str = g_strdup_printf("%u km", width_metric/1000); | ||
1315 | harbaum | 99 | width_metric /= m_per_pix; |
1316 | |||
1317 | harbaum | 102 | /* and now the hard part: scale for useful imperial values :-( */ |
1318 | /* try to convert to feet, 1ft == 0.3048 m */ | ||
1319 | width /= 0.3048; | ||
1320 | float imp_scale = 0.3048; | ||
1321 | char *dist_imp_unit = "ft"; | ||
1322 | harbaum | 99 | |
1323 | harbaum | 102 | if(width >= 100) { |
1324 | /* 1yd == 3 feet */ | ||
1325 | width /= 3.0; | ||
1326 | imp_scale *= 3.0; | ||
1327 | dist_imp_unit = "yd"; | ||
1328 | |||
1329 | if(width >= 1760.0) { | ||
1330 | /* 1mi == 1760 yd */ | ||
1331 | width /= 1760.0; | ||
1332 | imp_scale *= 1760.0; | ||
1333 | dist_imp_unit = "mi"; | ||
1334 | } | ||
1335 | } | ||
1336 | |||
1337 | harbaum | 103 | /* also convert this to full tens/hundreds */ |
1338 | exp = logf(width)*M_LOG10E; | ||
1339 | mant = width/pow(10,exp); | ||
1340 | int width_imp = mant * pow(10,exp); | ||
1341 | char *dist_str_imp = g_strdup_printf("%u %s", width_imp, dist_imp_unit); | ||
1342 | harbaum | 102 | |
1343 | harbaum | 103 | /* convert back to pixels */ |
1344 | width_imp *= imp_scale; | ||
1345 | width_imp /= m_per_pix; | ||
1346 | |||
1347 | harbaum | 99 | cairo_select_font_face (cr, "Sans", |
1348 | CAIRO_FONT_SLANT_NORMAL, | ||
1349 | CAIRO_FONT_WEIGHT_BOLD); | ||
1350 | harbaum | 102 | cairo_set_font_size (cr, OSD_SCALE_FONT_SIZE); |
1351 | harbaum | 99 | cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); |
1352 | |||
1353 | cairo_text_extents_t extents; | ||
1354 | cairo_text_extents (cr, dist_str, &extents); | ||
1355 | |||
1356 | harbaum | 100 | cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
1357 | harbaum | 103 | cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6); |
1358 | cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD); | ||
1359 | harbaum | 100 | cairo_text_path (cr, dist_str); |
1360 | cairo_stroke (cr); | ||
1361 | harbaum | 103 | cairo_move_to (cr, 2*OSD_SCALE_FD, |
1362 | OSD_SCALE_H2+OSD_SCALE_FD + extents.height); | ||
1363 | cairo_text_path (cr, dist_str_imp); | ||
1364 | cairo_stroke (cr); | ||
1365 | harbaum | 100 | |
1366 | cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); | ||
1367 | harbaum | 103 | cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD); |
1368 | harbaum | 99 | cairo_show_text (cr, dist_str); |
1369 | harbaum | 103 | cairo_move_to (cr, 2*OSD_SCALE_FD, |
1370 | OSD_SCALE_H2+OSD_SCALE_FD + extents.height); | ||
1371 | cairo_show_text (cr, dist_str_imp); | ||
1372 | harbaum | 99 | |
1373 | harbaum | 103 | g_free(dist_str); |
1374 | g_free(dist_str_imp); | ||
1375 | |||
1376 | harbaum | 99 | /* draw white line */ |
1377 | cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); | ||
1378 | cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); | ||
1379 | harbaum | 103 | cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/3); |
1380 | cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M); | ||
1381 | cairo_rel_line_to (cr, 0, OSD_SCALE_TICK); | ||
1382 | harbaum | 99 | cairo_rel_line_to (cr, width_metric, 0); |
1383 | harbaum | 103 | cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1384 | harbaum | 99 | cairo_stroke(cr); |
1385 | harbaum | 103 | cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I); |
1386 | cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); | ||
1387 | cairo_rel_line_to (cr, width_imp, 0); | ||
1388 | cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK); | ||
1389 | cairo_stroke(cr); | ||
1390 | harbaum | 99 | |
1391 | /* draw black line */ | ||
1392 | cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); | ||
1393 | harbaum | 103 | cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6); |
1394 | cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M); | ||
1395 | cairo_rel_line_to (cr, 0, OSD_SCALE_TICK); | ||
1396 | harbaum | 99 | cairo_rel_line_to (cr, width_metric, 0); |
1397 | harbaum | 103 | cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1398 | harbaum | 99 | cairo_stroke(cr); |
1399 | harbaum | 103 | cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I); |
1400 | cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); | ||
1401 | cairo_rel_line_to (cr, width_imp, 0); | ||
1402 | cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK); | ||
1403 | cairo_stroke(cr); | ||
1404 | harbaum | 99 | |
1405 | harbaum | 98 | cairo_destroy(cr); |
1406 | } | ||
1407 | harbaum | 105 | #endif |
1408 | harbaum | 98 | |
1409 | static void | ||
1410 | harbaum | 108 | osd_render_controls(osm_gps_map_osd_t *osd) |
1411 | harbaum | 98 | { |
1412 | osd_priv_t *priv = (osd_priv_t*)osd->priv; | ||
1413 | |||
1414 | harbaum | 108 | if(priv->controls.rendered |
1415 | #ifdef OSD_GPS_BUTTON | ||
1416 | && (priv->controls.gps_enabled == (osd->cb != NULL)) | ||
1417 | #endif | ||
1418 | ) | ||
1419 | return; | ||
1420 | |||
1421 | #ifdef OSD_GPS_BUTTON | ||
1422 | priv->controls.gps_enabled = (osd->cb != NULL); | ||
1423 | #endif | ||
1424 | harbaum | 110 | priv->controls.rendered = TRUE; |
1425 | harbaum | 108 | |
1426 | harbaum | 86 | #ifndef OSD_COLOR |
1427 | GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; | ||
1428 | GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; | ||
1429 | GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE]; | ||
1430 | harbaum | 74 | #endif |
1431 | harbaum | 70 | |
1432 | /* first fill with transparency */ | ||
1433 | harbaum | 108 | cairo_t *cr = cairo_create(priv->controls.surface); |
1434 | harbaum | 70 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1435 | cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); | ||
1436 | cairo_paint(cr); | ||
1437 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | ||
1438 | |||
1439 | /* --------- draw zoom and dpad shape shadow ----------- */ | ||
1440 | harbaum | 74 | #ifdef OSD_SHADOW_ENABLE |
1441 | harbaum | 86 | osd_zoom_shape(cr, 1+OSD_SHADOW, 1+OSD_SHADOW); |
1442 | osd_shape_shadow(cr); | ||
1443 | harbaum | 76 | #ifndef OSD_NO_DPAD |
1444 | harbaum | 86 | osd_dpad_shape(cr, 1+OSD_SHADOW, 1+OSD_SHADOW); |
1445 | osd_shape_shadow(cr); | ||
1446 | harbaum | 74 | #endif |
1447 | harbaum | 76 | #endif |
1448 | harbaum | 70 | |
1449 | /* --------- draw zoom and dpad shape ----------- */ | ||
1450 | |||
1451 | harbaum | 86 | osd_zoom_shape(cr, 1, 1); |
1452 | harbaum | 74 | #ifndef OSD_COLOR |
1453 | harbaum | 86 | osd_shape(cr, &bg, &fg); |
1454 | harbaum | 74 | #else |
1455 | harbaum | 86 | osd_shape(cr); |
1456 | harbaum | 74 | #endif |
1457 | harbaum | 76 | #ifndef OSD_NO_DPAD |
1458 | harbaum | 86 | osd_dpad_shape(cr, 1, 1); |
1459 | harbaum | 74 | #ifndef OSD_COLOR |
1460 | harbaum | 86 | osd_shape(cr, &bg, &fg); |
1461 | harbaum | 74 | #else |
1462 | harbaum | 86 | osd_shape(cr); |
1463 | harbaum | 74 | #endif |
1464 | harbaum | 76 | #endif |
1465 | harbaum | 70 | |
1466 | /* --------- draw zoom and dpad labels --------- */ | ||
1467 | |||
1468 | harbaum | 74 | #ifdef OSD_SHADOW_ENABLE |
1469 | harbaum | 87 | osd_labels_shadow(cr, Z_RAD/3, TRUE); |
1470 | harbaum | 86 | osd_zoom_labels(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW); |
1471 | harbaum | 76 | #ifndef OSD_NO_DPAD |
1472 | harbaum | 86 | osd_dpad_labels(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW); |
1473 | harbaum | 76 | #endif |
1474 | harbaum | 87 | cairo_stroke(cr); |
1475 | harbaum | 76 | #ifdef OSD_GPS_BUTTON |
1476 | harbaum | 87 | osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL); |
1477 | harbaum | 86 | osd_dpad_gps(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW); |
1478 | harbaum | 87 | cairo_stroke(cr); |
1479 | harbaum | 74 | #endif |
1480 | harbaum | 76 | #endif |
1481 | harbaum | 70 | |
1482 | harbaum | 74 | #ifndef OSD_COLOR |
1483 | harbaum | 86 | osd_labels(cr, Z_RAD/3, TRUE, &fg, &da); |
1484 | harbaum | 74 | #else |
1485 | harbaum | 86 | osd_labels(cr, Z_RAD/3, TRUE); |
1486 | harbaum | 74 | #endif |
1487 | harbaum | 87 | osd_zoom_labels(cr, 1, 1); |
1488 | #ifndef OSD_NO_DPAD | ||
1489 | osd_dpad_labels(cr, 1, 1); | ||
1490 | #endif | ||
1491 | cairo_stroke(cr); | ||
1492 | |||
1493 | harbaum | 74 | #ifndef OSD_COLOR |
1494 | harbaum | 86 | osd_labels(cr, Z_RAD/6, osd->cb != NULL, &fg, &da); |
1495 | harbaum | 74 | #else |
1496 | harbaum | 86 | osd_labels(cr, Z_RAD/6, osd->cb != NULL); |
1497 | harbaum | 74 | #endif |
1498 | harbaum | 87 | #ifdef OSD_GPS_BUTTON |
1499 | osd_dpad_gps(cr, 1, 1); | ||
1500 | harbaum | 76 | #endif |
1501 | harbaum | 87 | cairo_stroke(cr); |
1502 | harbaum | 70 | |
1503 | cairo_destroy(cr); | ||
1504 | harbaum | 108 | } |
1505 | harbaum | 86 | |
1506 | harbaum | 108 | static void |
1507 | osd_render(osm_gps_map_osd_t *osd) | ||
1508 | { | ||
1509 | harbaum | 111 | /* this function is actually called pretty often since the */ |
1510 | /* OSD contents may have changed (due to a coordinate/zoom change). */ | ||
1511 | /* The different OSD parts have to make sure that they don't */ | ||
1512 | /* render unneccessarily often and thus waste CPU power */ | ||
1513 | |||
1514 | harbaum | 108 | osd_render_controls(osd); |
1515 | |||
1516 | harbaum | 88 | #ifdef OSD_SOURCE_SEL |
1517 | harbaum | 111 | osd_render_source_sel(osd, FALSE); |
1518 | harbaum | 88 | #endif |
1519 | harbaum | 98 | |
1520 | #ifdef OSD_SCALE | ||
1521 | osd_render_scale(osd); | ||
1522 | #endif | ||
1523 | harbaum | 105 | |
1524 | #ifdef OSD_CROSSHAIR | ||
1525 | osd_render_crosshair(osd); | ||
1526 | #endif | ||
1527 | harbaum | 106 | |
1528 | #ifdef OSD_COORDINATES | ||
1529 | osd_render_coordinates(osd); | ||
1530 | #endif | ||
1531 | harbaum | 70 | } |
1532 | |||
1533 | static void | ||
1534 | harbaum | 86 | osd_draw(osm_gps_map_osd_t *osd, GdkDrawable *drawable) |
1535 | harbaum | 70 | { |
1536 | harbaum | 73 | osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1537 | harbaum | 70 | |
1538 | /* OSD itself uses some off-screen rendering, so check if the */ | ||
1539 | /* offscreen buffer is present and create it if not */ | ||
1540 | harbaum | 108 | if(!priv->controls.surface) { |
1541 | harbaum | 70 | /* create overlay ... */ |
1542 | harbaum | 108 | priv->controls.surface = |
1543 | harbaum | 86 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2); |
1544 | |||
1545 | harbaum | 108 | priv->controls.rendered = FALSE; |
1546 | #ifdef OSD_GPS_BUTTON | ||
1547 | priv->controls.gps_enabled = FALSE; | ||
1548 | #endif | ||
1549 | |||
1550 | harbaum | 88 | #ifdef OSD_SOURCE_SEL |
1551 | harbaum | 86 | /* the initial OSD state is alway not-expanded */ |
1552 | harbaum | 110 | priv->source_sel.surface = |
1553 | harbaum | 86 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1554 | OSD_S_W+2, OSD_S_H+2); | ||
1555 | harbaum | 111 | priv->source_sel.rendered = FALSE; |
1556 | harbaum | 88 | #endif |
1557 | harbaum | 86 | |
1558 | harbaum | 98 | #ifdef OSD_SCALE |
1559 | harbaum | 110 | priv->scale.surface = |
1560 | harbaum | 98 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1561 | harbaum | 103 | OSD_SCALE_W, OSD_SCALE_H); |
1562 | harbaum | 110 | priv->scale.zoom = -1; |
1563 | harbaum | 98 | #endif |
1564 | |||
1565 | harbaum | 105 | #ifdef OSD_CROSSHAIR |
1566 | harbaum | 110 | priv->crosshair.surface = |
1567 | harbaum | 105 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1568 | OSD_CROSSHAIR_W, OSD_CROSSHAIR_H); | ||
1569 | harbaum | 110 | priv->crosshair.rendered = FALSE; |
1570 | harbaum | 105 | #endif |
1571 | |||
1572 | harbaum | 106 | #ifdef OSD_COORDINATES |
1573 | harbaum | 110 | priv->coordinates.surface = |
1574 | harbaum | 106 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1575 | OSD_COORDINATES_W, OSD_COORDINATES_H); | ||
1576 | harbaum | 108 | |
1577 | harbaum | 110 | priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID; |
1578 | harbaum | 106 | #endif |
1579 | |||
1580 | harbaum | 70 | /* ... and render it */ |
1581 | harbaum | 86 | osd_render(osd); |
1582 | harbaum | 70 | } |
1583 | |||
1584 | // now draw this onto the original context | ||
1585 | harbaum | 75 | cairo_t *cr = gdk_cairo_create(drawable); |
1586 | harbaum | 77 | |
1587 | harbaum | 113 | gint x, y; |
1588 | harbaum | 77 | |
1589 | harbaum | 106 | #ifdef OSD_SCALE |
1590 | x = OSD_X; | ||
1591 | y = -OSD_Y; | ||
1592 | if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W; | ||
1593 | if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H; | ||
1594 | harbaum | 77 | |
1595 | harbaum | 110 | cairo_set_source_surface(cr, priv->scale.surface, x, y); |
1596 | harbaum | 106 | cairo_paint(cr); |
1597 | #endif | ||
1598 | |||
1599 | #ifdef OSD_CROSSHAIR | ||
1600 | x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2; | ||
1601 | y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2; | ||
1602 | |||
1603 | harbaum | 110 | cairo_set_source_surface(cr, priv->crosshair.surface, x, y); |
1604 | harbaum | 106 | cairo_paint(cr); |
1605 | #endif | ||
1606 | |||
1607 | #ifdef OSD_COORDINATES | ||
1608 | x = -OSD_X; | ||
1609 | y = -OSD_Y; | ||
1610 | if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W; | ||
1611 | if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H; | ||
1612 | |||
1613 | harbaum | 110 | cairo_set_source_surface(cr, priv->coordinates.surface, x, y); |
1614 | harbaum | 106 | cairo_paint(cr); |
1615 | #endif | ||
1616 | |||
1617 | harbaum | 113 | #ifdef OSD_BALLOON |
1618 | if(priv->balloon.surface) { | ||
1619 | |||
1620 | /* convert given lat lon into screen coordinates */ | ||
1621 | gint x, y; | ||
1622 | osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), | ||
1623 | priv->balloon.lat, priv->balloon.lon, | ||
1624 | &x, &y); | ||
1625 | |||
1626 | /* check if balloon needs to be rerendered */ | ||
1627 | osd_render_balloon(osd); | ||
1628 | |||
1629 | cairo_set_source_surface(cr, priv->balloon.surface, | ||
1630 | x + priv->balloon.offset_x, | ||
1631 | y + priv->balloon.offset_y); | ||
1632 | cairo_paint(cr); | ||
1633 | } | ||
1634 | #endif | ||
1635 | |||
1636 | harbaum | 106 | x = OSD_X; |
1637 | if(x < 0) | ||
1638 | x += osd->widget->allocation.width - OSD_W; | ||
1639 | |||
1640 | y = OSD_Y; | ||
1641 | if(y < 0) | ||
1642 | y += osd->widget->allocation.height - OSD_H; | ||
1643 | |||
1644 | harbaum | 108 | cairo_set_source_surface(cr, priv->controls.surface, x, y); |
1645 | harbaum | 70 | cairo_paint(cr); |
1646 | harbaum | 86 | |
1647 | #ifdef OSD_SOURCE_SEL | ||
1648 | harbaum | 110 | if(!priv->source_sel.handler_id) { |
1649 | harbaum | 86 | /* the OSD source selection is not being animated */ |
1650 | harbaum | 110 | if(!priv->source_sel.expanded) |
1651 | harbaum | 86 | x = osd->widget->allocation.width - OSD_S_W; |
1652 | else | ||
1653 | x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; | ||
1654 | } else | ||
1655 | harbaum | 110 | x = priv->source_sel.shift; |
1656 | harbaum | 86 | |
1657 | y = OSD_S_Y; | ||
1658 | if(OSD_S_Y < 0) { | ||
1659 | harbaum | 110 | if(!priv->source_sel.expanded) |
1660 | harbaum | 86 | y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y; |
1661 | else | ||
1662 | y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y; | ||
1663 | } | ||
1664 | |||
1665 | harbaum | 110 | cairo_set_source_surface(cr, priv->source_sel.surface, x, y); |
1666 | harbaum | 86 | cairo_paint(cr); |
1667 | #endif | ||
1668 | |||
1669 | harbaum | 70 | cairo_destroy(cr); |
1670 | } | ||
1671 | |||
1672 | static void | ||
1673 | harbaum | 86 | osd_free(osm_gps_map_osd_t *osd) |
1674 | harbaum | 70 | { |
1675 | harbaum | 73 | osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1676 | harbaum | 70 | |
1677 | harbaum | 108 | if (priv->controls.surface) |
1678 | cairo_surface_destroy(priv->controls.surface); | ||
1679 | harbaum | 88 | |
1680 | #ifdef OSD_SOURCE_SEL | ||
1681 | harbaum | 110 | if(priv->source_sel.handler_id) |
1682 | gtk_timeout_remove(priv->source_sel.handler_id); | ||
1683 | harbaum | 86 | |
1684 | harbaum | 110 | if (priv->source_sel.surface) |
1685 | cairo_surface_destroy(priv->source_sel.surface); | ||
1686 | harbaum | 88 | #endif |
1687 | harbaum | 86 | |
1688 | harbaum | 98 | #ifdef OSD_SCALE |
1689 | harbaum | 110 | if (priv->scale.surface) |
1690 | cairo_surface_destroy(priv->scale.surface); | ||
1691 | harbaum | 98 | #endif |
1692 | |||
1693 | harbaum | 105 | #ifdef OSD_CROSSHAIR |
1694 | harbaum | 110 | if (priv->crosshair.surface) |
1695 | cairo_surface_destroy(priv->crosshair.surface); | ||
1696 | harbaum | 105 | #endif |
1697 | |||
1698 | harbaum | 106 | #ifdef OSD_COORDINATES |
1699 | harbaum | 110 | if (priv->coordinates.surface) |
1700 | cairo_surface_destroy(priv->coordinates.surface); | ||
1701 | harbaum | 106 | #endif |
1702 | |||
1703 | harbaum | 112 | #ifdef OSD_BALLOON |
1704 | if (priv->balloon.surface) | ||
1705 | cairo_surface_destroy(priv->balloon.surface); | ||
1706 | #endif | ||
1707 | |||
1708 | harbaum | 73 | g_free(priv); |
1709 | } | ||
1710 | |||
1711 | harbaum | 87 | static gboolean |
1712 | osd_busy(osm_gps_map_osd_t *osd) | ||
1713 | { | ||
1714 | harbaum | 88 | #ifdef OSD_SOURCE_SEL |
1715 | harbaum | 87 | osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1716 | harbaum | 110 | return (priv->source_sel.handler_id != 0); |
1717 | harbaum | 88 | #else |
1718 | return FALSE; | ||
1719 | #endif | ||
1720 | harbaum | 87 | } |
1721 | |||
1722 | harbaum | 73 | static osm_gps_map_osd_t osd_classic = { |
1723 | harbaum | 88 | .widget = NULL, |
1724 | |||
1725 | harbaum | 86 | .draw = osd_draw, |
1726 | .check = osd_check, | ||
1727 | .render = osd_render, | ||
1728 | .free = osd_free, | ||
1729 | harbaum | 87 | .busy = osd_busy, |
1730 | harbaum | 73 | |
1731 | .cb = NULL, | ||
1732 | .data = NULL, | ||
1733 | |||
1734 | .priv = NULL | ||
1735 | }; | ||
1736 | |||
1737 | /* this is the only function that's externally visible */ | ||
1738 | void | ||
1739 | osm_gps_map_osd_classic_init(OsmGpsMap *map) | ||
1740 | { | ||
1741 | osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1); | ||
1742 | |||
1743 | harbaum | 112 | #ifdef OSD_BALLOON |
1744 | priv->balloon.lat = OSM_GPS_MAP_INVALID; | ||
1745 | priv->balloon.lon = OSM_GPS_MAP_INVALID; | ||
1746 | #endif | ||
1747 | |||
1748 | harbaum | 73 | osd_classic.priv = priv; |
1749 | |||
1750 | osm_gps_map_register_osd(map, &osd_classic); | ||
1751 | } | ||
1752 | |||
1753 | harbaum | 76 | #ifdef OSD_GPS_BUTTON |
1754 | harbaum | 74 | /* below are osd specific functions which aren't used by osm-gps-map */ |
1755 | /* but instead are to be used by the main application */ | ||
1756 | harbaum | 76 | void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, |
1757 | gpointer data) { | ||
1758 | harbaum | 73 | osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1759 | g_return_if_fail (osd); | ||
1760 | |||
1761 | osd->cb = cb; | ||
1762 | osd->data = data; | ||
1763 | |||
1764 | harbaum | 70 | /* this may have changed the state of the gps button */ |
1765 | /* we thus re-render the overlay */ | ||
1766 | harbaum | 73 | osd->render(osd); |
1767 | harbaum | 70 | |
1768 | harbaum | 73 | osm_gps_map_redraw(map); |
1769 | harbaum | 70 | } |
1770 | harbaum | 76 | #endif |
1771 | harbaum | 86 | |
1772 | osd_button_t | ||
1773 | osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) { | ||
1774 | osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); | ||
1775 | g_return_val_if_fail (osd, OSD_NONE); | ||
1776 | |||
1777 | harbaum | 114 | return osd_check(osd, TRUE, x, y); |
1778 | harbaum | 86 | } |