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 |
47 |
#endif |
#endif |
48 |
} controls; |
} 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 |
#ifdef OSD_SCALE |
67 |
struct { |
struct { |
68 |
cairo_surface_t *surface; |
cairo_surface_t *surface; |
77 |
} crosshair; |
} crosshair; |
78 |
#endif |
#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 |
#ifdef OSD_COORDINATES |
90 |
struct { |
struct { |
91 |
cairo_surface_t *surface; |
cairo_surface_t *surface; |
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 |
|
|
643 |
/* internal value to draw the arrow on the "puller" */ |
/* internal value to draw the arrow on the "puller" */ |
644 |
#define OSD_S_D0 (OSD_S_RAD/2) |
#define OSD_S_D0 (OSD_S_RAD/2) |
645 |
#ifndef OSD_FONT_SIZE |
#ifndef OSD_FONT_SIZE |
646 |
#define OSD_FONT_SIZE 16.0 |
#define OSD_FONT_SIZE (16.0) |
647 |
#endif |
#endif |
648 |
#define OSD_TEXT_BORDER (OSD_FONT_SIZE/2) |
#define OSD_TEXT_BORDER (OSD_FONT_SIZE/2) |
649 |
#define OSD_TEXT_SKIP (OSD_FONT_SIZE/8) |
#define OSD_TEXT_SKIP (OSD_FONT_SIZE/8) |
751 |
|
|
752 |
static void |
static void |
753 |
osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) { |
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) |
if(priv->source_sel.rendered && !force_rerender) |
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 */ |
/* re-allocate the buffer used to draw the menu. This is used */ |
806 |
/* to collapse/expand the buffer */ |
/* 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 */ |
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, TRUE); |
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; |
893 |
if(done) |
if(done) |
894 |
priv->source_sel.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 */ |
927 |
/* start timer to handle animation */ |
/* start timer to handle animation */ |
928 |
priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, |
priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, |
929 |
osd_source_animate, osd); |
osd_source_animate, osd); |
930 |
|
FOUT; |
931 |
} |
} |
932 |
|
|
933 |
/* check if the user clicked inside the source selection area */ |
/* 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->source_sel.expanded) |
if(!priv->source_sel.expanded) |
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 */ |
978 |
y /= step; |
y /= step; |
979 |
y += 1; |
y += 1; |
980 |
|
|
981 |
gint old = 0; |
if(down) { |
982 |
g_object_get(osd->widget, "map-source", &old, NULL); |
gint old = 0; |
983 |
|
g_object_get(osd->widget, "map-source", &old, NULL); |
984 |
if(y > OSM_GPS_MAP_SOURCE_NULL && |
|
985 |
y <= OSM_GPS_MAP_SOURCE_LAST && |
if(y > OSM_GPS_MAP_SOURCE_NULL && |
986 |
old != y) { |
y <= OSM_GPS_MAP_SOURCE_LAST && |
987 |
g_object_set(osd->widget, "map-source", y, NULL); |
old != y) { |
988 |
|
g_object_set(osd->widget, "map-source", y, NULL); |
989 |
osd_render_source_sel(osd, TRUE); |
|
990 |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
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 */ |
/* return "clicked in OSD background" to prevent further */ |
996 |
/* processing by application */ |
/* 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 |
|
|
1128 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1129 |
|
|
1130 |
#ifndef OSD_COORDINATES_FONT_SIZE |
#ifndef OSD_COORDINATES_FONT_SIZE |
1131 |
#define OSD_COORDINATES_FONT_SIZE 12 |
#define OSD_COORDINATES_FONT_SIZE (12.0) |
1132 |
#endif |
#endif |
1133 |
|
|
1134 |
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
1135 |
|
|
1136 |
#define OSD_COORDINATES_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
#define OSD_COORDINATES_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
1137 |
#define OSD_COORDINATES_H (2*OSD_COORDINATES_FONT_SIZE+OSD_COORDINATES_OFFSET) |
#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 */ |
/* these can be overwritten with versions that support */ |
1140 |
/* localization */ |
/* localization */ |
1192 |
c, (int)integral, fractional*60.0); |
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 |
|
|
1211 |
|
printf("test extents of \"abc\"\n"); |
1212 |
|
memset(&extents, 0, sizeof(cairo_text_extents_t)); |
1213 |
|
cairo_text_extents (cr, "abc", &extents); |
1214 |
|
printf("-> %f\n", extents.width); |
1215 |
|
|
1216 |
|
printf("test extents of \"49 00.000\"\n"); |
1217 |
|
memset(&extents, 0, sizeof(cairo_text_extents_t)); |
1218 |
|
cairo_text_extents (cr, "49 00.000", &extents); |
1219 |
|
printf("-> %f\n", extents.width); |
1220 |
|
|
1221 |
|
printf("test extents of \"49° 00.000\"\n"); |
1222 |
|
memset(&extents, 0, sizeof(cairo_text_extents_t)); |
1223 |
|
cairo_text_extents (cr, "49° 00.000", &extents); |
1224 |
|
printf("-> %f\n", extents.width); |
1225 |
|
|
1226 |
|
printf("getting extents for \"%s\"\n", p); // XXX |
1227 |
|
memset(&extents, 0, sizeof(cairo_text_extents_t)); |
1228 |
|
cairo_text_extents (cr, p, &extents); |
1229 |
|
printf("initial extents.width = %f\n", extents.width); // XXX |
1230 |
|
|
1231 |
|
/* check if text needs to be truncated */ |
1232 |
|
int trunc_at = strlen(text)-1; |
1233 |
|
while(extents.width > width) { |
1234 |
|
g_assert(trunc_at > 0); |
1235 |
|
|
1236 |
|
printf("trunc at %d\n", trunc_at); // XXX |
1237 |
|
|
1238 |
|
trunc_at--; |
1239 |
|
strcpy(p+trunc_at, "..."); |
1240 |
|
printf("getting extents for \"%s\"\n", p); // XXX |
1241 |
|
|
1242 |
|
memset(&extents, 0, sizeof(cairo_text_extents_t)); |
1243 |
|
cairo_text_extents (cr, p, &extents); |
1244 |
|
printf("extents.width = %f > %d\n", extents.width, width); // XXX |
1245 |
|
} |
1246 |
|
|
1247 |
|
printf("painting\n"); // XXX |
1248 |
|
|
1249 |
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
1250 |
|
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
1251 |
|
cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing); |
1252 |
|
cairo_text_path (cr, p); |
1253 |
|
cairo_stroke (cr); |
1254 |
|
|
1255 |
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
1256 |
|
cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing); |
1257 |
|
cairo_show_text (cr, p); |
1258 |
|
|
1259 |
|
g_free(p); |
1260 |
|
|
1261 |
|
/* skip + 1/5 line */ |
1262 |
|
FOUT; |
1263 |
|
return y + 6*OSD_COORDINATES_FONT_SIZE/5; |
1264 |
|
} |
1265 |
|
|
1266 |
static void |
static void |
1267 |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
1268 |
{ |
{ |
1269 |
|
FIN; |
1270 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1271 |
|
|
1272 |
/* get current map position */ |
/* get current map position */ |
1299 |
char *latitude = osd_latitude_str(lat); |
char *latitude = osd_latitude_str(lat); |
1300 |
char *longitude = osd_longitude_str(lon); |
char *longitude = osd_longitude_str(lon); |
1301 |
|
|
1302 |
cairo_text_extents_t lat_extents, lon_extents; |
int y = OSD_COORDINATES_OFFSET; |
1303 |
cairo_text_extents (cr, latitude, &lat_extents); |
y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, latitude); |
1304 |
cairo_text_extents (cr, longitude, &lon_extents); |
y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, longitude); |
1305 |
|
|
1306 |
|
g_free(latitude); |
1307 |
|
g_free(longitude); |
1308 |
|
|
1309 |
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
cairo_destroy(cr); |
1310 |
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
FOUT; |
1311 |
cairo_move_to (cr, |
} |
1312 |
(OSD_COORDINATES_W - lat_extents.width)/2, |
#endif // OSD_COORDINATES |
|
OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
|
|
cairo_text_path (cr, latitude); |
|
|
cairo_move_to (cr, |
|
|
(OSD_COORDINATES_W - lon_extents.width)/2, |
|
|
OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
|
|
OSD_COORDINATES_FONT_SIZE); |
|
|
cairo_text_path (cr, longitude); |
|
|
cairo_stroke (cr); |
|
1313 |
|
|
1314 |
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
#ifdef OSD_NAV |
1315 |
cairo_move_to (cr, |
#define OSD_NAV_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
1316 |
(OSD_COORDINATES_W - lat_extents.width)/2, |
#define OSD_NAV_H (11*OSD_COORDINATES_FONT_SIZE) |
1317 |
OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
|
1318 |
cairo_show_text (cr, latitude); |
/* http://mathforum.org/library/drmath/view/55417.html */ |
1319 |
cairo_move_to (cr, |
static float get_bearing(float lat1, float lon1, float lat2, float lon2) { |
1320 |
(OSD_COORDINATES_W - lon_extents.width)/2, |
return atan2( sin(lon2 - lon1) * cos(lat2), |
1321 |
OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
cos(lat1) * sin(lat2) - |
1322 |
OSD_COORDINATES_FONT_SIZE); |
sin(lat1) * cos(lat2) * cos(lon2 - lon1)); |
1323 |
cairo_show_text (cr, longitude); |
} |
1324 |
|
|
1325 |
|
/* http://mathforum.org/library/drmath/view/51722.html */ |
1326 |
|
static float get_distance(float lat1, float lon1, float lat2, float lon2) { |
1327 |
|
float aob = acos(cos(lat1) * cos(lat2) * cos(lon2 - lon1) + |
1328 |
|
sin(lat1) * sin(lat2)); |
1329 |
|
|
1330 |
|
// return(aob * 3959.0); /* great circle radius in miles */ |
1331 |
|
|
1332 |
|
return(aob * 6371000.0); /* great circle radius in meters */ |
1333 |
|
} |
1334 |
|
|
1335 |
|
static void |
1336 |
|
osd_render_nav(osm_gps_map_osd_t *osd) |
1337 |
|
{ |
1338 |
|
FIN; |
1339 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1340 |
|
|
1341 |
|
if(!priv->nav.surface || isnan(priv->nav.lat) || isnan(priv->nav.lon)) |
1342 |
|
return; |
1343 |
|
|
1344 |
|
/* first fill with transparency */ |
1345 |
|
cairo_t *cr = cairo_create(priv->nav.surface); |
1346 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1347 |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1348 |
|
cairo_paint(cr); |
1349 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1350 |
|
|
1351 |
|
cairo_select_font_face (cr, "Sans", |
1352 |
|
CAIRO_FONT_SLANT_NORMAL, |
1353 |
|
CAIRO_FONT_WEIGHT_BOLD); |
1354 |
|
cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE); |
1355 |
|
|
1356 |
|
char *latitude = osd_latitude_str(priv->nav.lat); |
1357 |
|
char *longitude = osd_longitude_str(priv->nav.lon); |
1358 |
|
|
1359 |
|
int y = OSD_COORDINATES_OFFSET; |
1360 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, priv->nav.name); |
1361 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, latitude); |
1362 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, longitude); |
1363 |
|
|
1364 |
g_free(latitude); |
g_free(latitude); |
1365 |
g_free(longitude); |
g_free(longitude); |
1366 |
|
|
1367 |
|
/* draw the compass */ |
1368 |
|
int radius = (OSD_NAV_H - y - 5*OSD_COORDINATES_FONT_SIZE/4)/2; |
1369 |
|
if(radius > OSD_NAV_W/2) |
1370 |
|
radius = OSD_NAV_W/2; |
1371 |
|
|
1372 |
|
int x = OSD_NAV_W/2+1; |
1373 |
|
y += radius; |
1374 |
|
|
1375 |
|
cairo_stroke (cr); |
1376 |
|
|
1377 |
|
/* draw background */ |
1378 |
|
cairo_arc(cr, x, y, radius, 0, 2*M_PI); |
1379 |
|
cairo_set_source_rgba (cr, 1, 1, 1, 0.5); |
1380 |
|
cairo_fill_preserve (cr); |
1381 |
|
cairo_set_source_rgb (cr, 0, 0, 0); |
1382 |
|
cairo_set_line_width (cr, 1); |
1383 |
|
cairo_stroke (cr); |
1384 |
|
|
1385 |
|
/* draw pointer */ |
1386 |
|
#define ARROW_WIDTH 0.3 |
1387 |
|
#define ARROW_LENGTH 0.7 |
1388 |
|
|
1389 |
|
coord_t *gps = osm_gps_map_get_gps (OSM_GPS_MAP(osd->widget)); |
1390 |
|
if(gps) { |
1391 |
|
float arot = get_bearing(gps->rlat, gps->rlon, |
1392 |
|
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
1393 |
|
|
1394 |
|
cairo_move_to(cr, |
1395 |
|
x + radius * ARROW_LENGTH * sin(arot), |
1396 |
|
y + radius * ARROW_LENGTH * -cos(arot)); |
1397 |
|
|
1398 |
|
cairo_line_to(cr, |
1399 |
|
x + radius * -ARROW_LENGTH * sin(arot+ARROW_WIDTH), |
1400 |
|
y + radius * -ARROW_LENGTH * -cos(arot+ARROW_WIDTH)); |
1401 |
|
|
1402 |
|
cairo_line_to(cr, |
1403 |
|
x + radius * -0.5 * ARROW_LENGTH * sin(arot), |
1404 |
|
y + radius * -0.5 * ARROW_LENGTH * -cos(arot)); |
1405 |
|
|
1406 |
|
cairo_line_to(cr, |
1407 |
|
x + radius * -ARROW_LENGTH * sin(arot-ARROW_WIDTH), |
1408 |
|
y + radius * -ARROW_LENGTH * -cos(arot-ARROW_WIDTH)); |
1409 |
|
|
1410 |
|
cairo_close_path(cr); |
1411 |
|
cairo_set_source_rgb (cr, 0, 0, 0); |
1412 |
|
cairo_fill (cr); |
1413 |
|
|
1414 |
|
y += radius + OSD_COORDINATES_FONT_SIZE/4; |
1415 |
|
|
1416 |
|
float dist = get_distance(gps->rlat, gps->rlon, |
1417 |
|
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
1418 |
|
|
1419 |
|
char *dist_str = NULL; |
1420 |
|
if(!priv->nav.imperial) { |
1421 |
|
/* metric is easy ... */ |
1422 |
|
if(dist<1000) |
1423 |
|
dist_str = g_strdup_printf("%u m", (int)dist); |
1424 |
|
else |
1425 |
|
dist_str = g_strdup_printf("%.1f km", dist/1000); |
1426 |
|
} else { |
1427 |
|
/* and now the hard part: scale for useful imperial values :-( */ |
1428 |
|
/* try to convert to feet, 1ft == 0.3048 m */ |
1429 |
|
|
1430 |
|
if(dist/(3*0.3048) >= 1760.0) /* more than 1760 yard? */ |
1431 |
|
dist_str = g_strdup_printf("%.1f mi", dist/(0.3048*3*1760.0)); |
1432 |
|
else if(dist/0.3048 >= 100) /* more than 100 feet? */ |
1433 |
|
dist_str = g_strdup_printf("%.1f yd", dist/(0.3048*3)); |
1434 |
|
else |
1435 |
|
dist_str = g_strdup_printf("%.0f ft", dist/0.3048); |
1436 |
|
} |
1437 |
|
|
1438 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, dist_str); |
1439 |
|
g_free(dist_str); |
1440 |
|
} |
1441 |
|
|
1442 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1443 |
|
FOUT; |
1444 |
} |
} |
1445 |
#endif // OSD_COORDINATES |
|
1446 |
|
void osm_gps_map_osd_clear_nav (OsmGpsMap *map) { |
1447 |
|
FIN; |
1448 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
1449 |
|
|
1450 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1451 |
|
g_return_if_fail (osd); |
1452 |
|
|
1453 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1454 |
|
g_return_if_fail (priv); |
1455 |
|
|
1456 |
|
if(priv->nav.surface) { |
1457 |
|
cairo_surface_destroy(priv->nav.surface); |
1458 |
|
priv->nav.surface = NULL; |
1459 |
|
priv->nav.lat = OSM_GPS_MAP_INVALID; |
1460 |
|
priv->nav.lon = OSM_GPS_MAP_INVALID; |
1461 |
|
if(priv->nav.name) g_free(priv->nav.name); |
1462 |
|
} |
1463 |
|
osm_gps_map_redraw(map); |
1464 |
|
FOUT; |
1465 |
|
} |
1466 |
|
|
1467 |
|
void |
1468 |
|
osm_gps_map_osd_draw_nav (OsmGpsMap *map, gboolean imperial, |
1469 |
|
float latitude, float longitude, char *name) { |
1470 |
|
FIN; |
1471 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
1472 |
|
|
1473 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1474 |
|
g_return_if_fail (osd); |
1475 |
|
|
1476 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1477 |
|
g_return_if_fail (priv); |
1478 |
|
|
1479 |
|
osm_gps_map_osd_clear_nav (map); |
1480 |
|
|
1481 |
|
/* allocate balloon surface */ |
1482 |
|
priv->nav.surface = |
1483 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1484 |
|
OSD_NAV_W+2, OSD_NAV_H+2); |
1485 |
|
|
1486 |
|
priv->nav.lat = latitude; |
1487 |
|
priv->nav.lon = longitude; |
1488 |
|
priv->nav.name = g_strdup(name); |
1489 |
|
priv->nav.imperial = imperial; |
1490 |
|
|
1491 |
|
osd_render_nav(osd); |
1492 |
|
|
1493 |
|
osm_gps_map_redraw(map); |
1494 |
|
FOUT; |
1495 |
|
} |
1496 |
|
|
1497 |
|
#endif // OSD_NAV |
1498 |
|
|
1499 |
|
|
1500 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
1501 |
|
|
1510 |
|
|
1511 |
static void |
static void |
1512 |
osd_render_crosshair_shape(cairo_t *cr) { |
osd_render_crosshair_shape(cairo_t *cr) { |
1513 |
|
FIN; |
1514 |
cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2, |
cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2, |
1515 |
OSD_CROSSHAIR_RADIUS, 0, 2*M_PI); |
OSD_CROSSHAIR_RADIUS, 0, 2*M_PI); |
1516 |
|
|
1529 |
cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK); |
cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK); |
1530 |
|
|
1531 |
cairo_stroke (cr); |
cairo_stroke (cr); |
1532 |
|
FOUT; |
1533 |
} |
} |
1534 |
|
|
1535 |
static void |
static void |
1536 |
osd_render_crosshair(osm_gps_map_osd_t *osd) |
osd_render_crosshair(osm_gps_map_osd_t *osd) |
1537 |
{ |
{ |
1538 |
|
FIN; |
1539 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1540 |
|
|
1541 |
if(priv->crosshair.rendered) |
if(priv->crosshair.rendered) |
1561 |
osd_render_crosshair_shape(cr); |
osd_render_crosshair_shape(cr); |
1562 |
|
|
1563 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1564 |
|
FOUT; |
1565 |
} |
} |
1566 |
#endif |
#endif |
1567 |
|
|
1568 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1569 |
|
|
1570 |
#ifndef OSD_SCALE_FONT_SIZE |
#ifndef OSD_SCALE_FONT_SIZE |
1571 |
#define OSD_SCALE_FONT_SIZE 12 |
#define OSD_SCALE_FONT_SIZE (12.0) |
1572 |
#endif |
#endif |
1573 |
#define OSD_SCALE_W (10*OSD_SCALE_FONT_SIZE) |
#define OSD_SCALE_W (10*OSD_SCALE_FONT_SIZE) |
1574 |
#define OSD_SCALE_H (5*OSD_SCALE_FONT_SIZE/2) |
#define OSD_SCALE_H (5*OSD_SCALE_FONT_SIZE/2) |
1583 |
static void |
static void |
1584 |
osd_render_scale(osm_gps_map_osd_t *osd) |
osd_render_scale(osm_gps_map_osd_t *osd) |
1585 |
{ |
{ |
1586 |
|
FIN; |
1587 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1588 |
|
|
1589 |
/* this only needs to be rendered if the zoom has changed */ |
/* this only needs to be rendered if the zoom has changed */ |
1707 |
cairo_stroke(cr); |
cairo_stroke(cr); |
1708 |
|
|
1709 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1710 |
|
FOUT; |
1711 |
} |
} |
1712 |
#endif |
#endif |
1713 |
|
|
1714 |
static void |
static void |
1715 |
osd_render_controls(osm_gps_map_osd_t *osd) |
osd_render_controls(osm_gps_map_osd_t *osd) |
1716 |
{ |
{ |
1717 |
|
FIN; |
1718 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1719 |
|
|
1720 |
if(priv->controls.rendered |
if(priv->controls.rendered |
1831 |
osd_render_crosshair(osd); |
osd_render_crosshair(osd); |
1832 |
#endif |
#endif |
1833 |
|
|
1834 |
|
#ifdef OSD_NAV |
1835 |
|
osd_render_nav(osd); |
1836 |
|
#endif |
1837 |
|
|
1838 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1839 |
osd_render_coordinates(osd); |
osd_render_coordinates(osd); |
1840 |
#endif |
#endif |
1894 |
// now draw this onto the original context |
// now draw this onto the original context |
1895 |
cairo_t *cr = gdk_cairo_create(drawable); |
cairo_t *cr = gdk_cairo_create(drawable); |
1896 |
|
|
1897 |
int x, y; |
gint x, y; |
1898 |
|
|
1899 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1900 |
x = OSD_X; |
x = OSD_X; |
1914 |
cairo_paint(cr); |
cairo_paint(cr); |
1915 |
#endif |
#endif |
1916 |
|
|
1917 |
|
#ifdef OSD_NAV |
1918 |
|
if(priv->nav.surface) { |
1919 |
|
x = OSD_X; |
1920 |
|
if(x < 0) x += osd->widget->allocation.width - OSD_NAV_W; |
1921 |
|
y = (osd->widget->allocation.height - OSD_NAV_H)/2; |
1922 |
|
|
1923 |
|
cairo_set_source_surface(cr, priv->nav.surface, x, y); |
1924 |
|
cairo_paint(cr); |
1925 |
|
} |
1926 |
|
#endif |
1927 |
|
|
1928 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1929 |
x = -OSD_X; |
x = -OSD_X; |
1930 |
y = -OSD_Y; |
y = -OSD_Y; |
1935 |
cairo_paint(cr); |
cairo_paint(cr); |
1936 |
#endif |
#endif |
1937 |
|
|
1938 |
|
#ifdef OSD_BALLOON |
1939 |
|
if(priv->balloon.surface) { |
1940 |
|
|
1941 |
|
/* convert given lat lon into screen coordinates */ |
1942 |
|
gint x, y; |
1943 |
|
osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
1944 |
|
priv->balloon.lat, priv->balloon.lon, |
1945 |
|
&x, &y); |
1946 |
|
|
1947 |
|
/* check if balloon needs to be rerendered */ |
1948 |
|
osd_render_balloon(osd); |
1949 |
|
|
1950 |
|
cairo_set_source_surface(cr, priv->balloon.surface, |
1951 |
|
x + priv->balloon.offset_x, |
1952 |
|
y + priv->balloon.offset_y); |
1953 |
|
cairo_paint(cr); |
1954 |
|
} |
1955 |
|
#endif |
1956 |
|
|
1957 |
x = OSD_X; |
x = OSD_X; |
1958 |
if(x < 0) |
if(x < 0) |
1959 |
x += osd->widget->allocation.width - OSD_W; |
x += osd->widget->allocation.width - OSD_W; |
1988 |
#endif |
#endif |
1989 |
|
|
1990 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1991 |
|
FOUT; |
1992 |
} |
} |
1993 |
|
|
1994 |
static void |
static void |
1995 |
osd_free(osm_gps_map_osd_t *osd) |
osd_free(osm_gps_map_osd_t *osd) |
1996 |
{ |
{ |
1997 |
|
FIN; |
1998 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1999 |
|
|
2000 |
if (priv->controls.surface) |
if (priv->controls.surface) |
2018 |
cairo_surface_destroy(priv->crosshair.surface); |
cairo_surface_destroy(priv->crosshair.surface); |
2019 |
#endif |
#endif |
2020 |
|
|
2021 |
|
#ifdef OSD_NAV |
2022 |
|
if (priv->nav.surface) |
2023 |
|
cairo_surface_destroy(priv->nav.surface); |
2024 |
|
#endif |
2025 |
|
|
2026 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
2027 |
if (priv->coordinates.surface) |
if (priv->coordinates.surface) |
2028 |
cairo_surface_destroy(priv->coordinates.surface); |
cairo_surface_destroy(priv->coordinates.surface); |
2029 |
#endif |
#endif |
2030 |
|
|
2031 |
|
#ifdef OSD_BALLOON |
2032 |
|
if (priv->balloon.surface) |
2033 |
|
cairo_surface_destroy(priv->balloon.surface); |
2034 |
|
#endif |
2035 |
|
|
2036 |
g_free(priv); |
g_free(priv); |
2037 |
|
FOUT; |
2038 |
} |
} |
2039 |
|
|
2040 |
static gboolean |
static gboolean |
2041 |
osd_busy(osm_gps_map_osd_t *osd) |
osd_busy(osm_gps_map_osd_t *osd) |
2042 |
{ |
{ |
2043 |
|
FIN; |
2044 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
2045 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
2046 |
return (priv->source_sel.handler_id != 0); |
return (priv->source_sel.handler_id != 0); |
2049 |
#endif |
#endif |
2050 |
} |
} |
2051 |
|
|
2052 |
|
static osd_button_t |
2053 |
|
osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
2054 |
|
FIN; |
2055 |
|
return osd_check_int(osd, TRUE, down, x, y); |
2056 |
|
} |
2057 |
|
|
2058 |
static osm_gps_map_osd_t osd_classic = { |
static osm_gps_map_osd_t osd_classic = { |
2059 |
.widget = NULL, |
.widget = NULL, |
2060 |
|
|
2074 |
void |
void |
2075 |
osm_gps_map_osd_classic_init(OsmGpsMap *map) |
osm_gps_map_osd_classic_init(OsmGpsMap *map) |
2076 |
{ |
{ |
2077 |
|
FIN; |
2078 |
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); |
2079 |
|
|
2080 |
|
#ifdef OSD_BALLOON |
2081 |
|
priv->balloon.lat = OSM_GPS_MAP_INVALID; |
2082 |
|
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
2083 |
|
#endif |
2084 |
|
|
2085 |
osd_classic.priv = priv; |
osd_classic.priv = priv; |
2086 |
|
|
2087 |
osm_gps_map_register_osd(map, &osd_classic); |
osm_gps_map_register_osd(map, &osd_classic); |
2088 |
|
FOUT; |
2089 |
} |
} |
2090 |
|
|
2091 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
2093 |
/* but instead are to be used by the main application */ |
/* but instead are to be used by the main application */ |
2094 |
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, |
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, |
2095 |
gpointer data) { |
gpointer data) { |
2096 |
|
FIN; |
2097 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
2098 |
g_return_if_fail (osd); |
g_return_if_fail (osd); |
2099 |
|
|
2105 |
osd->render(osd); |
osd->render(osd); |
2106 |
|
|
2107 |
osm_gps_map_redraw(map); |
osm_gps_map_redraw(map); |
2108 |
|
FOUT; |
2109 |
} |
} |
2110 |
#endif |
#endif |
2111 |
|
|
2112 |
osd_button_t |
osd_button_t |
2113 |
osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) { |
osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) { |
2114 |
|
FIN; |
2115 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
2116 |
g_return_val_if_fail (osd, OSD_NONE); |
g_return_val_if_fail (osd, OSD_NONE); |
2117 |
|
|
2118 |
return osd_check(osd, x, y); |
return osd_check_int(osd, FALSE, TRUE, x, y); |
2119 |
} |
} |