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