19 |
|
|
20 |
#include "config.h" |
#include "config.h" |
21 |
#include <stdlib.h> // abs |
#include <stdlib.h> // abs |
22 |
|
#include <string.h> |
23 |
#include <math.h> // M_PI/cos() |
#include <math.h> // M_PI/cos() |
24 |
|
|
25 |
/* parameters that can be overwritten from the config file: */ |
/* parameters that can be overwritten from the config file: */ |
33 |
#include <cairo.h> |
#include <cairo.h> |
34 |
|
|
35 |
#include "osm-gps-map.h" |
#include "osm-gps-map.h" |
36 |
|
#include "converter.h" |
37 |
#include "osm-gps-map-osd-classic.h" |
#include "osm-gps-map-osd-classic.h" |
38 |
|
|
39 |
//the osd controls |
//the osd controls |
40 |
typedef struct { |
typedef struct { |
41 |
/* the offscreen representation of the OSD */ |
/* the offscreen representation of the OSD */ |
42 |
cairo_surface_t *overlay; |
struct { |
43 |
|
cairo_surface_t *surface; |
44 |
|
gboolean rendered; |
45 |
|
#ifdef OSD_GPS_BUTTON |
46 |
|
gboolean gps_enabled; |
47 |
|
#endif |
48 |
|
} controls; |
49 |
|
|
50 |
|
#ifdef OSD_BALLOON |
51 |
|
//a balloon with additional info |
52 |
|
struct { |
53 |
|
cairo_surface_t *surface; |
54 |
|
int orientation, offset_x, offset_y; |
55 |
|
|
56 |
|
gboolean just_created; |
57 |
|
float lat, lon; |
58 |
|
OsmGpsMapRect_t rect; |
59 |
|
|
60 |
|
/* function called to have the user app draw the contents */ |
61 |
|
OsmGpsMapBalloonCallback cb; |
62 |
|
gpointer data; |
63 |
|
} balloon; |
64 |
|
#endif |
65 |
|
|
66 |
|
#ifdef OSD_SCALE |
67 |
|
struct { |
68 |
|
cairo_surface_t *surface; |
69 |
|
int zoom; |
70 |
|
} scale; |
71 |
|
#endif |
72 |
|
|
73 |
|
#ifdef OSD_CROSSHAIR |
74 |
|
struct { |
75 |
|
cairo_surface_t *surface; |
76 |
|
gboolean rendered; |
77 |
|
} crosshair; |
78 |
|
#endif |
79 |
|
|
80 |
|
#ifdef OSD_NAV |
81 |
|
struct { |
82 |
|
cairo_surface_t *surface; |
83 |
|
float lat, lon; |
84 |
|
char *name; |
85 |
|
gboolean imperial; // display distance imperial/metric |
86 |
|
} nav; |
87 |
|
#endif |
88 |
|
|
89 |
|
#ifdef OSD_COORDINATES |
90 |
|
struct { |
91 |
|
cairo_surface_t *surface; |
92 |
|
float lat, lon; |
93 |
|
} coordinates; |
94 |
|
#endif |
95 |
|
|
96 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
97 |
/* values to handle the "source" menu */ |
struct { |
98 |
cairo_surface_t *map_source; |
/* values to handle the "source" menu */ |
99 |
gboolean expanded; |
cairo_surface_t *surface; |
100 |
gint shift, dir, count; |
gboolean expanded; |
101 |
gint handler_id; |
gint shift, dir, count; |
102 |
gint width, height; |
gint handler_id; |
103 |
|
gint width, height; |
104 |
|
gboolean rendered; |
105 |
|
} source_sel; |
106 |
#endif |
#endif |
107 |
|
|
108 |
} osd_priv_t; |
} osd_priv_t; |
109 |
|
|
110 |
|
#ifdef OSD_BALLOON |
111 |
|
/* most visual effects are hardcoded by now, but may be made */ |
112 |
|
/* available via properties later */ |
113 |
|
#ifndef BALLOON_AREA_WIDTH |
114 |
|
#define BALLOON_AREA_WIDTH 290 |
115 |
|
#endif |
116 |
|
#ifndef BALLOON_AREA_HEIGHT |
117 |
|
#define BALLOON_AREA_HEIGHT 75 |
118 |
|
#endif |
119 |
|
#ifndef BALLOON_CORNER_RADIUS |
120 |
|
#define BALLOON_CORNER_RADIUS 10 |
121 |
|
#endif |
122 |
|
|
123 |
|
#define BALLOON_BORDER (BALLOON_CORNER_RADIUS/2) |
124 |
|
#define BALLOON_WIDTH (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER) |
125 |
|
#define BALLOON_HEIGHT (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER) |
126 |
|
#define BALLOON_TRANSPARENCY 0.8 |
127 |
|
#define POINTER_HEIGHT 20 |
128 |
|
#define POINTER_FOOT_WIDTH 20 |
129 |
|
#define POINTER_OFFSET (BALLOON_CORNER_RADIUS*3/4) |
130 |
|
#define BALLOON_SHADOW (BALLOON_CORNER_RADIUS/2) |
131 |
|
#define BALLOON_SHADOW_TRANSPARENCY 0.2 |
132 |
|
|
133 |
|
#define BALLOON_W (BALLOON_WIDTH + BALLOON_SHADOW) |
134 |
|
#define BALLOON_H (BALLOON_HEIGHT + POINTER_HEIGHT + BALLOON_SHADOW) |
135 |
|
|
136 |
|
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) |
137 |
|
|
138 |
|
#define FIN printf("entering function %s\n", __func__); |
139 |
|
#define FOUT printf("leaving function %s\n", __func__); |
140 |
|
|
141 |
|
/* draw the bubble shape. this is used twice, once for the shape and once */ |
142 |
|
/* for the shadow */ |
143 |
|
static void |
144 |
|
osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1, |
145 |
|
gboolean bottom, int px, int py, int px0, int px1) { |
146 |
|
|
147 |
|
FIN; |
148 |
|
|
149 |
|
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
150 |
|
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
151 |
|
BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2); |
152 |
|
if(!bottom) { |
153 |
|
/* insert top pointer */ |
154 |
|
cairo_line_to (cr, px1, y0); |
155 |
|
cairo_line_to (cr, px, py); |
156 |
|
cairo_line_to (cr, px0, y0); |
157 |
|
} |
158 |
|
|
159 |
|
cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0); |
160 |
|
cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
161 |
|
BALLOON_CORNER_RADIUS, -M_PI/2, 0); |
162 |
|
cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS); |
163 |
|
cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, |
164 |
|
BALLOON_CORNER_RADIUS, 0, M_PI/2); |
165 |
|
if(bottom) { |
166 |
|
/* insert bottom pointer */ |
167 |
|
cairo_line_to (cr, px0, y1); |
168 |
|
cairo_line_to (cr, px, py); |
169 |
|
cairo_line_to (cr, px1, y1); |
170 |
|
} |
171 |
|
|
172 |
|
cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1); |
173 |
|
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, |
174 |
|
BALLOON_CORNER_RADIUS, M_PI/2, M_PI); |
175 |
|
|
176 |
|
cairo_close_path (cr); |
177 |
|
|
178 |
|
FOUT; |
179 |
|
} |
180 |
|
|
181 |
|
static void |
182 |
|
osd_render_balloon(osm_gps_map_osd_t *osd) { |
183 |
|
FIN; |
184 |
|
|
185 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
186 |
|
|
187 |
|
/* get zoom */ |
188 |
|
gint zoom; |
189 |
|
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
190 |
|
|
191 |
|
/* ------- convert given coordinate into screen position --------- */ |
192 |
|
gint xs, ys; |
193 |
|
osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
194 |
|
priv->balloon.lat, priv->balloon.lon, |
195 |
|
&xs, &ys); |
196 |
|
|
197 |
|
gint x0 = 1, y0 = 1; |
198 |
|
|
199 |
|
/* check position of this relative to screen center to determine */ |
200 |
|
/* pointer direction ... */ |
201 |
|
int pointer_x, pointer_x0, pointer_x1; |
202 |
|
int pointer_y; |
203 |
|
|
204 |
|
/* ... and calculate position */ |
205 |
|
int orientation = 0; |
206 |
|
if(xs > osd->widget->allocation.width/2) { |
207 |
|
priv->balloon.offset_x = -BALLOON_WIDTH + POINTER_OFFSET; |
208 |
|
pointer_x = x0 - priv->balloon.offset_x; |
209 |
|
pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
210 |
|
pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH; |
211 |
|
orientation |= 1; |
212 |
|
} else { |
213 |
|
priv->balloon.offset_x = -POINTER_OFFSET; |
214 |
|
pointer_x = x0 - priv->balloon.offset_x; |
215 |
|
pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
216 |
|
pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH; |
217 |
|
} |
218 |
|
|
219 |
|
gboolean bottom = FALSE; |
220 |
|
if(ys > osd->widget->allocation.height/2) { |
221 |
|
priv->balloon.offset_y = -BALLOON_HEIGHT - POINTER_HEIGHT; |
222 |
|
pointer_y = y0 - priv->balloon.offset_y; |
223 |
|
bottom = TRUE; |
224 |
|
orientation |= 2; |
225 |
|
} else { |
226 |
|
priv->balloon.offset_y = 0; |
227 |
|
pointer_y = y0 - priv->balloon.offset_y; |
228 |
|
y0 += POINTER_HEIGHT; |
229 |
|
} |
230 |
|
|
231 |
|
/* if required orientation equals current one, then don't render */ |
232 |
|
/* anything */ |
233 |
|
if(orientation == priv->balloon.orientation) |
234 |
|
return; |
235 |
|
|
236 |
|
priv->balloon.orientation = orientation; |
237 |
|
|
238 |
|
/* calculate bottom/right of box */ |
239 |
|
int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT; |
240 |
|
|
241 |
|
/* save balloon screen coordinates for later use */ |
242 |
|
priv->balloon.rect.x = x0 + BALLOON_BORDER; |
243 |
|
priv->balloon.rect.y = y0 + BALLOON_BORDER; |
244 |
|
priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER; |
245 |
|
priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; |
246 |
|
|
247 |
|
cairo_t *cr = cairo_create(priv->balloon.surface); |
248 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
249 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
250 |
|
cairo_paint(cr); |
251 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
252 |
|
|
253 |
|
/* --------- draw shadow --------------- */ |
254 |
|
osm_gps_map_draw_balloon_shape (cr, |
255 |
|
x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW, |
256 |
|
x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW, |
257 |
|
bottom, pointer_x, pointer_y, |
258 |
|
pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW); |
259 |
|
|
260 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY); |
261 |
|
cairo_fill_preserve (cr); |
262 |
|
cairo_set_source_rgba (cr, 1, 0, 0, 1.0); |
263 |
|
cairo_set_line_width (cr, 0); |
264 |
|
cairo_stroke (cr); |
265 |
|
|
266 |
|
/* --------- draw main shape ----------- */ |
267 |
|
osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1, |
268 |
|
bottom, pointer_x, pointer_y, pointer_x0, pointer_x1); |
269 |
|
|
270 |
|
cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY); |
271 |
|
cairo_fill_preserve (cr); |
272 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY); |
273 |
|
cairo_set_line_width (cr, 1); |
274 |
|
cairo_stroke (cr); |
275 |
|
|
276 |
|
if (priv->balloon.cb) { |
277 |
|
osm_gps_map_balloon_event_t event; |
278 |
|
|
279 |
|
/* clip in case application tries to draw in */ |
280 |
|
/* exceed of the balloon */ |
281 |
|
cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y, |
282 |
|
priv->balloon.rect.w, priv->balloon.rect.h); |
283 |
|
cairo_clip (cr); |
284 |
|
cairo_new_path (cr); /* current path is not consumed by cairo_clip */ |
285 |
|
|
286 |
|
/* request the application to draw the balloon contents */ |
287 |
|
event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_DRAW; |
288 |
|
event.data.draw.rect = &priv->balloon.rect; |
289 |
|
event.data.draw.cr = cr; |
290 |
|
|
291 |
|
priv->balloon.cb(&event, priv->balloon.data); |
292 |
|
} |
293 |
|
|
294 |
|
cairo_destroy(cr); |
295 |
|
|
296 |
|
FOUT; |
297 |
|
} |
298 |
|
|
299 |
|
/* return true if balloon is being displayed and if */ |
300 |
|
/* the given coordinate is within this balloon */ |
301 |
|
static gboolean |
302 |
|
osd_balloon_check(osm_gps_map_osd_t *osd, gboolean click, gboolean down, gint x, gint y) |
303 |
|
{ |
304 |
|
FIN; |
305 |
|
|
306 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
307 |
|
|
308 |
|
if(!priv->balloon.surface) |
309 |
|
return FALSE; |
310 |
|
|
311 |
|
gint xs, ys; |
312 |
|
osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
313 |
|
priv->balloon.lat, priv->balloon.lon, |
314 |
|
&xs, &ys); |
315 |
|
|
316 |
|
xs += priv->balloon.rect.x + priv->balloon.offset_x; |
317 |
|
ys += priv->balloon.rect.y + priv->balloon.offset_y; |
318 |
|
|
319 |
|
gboolean is_in = |
320 |
|
(x > xs) && (x < xs + priv->balloon.rect.w) && |
321 |
|
(y > ys) && (y < ys + priv->balloon.rect.h); |
322 |
|
|
323 |
|
/* is this a real click or is the application just checking for something? */ |
324 |
|
if(click) { |
325 |
|
|
326 |
|
/* handle the fact that the balloon may have been created by the */ |
327 |
|
/* button down event */ |
328 |
|
if(!is_in && !down && !priv->balloon.just_created) { |
329 |
|
/* the user actually clicked outside the balloon */ |
330 |
|
|
331 |
|
/* close the balloon! */ |
332 |
|
osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget)); |
333 |
|
|
334 |
|
/* and inform application about this */ |
335 |
|
if(priv->balloon.cb) { |
336 |
|
osm_gps_map_balloon_event_t event; |
337 |
|
event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_REMOVED; |
338 |
|
priv->balloon.cb(&event, priv->balloon.data); |
339 |
|
} |
340 |
|
|
341 |
|
} |
342 |
|
|
343 |
|
if(is_in && priv->balloon.cb) { |
344 |
|
osm_gps_map_balloon_event_t event; |
345 |
|
|
346 |
|
/* notify application of click */ |
347 |
|
event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_CLICK; |
348 |
|
event.data.click.x = x - xs; |
349 |
|
event.data.click.y = y - ys; |
350 |
|
event.data.click.down = down; |
351 |
|
|
352 |
|
priv->balloon.cb(&event, priv->balloon.data); |
353 |
|
} |
354 |
|
} |
355 |
|
FOUT; |
356 |
|
return is_in; |
357 |
|
} |
358 |
|
|
359 |
|
void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) { |
360 |
|
FIN; |
361 |
|
|
362 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
363 |
|
|
364 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
365 |
|
g_return_if_fail (osd); |
366 |
|
|
367 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
368 |
|
g_return_if_fail (priv); |
369 |
|
|
370 |
|
if(priv->balloon.surface) { |
371 |
|
cairo_surface_destroy(priv->balloon.surface); |
372 |
|
priv->balloon.surface = NULL; |
373 |
|
priv->balloon.lat = OSM_GPS_MAP_INVALID; |
374 |
|
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
375 |
|
} |
376 |
|
osm_gps_map_redraw(map); |
377 |
|
FOUT; |
378 |
|
} |
379 |
|
|
380 |
|
void |
381 |
|
osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
382 |
|
OsmGpsMapBalloonCallback cb, gpointer data) { |
383 |
|
FIN; |
384 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
385 |
|
|
386 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
387 |
|
g_return_if_fail (osd); |
388 |
|
|
389 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
390 |
|
g_return_if_fail (priv); |
391 |
|
|
392 |
|
osm_gps_map_osd_clear_balloon (map); |
393 |
|
|
394 |
|
/* allocate balloon surface */ |
395 |
|
priv->balloon.surface = |
396 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
397 |
|
BALLOON_W+2, BALLOON_H+2); |
398 |
|
|
399 |
|
priv->balloon.lat = latitude; |
400 |
|
priv->balloon.lon = longitude; |
401 |
|
priv->balloon.cb = cb; |
402 |
|
priv->balloon.data = data; |
403 |
|
priv->balloon.just_created = TRUE; |
404 |
|
|
405 |
|
priv->balloon.orientation = -1; |
406 |
|
|
407 |
|
osd_render_balloon(osd); |
408 |
|
|
409 |
|
osm_gps_map_redraw(map); |
410 |
|
FOUT; |
411 |
|
} |
412 |
|
|
413 |
|
#endif // OSD_BALLOON |
414 |
|
|
415 |
/* position and extent of bounding box */ |
/* position and extent of bounding box */ |
416 |
#ifndef OSD_X |
#ifndef OSD_X |
417 |
#define OSD_X (10) |
#define OSD_X (10) |
552 |
static gboolean |
static gboolean |
553 |
osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad) |
osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad) |
554 |
{ |
{ |
555 |
|
FIN; |
556 |
return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad); |
return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad); |
557 |
} |
} |
558 |
|
|
635 |
#define OSD_S_H (OSD_S_PH + OSD_SHADOW) |
#define OSD_S_H (OSD_S_PH + OSD_SHADOW) |
636 |
|
|
637 |
/* size of usable area when expanded */ |
/* size of usable area when expanded */ |
638 |
#define OSD_S_AREA_W (priv->width) |
#define OSD_S_AREA_W (priv->source_sel.width) |
639 |
#define OSD_S_AREA_H (priv->height) |
#define OSD_S_AREA_H (priv->source_sel.height) |
640 |
#define OSD_S_EXP_W (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW) |
#define OSD_S_EXP_W (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW) |
641 |
#define OSD_S_EXP_H (OSD_S_AREA_H + OSD_SHADOW) |
#define OSD_S_EXP_H (OSD_S_AREA_H + OSD_SHADOW) |
642 |
|
|
652 |
/* or the entire menu incl. the puller (expanded) */ |
/* or the entire menu incl. the puller (expanded) */ |
653 |
static void |
static void |
654 |
osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) { |
osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) { |
655 |
if(!priv->expanded) { |
if(!priv->source_sel.expanded) { |
656 |
/* just draw the puller */ |
/* just draw the puller */ |
657 |
cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH); |
cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH); |
658 |
cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); |
cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); |
680 |
|
|
681 |
int py = offset + OSD_S_RAD - OSD_S_D0; |
int py = offset + OSD_S_RAD - OSD_S_D0; |
682 |
|
|
683 |
if(!priv->expanded) { |
if(!priv->source_sel.expanded) { |
684 |
/* draw the "puller" open (<) arrow */ |
/* draw the "puller" open (<) arrow */ |
685 |
cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py); |
cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py); |
686 |
cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); |
cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); |
705 |
CAIRO_FONT_WEIGHT_BOLD); |
CAIRO_FONT_WEIGHT_BOLD); |
706 |
cairo_set_font_size (cr, OSD_FONT_SIZE); |
cairo_set_font_size (cr, OSD_FONT_SIZE); |
707 |
|
|
708 |
int i, step = (priv->height - 2*OSD_TEXT_BORDER) |
int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) / |
709 |
/ OSM_GPS_MAP_SOURCE_LAST; |
OSM_GPS_MAP_SOURCE_LAST; |
710 |
for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) { |
for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) { |
711 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
712 |
const char *src = osm_gps_map_source_get_friendly_name(i); |
const char *src = osm_gps_map_source_get_friendly_name(i); |
719 |
if(source == i) { |
if(source == i) { |
720 |
cairo_rectangle(cr, x - OSD_TEXT_BORDER/2, |
cairo_rectangle(cr, x - OSD_TEXT_BORDER/2, |
721 |
y - OSD_TEXT_SKIP, |
y - OSD_TEXT_SKIP, |
722 |
priv->width - OSD_TEXT_BORDER, |
priv->source_sel.width - OSD_TEXT_BORDER, |
723 |
step + OSD_TEXT_SKIP); |
step + OSD_TEXT_SKIP); |
724 |
cairo_fill(cr); |
cairo_fill(cr); |
725 |
|
|
750 |
} |
} |
751 |
|
|
752 |
static void |
static void |
753 |
osd_render_source_sel(osm_gps_map_osd_t *osd) { |
osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) { |
754 |
|
FIN; |
755 |
|
|
756 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
757 |
|
|
758 |
|
if(priv->source_sel.rendered && !force_rerender) |
759 |
|
return; |
760 |
|
|
761 |
|
priv->source_sel.rendered = TRUE; |
762 |
|
|
763 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
764 |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
765 |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
767 |
#endif |
#endif |
768 |
|
|
769 |
/* draw source selector */ |
/* draw source selector */ |
770 |
cairo_t *cr = cairo_create(priv->map_source); |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
771 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
772 |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
773 |
cairo_paint(cr); |
cairo_paint(cr); |
799 |
cairo_stroke (cr); |
cairo_stroke (cr); |
800 |
|
|
801 |
cairo_destroy(cr); |
cairo_destroy(cr); |
802 |
|
FOUT; |
803 |
} |
} |
804 |
|
|
805 |
|
/* re-allocate the buffer used to draw the menu. This is used */ |
806 |
|
/* to collapse/expand the buffer */ |
807 |
static void |
static void |
808 |
osd_source_reallocate(osm_gps_map_osd_t *osd) { |
osd_source_reallocate(osm_gps_map_osd_t *osd) { |
809 |
|
FIN; |
810 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
811 |
|
|
812 |
/* re-allocate offscreen bitmap */ |
/* re-allocate offscreen bitmap */ |
813 |
g_assert (priv->map_source); |
g_assert (priv->source_sel.surface); |
814 |
|
|
815 |
int w = OSD_S_W, h = OSD_S_H; |
int w = OSD_S_W, h = OSD_S_H; |
816 |
if(priv->expanded) { |
if(priv->source_sel.expanded) { |
|
/* ... and right of it the waypoint id */ |
|
817 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
818 |
|
|
819 |
/* determine content size */ |
/* determine content size */ |
820 |
cairo_t *cr = cairo_create(priv->map_source); |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
821 |
cairo_select_font_face (cr, "Sans", |
cairo_select_font_face (cr, "Sans", |
822 |
CAIRO_FONT_SLANT_NORMAL, |
CAIRO_FONT_SLANT_NORMAL, |
823 |
CAIRO_FONT_WEIGHT_BOLD); |
CAIRO_FONT_WEIGHT_BOLD); |
829 |
const char *src = osm_gps_map_source_get_friendly_name(i); |
const char *src = osm_gps_map_source_get_friendly_name(i); |
830 |
cairo_text_extents (cr, src, &extents); |
cairo_text_extents (cr, src, &extents); |
831 |
|
|
|
// printf("Source %d: %s = %f %f\n", i, src, |
|
|
// extents.width, extents.height); |
|
|
|
|
832 |
if(extents.width > max_w) max_w = extents.width; |
if(extents.width > max_w) max_w = extents.width; |
833 |
if(extents.height > max_h) max_h = extents.height; |
if(extents.height > max_h) max_h = extents.height; |
834 |
} |
} |
835 |
cairo_destroy(cr); |
cairo_destroy(cr); |
836 |
|
|
837 |
priv->width = max_w + 2*OSD_TEXT_BORDER; |
priv->source_sel.width = max_w + 2*OSD_TEXT_BORDER; |
838 |
priv->height = OSM_GPS_MAP_SOURCE_LAST * |
priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST * |
839 |
(max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER; |
(max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER; |
840 |
|
|
841 |
w = OSD_S_EXP_W; |
w = OSD_S_EXP_W; |
842 |
h = OSD_S_EXP_H; |
h = OSD_S_EXP_H; |
843 |
} |
} |
844 |
|
|
845 |
cairo_surface_destroy(priv->map_source); |
cairo_surface_destroy(priv->source_sel.surface); |
846 |
priv->map_source = |
priv->source_sel.surface = |
847 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
848 |
|
|
849 |
osd_render_source_sel(osd); |
osd_render_source_sel(osd, TRUE); |
850 |
|
FOUT; |
851 |
} |
} |
852 |
|
|
853 |
#define OSD_HZ 15 |
#define OSD_HZ 15 |
854 |
#define OSD_TIME 500 |
#define OSD_TIME 500 |
855 |
|
|
856 |
static gboolean osd_source_animate(gpointer data) { |
static gboolean osd_source_animate(gpointer data) { |
857 |
|
FIN; |
858 |
osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data; |
osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data; |
859 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
860 |
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
861 |
gboolean done = FALSE; |
gboolean done = FALSE; |
862 |
priv->count += priv->dir; |
priv->source_sel.count += priv->source_sel.dir; |
863 |
|
|
864 |
/* shifting in */ |
/* shifting in */ |
865 |
if(priv->dir < 0) { |
if(priv->source_sel.dir < 0) { |
866 |
if(priv->count <= 0) { |
if(priv->source_sel.count <= 0) { |
867 |
priv->count = 0; |
priv->source_sel.count = 0; |
868 |
done = TRUE; |
done = TRUE; |
869 |
} |
} |
870 |
} else { |
} else { |
871 |
if(priv->count >= 1000) { |
if(priv->source_sel.count >= 1000) { |
872 |
priv->expanded = FALSE; |
priv->source_sel.expanded = FALSE; |
873 |
osd_source_reallocate(osd); |
osd_source_reallocate(osd); |
874 |
|
|
875 |
priv->count = 1000; |
priv->source_sel.count = 1000; |
876 |
done = TRUE; |
done = TRUE; |
877 |
} |
} |
878 |
} |
} |
880 |
|
|
881 |
/* count runs linearly from 0 to 1000, map this nicely onto a position */ |
/* count runs linearly from 0 to 1000, map this nicely onto a position */ |
882 |
|
|
883 |
/* simple linear mapping */ |
/* nice sinoid mapping */ |
884 |
// priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
float m = 0.5-cos(priv->source_sel.count * M_PI / 1000.0)/2; |
885 |
// (diff * priv->count)/1000; |
priv->source_sel.shift = |
886 |
|
(osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
|
/* nicer sinoid mapping */ |
|
|
float m = 0.5-cos(priv->count * M_PI / 1000.0)/2; |
|
|
priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
|
887 |
m * diff; |
m * diff; |
888 |
|
|
889 |
|
/* make sure the screen is updated */ |
890 |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
891 |
|
|
892 |
|
/* stop animation if done */ |
893 |
if(done) |
if(done) |
894 |
priv->handler_id = 0; |
priv->source_sel.handler_id = 0; |
895 |
|
|
896 |
|
FOUT; |
897 |
return !done; |
return !done; |
898 |
} |
} |
899 |
|
|
901 |
static void |
static void |
902 |
osd_source_toggle(osm_gps_map_osd_t *osd) |
osd_source_toggle(osm_gps_map_osd_t *osd) |
903 |
{ |
{ |
904 |
|
FIN; |
905 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
906 |
|
|
907 |
/* ignore clicks while animation is running */ |
/* ignore clicks while animation is running */ |
908 |
if(priv->handler_id) |
if(priv->source_sel.handler_id) |
909 |
return; |
return; |
910 |
|
|
911 |
/* expand immediately, collapse is handle at the end of the collapse animation */ |
/* expand immediately, collapse is handle at the end of the */ |
912 |
if(!priv->expanded) { |
/* collapse animation */ |
913 |
priv->expanded = TRUE; |
if(!priv->source_sel.expanded) { |
914 |
|
priv->source_sel.expanded = TRUE; |
915 |
osd_source_reallocate(osd); |
osd_source_reallocate(osd); |
916 |
|
|
917 |
priv->count = 1000; |
priv->source_sel.count = 1000; |
918 |
priv->shift = osd->widget->allocation.width - OSD_S_W; |
priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W; |
919 |
priv->dir = -1000/OSD_HZ; |
priv->source_sel.dir = -1000/OSD_HZ; |
920 |
} else { |
} else { |
921 |
priv->count = 0; |
priv->source_sel.count = 0; |
922 |
priv->shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
priv->source_sel.shift = osd->widget->allocation.width - |
923 |
priv->dir = +1000/OSD_HZ; |
OSD_S_EXP_W + OSD_S_X; |
924 |
|
priv->source_sel.dir = +1000/OSD_HZ; |
925 |
} |
} |
926 |
|
|
927 |
priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd); |
/* start timer to handle animation */ |
928 |
|
priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, |
929 |
|
osd_source_animate, osd); |
930 |
|
FOUT; |
931 |
} |
} |
932 |
|
|
933 |
|
/* check if the user clicked inside the source selection area */ |
934 |
static osd_button_t |
static osd_button_t |
935 |
osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
osd_source_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
936 |
|
FIN; |
937 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
938 |
|
|
939 |
if(!priv->expanded) |
if(!priv->source_sel.expanded) |
940 |
x -= osd->widget->allocation.width - OSD_S_W; |
x -= osd->widget->allocation.width - OSD_S_W; |
941 |
else |
else |
942 |
x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
951 |
/* really within puller shape? */ |
/* really within puller shape? */ |
952 |
if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) { |
if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) { |
953 |
/* expand source selector */ |
/* expand source selector */ |
954 |
osd_source_toggle(osd); |
if(down) |
955 |
|
osd_source_toggle(osd); |
956 |
|
|
957 |
/* tell upper layers that user clicked some background element */ |
/* tell upper layers that user clicked some background element */ |
958 |
/* of the OSD */ |
/* of the OSD */ |
961 |
} |
} |
962 |
|
|
963 |
/* check for clicks into data area */ |
/* check for clicks into data area */ |
964 |
if(priv->expanded) { |
if(priv->source_sel.expanded && !priv->source_sel.handler_id) { |
965 |
|
/* re-adjust from puller top to content top */ |
966 |
|
if(OSD_S_Y < 0) |
967 |
|
y += OSD_S_EXP_H - OSD_S_PH; |
968 |
|
|
969 |
if(x > OSD_S_PW && |
if(x > OSD_S_PW && |
970 |
x < OSD_S_PW + OSD_S_EXP_W && |
x < OSD_S_PW + OSD_S_EXP_W && |
971 |
y > 0 && |
y > 0 && |
972 |
y < OSD_S_EXP_H) { |
y < OSD_S_EXP_H) { |
973 |
|
|
974 |
|
int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) |
975 |
|
/ OSM_GPS_MAP_SOURCE_LAST; |
976 |
|
|
977 |
printf("in OSD source menu area\n"); |
y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP; |
978 |
|
y /= step; |
979 |
|
y += 1; |
980 |
|
|
981 |
|
if(down) { |
982 |
|
gint old = 0; |
983 |
|
g_object_get(osd->widget, "map-source", &old, NULL); |
984 |
|
|
985 |
|
if(y > OSM_GPS_MAP_SOURCE_NULL && |
986 |
|
y <= OSM_GPS_MAP_SOURCE_LAST && |
987 |
|
old != y) { |
988 |
|
g_object_set(osd->widget, "map-source", y, NULL); |
989 |
|
|
990 |
|
osd_render_source_sel(osd, TRUE); |
991 |
|
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
992 |
|
} |
993 |
|
} |
994 |
|
|
995 |
|
/* return "clicked in OSD background" to prevent further */ |
996 |
|
/* processing by application */ |
997 |
return OSD_BG; |
return OSD_BG; |
998 |
} |
} |
999 |
} |
} |
1000 |
|
|
1001 |
|
FOUT; |
1002 |
return OSD_NONE; |
return OSD_NONE; |
1003 |
} |
} |
1004 |
#endif // OSD_SOURCE_SEL |
#endif // OSD_SOURCE_SEL |
1005 |
|
|
1006 |
static osd_button_t |
static osd_button_t |
1007 |
osd_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
osd_check_int(osm_gps_map_osd_t *osd, gboolean click, gboolean down, gint x, gint y) { |
1008 |
|
FIN; |
1009 |
osd_button_t but = OSD_NONE; |
osd_button_t but = OSD_NONE; |
1010 |
|
|
1011 |
|
#ifdef OSD_BALLOON |
1012 |
|
if(down) { |
1013 |
|
/* needed to handle balloons that are created at click */ |
1014 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1015 |
|
priv->balloon.just_created = FALSE; |
1016 |
|
} |
1017 |
|
#endif |
1018 |
|
|
1019 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1020 |
/* the source selection area is handles internally */ |
/* the source selection area is handles internally */ |
1021 |
but = osd_source_check(osd, x, y); |
but = osd_source_check(osd, down, x, y); |
|
if(but != OSD_NONE) |
|
|
return but; |
|
1022 |
#endif |
#endif |
1023 |
|
|
1024 |
x -= OSD_X; |
if(but == OSD_NONE) { |
1025 |
y -= OSD_Y; |
gint mx = x - OSD_X; |
1026 |
|
gint my = y - OSD_Y; |
1027 |
if(OSD_X < 0) |
|
1028 |
x -= (osd->widget->allocation.width - OSD_W); |
if(OSD_X < 0) |
1029 |
|
mx -= (osd->widget->allocation.width - OSD_W); |
1030 |
if(OSD_Y < 0) |
|
1031 |
y -= (osd->widget->allocation.height - OSD_H); |
if(OSD_Y < 0) |
1032 |
|
my -= (osd->widget->allocation.height - OSD_H); |
1033 |
/* first do a rough test for the OSD area. */ |
|
1034 |
/* this is just to avoid an unnecessary detailed test */ |
/* first do a rough test for the OSD area. */ |
1035 |
if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) { |
/* this is just to avoid an unnecessary detailed test */ |
1036 |
|
if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) { |
1037 |
#ifndef OSD_NO_DPAD |
#ifndef OSD_NO_DPAD |
1038 |
but = osd_check_dpad(x, y); |
but = osd_check_dpad(mx, my); |
1039 |
#endif |
#endif |
1040 |
|
} |
1041 |
|
|
1042 |
if(but == OSD_NONE) |
if(but == OSD_NONE) |
1043 |
but = osd_check_zoom(x, y); |
but = osd_check_zoom(mx, my); |
1044 |
} |
} |
1045 |
|
|
1046 |
|
#ifdef OSD_BALLOON |
1047 |
|
if(but == OSD_NONE) { |
1048 |
|
/* check if user clicked into balloon */ |
1049 |
|
if(osd_balloon_check(osd, click, down, x, y)) |
1050 |
|
but = OSD_BG; |
1051 |
|
} |
1052 |
|
#endif |
1053 |
|
|
1054 |
|
FOUT; |
1055 |
return but; |
return but; |
1056 |
} |
} |
1057 |
|
|
1125 |
cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); |
cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); |
1126 |
} |
} |
1127 |
|
|
1128 |
|
#ifdef OSD_COORDINATES |
1129 |
|
|
1130 |
|
#ifndef OSD_COORDINATES_FONT_SIZE |
1131 |
|
#define OSD_COORDINATES_FONT_SIZE 12 |
1132 |
|
#endif |
1133 |
|
|
1134 |
|
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
1135 |
|
|
1136 |
|
#define OSD_COORDINATES_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
1137 |
|
#define OSD_COORDINATES_H (2*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET+OSD_COORDINATES_FONT_SIZE/4) |
1138 |
|
|
1139 |
|
/* these can be overwritten with versions that support */ |
1140 |
|
/* localization */ |
1141 |
|
#ifndef OSD_COORDINATES_CHR_N |
1142 |
|
#define OSD_COORDINATES_CHR_N "N" |
1143 |
|
#endif |
1144 |
|
#ifndef OSD_COORDINATES_CHR_S |
1145 |
|
#define OSD_COORDINATES_CHR_S "S" |
1146 |
|
#endif |
1147 |
|
#ifndef OSD_COORDINATES_CHR_E |
1148 |
|
#define OSD_COORDINATES_CHR_E "E" |
1149 |
|
#endif |
1150 |
|
#ifndef OSD_COORDINATES_CHR_W |
1151 |
|
#define OSD_COORDINATES_CHR_W "W" |
1152 |
|
#endif |
1153 |
|
|
1154 |
|
|
1155 |
|
|
1156 |
|
/* this is the classic geocaching notation */ |
1157 |
|
static char |
1158 |
|
*osd_latitude_str(float latitude) { |
1159 |
|
char *c = OSD_COORDINATES_CHR_N; |
1160 |
|
float integral, fractional; |
1161 |
|
|
1162 |
|
if(isnan(latitude)) |
1163 |
|
return NULL; |
1164 |
|
|
1165 |
|
if(latitude < 0) { |
1166 |
|
latitude = fabs(latitude); |
1167 |
|
c = OSD_COORDINATES_CHR_S; |
1168 |
|
} |
1169 |
|
|
1170 |
|
fractional = modff(latitude, &integral); |
1171 |
|
|
1172 |
|
return g_strdup_printf("%s %02d° %06.3f'", |
1173 |
|
c, (int)integral, fractional*60.0); |
1174 |
|
} |
1175 |
|
|
1176 |
|
static char |
1177 |
|
*osd_longitude_str(float longitude) { |
1178 |
|
char *c = OSD_COORDINATES_CHR_E; |
1179 |
|
float integral, fractional; |
1180 |
|
|
1181 |
|
if(isnan(longitude)) |
1182 |
|
return NULL; |
1183 |
|
|
1184 |
|
if(longitude < 0) { |
1185 |
|
longitude = fabs(longitude); |
1186 |
|
c = OSD_COORDINATES_CHR_W; |
1187 |
|
} |
1188 |
|
|
1189 |
|
fractional = modff(longitude, &integral); |
1190 |
|
|
1191 |
|
return g_strdup_printf("%s %03d° %06.3f'", |
1192 |
|
c, (int)integral, fractional*60.0); |
1193 |
|
} |
1194 |
|
|
1195 |
|
/* render a string at the given screen position */ |
1196 |
|
static int |
1197 |
|
osd_render_centered_text(cairo_t *cr, int y, int width, char *text) { |
1198 |
|
FIN; |
1199 |
|
|
1200 |
|
printf("params: %p %d %d %p\n", cr, y, width, text); // XXX |
1201 |
|
|
1202 |
|
if(!text) return y; |
1203 |
|
|
1204 |
|
printf("text given: %s\n", text); // XXX |
1205 |
|
|
1206 |
|
char *p = g_malloc(strlen(text)+4); // space for "...\n" |
1207 |
|
strcpy(p, text); |
1208 |
|
|
1209 |
|
cairo_text_extents_t extents; |
1210 |
|
printf("getting extents for \"%s\"\n", p); // XXX |
1211 |
|
cairo_text_extents (cr, p, &extents); |
1212 |
|
printf("initial extents.width = %f\n", extents.width); // XXX |
1213 |
|
|
1214 |
|
/* check if text needs to be truncated */ |
1215 |
|
int trunc_at = strlen(text)-1; |
1216 |
|
while(extents.width > width) { |
1217 |
|
g_assert(trunc_at > 0); |
1218 |
|
|
1219 |
|
printf("trunc at %d\n", trunc_at); // XXX |
1220 |
|
printf("extents.width = %f > %d\n", extents.width, width); // XXX |
1221 |
|
|
1222 |
|
trunc_at--; |
1223 |
|
strcpy(p+trunc_at, "..."); |
1224 |
|
printf("getting extents for \"%s\"\n", p); // XXX |
1225 |
|
cairo_text_extents (cr, p, &extents); |
1226 |
|
} |
1227 |
|
|
1228 |
|
printf("painting\n"); // XXX |
1229 |
|
|
1230 |
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
1231 |
|
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
1232 |
|
cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing); |
1233 |
|
cairo_text_path (cr, p); |
1234 |
|
cairo_stroke (cr); |
1235 |
|
|
1236 |
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
1237 |
|
cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing); |
1238 |
|
cairo_show_text (cr, p); |
1239 |
|
|
1240 |
|
g_free(p); |
1241 |
|
|
1242 |
|
/* skip + 1/5 line */ |
1243 |
|
FOUT; |
1244 |
|
return y + 6*OSD_COORDINATES_FONT_SIZE/5; |
1245 |
|
} |
1246 |
|
|
1247 |
|
static void |
1248 |
|
osd_render_coordinates(osm_gps_map_osd_t *osd) |
1249 |
|
{ |
1250 |
|
FIN; |
1251 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1252 |
|
|
1253 |
|
/* get current map position */ |
1254 |
|
gfloat lat, lon; |
1255 |
|
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
1256 |
|
|
1257 |
|
/* check if position has changed enough to require redraw */ |
1258 |
|
if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon)) |
1259 |
|
/* 1/60000 == 1/1000 minute */ |
1260 |
|
if((fabsf(lat - priv->coordinates.lat) < 1/60000) && |
1261 |
|
(fabsf(lon - priv->coordinates.lon) < 1/60000)) |
1262 |
|
return; |
1263 |
|
|
1264 |
|
priv->coordinates.lat = lat; |
1265 |
|
priv->coordinates.lon = lon; |
1266 |
|
|
1267 |
|
/* first fill with transparency */ |
1268 |
|
cairo_t *cr = cairo_create(priv->coordinates.surface); |
1269 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1270 |
|
// cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); |
1271 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
1272 |
|
cairo_paint(cr); |
1273 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1274 |
|
|
1275 |
|
cairo_select_font_face (cr, "Sans", |
1276 |
|
CAIRO_FONT_SLANT_NORMAL, |
1277 |
|
CAIRO_FONT_WEIGHT_BOLD); |
1278 |
|
cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE); |
1279 |
|
|
1280 |
|
char *latitude = osd_latitude_str(lat); |
1281 |
|
char *longitude = osd_longitude_str(lon); |
1282 |
|
|
1283 |
|
int y = OSD_COORDINATES_OFFSET; |
1284 |
|
y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, latitude); |
1285 |
|
y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, longitude); |
1286 |
|
|
1287 |
|
g_free(latitude); |
1288 |
|
g_free(longitude); |
1289 |
|
|
1290 |
|
cairo_destroy(cr); |
1291 |
|
FOUT; |
1292 |
|
} |
1293 |
|
#endif // OSD_COORDINATES |
1294 |
|
|
1295 |
|
#ifdef OSD_NAV |
1296 |
|
#define OSD_NAV_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
1297 |
|
#define OSD_NAV_H (11*OSD_COORDINATES_FONT_SIZE) |
1298 |
|
|
1299 |
|
/* http://mathforum.org/library/drmath/view/55417.html */ |
1300 |
|
static float get_bearing(float lat1, float lon1, float lat2, float lon2) { |
1301 |
|
return atan2( sin(lon2 - lon1) * cos(lat2), |
1302 |
|
cos(lat1) * sin(lat2) - |
1303 |
|
sin(lat1) * cos(lat2) * cos(lon2 - lon1)); |
1304 |
|
} |
1305 |
|
|
1306 |
|
/* http://mathforum.org/library/drmath/view/51722.html */ |
1307 |
|
static float get_distance(float lat1, float lon1, float lat2, float lon2) { |
1308 |
|
float aob = acos(cos(lat1) * cos(lat2) * cos(lon2 - lon1) + |
1309 |
|
sin(lat1) * sin(lat2)); |
1310 |
|
|
1311 |
|
// return(aob * 3959.0); /* great circle radius in miles */ |
1312 |
|
|
1313 |
|
return(aob * 6371000.0); /* great circle radius in meters */ |
1314 |
|
} |
1315 |
|
|
1316 |
|
static void |
1317 |
|
osd_render_nav(osm_gps_map_osd_t *osd) |
1318 |
|
{ |
1319 |
|
FIN; |
1320 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1321 |
|
|
1322 |
|
if(!priv->nav.surface || isnan(priv->nav.lat) || isnan(priv->nav.lon)) |
1323 |
|
return; |
1324 |
|
|
1325 |
|
/* first fill with transparency */ |
1326 |
|
cairo_t *cr = cairo_create(priv->nav.surface); |
1327 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1328 |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1329 |
|
cairo_paint(cr); |
1330 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1331 |
|
|
1332 |
|
cairo_select_font_face (cr, "Sans", |
1333 |
|
CAIRO_FONT_SLANT_NORMAL, |
1334 |
|
CAIRO_FONT_WEIGHT_BOLD); |
1335 |
|
cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE); |
1336 |
|
|
1337 |
|
char *latitude = osd_latitude_str(priv->nav.lat); |
1338 |
|
char *longitude = osd_longitude_str(priv->nav.lon); |
1339 |
|
|
1340 |
|
int y = OSD_COORDINATES_OFFSET; |
1341 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, priv->nav.name); |
1342 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, latitude); |
1343 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, longitude); |
1344 |
|
|
1345 |
|
g_free(latitude); |
1346 |
|
g_free(longitude); |
1347 |
|
|
1348 |
|
/* draw the compass */ |
1349 |
|
int radius = (OSD_NAV_H - y - 5*OSD_COORDINATES_FONT_SIZE/4)/2; |
1350 |
|
if(radius > OSD_NAV_W/2) |
1351 |
|
radius = OSD_NAV_W/2; |
1352 |
|
|
1353 |
|
int x = OSD_NAV_W/2+1; |
1354 |
|
y += radius; |
1355 |
|
|
1356 |
|
cairo_stroke (cr); |
1357 |
|
|
1358 |
|
/* draw background */ |
1359 |
|
cairo_arc(cr, x, y, radius, 0, 2*M_PI); |
1360 |
|
cairo_set_source_rgba (cr, 1, 1, 1, 0.5); |
1361 |
|
cairo_fill_preserve (cr); |
1362 |
|
cairo_set_source_rgb (cr, 0, 0, 0); |
1363 |
|
cairo_set_line_width (cr, 1); |
1364 |
|
cairo_stroke (cr); |
1365 |
|
|
1366 |
|
/* draw pointer */ |
1367 |
|
#define ARROW_WIDTH 0.3 |
1368 |
|
#define ARROW_LENGTH 0.7 |
1369 |
|
|
1370 |
|
coord_t *gps = osm_gps_map_get_gps (OSM_GPS_MAP(osd->widget)); |
1371 |
|
if(gps) { |
1372 |
|
float arot = get_bearing(gps->rlat, gps->rlon, |
1373 |
|
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
1374 |
|
|
1375 |
|
cairo_move_to(cr, |
1376 |
|
x + radius * ARROW_LENGTH * sin(arot), |
1377 |
|
y + radius * ARROW_LENGTH * -cos(arot)); |
1378 |
|
|
1379 |
|
cairo_line_to(cr, |
1380 |
|
x + radius * -ARROW_LENGTH * sin(arot+ARROW_WIDTH), |
1381 |
|
y + radius * -ARROW_LENGTH * -cos(arot+ARROW_WIDTH)); |
1382 |
|
|
1383 |
|
cairo_line_to(cr, |
1384 |
|
x + radius * -0.5 * ARROW_LENGTH * sin(arot), |
1385 |
|
y + radius * -0.5 * ARROW_LENGTH * -cos(arot)); |
1386 |
|
|
1387 |
|
cairo_line_to(cr, |
1388 |
|
x + radius * -ARROW_LENGTH * sin(arot-ARROW_WIDTH), |
1389 |
|
y + radius * -ARROW_LENGTH * -cos(arot-ARROW_WIDTH)); |
1390 |
|
|
1391 |
|
cairo_close_path(cr); |
1392 |
|
cairo_set_source_rgb (cr, 0, 0, 0); |
1393 |
|
cairo_fill (cr); |
1394 |
|
|
1395 |
|
y += radius + OSD_COORDINATES_FONT_SIZE/4; |
1396 |
|
|
1397 |
|
float dist = get_distance(gps->rlat, gps->rlon, |
1398 |
|
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
1399 |
|
|
1400 |
|
char *dist_str = NULL; |
1401 |
|
if(!priv->nav.imperial) { |
1402 |
|
/* metric is easy ... */ |
1403 |
|
if(dist<1000) |
1404 |
|
dist_str = g_strdup_printf("%u m", (int)dist); |
1405 |
|
else |
1406 |
|
dist_str = g_strdup_printf("%.1f km", dist/1000); |
1407 |
|
} else { |
1408 |
|
/* and now the hard part: scale for useful imperial values :-( */ |
1409 |
|
/* try to convert to feet, 1ft == 0.3048 m */ |
1410 |
|
|
1411 |
|
if(dist/(3*0.3048) >= 1760.0) /* more than 1760 yard? */ |
1412 |
|
dist_str = g_strdup_printf("%.1f mi", dist/(0.3048*3*1760.0)); |
1413 |
|
else if(dist/0.3048 >= 100) /* more than 100 feet? */ |
1414 |
|
dist_str = g_strdup_printf("%.1f yd", dist/(0.3048*3)); |
1415 |
|
else |
1416 |
|
dist_str = g_strdup_printf("%.0f ft", dist/0.3048); |
1417 |
|
} |
1418 |
|
|
1419 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, dist_str); |
1420 |
|
g_free(dist_str); |
1421 |
|
} |
1422 |
|
|
1423 |
|
cairo_destroy(cr); |
1424 |
|
FOUT; |
1425 |
|
} |
1426 |
|
|
1427 |
|
void osm_gps_map_osd_clear_nav (OsmGpsMap *map) { |
1428 |
|
FIN; |
1429 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
1430 |
|
|
1431 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1432 |
|
g_return_if_fail (osd); |
1433 |
|
|
1434 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1435 |
|
g_return_if_fail (priv); |
1436 |
|
|
1437 |
|
if(priv->nav.surface) { |
1438 |
|
cairo_surface_destroy(priv->nav.surface); |
1439 |
|
priv->nav.surface = NULL; |
1440 |
|
priv->nav.lat = OSM_GPS_MAP_INVALID; |
1441 |
|
priv->nav.lon = OSM_GPS_MAP_INVALID; |
1442 |
|
if(priv->nav.name) g_free(priv->nav.name); |
1443 |
|
} |
1444 |
|
osm_gps_map_redraw(map); |
1445 |
|
FOUT; |
1446 |
|
} |
1447 |
|
|
1448 |
|
void |
1449 |
|
osm_gps_map_osd_draw_nav (OsmGpsMap *map, gboolean imperial, |
1450 |
|
float latitude, float longitude, char *name) { |
1451 |
|
FIN; |
1452 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
1453 |
|
|
1454 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1455 |
|
g_return_if_fail (osd); |
1456 |
|
|
1457 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1458 |
|
g_return_if_fail (priv); |
1459 |
|
|
1460 |
|
osm_gps_map_osd_clear_nav (map); |
1461 |
|
|
1462 |
|
/* allocate balloon surface */ |
1463 |
|
priv->nav.surface = |
1464 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1465 |
|
OSD_NAV_W+2, OSD_NAV_H+2); |
1466 |
|
|
1467 |
|
priv->nav.lat = latitude; |
1468 |
|
priv->nav.lon = longitude; |
1469 |
|
priv->nav.name = g_strdup(name); |
1470 |
|
priv->nav.imperial = imperial; |
1471 |
|
|
1472 |
|
osd_render_nav(osd); |
1473 |
|
|
1474 |
|
osm_gps_map_redraw(map); |
1475 |
|
FOUT; |
1476 |
|
} |
1477 |
|
|
1478 |
|
#endif // OSD_NAV |
1479 |
|
|
1480 |
|
|
1481 |
|
#ifdef OSD_CROSSHAIR |
1482 |
|
|
1483 |
|
#ifndef OSD_CROSSHAIR_RADIUS |
1484 |
|
#define OSD_CROSSHAIR_RADIUS 10 |
1485 |
|
#endif |
1486 |
|
|
1487 |
|
#define OSD_CROSSHAIR_TICK (OSD_CROSSHAIR_RADIUS/2) |
1488 |
|
#define OSD_CROSSHAIR_BORDER (OSD_CROSSHAIR_TICK + OSD_CROSSHAIR_RADIUS/4) |
1489 |
|
#define OSD_CROSSHAIR_W ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2) |
1490 |
|
#define OSD_CROSSHAIR_H ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2) |
1491 |
|
|
1492 |
|
static void |
1493 |
|
osd_render_crosshair_shape(cairo_t *cr) { |
1494 |
|
FIN; |
1495 |
|
cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2, |
1496 |
|
OSD_CROSSHAIR_RADIUS, 0, 2*M_PI); |
1497 |
|
|
1498 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2 - OSD_CROSSHAIR_RADIUS, |
1499 |
|
OSD_CROSSHAIR_H/2); |
1500 |
|
cairo_rel_line_to (cr, -OSD_CROSSHAIR_TICK, 0); |
1501 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2 + OSD_CROSSHAIR_RADIUS, |
1502 |
|
OSD_CROSSHAIR_H/2); |
1503 |
|
cairo_rel_line_to (cr, OSD_CROSSHAIR_TICK, 0); |
1504 |
|
|
1505 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2, |
1506 |
|
OSD_CROSSHAIR_H/2 - OSD_CROSSHAIR_RADIUS); |
1507 |
|
cairo_rel_line_to (cr, 0, -OSD_CROSSHAIR_TICK); |
1508 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2, |
1509 |
|
OSD_CROSSHAIR_H/2 + OSD_CROSSHAIR_RADIUS); |
1510 |
|
cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK); |
1511 |
|
|
1512 |
|
cairo_stroke (cr); |
1513 |
|
FOUT; |
1514 |
|
} |
1515 |
|
|
1516 |
static void |
static void |
1517 |
osd_render(osm_gps_map_osd_t *osd) { |
osd_render_crosshair(osm_gps_map_osd_t *osd) |
1518 |
|
{ |
1519 |
|
FIN; |
1520 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1521 |
|
|
1522 |
|
if(priv->crosshair.rendered) |
1523 |
|
return; |
1524 |
|
|
1525 |
|
priv->crosshair.rendered = TRUE; |
1526 |
|
|
1527 |
|
/* first fill with transparency */ |
1528 |
|
cairo_t *cr = cairo_create(priv->crosshair.surface); |
1529 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1530 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
1531 |
|
cairo_paint(cr); |
1532 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1533 |
|
|
1534 |
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
1535 |
|
|
1536 |
|
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5); |
1537 |
|
cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/2); |
1538 |
|
osd_render_crosshair_shape(cr); |
1539 |
|
|
1540 |
|
cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5); |
1541 |
|
cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/4); |
1542 |
|
osd_render_crosshair_shape(cr); |
1543 |
|
|
1544 |
|
cairo_destroy(cr); |
1545 |
|
FOUT; |
1546 |
|
} |
1547 |
|
#endif |
1548 |
|
|
1549 |
|
#ifdef OSD_SCALE |
1550 |
|
|
1551 |
|
#ifndef OSD_SCALE_FONT_SIZE |
1552 |
|
#define OSD_SCALE_FONT_SIZE 12 |
1553 |
|
#endif |
1554 |
|
#define OSD_SCALE_W (10*OSD_SCALE_FONT_SIZE) |
1555 |
|
#define OSD_SCALE_H (5*OSD_SCALE_FONT_SIZE/2) |
1556 |
|
|
1557 |
|
/* various parameters used to create the scale */ |
1558 |
|
#define OSD_SCALE_H2 (OSD_SCALE_H/2) |
1559 |
|
#define OSD_SCALE_TICK (2*OSD_SCALE_FONT_SIZE/3) |
1560 |
|
#define OSD_SCALE_M (OSD_SCALE_H2 - OSD_SCALE_TICK) |
1561 |
|
#define OSD_SCALE_I (OSD_SCALE_H2 + OSD_SCALE_TICK) |
1562 |
|
#define OSD_SCALE_FD (OSD_SCALE_FONT_SIZE/4) |
1563 |
|
|
1564 |
|
static void |
1565 |
|
osd_render_scale(osm_gps_map_osd_t *osd) |
1566 |
|
{ |
1567 |
|
FIN; |
1568 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1569 |
|
|
1570 |
|
/* this only needs to be rendered if the zoom has changed */ |
1571 |
|
gint zoom; |
1572 |
|
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
1573 |
|
if(zoom == priv->scale.zoom) |
1574 |
|
return; |
1575 |
|
|
1576 |
|
priv->scale.zoom = zoom; |
1577 |
|
|
1578 |
|
float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget)); |
1579 |
|
|
1580 |
|
/* first fill with transparency */ |
1581 |
|
cairo_t *cr = cairo_create(priv->scale.surface); |
1582 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1583 |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1584 |
|
// pink for testing: cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
1585 |
|
cairo_paint(cr); |
1586 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1587 |
|
|
1588 |
|
/* determine the size of the scale width in meters */ |
1589 |
|
float width = (OSD_SCALE_W-OSD_SCALE_FONT_SIZE/6) * m_per_pix; |
1590 |
|
|
1591 |
|
/* scale this to useful values */ |
1592 |
|
int exp = logf(width)*M_LOG10E; |
1593 |
|
int mant = width/pow(10,exp); |
1594 |
|
int width_metric = mant * pow(10,exp); |
1595 |
|
char *dist_str = NULL; |
1596 |
|
if(width_metric<1000) |
1597 |
|
dist_str = g_strdup_printf("%u m", width_metric); |
1598 |
|
else |
1599 |
|
dist_str = g_strdup_printf("%u km", width_metric/1000); |
1600 |
|
width_metric /= m_per_pix; |
1601 |
|
|
1602 |
|
/* and now the hard part: scale for useful imperial values :-( */ |
1603 |
|
/* try to convert to feet, 1ft == 0.3048 m */ |
1604 |
|
width /= 0.3048; |
1605 |
|
float imp_scale = 0.3048; |
1606 |
|
char *dist_imp_unit = "ft"; |
1607 |
|
|
1608 |
|
if(width >= 100) { |
1609 |
|
/* 1yd == 3 feet */ |
1610 |
|
width /= 3.0; |
1611 |
|
imp_scale *= 3.0; |
1612 |
|
dist_imp_unit = "yd"; |
1613 |
|
|
1614 |
|
if(width >= 1760.0) { |
1615 |
|
/* 1mi == 1760 yd */ |
1616 |
|
width /= 1760.0; |
1617 |
|
imp_scale *= 1760.0; |
1618 |
|
dist_imp_unit = "mi"; |
1619 |
|
} |
1620 |
|
} |
1621 |
|
|
1622 |
|
/* also convert this to full tens/hundreds */ |
1623 |
|
exp = logf(width)*M_LOG10E; |
1624 |
|
mant = width/pow(10,exp); |
1625 |
|
int width_imp = mant * pow(10,exp); |
1626 |
|
char *dist_str_imp = g_strdup_printf("%u %s", width_imp, dist_imp_unit); |
1627 |
|
|
1628 |
|
/* convert back to pixels */ |
1629 |
|
width_imp *= imp_scale; |
1630 |
|
width_imp /= m_per_pix; |
1631 |
|
|
1632 |
|
cairo_select_font_face (cr, "Sans", |
1633 |
|
CAIRO_FONT_SLANT_NORMAL, |
1634 |
|
CAIRO_FONT_WEIGHT_BOLD); |
1635 |
|
cairo_set_font_size (cr, OSD_SCALE_FONT_SIZE); |
1636 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); |
1637 |
|
|
1638 |
|
cairo_text_extents_t extents; |
1639 |
|
cairo_text_extents (cr, dist_str, &extents); |
1640 |
|
|
1641 |
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
1642 |
|
cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6); |
1643 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD); |
1644 |
|
cairo_text_path (cr, dist_str); |
1645 |
|
cairo_stroke (cr); |
1646 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, |
1647 |
|
OSD_SCALE_H2+OSD_SCALE_FD + extents.height); |
1648 |
|
cairo_text_path (cr, dist_str_imp); |
1649 |
|
cairo_stroke (cr); |
1650 |
|
|
1651 |
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
1652 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD); |
1653 |
|
cairo_show_text (cr, dist_str); |
1654 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, |
1655 |
|
OSD_SCALE_H2+OSD_SCALE_FD + extents.height); |
1656 |
|
cairo_show_text (cr, dist_str_imp); |
1657 |
|
|
1658 |
|
g_free(dist_str); |
1659 |
|
g_free(dist_str_imp); |
1660 |
|
|
1661 |
|
/* draw white line */ |
1662 |
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
1663 |
|
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); |
1664 |
|
cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/3); |
1665 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M); |
1666 |
|
cairo_rel_line_to (cr, 0, OSD_SCALE_TICK); |
1667 |
|
cairo_rel_line_to (cr, width_metric, 0); |
1668 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1669 |
|
cairo_stroke(cr); |
1670 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I); |
1671 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1672 |
|
cairo_rel_line_to (cr, width_imp, 0); |
1673 |
|
cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK); |
1674 |
|
cairo_stroke(cr); |
1675 |
|
|
1676 |
|
/* draw black line */ |
1677 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); |
1678 |
|
cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6); |
1679 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M); |
1680 |
|
cairo_rel_line_to (cr, 0, OSD_SCALE_TICK); |
1681 |
|
cairo_rel_line_to (cr, width_metric, 0); |
1682 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1683 |
|
cairo_stroke(cr); |
1684 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I); |
1685 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1686 |
|
cairo_rel_line_to (cr, width_imp, 0); |
1687 |
|
cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK); |
1688 |
|
cairo_stroke(cr); |
1689 |
|
|
1690 |
|
cairo_destroy(cr); |
1691 |
|
FOUT; |
1692 |
|
} |
1693 |
|
#endif |
1694 |
|
|
1695 |
|
static void |
1696 |
|
osd_render_controls(osm_gps_map_osd_t *osd) |
1697 |
|
{ |
1698 |
|
FIN; |
1699 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1700 |
|
|
1701 |
|
if(priv->controls.rendered |
1702 |
|
#ifdef OSD_GPS_BUTTON |
1703 |
|
&& (priv->controls.gps_enabled == (osd->cb != NULL)) |
1704 |
|
#endif |
1705 |
|
) |
1706 |
|
return; |
1707 |
|
|
1708 |
|
#ifdef OSD_GPS_BUTTON |
1709 |
|
priv->controls.gps_enabled = (osd->cb != NULL); |
1710 |
|
#endif |
1711 |
|
priv->controls.rendered = TRUE; |
1712 |
|
|
1713 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
1714 |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
1715 |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
1717 |
#endif |
#endif |
1718 |
|
|
1719 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1720 |
cairo_t *cr = cairo_create(priv->overlay); |
cairo_t *cr = cairo_create(priv->controls.surface); |
1721 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1722 |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1723 |
cairo_paint(cr); |
cairo_paint(cr); |
1788 |
cairo_stroke(cr); |
cairo_stroke(cr); |
1789 |
|
|
1790 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1791 |
|
} |
1792 |
|
|
1793 |
|
static void |
1794 |
|
osd_render(osm_gps_map_osd_t *osd) |
1795 |
|
{ |
1796 |
|
/* this function is actually called pretty often since the */ |
1797 |
|
/* OSD contents may have changed (due to a coordinate/zoom change). */ |
1798 |
|
/* The different OSD parts have to make sure that they don't */ |
1799 |
|
/* render unneccessarily often and thus waste CPU power */ |
1800 |
|
|
1801 |
|
osd_render_controls(osd); |
1802 |
|
|
1803 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1804 |
osd_render_source_sel(osd); |
osd_render_source_sel(osd, FALSE); |
1805 |
|
#endif |
1806 |
|
|
1807 |
|
#ifdef OSD_SCALE |
1808 |
|
osd_render_scale(osd); |
1809 |
|
#endif |
1810 |
|
|
1811 |
|
#ifdef OSD_CROSSHAIR |
1812 |
|
osd_render_crosshair(osd); |
1813 |
|
#endif |
1814 |
|
|
1815 |
|
#ifdef OSD_NAV |
1816 |
|
osd_render_nav(osd); |
1817 |
|
#endif |
1818 |
|
|
1819 |
|
#ifdef OSD_COORDINATES |
1820 |
|
osd_render_coordinates(osd); |
1821 |
#endif |
#endif |
1822 |
} |
} |
1823 |
|
|
1828 |
|
|
1829 |
/* OSD itself uses some off-screen rendering, so check if the */ |
/* OSD itself uses some off-screen rendering, so check if the */ |
1830 |
/* offscreen buffer is present and create it if not */ |
/* offscreen buffer is present and create it if not */ |
1831 |
if(!priv->overlay) { |
if(!priv->controls.surface) { |
1832 |
/* create overlay ... */ |
/* create overlay ... */ |
1833 |
priv->overlay = |
priv->controls.surface = |
1834 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2); |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2); |
1835 |
|
|
1836 |
|
priv->controls.rendered = FALSE; |
1837 |
|
#ifdef OSD_GPS_BUTTON |
1838 |
|
priv->controls.gps_enabled = FALSE; |
1839 |
|
#endif |
1840 |
|
|
1841 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1842 |
/* the initial OSD state is alway not-expanded */ |
/* the initial OSD state is alway not-expanded */ |
1843 |
priv->map_source = |
priv->source_sel.surface = |
1844 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1845 |
OSD_S_W+2, OSD_S_H+2); |
OSD_S_W+2, OSD_S_H+2); |
1846 |
|
priv->source_sel.rendered = FALSE; |
1847 |
|
#endif |
1848 |
|
|
1849 |
|
#ifdef OSD_SCALE |
1850 |
|
priv->scale.surface = |
1851 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1852 |
|
OSD_SCALE_W, OSD_SCALE_H); |
1853 |
|
priv->scale.zoom = -1; |
1854 |
|
#endif |
1855 |
|
|
1856 |
|
#ifdef OSD_CROSSHAIR |
1857 |
|
priv->crosshair.surface = |
1858 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1859 |
|
OSD_CROSSHAIR_W, OSD_CROSSHAIR_H); |
1860 |
|
priv->crosshair.rendered = FALSE; |
1861 |
|
#endif |
1862 |
|
|
1863 |
|
#ifdef OSD_COORDINATES |
1864 |
|
priv->coordinates.surface = |
1865 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1866 |
|
OSD_COORDINATES_W, OSD_COORDINATES_H); |
1867 |
|
|
1868 |
|
priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID; |
1869 |
#endif |
#endif |
1870 |
|
|
1871 |
/* ... and render it */ |
/* ... and render it */ |
1875 |
// now draw this onto the original context |
// now draw this onto the original context |
1876 |
cairo_t *cr = gdk_cairo_create(drawable); |
cairo_t *cr = gdk_cairo_create(drawable); |
1877 |
|
|
1878 |
int x = OSD_X, y = OSD_Y; |
gint x, y; |
1879 |
if(OSD_X < 0) |
|
1880 |
x = osd->widget->allocation.width - OSD_W + OSD_X; |
#ifdef OSD_SCALE |
1881 |
|
x = OSD_X; |
1882 |
|
y = -OSD_Y; |
1883 |
|
if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W; |
1884 |
|
if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H; |
1885 |
|
|
1886 |
|
cairo_set_source_surface(cr, priv->scale.surface, x, y); |
1887 |
|
cairo_paint(cr); |
1888 |
|
#endif |
1889 |
|
|
1890 |
|
#ifdef OSD_CROSSHAIR |
1891 |
|
x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2; |
1892 |
|
y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2; |
1893 |
|
|
1894 |
|
cairo_set_source_surface(cr, priv->crosshair.surface, x, y); |
1895 |
|
cairo_paint(cr); |
1896 |
|
#endif |
1897 |
|
|
1898 |
|
#ifdef OSD_NAV |
1899 |
|
if(priv->nav.surface) { |
1900 |
|
x = OSD_X; |
1901 |
|
if(x < 0) x += osd->widget->allocation.width - OSD_NAV_W; |
1902 |
|
y = (osd->widget->allocation.height - OSD_NAV_H)/2; |
1903 |
|
|
1904 |
|
cairo_set_source_surface(cr, priv->nav.surface, x, y); |
1905 |
|
cairo_paint(cr); |
1906 |
|
} |
1907 |
|
#endif |
1908 |
|
|
1909 |
|
#ifdef OSD_COORDINATES |
1910 |
|
x = -OSD_X; |
1911 |
|
y = -OSD_Y; |
1912 |
|
if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W; |
1913 |
|
if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H; |
1914 |
|
|
1915 |
|
cairo_set_source_surface(cr, priv->coordinates.surface, x, y); |
1916 |
|
cairo_paint(cr); |
1917 |
|
#endif |
1918 |
|
|
1919 |
|
#ifdef OSD_BALLOON |
1920 |
|
if(priv->balloon.surface) { |
1921 |
|
|
1922 |
|
/* convert given lat lon into screen coordinates */ |
1923 |
|
gint x, y; |
1924 |
|
osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
1925 |
|
priv->balloon.lat, priv->balloon.lon, |
1926 |
|
&x, &y); |
1927 |
|
|
1928 |
|
/* check if balloon needs to be rerendered */ |
1929 |
|
osd_render_balloon(osd); |
1930 |
|
|
1931 |
|
cairo_set_source_surface(cr, priv->balloon.surface, |
1932 |
|
x + priv->balloon.offset_x, |
1933 |
|
y + priv->balloon.offset_y); |
1934 |
|
cairo_paint(cr); |
1935 |
|
} |
1936 |
|
#endif |
1937 |
|
|
1938 |
if(OSD_Y < 0) |
x = OSD_X; |
1939 |
y = osd->widget->allocation.height - OSD_H + OSD_Y; |
if(x < 0) |
1940 |
|
x += osd->widget->allocation.width - OSD_W; |
1941 |
|
|
1942 |
|
y = OSD_Y; |
1943 |
|
if(y < 0) |
1944 |
|
y += osd->widget->allocation.height - OSD_H; |
1945 |
|
|
1946 |
cairo_set_source_surface(cr, priv->overlay, x, y); |
cairo_set_source_surface(cr, priv->controls.surface, x, y); |
1947 |
cairo_paint(cr); |
cairo_paint(cr); |
1948 |
|
|
1949 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1950 |
if(!priv->handler_id) { |
if(!priv->source_sel.handler_id) { |
1951 |
/* the OSD source selection is not being animated */ |
/* the OSD source selection is not being animated */ |
1952 |
if(!priv->expanded) |
if(!priv->source_sel.expanded) |
1953 |
x = osd->widget->allocation.width - OSD_S_W; |
x = osd->widget->allocation.width - OSD_S_W; |
1954 |
else |
else |
1955 |
x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
1956 |
} else |
} else |
1957 |
x = priv->shift; |
x = priv->source_sel.shift; |
1958 |
|
|
1959 |
y = OSD_S_Y; |
y = OSD_S_Y; |
1960 |
if(OSD_S_Y < 0) { |
if(OSD_S_Y < 0) { |
1961 |
if(!priv->expanded) |
if(!priv->source_sel.expanded) |
1962 |
y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y; |
y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y; |
1963 |
else |
else |
1964 |
y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y; |
y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y; |
1965 |
} |
} |
1966 |
|
|
1967 |
cairo_set_source_surface(cr, priv->map_source, x, y); |
cairo_set_source_surface(cr, priv->source_sel.surface, x, y); |
1968 |
cairo_paint(cr); |
cairo_paint(cr); |
1969 |
#endif |
#endif |
1970 |
|
|
1971 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1972 |
|
FOUT; |
1973 |
} |
} |
1974 |
|
|
1975 |
static void |
static void |
1976 |
osd_free(osm_gps_map_osd_t *osd) |
osd_free(osm_gps_map_osd_t *osd) |
1977 |
{ |
{ |
1978 |
|
FIN; |
1979 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1980 |
|
|
1981 |
if (priv->overlay) |
if (priv->controls.surface) |
1982 |
cairo_surface_destroy(priv->overlay); |
cairo_surface_destroy(priv->controls.surface); |
1983 |
|
|
1984 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1985 |
if(priv->handler_id) |
if(priv->source_sel.handler_id) |
1986 |
gtk_timeout_remove(priv->handler_id); |
gtk_timeout_remove(priv->source_sel.handler_id); |
1987 |
|
|
1988 |
|
if (priv->source_sel.surface) |
1989 |
|
cairo_surface_destroy(priv->source_sel.surface); |
1990 |
|
#endif |
1991 |
|
|
1992 |
|
#ifdef OSD_SCALE |
1993 |
|
if (priv->scale.surface) |
1994 |
|
cairo_surface_destroy(priv->scale.surface); |
1995 |
|
#endif |
1996 |
|
|
1997 |
if (priv->map_source) |
#ifdef OSD_CROSSHAIR |
1998 |
cairo_surface_destroy(priv->map_source); |
if (priv->crosshair.surface) |
1999 |
|
cairo_surface_destroy(priv->crosshair.surface); |
2000 |
|
#endif |
2001 |
|
|
2002 |
|
#ifdef OSD_NAV |
2003 |
|
if (priv->nav.surface) |
2004 |
|
cairo_surface_destroy(priv->nav.surface); |
2005 |
|
#endif |
2006 |
|
|
2007 |
|
#ifdef OSD_COORDINATES |
2008 |
|
if (priv->coordinates.surface) |
2009 |
|
cairo_surface_destroy(priv->coordinates.surface); |
2010 |
|
#endif |
2011 |
|
|
2012 |
|
#ifdef OSD_BALLOON |
2013 |
|
if (priv->balloon.surface) |
2014 |
|
cairo_surface_destroy(priv->balloon.surface); |
2015 |
#endif |
#endif |
2016 |
|
|
2017 |
g_free(priv); |
g_free(priv); |
2018 |
|
FOUT; |
2019 |
} |
} |
2020 |
|
|
2021 |
static gboolean |
static gboolean |
2022 |
osd_busy(osm_gps_map_osd_t *osd) |
osd_busy(osm_gps_map_osd_t *osd) |
2023 |
{ |
{ |
2024 |
|
FIN; |
2025 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
2026 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
2027 |
return (priv->handler_id != 0); |
return (priv->source_sel.handler_id != 0); |
2028 |
#else |
#else |
2029 |
return FALSE; |
return FALSE; |
2030 |
#endif |
#endif |
2031 |
} |
} |
2032 |
|
|
2033 |
|
static osd_button_t |
2034 |
|
osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
2035 |
|
FIN; |
2036 |
|
return osd_check_int(osd, TRUE, down, x, y); |
2037 |
|
} |
2038 |
|
|
2039 |
static osm_gps_map_osd_t osd_classic = { |
static osm_gps_map_osd_t osd_classic = { |
2040 |
.widget = NULL, |
.widget = NULL, |
2041 |
|
|
2055 |
void |
void |
2056 |
osm_gps_map_osd_classic_init(OsmGpsMap *map) |
osm_gps_map_osd_classic_init(OsmGpsMap *map) |
2057 |
{ |
{ |
2058 |
|
FIN; |
2059 |
osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1); |
osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1); |
2060 |
|
|
2061 |
|
#ifdef OSD_BALLOON |
2062 |
|
priv->balloon.lat = OSM_GPS_MAP_INVALID; |
2063 |
|
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
2064 |
|
#endif |
2065 |
|
|
2066 |
osd_classic.priv = priv; |
osd_classic.priv = priv; |
2067 |
|
|
2068 |
osm_gps_map_register_osd(map, &osd_classic); |
osm_gps_map_register_osd(map, &osd_classic); |
2069 |
|
FOUT; |
2070 |
} |
} |
2071 |
|
|
2072 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
2074 |
/* but instead are to be used by the main application */ |
/* but instead are to be used by the main application */ |
2075 |
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, |
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, |
2076 |
gpointer data) { |
gpointer data) { |
2077 |
|
FIN; |
2078 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
2079 |
g_return_if_fail (osd); |
g_return_if_fail (osd); |
2080 |
|
|
2086 |
osd->render(osd); |
osd->render(osd); |
2087 |
|
|
2088 |
osm_gps_map_redraw(map); |
osm_gps_map_redraw(map); |
2089 |
|
FOUT; |
2090 |
} |
} |
2091 |
#endif |
#endif |
2092 |
|
|
2093 |
osd_button_t |
osd_button_t |
2094 |
osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) { |
osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) { |
2095 |
|
FIN; |
2096 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
2097 |
g_return_val_if_fail (osd, OSD_NONE); |
g_return_val_if_fail (osd, OSD_NONE); |
2098 |
|
|
2099 |
return osd_check(osd, x, y); |
return osd_check_int(osd, FALSE, TRUE, x, y); |
2100 |
} |
} |