32 |
#include <cairo.h> |
#include <cairo.h> |
33 |
|
|
34 |
#include "osm-gps-map.h" |
#include "osm-gps-map.h" |
35 |
|
#include "converter.h" |
36 |
#include "osm-gps-map-osd-classic.h" |
#include "osm-gps-map-osd-classic.h" |
37 |
|
|
|
#define OSD_COORDINATES |
|
|
|
|
38 |
//the osd controls |
//the osd controls |
39 |
typedef struct { |
typedef struct { |
40 |
/* the offscreen representation of the OSD */ |
/* the offscreen representation of the OSD */ |
41 |
cairo_surface_t *overlay; |
struct { |
42 |
|
cairo_surface_t *surface; |
43 |
|
gboolean rendered; |
44 |
|
#ifdef OSD_GPS_BUTTON |
45 |
|
gboolean gps_enabled; |
46 |
|
#endif |
47 |
|
} controls; |
48 |
|
|
49 |
#ifdef OSD_SCALE |
#ifdef OSD_BALLOON |
50 |
cairo_surface_t *scale; |
//a balloon with additional info |
51 |
int scale_zoom; |
struct { |
52 |
|
cairo_surface_t *surface; |
53 |
|
|
54 |
|
float lat, lon; |
55 |
|
gboolean valid; |
56 |
|
OsmGpsMapRect_t rect; |
57 |
|
|
58 |
|
/* function called to have the user app draw the contents */ |
59 |
|
OsmGpsMapBalloonCallback cb; |
60 |
|
gpointer data; |
61 |
|
} balloon; |
62 |
#endif |
#endif |
63 |
|
|
64 |
|
#ifdef OSD_SCALE |
65 |
|
struct { |
66 |
|
cairo_surface_t *surface; |
67 |
|
int zoom; |
68 |
|
} scale; |
69 |
|
#endif |
70 |
|
|
71 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
72 |
cairo_surface_t *crosshair; |
struct { |
73 |
|
cairo_surface_t *surface; |
74 |
|
gboolean rendered; |
75 |
|
} crosshair; |
76 |
#endif |
#endif |
77 |
|
|
78 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
79 |
cairo_surface_t *coordinates; |
struct { |
80 |
|
cairo_surface_t *surface; |
81 |
|
float lat, lon; |
82 |
|
} coordinates; |
83 |
#endif |
#endif |
84 |
|
|
85 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
86 |
/* values to handle the "source" menu */ |
struct { |
87 |
cairo_surface_t *map_source; |
/* values to handle the "source" menu */ |
88 |
gboolean expanded; |
cairo_surface_t *surface; |
89 |
gint shift, dir, count; |
gboolean expanded; |
90 |
gint handler_id; |
gint shift, dir, count; |
91 |
gint width, height; |
gint handler_id; |
92 |
|
gint width, height; |
93 |
|
gboolean rendered; |
94 |
|
} source_sel; |
95 |
#endif |
#endif |
96 |
|
|
97 |
} osd_priv_t; |
} osd_priv_t; |
98 |
|
|
99 |
|
#ifdef OSD_BALLOON |
100 |
|
/* most visual effects are hardcoded by now, but may be made */ |
101 |
|
/* available via properties later */ |
102 |
|
#ifndef BALLOON_AREA_WIDTH |
103 |
|
#define BALLOON_AREA_WIDTH 290 |
104 |
|
#endif |
105 |
|
#ifndef BALLOON_AREA_HEIGHT |
106 |
|
#define BALLOON_AREA_HEIGHT 75 |
107 |
|
#endif |
108 |
|
#ifndef BALLOON_CORNER_RADIUS |
109 |
|
#define BALLOON_CORNER_RADIUS 10 |
110 |
|
#endif |
111 |
|
|
112 |
|
#define BALLOON_BORDER (BALLOON_CORNER_RADIUS/2) |
113 |
|
#define BALLOON_WIDTH (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER) |
114 |
|
#define BALLOON_HEIGHT (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER) |
115 |
|
#define BALLOON_TRANSPARENCY 0.8 |
116 |
|
#define POINTER_HEIGHT 20 |
117 |
|
#define POINTER_FOOT_WIDTH 20 |
118 |
|
#define POINTER_OFFSET (BALLOON_CORNER_RADIUS*3/4) |
119 |
|
#define BALLOON_SHADOW (BALLOON_CORNER_RADIUS/2) |
120 |
|
#define BALLOON_SHADOW_TRANSPARENCY 0.2 |
121 |
|
|
122 |
|
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) |
123 |
|
|
124 |
|
|
125 |
|
/* draw the bubble shape. this is used twice, once for the shape and once */ |
126 |
|
/* for the shadow */ |
127 |
|
static void |
128 |
|
osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1, |
129 |
|
gboolean bottom, int px, int py, int px0, int px1) { |
130 |
|
|
131 |
|
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
132 |
|
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
133 |
|
BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2); |
134 |
|
if(!bottom) { |
135 |
|
/* insert top pointer */ |
136 |
|
cairo_line_to (cr, px1, y0); |
137 |
|
cairo_line_to (cr, px, py); |
138 |
|
cairo_line_to (cr, px0, y0); |
139 |
|
} |
140 |
|
|
141 |
|
cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0); |
142 |
|
cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
143 |
|
BALLOON_CORNER_RADIUS, -M_PI/2, 0); |
144 |
|
cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS); |
145 |
|
cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, |
146 |
|
BALLOON_CORNER_RADIUS, 0, M_PI/2); |
147 |
|
if(bottom) { |
148 |
|
/* insert bottom pointer */ |
149 |
|
cairo_line_to (cr, px0, y1); |
150 |
|
cairo_line_to (cr, px, py); |
151 |
|
cairo_line_to (cr, px1, y1); |
152 |
|
} |
153 |
|
|
154 |
|
cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1); |
155 |
|
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, |
156 |
|
BALLOON_CORNER_RADIUS, M_PI/2, M_PI); |
157 |
|
|
158 |
|
cairo_close_path (cr); |
159 |
|
} |
160 |
|
|
161 |
|
/* xyz */ |
162 |
|
|
163 |
|
static void |
164 |
|
osd_render_balloon(osm_gps_map_osd_t *osd) { |
165 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
166 |
|
|
167 |
|
/* get zoom */ |
168 |
|
gint zoom; |
169 |
|
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
170 |
|
|
171 |
|
/* ------- convert given coordinate into screen position --------- */ |
172 |
|
gint x0, y0; |
173 |
|
osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
174 |
|
priv->balloon.lat, priv->balloon.lon, |
175 |
|
&x0, &y0); |
176 |
|
|
177 |
|
/* check position of this relative to screen center to determine */ |
178 |
|
/* pointer direction ... */ |
179 |
|
int pointer_x = x0, pointer_x0, pointer_x1; |
180 |
|
int pointer_y = y0; |
181 |
|
|
182 |
|
/* ... and calculate position */ |
183 |
|
if(x0 > osd->widget->allocation.width/2) { |
184 |
|
x0 += POINTER_OFFSET; |
185 |
|
pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
186 |
|
pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH; |
187 |
|
} else { |
188 |
|
x0 -= POINTER_OFFSET; |
189 |
|
pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
190 |
|
pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH; |
191 |
|
} |
192 |
|
|
193 |
|
gboolean bottom = FALSE; |
194 |
|
if(y0 > osd->widget->allocation.height/2) { |
195 |
|
bottom = TRUE; |
196 |
|
y0 -= BALLOON_HEIGHT + POINTER_HEIGHT; |
197 |
|
} else |
198 |
|
y0 += POINTER_HEIGHT; |
199 |
|
|
200 |
|
/* calculate bottom/right of box */ |
201 |
|
int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT; |
202 |
|
|
203 |
|
/* save balloon screen coordinates for later use */ |
204 |
|
priv->balloon.rect.x = x0 + BALLOON_BORDER; |
205 |
|
priv->balloon.rect.y = y0 + BALLOON_BORDER; |
206 |
|
priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER; |
207 |
|
priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; |
208 |
|
|
209 |
|
cairo_t *cr = cairo_create(priv->balloon.surface); |
210 |
|
|
211 |
|
/* --------- draw shadow --------------- */ |
212 |
|
osm_gps_map_draw_balloon_shape (cr, |
213 |
|
x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW, |
214 |
|
x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW, |
215 |
|
bottom, pointer_x, pointer_y, |
216 |
|
pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW); |
217 |
|
|
218 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY); |
219 |
|
cairo_fill_preserve (cr); |
220 |
|
cairo_set_source_rgba (cr, 1, 0, 0, 1.0); |
221 |
|
cairo_set_line_width (cr, 0); |
222 |
|
cairo_stroke (cr); |
223 |
|
|
224 |
|
/* --------- draw main shape ----------- */ |
225 |
|
osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1, |
226 |
|
bottom, pointer_x, pointer_y, pointer_x0, pointer_x1); |
227 |
|
|
228 |
|
cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY); |
229 |
|
cairo_fill_preserve (cr); |
230 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY); |
231 |
|
cairo_set_line_width (cr, 1); |
232 |
|
cairo_stroke (cr); |
233 |
|
|
234 |
|
|
235 |
|
/* ---------- draw close button --------- */ |
236 |
|
|
237 |
|
int cx = x1 - BALLOON_BORDER - CLOSE_BUTTON_RADIUS; |
238 |
|
int cy = y0 + BALLOON_BORDER + CLOSE_BUTTON_RADIUS; |
239 |
|
int crad = CLOSE_BUTTON_RADIUS; |
240 |
|
|
241 |
|
cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI); |
242 |
|
cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0); |
243 |
|
cairo_fill_preserve (cr); |
244 |
|
cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0); |
245 |
|
cairo_set_line_width (cr, 2); |
246 |
|
cairo_stroke(cr); |
247 |
|
|
248 |
|
cairo_set_source_rgba (cr, 1, 1, 1, 1.0); |
249 |
|
cairo_set_line_width (cr, BALLOON_CORNER_RADIUS/3.3); |
250 |
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
251 |
|
cairo_move_to (cr, cx - crad/2, cy - crad/2); |
252 |
|
cairo_line_to (cr, cx + crad/2, cy + crad/2); |
253 |
|
cairo_stroke (cr); |
254 |
|
cairo_move_to (cr, cx + crad/2, cy - crad/2); |
255 |
|
cairo_line_to (cr, cx - crad/2, cy + crad/2); |
256 |
|
cairo_stroke (cr); |
257 |
|
|
258 |
|
if (priv->balloon.cb) { |
259 |
|
/* clip in case application tries to draw in */ |
260 |
|
/* exceed of the balloon */ |
261 |
|
cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y, |
262 |
|
priv->balloon.rect.w, priv->balloon.rect.h); |
263 |
|
cairo_clip (cr); |
264 |
|
cairo_new_path (cr); /* current path is not |
265 |
|
consumed by cairo_clip() */ |
266 |
|
|
267 |
|
priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data); |
268 |
|
} |
269 |
|
|
270 |
|
cairo_destroy(cr); |
271 |
|
} |
272 |
|
|
273 |
|
#if 0 |
274 |
|
/* the user clicked into the balloons main area. handle this */ |
275 |
|
static void |
276 |
|
osm_gps_map_handle_balloon_click(OsmGpsMap *map, gint x, gint y) |
277 |
|
{ |
278 |
|
OsmGpsMapPrivate *priv = map->priv; |
279 |
|
|
280 |
|
if (!priv->balloon.valid) |
281 |
|
return; |
282 |
|
|
283 |
|
/* check if the close button was clicked */ |
284 |
|
if ((x > priv->balloon.rect.w - 2*CLOSE_BUTTON_RADIUS) && |
285 |
|
(x < priv->balloon.rect.w) && |
286 |
|
(y > 0) && (y < 2*CLOSE_BUTTON_RADIUS)) { |
287 |
|
|
288 |
|
priv->balloon.valid = FALSE; |
289 |
|
osm_gps_map_map_redraw_idle(map); |
290 |
|
} |
291 |
|
} |
292 |
|
|
293 |
|
/* return true if balloon is being displayed and if */ |
294 |
|
/* the given coordinate is within this balloon */ |
295 |
|
static gboolean |
296 |
|
osm_gps_map_in_balloon(OsmGpsMapPrivate *priv, gint x, gint y) |
297 |
|
{ |
298 |
|
return (priv->balloon.valid && |
299 |
|
(x > priv->balloon.rect.x) && |
300 |
|
(x < priv->balloon.rect.x + priv->balloon.rect.w) && |
301 |
|
(y > priv->balloon.rect.y) && |
302 |
|
(y < priv->balloon.rect.y + priv->balloon.rect.h)); |
303 |
|
} |
304 |
|
|
305 |
|
#if 0 |
306 |
|
/* don't drag if the user clicked within the balloon */ |
307 |
|
if (osm_gps_map_in_balloon(priv, |
308 |
|
event->x + EXTRA_BORDER, |
309 |
|
event->y + EXTRA_BORDER)) |
310 |
|
{ |
311 |
|
priv->drag_counter = -1; |
312 |
|
return FALSE; |
313 |
|
} |
314 |
|
|
315 |
|
#ifdef ENABLE_BALLOON |
316 |
|
/* released inside the balloon? */ |
317 |
|
if (osm_gps_map_in_balloon(priv, |
318 |
|
event->x + EXTRA_BORDER, |
319 |
|
event->y + EXTRA_BORDER)) |
320 |
|
{ |
321 |
|
osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget), |
322 |
|
event->x - priv->balloon.rect.x + EXTRA_BORDER, |
323 |
|
event->y - priv->balloon.rect.y + EXTRA_BORDER); |
324 |
|
} |
325 |
|
#endif |
326 |
|
|
327 |
|
#endif |
328 |
|
|
329 |
|
void |
330 |
|
osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
331 |
|
OsmGpsMapBalloonCallback cb, gpointer data) |
332 |
|
{ |
333 |
|
OsmGpsMapPrivate *priv; |
334 |
|
|
335 |
|
/* remove and previously installed balloon */ |
336 |
|
osm_gps_map_clear_balloon (map); |
337 |
|
|
338 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
339 |
|
priv = map->priv; |
340 |
|
|
341 |
|
priv->balloon.lat = latitude; |
342 |
|
priv->balloon.lon = longitude; |
343 |
|
priv->balloon.valid = TRUE; |
344 |
|
|
345 |
|
priv->balloon.cb = cb; |
346 |
|
priv->balloon.data = data; |
347 |
|
|
348 |
|
// this redraws the map |
349 |
|
osm_gps_map_map_redraw_idle(map); |
350 |
|
} |
351 |
|
|
352 |
|
void |
353 |
|
osm_gps_map_clear_balloon (OsmGpsMap *map) |
354 |
|
{ |
355 |
|
OsmGpsMapPrivate *priv; |
356 |
|
|
357 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
358 |
|
priv = map->priv; |
359 |
|
|
360 |
|
priv->balloon.valid = FALSE; |
361 |
|
|
362 |
|
osm_gps_map_map_redraw_idle(map); |
363 |
|
} |
364 |
|
#endif |
365 |
|
|
366 |
|
void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) { |
367 |
|
printf("request to clear balloon\n"); |
368 |
|
} |
369 |
|
|
370 |
|
void |
371 |
|
osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
372 |
|
OsmGpsMapBalloonCallback cb, gpointer data) |
373 |
|
{ |
374 |
|
printf("request to draw balloon at %f %f\n", latitude, longitude); |
375 |
|
} |
376 |
|
|
377 |
|
#endif // OSD_BALLOON |
378 |
|
|
379 |
/* position and extent of bounding box */ |
/* position and extent of bounding box */ |
380 |
#ifndef OSD_X |
#ifndef OSD_X |
381 |
#define OSD_X (10) |
#define OSD_X (10) |
598 |
#define OSD_S_H (OSD_S_PH + OSD_SHADOW) |
#define OSD_S_H (OSD_S_PH + OSD_SHADOW) |
599 |
|
|
600 |
/* size of usable area when expanded */ |
/* size of usable area when expanded */ |
601 |
#define OSD_S_AREA_W (priv->width) |
#define OSD_S_AREA_W (priv->source_sel.width) |
602 |
#define OSD_S_AREA_H (priv->height) |
#define OSD_S_AREA_H (priv->source_sel.height) |
603 |
#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) |
604 |
#define OSD_S_EXP_H (OSD_S_AREA_H + OSD_SHADOW) |
#define OSD_S_EXP_H (OSD_S_AREA_H + OSD_SHADOW) |
605 |
|
|
615 |
/* or the entire menu incl. the puller (expanded) */ |
/* or the entire menu incl. the puller (expanded) */ |
616 |
static void |
static void |
617 |
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) { |
618 |
if(!priv->expanded) { |
if(!priv->source_sel.expanded) { |
619 |
/* just draw the puller */ |
/* just draw the puller */ |
620 |
cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH); |
cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH); |
621 |
cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); |
cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); |
643 |
|
|
644 |
int py = offset + OSD_S_RAD - OSD_S_D0; |
int py = offset + OSD_S_RAD - OSD_S_D0; |
645 |
|
|
646 |
if(!priv->expanded) { |
if(!priv->source_sel.expanded) { |
647 |
/* draw the "puller" open (<) arrow */ |
/* draw the "puller" open (<) arrow */ |
648 |
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); |
649 |
cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); |
cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); |
668 |
CAIRO_FONT_WEIGHT_BOLD); |
CAIRO_FONT_WEIGHT_BOLD); |
669 |
cairo_set_font_size (cr, OSD_FONT_SIZE); |
cairo_set_font_size (cr, OSD_FONT_SIZE); |
670 |
|
|
671 |
int i, step = (priv->height - 2*OSD_TEXT_BORDER) / |
int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) / |
672 |
OSM_GPS_MAP_SOURCE_LAST; |
OSM_GPS_MAP_SOURCE_LAST; |
673 |
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++) { |
674 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
682 |
if(source == i) { |
if(source == i) { |
683 |
cairo_rectangle(cr, x - OSD_TEXT_BORDER/2, |
cairo_rectangle(cr, x - OSD_TEXT_BORDER/2, |
684 |
y - OSD_TEXT_SKIP, |
y - OSD_TEXT_SKIP, |
685 |
priv->width - OSD_TEXT_BORDER, |
priv->source_sel.width - OSD_TEXT_BORDER, |
686 |
step + OSD_TEXT_SKIP); |
step + OSD_TEXT_SKIP); |
687 |
cairo_fill(cr); |
cairo_fill(cr); |
688 |
|
|
713 |
} |
} |
714 |
|
|
715 |
static void |
static void |
716 |
osd_render_source_sel(osm_gps_map_osd_t *osd) { |
osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) { |
717 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
718 |
|
|
719 |
|
if(priv->source_sel.rendered && !force_rerender) |
720 |
|
return; |
721 |
|
|
722 |
|
priv->source_sel.rendered = TRUE; |
723 |
|
|
724 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
725 |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
726 |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
728 |
#endif |
#endif |
729 |
|
|
730 |
/* draw source selector */ |
/* draw source selector */ |
731 |
cairo_t *cr = cairo_create(priv->map_source); |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
732 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
733 |
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); |
734 |
cairo_paint(cr); |
cairo_paint(cr); |
769 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
770 |
|
|
771 |
/* re-allocate offscreen bitmap */ |
/* re-allocate offscreen bitmap */ |
772 |
g_assert (priv->map_source); |
g_assert (priv->source_sel.surface); |
773 |
|
|
774 |
int w = OSD_S_W, h = OSD_S_H; |
int w = OSD_S_W, h = OSD_S_H; |
775 |
if(priv->expanded) { |
if(priv->source_sel.expanded) { |
776 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
777 |
|
|
778 |
/* determine content size */ |
/* determine content size */ |
779 |
cairo_t *cr = cairo_create(priv->map_source); |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
780 |
cairo_select_font_face (cr, "Sans", |
cairo_select_font_face (cr, "Sans", |
781 |
CAIRO_FONT_SLANT_NORMAL, |
CAIRO_FONT_SLANT_NORMAL, |
782 |
CAIRO_FONT_WEIGHT_BOLD); |
CAIRO_FONT_WEIGHT_BOLD); |
793 |
} |
} |
794 |
cairo_destroy(cr); |
cairo_destroy(cr); |
795 |
|
|
796 |
priv->width = max_w + 2*OSD_TEXT_BORDER; |
priv->source_sel.width = max_w + 2*OSD_TEXT_BORDER; |
797 |
priv->height = OSM_GPS_MAP_SOURCE_LAST * |
priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST * |
798 |
(max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER; |
(max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER; |
799 |
|
|
800 |
w = OSD_S_EXP_W; |
w = OSD_S_EXP_W; |
801 |
h = OSD_S_EXP_H; |
h = OSD_S_EXP_H; |
802 |
} |
} |
803 |
|
|
804 |
cairo_surface_destroy(priv->map_source); |
cairo_surface_destroy(priv->source_sel.surface); |
805 |
priv->map_source = |
priv->source_sel.surface = |
806 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
807 |
|
|
808 |
osd_render_source_sel(osd); |
osd_render_source_sel(osd, TRUE); |
809 |
} |
} |
810 |
|
|
811 |
#define OSD_HZ 15 |
#define OSD_HZ 15 |
816 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
817 |
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
818 |
gboolean done = FALSE; |
gboolean done = FALSE; |
819 |
priv->count += priv->dir; |
priv->source_sel.count += priv->source_sel.dir; |
820 |
|
|
821 |
/* shifting in */ |
/* shifting in */ |
822 |
if(priv->dir < 0) { |
if(priv->source_sel.dir < 0) { |
823 |
if(priv->count <= 0) { |
if(priv->source_sel.count <= 0) { |
824 |
priv->count = 0; |
priv->source_sel.count = 0; |
825 |
done = TRUE; |
done = TRUE; |
826 |
} |
} |
827 |
} else { |
} else { |
828 |
if(priv->count >= 1000) { |
if(priv->source_sel.count >= 1000) { |
829 |
priv->expanded = FALSE; |
priv->source_sel.expanded = FALSE; |
830 |
osd_source_reallocate(osd); |
osd_source_reallocate(osd); |
831 |
|
|
832 |
priv->count = 1000; |
priv->source_sel.count = 1000; |
833 |
done = TRUE; |
done = TRUE; |
834 |
} |
} |
835 |
} |
} |
837 |
|
|
838 |
/* 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 */ |
839 |
|
|
840 |
/* nicer sinoid mapping */ |
/* nice sinoid mapping */ |
841 |
float m = 0.5-cos(priv->count * M_PI / 1000.0)/2; |
float m = 0.5-cos(priv->source_sel.count * M_PI / 1000.0)/2; |
842 |
priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
priv->source_sel.shift = |
843 |
|
(osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
844 |
m * diff; |
m * diff; |
845 |
|
|
846 |
|
/* make sure the screen is updated */ |
847 |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
848 |
|
|
849 |
|
/* stop animation if done */ |
850 |
if(done) |
if(done) |
851 |
priv->handler_id = 0; |
priv->source_sel.handler_id = 0; |
852 |
|
|
853 |
return !done; |
return !done; |
854 |
} |
} |
860 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
861 |
|
|
862 |
/* ignore clicks while animation is running */ |
/* ignore clicks while animation is running */ |
863 |
if(priv->handler_id) |
if(priv->source_sel.handler_id) |
864 |
return; |
return; |
865 |
|
|
866 |
/* expand immediately, collapse is handle at the end of the collapse animation */ |
/* expand immediately, collapse is handle at the end of the */ |
867 |
if(!priv->expanded) { |
/* collapse animation */ |
868 |
priv->expanded = TRUE; |
if(!priv->source_sel.expanded) { |
869 |
|
priv->source_sel.expanded = TRUE; |
870 |
osd_source_reallocate(osd); |
osd_source_reallocate(osd); |
871 |
|
|
872 |
priv->count = 1000; |
priv->source_sel.count = 1000; |
873 |
priv->shift = osd->widget->allocation.width - OSD_S_W; |
priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W; |
874 |
priv->dir = -1000/OSD_HZ; |
priv->source_sel.dir = -1000/OSD_HZ; |
875 |
} else { |
} else { |
876 |
priv->count = 0; |
priv->source_sel.count = 0; |
877 |
priv->shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
priv->source_sel.shift = osd->widget->allocation.width - |
878 |
priv->dir = +1000/OSD_HZ; |
OSD_S_EXP_W + OSD_S_X; |
879 |
|
priv->source_sel.dir = +1000/OSD_HZ; |
880 |
} |
} |
881 |
|
|
882 |
priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd); |
/* start timer to handle animation */ |
883 |
|
priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, |
884 |
|
osd_source_animate, osd); |
885 |
} |
} |
886 |
|
|
887 |
/* check if the user clicked inside the source selection area */ |
/* check if the user clicked inside the source selection area */ |
889 |
osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
890 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
891 |
|
|
892 |
if(!priv->expanded) |
if(!priv->source_sel.expanded) |
893 |
x -= osd->widget->allocation.width - OSD_S_W; |
x -= osd->widget->allocation.width - OSD_S_W; |
894 |
else |
else |
895 |
x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
913 |
} |
} |
914 |
|
|
915 |
/* check for clicks into data area */ |
/* check for clicks into data area */ |
916 |
if(priv->expanded && !priv->handler_id) { |
if(priv->source_sel.expanded && !priv->source_sel.handler_id) { |
917 |
/* re-adjust from puller top to content top */ |
/* re-adjust from puller top to content top */ |
918 |
if(OSD_S_Y < 0) |
if(OSD_S_Y < 0) |
919 |
y += OSD_S_EXP_H - OSD_S_PH; |
y += OSD_S_EXP_H - OSD_S_PH; |
923 |
y > 0 && |
y > 0 && |
924 |
y < OSD_S_EXP_H) { |
y < OSD_S_EXP_H) { |
925 |
|
|
926 |
int step = (priv->height - 2*OSD_TEXT_BORDER) |
int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) |
927 |
/ OSM_GPS_MAP_SOURCE_LAST; |
/ OSM_GPS_MAP_SOURCE_LAST; |
928 |
|
|
929 |
y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP; |
y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP; |
938 |
old != y) { |
old != y) { |
939 |
g_object_set(osd->widget, "map-source", y, NULL); |
g_object_set(osd->widget, "map-source", y, NULL); |
940 |
|
|
941 |
osd_render_source_sel(osd); |
osd_render_source_sel(osd, TRUE); |
942 |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
943 |
} |
} |
944 |
|
|
1057 |
} |
} |
1058 |
|
|
1059 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1060 |
#define OSD_COORDINATES_W 100 |
|
1061 |
#define OSD_COORDINATES_H 50 |
#ifndef OSD_COORDINATES_FONT_SIZE |
1062 |
|
#define OSD_COORDINATES_FONT_SIZE 12 |
1063 |
|
#endif |
1064 |
|
|
1065 |
|
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
1066 |
|
|
1067 |
|
#define OSD_COORDINATES_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
1068 |
|
#define OSD_COORDINATES_H (2*OSD_COORDINATES_FONT_SIZE+OSD_COORDINATES_OFFSET) |
1069 |
|
|
1070 |
|
/* these can be overwritten with versions that support */ |
1071 |
|
/* localization */ |
1072 |
|
#ifndef OSD_COORDINATES_CHR_N |
1073 |
|
#define OSD_COORDINATES_CHR_N "N" |
1074 |
|
#endif |
1075 |
|
#ifndef OSD_COORDINATES_CHR_S |
1076 |
|
#define OSD_COORDINATES_CHR_S "S" |
1077 |
|
#endif |
1078 |
|
#ifndef OSD_COORDINATES_CHR_E |
1079 |
|
#define OSD_COORDINATES_CHR_E "E" |
1080 |
|
#endif |
1081 |
|
#ifndef OSD_COORDINATES_CHR_W |
1082 |
|
#define OSD_COORDINATES_CHR_W "W" |
1083 |
|
#endif |
1084 |
|
|
1085 |
|
|
1086 |
|
|
1087 |
|
/* this is the classic geocaching notation */ |
1088 |
|
static char |
1089 |
|
*osd_latitude_str(float latitude) { |
1090 |
|
char *c = OSD_COORDINATES_CHR_N; |
1091 |
|
float integral, fractional; |
1092 |
|
|
1093 |
|
if(isnan(latitude)) |
1094 |
|
return NULL; |
1095 |
|
|
1096 |
|
if(latitude < 0) { |
1097 |
|
latitude = fabs(latitude); |
1098 |
|
c = OSD_COORDINATES_CHR_S; |
1099 |
|
} |
1100 |
|
|
1101 |
|
fractional = modff(latitude, &integral); |
1102 |
|
|
1103 |
|
return g_strdup_printf("%s %02d° %06.3f'", |
1104 |
|
c, (int)integral, fractional*60.0); |
1105 |
|
} |
1106 |
|
|
1107 |
|
static char |
1108 |
|
*osd_longitude_str(float longitude) { |
1109 |
|
char *c = OSD_COORDINATES_CHR_E; |
1110 |
|
float integral, fractional; |
1111 |
|
|
1112 |
|
if(isnan(longitude)) |
1113 |
|
return NULL; |
1114 |
|
|
1115 |
|
if(longitude < 0) { |
1116 |
|
longitude = fabs(longitude); |
1117 |
|
c = OSD_COORDINATES_CHR_W; |
1118 |
|
} |
1119 |
|
|
1120 |
|
fractional = modff(longitude, &integral); |
1121 |
|
|
1122 |
|
return g_strdup_printf("%s %03d° %06.3f'", |
1123 |
|
c, (int)integral, fractional*60.0); |
1124 |
|
} |
1125 |
|
|
1126 |
static void |
static void |
1127 |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
1128 |
{ |
{ |
1129 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1130 |
|
|
1131 |
|
/* get current map position */ |
1132 |
|
gfloat lat, lon; |
1133 |
|
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
1134 |
|
|
1135 |
|
/* check if position has changed enough to require redraw */ |
1136 |
|
if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon)) |
1137 |
|
/* 1/60000 == 1/1000 minute */ |
1138 |
|
if((fabsf(lat - priv->coordinates.lat) < 1/60000) && |
1139 |
|
(fabsf(lon - priv->coordinates.lon) < 1/60000)) |
1140 |
|
return; |
1141 |
|
|
1142 |
|
priv->coordinates.lat = lat; |
1143 |
|
priv->coordinates.lon = lon; |
1144 |
|
|
1145 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1146 |
cairo_t *cr = cairo_create(priv->coordinates); |
cairo_t *cr = cairo_create(priv->coordinates.surface); |
1147 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1148 |
// cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
// cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); |
1149 |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
1150 |
cairo_paint(cr); |
cairo_paint(cr); |
1151 |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1152 |
|
|
1153 |
|
cairo_select_font_face (cr, "Sans", |
1154 |
|
CAIRO_FONT_SLANT_NORMAL, |
1155 |
|
CAIRO_FONT_WEIGHT_BOLD); |
1156 |
|
cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE); |
1157 |
|
|
1158 |
|
char *latitude = osd_latitude_str(lat); |
1159 |
|
char *longitude = osd_longitude_str(lon); |
1160 |
|
|
1161 |
|
cairo_text_extents_t lat_extents, lon_extents; |
1162 |
|
cairo_text_extents (cr, latitude, &lat_extents); |
1163 |
|
cairo_text_extents (cr, longitude, &lon_extents); |
1164 |
|
|
1165 |
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
1166 |
|
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
1167 |
|
cairo_move_to (cr, |
1168 |
|
(OSD_COORDINATES_W - lat_extents.width)/2, |
1169 |
|
OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
1170 |
|
cairo_text_path (cr, latitude); |
1171 |
|
cairo_move_to (cr, |
1172 |
|
(OSD_COORDINATES_W - lon_extents.width)/2, |
1173 |
|
OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
1174 |
|
OSD_COORDINATES_FONT_SIZE); |
1175 |
|
cairo_text_path (cr, longitude); |
1176 |
|
cairo_stroke (cr); |
1177 |
|
|
1178 |
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
1179 |
|
cairo_move_to (cr, |
1180 |
|
(OSD_COORDINATES_W - lat_extents.width)/2, |
1181 |
|
OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
1182 |
|
cairo_show_text (cr, latitude); |
1183 |
|
cairo_move_to (cr, |
1184 |
|
(OSD_COORDINATES_W - lon_extents.width)/2, |
1185 |
|
OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
1186 |
|
OSD_COORDINATES_FONT_SIZE); |
1187 |
|
cairo_show_text (cr, longitude); |
1188 |
|
|
1189 |
|
g_free(latitude); |
1190 |
|
g_free(longitude); |
1191 |
|
|
1192 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1193 |
} |
} |
1194 |
#endif // OSD_COORDINATES |
#endif // OSD_COORDINATES |
1231 |
{ |
{ |
1232 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1233 |
|
|
1234 |
|
if(priv->crosshair.rendered) |
1235 |
|
return; |
1236 |
|
|
1237 |
|
priv->crosshair.rendered = TRUE; |
1238 |
|
|
1239 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1240 |
cairo_t *cr = cairo_create(priv->crosshair); |
cairo_t *cr = cairo_create(priv->crosshair.surface); |
1241 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1242 |
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
|
// cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
|
1243 |
cairo_paint(cr); |
cairo_paint(cr); |
1244 |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1245 |
|
|
1280 |
/* this only needs to be rendered if the zoom has changed */ |
/* this only needs to be rendered if the zoom has changed */ |
1281 |
gint zoom; |
gint zoom; |
1282 |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
1283 |
if(zoom == priv->scale_zoom) |
if(zoom == priv->scale.zoom) |
1284 |
return; |
return; |
1285 |
|
|
1286 |
priv->scale_zoom = zoom; |
priv->scale.zoom = zoom; |
1287 |
|
|
1288 |
float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget)); |
float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget)); |
1289 |
|
|
1290 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1291 |
cairo_t *cr = cairo_create(priv->scale); |
cairo_t *cr = cairo_create(priv->scale.surface); |
1292 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1293 |
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); |
1294 |
// pink for testing: cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
// pink for testing: cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
1402 |
#endif |
#endif |
1403 |
|
|
1404 |
static void |
static void |
1405 |
osd_render(osm_gps_map_osd_t *osd) |
osd_render_controls(osm_gps_map_osd_t *osd) |
1406 |
{ |
{ |
1407 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1408 |
|
|
1409 |
|
if(priv->controls.rendered |
1410 |
|
#ifdef OSD_GPS_BUTTON |
1411 |
|
&& (priv->controls.gps_enabled == (osd->cb != NULL)) |
1412 |
|
#endif |
1413 |
|
) |
1414 |
|
return; |
1415 |
|
|
1416 |
|
#ifdef OSD_GPS_BUTTON |
1417 |
|
priv->controls.gps_enabled = (osd->cb != NULL); |
1418 |
|
#endif |
1419 |
|
priv->controls.rendered = TRUE; |
1420 |
|
|
1421 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
1422 |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
1423 |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
1425 |
#endif |
#endif |
1426 |
|
|
1427 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1428 |
cairo_t *cr = cairo_create(priv->overlay); |
cairo_t *cr = cairo_create(priv->controls.surface); |
1429 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1430 |
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); |
1431 |
cairo_paint(cr); |
cairo_paint(cr); |
1496 |
cairo_stroke(cr); |
cairo_stroke(cr); |
1497 |
|
|
1498 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1499 |
|
} |
1500 |
|
|
1501 |
|
static void |
1502 |
|
osd_render(osm_gps_map_osd_t *osd) |
1503 |
|
{ |
1504 |
|
/* this function is actually called pretty often since the */ |
1505 |
|
/* OSD contents may have changed (due to a coordinate/zoom change). */ |
1506 |
|
/* The different OSD parts have to make sure that they don't */ |
1507 |
|
/* render unneccessarily often and thus waste CPU power */ |
1508 |
|
|
1509 |
|
osd_render_controls(osd); |
1510 |
|
|
1511 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1512 |
osd_render_source_sel(osd); |
osd_render_source_sel(osd, FALSE); |
1513 |
#endif |
#endif |
1514 |
|
|
1515 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1532 |
|
|
1533 |
/* OSD itself uses some off-screen rendering, so check if the */ |
/* OSD itself uses some off-screen rendering, so check if the */ |
1534 |
/* offscreen buffer is present and create it if not */ |
/* offscreen buffer is present and create it if not */ |
1535 |
if(!priv->overlay) { |
if(!priv->controls.surface) { |
1536 |
/* create overlay ... */ |
/* create overlay ... */ |
1537 |
priv->overlay = |
priv->controls.surface = |
1538 |
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); |
1539 |
|
|
1540 |
|
priv->controls.rendered = FALSE; |
1541 |
|
#ifdef OSD_GPS_BUTTON |
1542 |
|
priv->controls.gps_enabled = FALSE; |
1543 |
|
#endif |
1544 |
|
|
1545 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1546 |
/* the initial OSD state is alway not-expanded */ |
/* the initial OSD state is alway not-expanded */ |
1547 |
priv->map_source = |
priv->source_sel.surface = |
1548 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1549 |
OSD_S_W+2, OSD_S_H+2); |
OSD_S_W+2, OSD_S_H+2); |
1550 |
|
priv->source_sel.rendered = FALSE; |
1551 |
#endif |
#endif |
1552 |
|
|
1553 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1554 |
priv->scale = |
priv->scale.surface = |
1555 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1556 |
OSD_SCALE_W, OSD_SCALE_H); |
OSD_SCALE_W, OSD_SCALE_H); |
1557 |
priv->scale_zoom = -1; |
priv->scale.zoom = -1; |
1558 |
#endif |
#endif |
1559 |
|
|
1560 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
1561 |
priv->crosshair = |
priv->crosshair.surface = |
1562 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1563 |
OSD_CROSSHAIR_W, OSD_CROSSHAIR_H); |
OSD_CROSSHAIR_W, OSD_CROSSHAIR_H); |
1564 |
|
priv->crosshair.rendered = FALSE; |
1565 |
#endif |
#endif |
1566 |
|
|
1567 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1568 |
priv->coordinates = |
priv->coordinates.surface = |
1569 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1570 |
OSD_COORDINATES_W, OSD_COORDINATES_H); |
OSD_COORDINATES_W, OSD_COORDINATES_H); |
1571 |
|
|
1572 |
|
priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID; |
1573 |
#endif |
#endif |
1574 |
|
|
1575 |
/* ... and render it */ |
/* ... and render it */ |
1587 |
if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W; |
if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W; |
1588 |
if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H; |
if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H; |
1589 |
|
|
1590 |
cairo_set_source_surface(cr, priv->scale, x, y); |
cairo_set_source_surface(cr, priv->scale.surface, x, y); |
1591 |
cairo_paint(cr); |
cairo_paint(cr); |
1592 |
#endif |
#endif |
1593 |
|
|
1595 |
x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2; |
x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2; |
1596 |
y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2; |
y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2; |
1597 |
|
|
1598 |
cairo_set_source_surface(cr, priv->crosshair, x, y); |
cairo_set_source_surface(cr, priv->crosshair.surface, x, y); |
1599 |
cairo_paint(cr); |
cairo_paint(cr); |
1600 |
#endif |
#endif |
1601 |
|
|
1605 |
if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W; |
if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W; |
1606 |
if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H; |
if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H; |
1607 |
|
|
1608 |
cairo_set_source_surface(cr, priv->coordinates, x, y); |
cairo_set_source_surface(cr, priv->coordinates.surface, x, y); |
1609 |
cairo_paint(cr); |
cairo_paint(cr); |
1610 |
#endif |
#endif |
1611 |
|
|
1617 |
if(y < 0) |
if(y < 0) |
1618 |
y += osd->widget->allocation.height - OSD_H; |
y += osd->widget->allocation.height - OSD_H; |
1619 |
|
|
1620 |
cairo_set_source_surface(cr, priv->overlay, x, y); |
cairo_set_source_surface(cr, priv->controls.surface, x, y); |
1621 |
cairo_paint(cr); |
cairo_paint(cr); |
1622 |
|
|
1623 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1624 |
if(!priv->handler_id) { |
if(!priv->source_sel.handler_id) { |
1625 |
/* the OSD source selection is not being animated */ |
/* the OSD source selection is not being animated */ |
1626 |
if(!priv->expanded) |
if(!priv->source_sel.expanded) |
1627 |
x = osd->widget->allocation.width - OSD_S_W; |
x = osd->widget->allocation.width - OSD_S_W; |
1628 |
else |
else |
1629 |
x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
1630 |
} else |
} else |
1631 |
x = priv->shift; |
x = priv->source_sel.shift; |
1632 |
|
|
1633 |
y = OSD_S_Y; |
y = OSD_S_Y; |
1634 |
if(OSD_S_Y < 0) { |
if(OSD_S_Y < 0) { |
1635 |
if(!priv->expanded) |
if(!priv->source_sel.expanded) |
1636 |
y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y; |
y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y; |
1637 |
else |
else |
1638 |
y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y; |
y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y; |
1639 |
} |
} |
1640 |
|
|
1641 |
cairo_set_source_surface(cr, priv->map_source, x, y); |
cairo_set_source_surface(cr, priv->source_sel.surface, x, y); |
1642 |
cairo_paint(cr); |
cairo_paint(cr); |
1643 |
#endif |
#endif |
1644 |
|
|
1650 |
{ |
{ |
1651 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1652 |
|
|
1653 |
if (priv->overlay) |
if (priv->controls.surface) |
1654 |
cairo_surface_destroy(priv->overlay); |
cairo_surface_destroy(priv->controls.surface); |
1655 |
|
|
1656 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1657 |
if(priv->handler_id) |
if(priv->source_sel.handler_id) |
1658 |
gtk_timeout_remove(priv->handler_id); |
gtk_timeout_remove(priv->source_sel.handler_id); |
1659 |
|
|
1660 |
if (priv->map_source) |
if (priv->source_sel.surface) |
1661 |
cairo_surface_destroy(priv->map_source); |
cairo_surface_destroy(priv->source_sel.surface); |
1662 |
#endif |
#endif |
1663 |
|
|
1664 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1665 |
if (priv->scale) |
if (priv->scale.surface) |
1666 |
cairo_surface_destroy(priv->scale); |
cairo_surface_destroy(priv->scale.surface); |
1667 |
#endif |
#endif |
1668 |
|
|
1669 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
1670 |
if (priv->crosshair) |
if (priv->crosshair.surface) |
1671 |
cairo_surface_destroy(priv->crosshair); |
cairo_surface_destroy(priv->crosshair.surface); |
1672 |
#endif |
#endif |
1673 |
|
|
1674 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1675 |
if (priv->coordinates) |
if (priv->coordinates.surface) |
1676 |
cairo_surface_destroy(priv->coordinates); |
cairo_surface_destroy(priv->coordinates.surface); |
1677 |
|
#endif |
1678 |
|
|
1679 |
|
#ifdef OSD_BALLOON |
1680 |
|
if (priv->balloon.surface) |
1681 |
|
cairo_surface_destroy(priv->balloon.surface); |
1682 |
#endif |
#endif |
1683 |
|
|
1684 |
g_free(priv); |
g_free(priv); |
1689 |
{ |
{ |
1690 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1691 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1692 |
return (priv->handler_id != 0); |
return (priv->source_sel.handler_id != 0); |
1693 |
#else |
#else |
1694 |
return FALSE; |
return FALSE; |
1695 |
#endif |
#endif |
1716 |
{ |
{ |
1717 |
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); |
1718 |
|
|
1719 |
|
#ifdef OSD_BALLOON |
1720 |
|
priv->balloon.lat = OSM_GPS_MAP_INVALID; |
1721 |
|
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
1722 |
|
#endif |
1723 |
|
|
1724 |
osd_classic.priv = priv; |
osd_classic.priv = priv; |
1725 |
|
|
1726 |
osm_gps_map_register_osd(map, &osd_classic); |
osm_gps_map_register_osd(map, &osd_classic); |