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 |
|
|
38 |
//the osd controls |
//the osd controls |
46 |
#endif |
#endif |
47 |
} controls; |
} 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 |
|
int orientation, offset_x, offset_y; |
54 |
|
|
55 |
|
gboolean just_created; |
56 |
|
float lat, lon; |
57 |
|
OsmGpsMapRect_t rect; |
58 |
|
|
59 |
|
/* function called to have the user app draw the contents */ |
60 |
|
OsmGpsMapBalloonCallback cb; |
61 |
|
gpointer data; |
62 |
|
} balloon; |
63 |
#endif |
#endif |
64 |
|
|
65 |
|
#ifdef OSD_SCALE |
66 |
|
struct { |
67 |
|
cairo_surface_t *surface; |
68 |
|
int zoom; |
69 |
|
} scale; |
70 |
|
#endif |
71 |
|
|
72 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
73 |
cairo_surface_t *crosshair; |
struct { |
74 |
|
cairo_surface_t *surface; |
75 |
|
gboolean rendered; |
76 |
|
} crosshair; |
77 |
#endif |
#endif |
78 |
|
|
79 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
80 |
cairo_surface_t *coordinates; |
struct { |
81 |
float coo_lat, coo_lon; |
cairo_surface_t *surface; |
82 |
|
float lat, lon; |
83 |
|
} coordinates; |
84 |
#endif |
#endif |
85 |
|
|
86 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
87 |
/* values to handle the "source" menu */ |
struct { |
88 |
cairo_surface_t *map_source; |
/* values to handle the "source" menu */ |
89 |
gboolean expanded; |
cairo_surface_t *surface; |
90 |
gint shift, dir, count; |
gboolean expanded; |
91 |
gint handler_id; |
gint shift, dir, count; |
92 |
gint width, height; |
gint handler_id; |
93 |
|
gint width, height; |
94 |
|
gboolean rendered; |
95 |
|
} source_sel; |
96 |
#endif |
#endif |
97 |
|
|
98 |
} osd_priv_t; |
} osd_priv_t; |
99 |
|
|
100 |
|
#ifdef OSD_BALLOON |
101 |
|
/* most visual effects are hardcoded by now, but may be made */ |
102 |
|
/* available via properties later */ |
103 |
|
#ifndef BALLOON_AREA_WIDTH |
104 |
|
#define BALLOON_AREA_WIDTH 290 |
105 |
|
#endif |
106 |
|
#ifndef BALLOON_AREA_HEIGHT |
107 |
|
#define BALLOON_AREA_HEIGHT 75 |
108 |
|
#endif |
109 |
|
#ifndef BALLOON_CORNER_RADIUS |
110 |
|
#define BALLOON_CORNER_RADIUS 10 |
111 |
|
#endif |
112 |
|
|
113 |
|
#define BALLOON_BORDER (BALLOON_CORNER_RADIUS/2) |
114 |
|
#define BALLOON_WIDTH (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER) |
115 |
|
#define BALLOON_HEIGHT (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER) |
116 |
|
#define BALLOON_TRANSPARENCY 0.8 |
117 |
|
#define POINTER_HEIGHT 20 |
118 |
|
#define POINTER_FOOT_WIDTH 20 |
119 |
|
#define POINTER_OFFSET (BALLOON_CORNER_RADIUS*3/4) |
120 |
|
#define BALLOON_SHADOW (BALLOON_CORNER_RADIUS/2) |
121 |
|
#define BALLOON_SHADOW_TRANSPARENCY 0.2 |
122 |
|
|
123 |
|
#define BALLOON_W (BALLOON_WIDTH + BALLOON_SHADOW) |
124 |
|
#define BALLOON_H (BALLOON_HEIGHT + POINTER_HEIGHT + BALLOON_SHADOW) |
125 |
|
|
126 |
|
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) |
127 |
|
|
128 |
|
|
129 |
|
/* draw the bubble shape. this is used twice, once for the shape and once */ |
130 |
|
/* for the shadow */ |
131 |
|
static void |
132 |
|
osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1, |
133 |
|
gboolean bottom, int px, int py, int px0, int px1) { |
134 |
|
|
135 |
|
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
136 |
|
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
137 |
|
BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2); |
138 |
|
if(!bottom) { |
139 |
|
/* insert top pointer */ |
140 |
|
cairo_line_to (cr, px1, y0); |
141 |
|
cairo_line_to (cr, px, py); |
142 |
|
cairo_line_to (cr, px0, y0); |
143 |
|
} |
144 |
|
|
145 |
|
cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0); |
146 |
|
cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
147 |
|
BALLOON_CORNER_RADIUS, -M_PI/2, 0); |
148 |
|
cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS); |
149 |
|
cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, |
150 |
|
BALLOON_CORNER_RADIUS, 0, M_PI/2); |
151 |
|
if(bottom) { |
152 |
|
/* insert bottom pointer */ |
153 |
|
cairo_line_to (cr, px0, y1); |
154 |
|
cairo_line_to (cr, px, py); |
155 |
|
cairo_line_to (cr, px1, y1); |
156 |
|
} |
157 |
|
|
158 |
|
cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1); |
159 |
|
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, |
160 |
|
BALLOON_CORNER_RADIUS, M_PI/2, M_PI); |
161 |
|
|
162 |
|
cairo_close_path (cr); |
163 |
|
} |
164 |
|
|
165 |
|
static void |
166 |
|
osd_render_balloon(osm_gps_map_osd_t *osd) { |
167 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
168 |
|
|
169 |
|
/* get zoom */ |
170 |
|
gint zoom; |
171 |
|
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
172 |
|
|
173 |
|
/* ------- convert given coordinate into screen position --------- */ |
174 |
|
gint xs, ys; |
175 |
|
osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
176 |
|
priv->balloon.lat, priv->balloon.lon, |
177 |
|
&xs, &ys); |
178 |
|
|
179 |
|
gint x0 = 1, y0 = 1; |
180 |
|
|
181 |
|
/* check position of this relative to screen center to determine */ |
182 |
|
/* pointer direction ... */ |
183 |
|
int pointer_x, pointer_x0, pointer_x1; |
184 |
|
int pointer_y; |
185 |
|
|
186 |
|
/* ... and calculate position */ |
187 |
|
int orientation = 0; |
188 |
|
if(xs > osd->widget->allocation.width/2) { |
189 |
|
priv->balloon.offset_x = -BALLOON_WIDTH + POINTER_OFFSET; |
190 |
|
pointer_x = x0 - priv->balloon.offset_x; |
191 |
|
pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
192 |
|
pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH; |
193 |
|
orientation |= 1; |
194 |
|
} else { |
195 |
|
priv->balloon.offset_x = -POINTER_OFFSET; |
196 |
|
pointer_x = x0 - priv->balloon.offset_x; |
197 |
|
pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET); |
198 |
|
pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH; |
199 |
|
} |
200 |
|
|
201 |
|
gboolean bottom = FALSE; |
202 |
|
if(ys > osd->widget->allocation.height/2) { |
203 |
|
priv->balloon.offset_y = -BALLOON_HEIGHT - POINTER_HEIGHT; |
204 |
|
pointer_y = y0 - priv->balloon.offset_y; |
205 |
|
bottom = TRUE; |
206 |
|
orientation |= 2; |
207 |
|
} else { |
208 |
|
priv->balloon.offset_y = 0; |
209 |
|
pointer_y = y0 - priv->balloon.offset_y; |
210 |
|
y0 += POINTER_HEIGHT; |
211 |
|
} |
212 |
|
|
213 |
|
/* if required orientation equals current one, then don't render */ |
214 |
|
/* anything */ |
215 |
|
if(orientation == priv->balloon.orientation) |
216 |
|
return; |
217 |
|
|
218 |
|
priv->balloon.orientation = orientation; |
219 |
|
|
220 |
|
/* calculate bottom/right of box */ |
221 |
|
int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT; |
222 |
|
|
223 |
|
/* save balloon screen coordinates for later use */ |
224 |
|
priv->balloon.rect.x = x0 + BALLOON_BORDER; |
225 |
|
priv->balloon.rect.y = y0 + BALLOON_BORDER; |
226 |
|
priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER; |
227 |
|
priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; |
228 |
|
|
229 |
|
cairo_t *cr = cairo_create(priv->balloon.surface); |
230 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
231 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
232 |
|
cairo_paint(cr); |
233 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
234 |
|
|
235 |
|
/* --------- draw shadow --------------- */ |
236 |
|
osm_gps_map_draw_balloon_shape (cr, |
237 |
|
x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW, |
238 |
|
x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW, |
239 |
|
bottom, pointer_x, pointer_y, |
240 |
|
pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW); |
241 |
|
|
242 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY); |
243 |
|
cairo_fill_preserve (cr); |
244 |
|
cairo_set_source_rgba (cr, 1, 0, 0, 1.0); |
245 |
|
cairo_set_line_width (cr, 0); |
246 |
|
cairo_stroke (cr); |
247 |
|
|
248 |
|
/* --------- draw main shape ----------- */ |
249 |
|
osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1, |
250 |
|
bottom, pointer_x, pointer_y, pointer_x0, pointer_x1); |
251 |
|
|
252 |
|
cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY); |
253 |
|
cairo_fill_preserve (cr); |
254 |
|
cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY); |
255 |
|
cairo_set_line_width (cr, 1); |
256 |
|
cairo_stroke (cr); |
257 |
|
|
258 |
|
if (priv->balloon.cb) { |
259 |
|
/* clip in case application tries to draw in */ |
260 |
|
/* exceed of the balloon */ |
261 |
|
cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y, |
262 |
|
priv->balloon.rect.w, priv->balloon.rect.h); |
263 |
|
cairo_clip (cr); |
264 |
|
cairo_new_path (cr); /* current path is not |
265 |
|
consumed by cairo_clip() */ |
266 |
|
|
267 |
|
priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data); |
268 |
|
} |
269 |
|
|
270 |
|
cairo_destroy(cr); |
271 |
|
} |
272 |
|
|
273 |
|
/* return true if balloon is being displayed and if */ |
274 |
|
/* the given coordinate is within this balloon */ |
275 |
|
static gboolean |
276 |
|
osd_balloon_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) |
277 |
|
{ |
278 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
279 |
|
|
280 |
|
if(!priv->balloon.surface) |
281 |
|
return FALSE; |
282 |
|
|
283 |
|
gint xs, ys; |
284 |
|
osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
285 |
|
priv->balloon.lat, priv->balloon.lon, |
286 |
|
&xs, &ys); |
287 |
|
|
288 |
|
xs += priv->balloon.rect.x + priv->balloon.offset_x; |
289 |
|
ys += priv->balloon.rect.y + priv->balloon.offset_y; |
290 |
|
|
291 |
|
/* handle the fact that the balloon may have been created by the */ |
292 |
|
/* button down event */ |
293 |
|
|
294 |
|
gboolean is_in = |
295 |
|
(x > xs) && (x < xs + priv->balloon.rect.w) && |
296 |
|
(y > ys) && (y < ys + priv->balloon.rect.h); |
297 |
|
|
298 |
|
if(!is_in && !down && !priv->balloon.just_created) { |
299 |
|
/* the user actually clicked outside the balloon */ |
300 |
|
|
301 |
|
/* close the balloon! */ |
302 |
|
osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget)); |
303 |
|
} |
304 |
|
|
305 |
|
return is_in; |
306 |
|
} |
307 |
|
|
308 |
|
void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) { |
309 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
310 |
|
|
311 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
312 |
|
g_return_if_fail (osd); |
313 |
|
|
314 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
315 |
|
g_return_if_fail (priv); |
316 |
|
|
317 |
|
if(priv->balloon.surface) { |
318 |
|
cairo_surface_destroy(priv->balloon.surface); |
319 |
|
priv->balloon.surface = NULL; |
320 |
|
priv->balloon.lat = OSM_GPS_MAP_INVALID; |
321 |
|
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
322 |
|
} |
323 |
|
osm_gps_map_redraw(map); |
324 |
|
} |
325 |
|
|
326 |
|
void |
327 |
|
osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
328 |
|
OsmGpsMapBalloonCallback cb, gpointer data) { |
329 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
330 |
|
|
331 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
332 |
|
g_return_if_fail (osd); |
333 |
|
|
334 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
335 |
|
g_return_if_fail (priv); |
336 |
|
|
337 |
|
osm_gps_map_osd_clear_balloon (map); |
338 |
|
|
339 |
|
/* allocate balloon surface */ |
340 |
|
priv->balloon.surface = |
341 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
342 |
|
BALLOON_W+2, BALLOON_H+2); |
343 |
|
|
344 |
|
priv->balloon.lat = latitude; |
345 |
|
priv->balloon.lon = longitude; |
346 |
|
priv->balloon.cb = cb; |
347 |
|
priv->balloon.data = data; |
348 |
|
priv->balloon.just_created = TRUE; |
349 |
|
|
350 |
|
priv->balloon.orientation = -1; |
351 |
|
|
352 |
|
osd_render_balloon(osd); |
353 |
|
|
354 |
|
osm_gps_map_redraw(map); |
355 |
|
} |
356 |
|
|
357 |
|
#endif // OSD_BALLOON |
358 |
|
|
359 |
/* position and extent of bounding box */ |
/* position and extent of bounding box */ |
360 |
#ifndef OSD_X |
#ifndef OSD_X |
361 |
#define OSD_X (10) |
#define OSD_X (10) |
578 |
#define OSD_S_H (OSD_S_PH + OSD_SHADOW) |
#define OSD_S_H (OSD_S_PH + OSD_SHADOW) |
579 |
|
|
580 |
/* size of usable area when expanded */ |
/* size of usable area when expanded */ |
581 |
#define OSD_S_AREA_W (priv->width) |
#define OSD_S_AREA_W (priv->source_sel.width) |
582 |
#define OSD_S_AREA_H (priv->height) |
#define OSD_S_AREA_H (priv->source_sel.height) |
583 |
#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) |
584 |
#define OSD_S_EXP_H (OSD_S_AREA_H + OSD_SHADOW) |
#define OSD_S_EXP_H (OSD_S_AREA_H + OSD_SHADOW) |
585 |
|
|
595 |
/* or the entire menu incl. the puller (expanded) */ |
/* or the entire menu incl. the puller (expanded) */ |
596 |
static void |
static void |
597 |
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) { |
598 |
if(!priv->expanded) { |
if(!priv->source_sel.expanded) { |
599 |
/* just draw the puller */ |
/* just draw the puller */ |
600 |
cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH); |
cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH); |
601 |
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); |
623 |
|
|
624 |
int py = offset + OSD_S_RAD - OSD_S_D0; |
int py = offset + OSD_S_RAD - OSD_S_D0; |
625 |
|
|
626 |
if(!priv->expanded) { |
if(!priv->source_sel.expanded) { |
627 |
/* draw the "puller" open (<) arrow */ |
/* draw the "puller" open (<) arrow */ |
628 |
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); |
629 |
cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); |
cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); |
648 |
CAIRO_FONT_WEIGHT_BOLD); |
CAIRO_FONT_WEIGHT_BOLD); |
649 |
cairo_set_font_size (cr, OSD_FONT_SIZE); |
cairo_set_font_size (cr, OSD_FONT_SIZE); |
650 |
|
|
651 |
int i, step = (priv->height - 2*OSD_TEXT_BORDER) / |
int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) / |
652 |
OSM_GPS_MAP_SOURCE_LAST; |
OSM_GPS_MAP_SOURCE_LAST; |
653 |
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++) { |
654 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
662 |
if(source == i) { |
if(source == i) { |
663 |
cairo_rectangle(cr, x - OSD_TEXT_BORDER/2, |
cairo_rectangle(cr, x - OSD_TEXT_BORDER/2, |
664 |
y - OSD_TEXT_SKIP, |
y - OSD_TEXT_SKIP, |
665 |
priv->width - OSD_TEXT_BORDER, |
priv->source_sel.width - OSD_TEXT_BORDER, |
666 |
step + OSD_TEXT_SKIP); |
step + OSD_TEXT_SKIP); |
667 |
cairo_fill(cr); |
cairo_fill(cr); |
668 |
|
|
693 |
} |
} |
694 |
|
|
695 |
static void |
static void |
696 |
osd_render_source_sel(osm_gps_map_osd_t *osd) { |
osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) { |
697 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
698 |
|
|
699 |
|
if(priv->source_sel.rendered && !force_rerender) |
700 |
|
return; |
701 |
|
|
702 |
|
priv->source_sel.rendered = TRUE; |
703 |
|
|
704 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
705 |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
706 |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
708 |
#endif |
#endif |
709 |
|
|
710 |
/* draw source selector */ |
/* draw source selector */ |
711 |
cairo_t *cr = cairo_create(priv->map_source); |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
712 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
713 |
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); |
714 |
cairo_paint(cr); |
cairo_paint(cr); |
749 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
750 |
|
|
751 |
/* re-allocate offscreen bitmap */ |
/* re-allocate offscreen bitmap */ |
752 |
g_assert (priv->map_source); |
g_assert (priv->source_sel.surface); |
753 |
|
|
754 |
int w = OSD_S_W, h = OSD_S_H; |
int w = OSD_S_W, h = OSD_S_H; |
755 |
if(priv->expanded) { |
if(priv->source_sel.expanded) { |
756 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
757 |
|
|
758 |
/* determine content size */ |
/* determine content size */ |
759 |
cairo_t *cr = cairo_create(priv->map_source); |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
760 |
cairo_select_font_face (cr, "Sans", |
cairo_select_font_face (cr, "Sans", |
761 |
CAIRO_FONT_SLANT_NORMAL, |
CAIRO_FONT_SLANT_NORMAL, |
762 |
CAIRO_FONT_WEIGHT_BOLD); |
CAIRO_FONT_WEIGHT_BOLD); |
773 |
} |
} |
774 |
cairo_destroy(cr); |
cairo_destroy(cr); |
775 |
|
|
776 |
priv->width = max_w + 2*OSD_TEXT_BORDER; |
priv->source_sel.width = max_w + 2*OSD_TEXT_BORDER; |
777 |
priv->height = OSM_GPS_MAP_SOURCE_LAST * |
priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST * |
778 |
(max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER; |
(max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER; |
779 |
|
|
780 |
w = OSD_S_EXP_W; |
w = OSD_S_EXP_W; |
781 |
h = OSD_S_EXP_H; |
h = OSD_S_EXP_H; |
782 |
} |
} |
783 |
|
|
784 |
cairo_surface_destroy(priv->map_source); |
cairo_surface_destroy(priv->source_sel.surface); |
785 |
priv->map_source = |
priv->source_sel.surface = |
786 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
787 |
|
|
788 |
osd_render_source_sel(osd); |
osd_render_source_sel(osd, TRUE); |
789 |
} |
} |
790 |
|
|
791 |
#define OSD_HZ 15 |
#define OSD_HZ 15 |
796 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
797 |
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
798 |
gboolean done = FALSE; |
gboolean done = FALSE; |
799 |
priv->count += priv->dir; |
priv->source_sel.count += priv->source_sel.dir; |
800 |
|
|
801 |
/* shifting in */ |
/* shifting in */ |
802 |
if(priv->dir < 0) { |
if(priv->source_sel.dir < 0) { |
803 |
if(priv->count <= 0) { |
if(priv->source_sel.count <= 0) { |
804 |
priv->count = 0; |
priv->source_sel.count = 0; |
805 |
done = TRUE; |
done = TRUE; |
806 |
} |
} |
807 |
} else { |
} else { |
808 |
if(priv->count >= 1000) { |
if(priv->source_sel.count >= 1000) { |
809 |
priv->expanded = FALSE; |
priv->source_sel.expanded = FALSE; |
810 |
osd_source_reallocate(osd); |
osd_source_reallocate(osd); |
811 |
|
|
812 |
priv->count = 1000; |
priv->source_sel.count = 1000; |
813 |
done = TRUE; |
done = TRUE; |
814 |
} |
} |
815 |
} |
} |
817 |
|
|
818 |
/* 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 */ |
819 |
|
|
820 |
/* nicer sinoid mapping */ |
/* nice sinoid mapping */ |
821 |
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; |
822 |
priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
priv->source_sel.shift = |
823 |
|
(osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
824 |
m * diff; |
m * diff; |
825 |
|
|
826 |
|
/* make sure the screen is updated */ |
827 |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
828 |
|
|
829 |
|
/* stop animation if done */ |
830 |
if(done) |
if(done) |
831 |
priv->handler_id = 0; |
priv->source_sel.handler_id = 0; |
832 |
|
|
833 |
return !done; |
return !done; |
834 |
} |
} |
840 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
841 |
|
|
842 |
/* ignore clicks while animation is running */ |
/* ignore clicks while animation is running */ |
843 |
if(priv->handler_id) |
if(priv->source_sel.handler_id) |
844 |
return; |
return; |
845 |
|
|
846 |
/* expand immediately, collapse is handle at the end of the collapse animation */ |
/* expand immediately, collapse is handle at the end of the */ |
847 |
if(!priv->expanded) { |
/* collapse animation */ |
848 |
priv->expanded = TRUE; |
if(!priv->source_sel.expanded) { |
849 |
|
priv->source_sel.expanded = TRUE; |
850 |
osd_source_reallocate(osd); |
osd_source_reallocate(osd); |
851 |
|
|
852 |
priv->count = 1000; |
priv->source_sel.count = 1000; |
853 |
priv->shift = osd->widget->allocation.width - OSD_S_W; |
priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W; |
854 |
priv->dir = -1000/OSD_HZ; |
priv->source_sel.dir = -1000/OSD_HZ; |
855 |
} else { |
} else { |
856 |
priv->count = 0; |
priv->source_sel.count = 0; |
857 |
priv->shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
priv->source_sel.shift = osd->widget->allocation.width - |
858 |
priv->dir = +1000/OSD_HZ; |
OSD_S_EXP_W + OSD_S_X; |
859 |
|
priv->source_sel.dir = +1000/OSD_HZ; |
860 |
} |
} |
861 |
|
|
862 |
priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd); |
/* start timer to handle animation */ |
863 |
|
priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, |
864 |
|
osd_source_animate, osd); |
865 |
} |
} |
866 |
|
|
867 |
/* check if the user clicked inside the source selection area */ |
/* check if the user clicked inside the source selection area */ |
868 |
static osd_button_t |
static osd_button_t |
869 |
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) { |
870 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
871 |
|
|
872 |
if(!priv->expanded) |
if(!priv->source_sel.expanded) |
873 |
x -= osd->widget->allocation.width - OSD_S_W; |
x -= osd->widget->allocation.width - OSD_S_W; |
874 |
else |
else |
875 |
x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
884 |
/* really within puller shape? */ |
/* really within puller shape? */ |
885 |
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)) { |
886 |
/* expand source selector */ |
/* expand source selector */ |
887 |
osd_source_toggle(osd); |
if(down) |
888 |
|
osd_source_toggle(osd); |
889 |
|
|
890 |
/* tell upper layers that user clicked some background element */ |
/* tell upper layers that user clicked some background element */ |
891 |
/* of the OSD */ |
/* of the OSD */ |
894 |
} |
} |
895 |
|
|
896 |
/* check for clicks into data area */ |
/* check for clicks into data area */ |
897 |
if(priv->expanded && !priv->handler_id) { |
if(priv->source_sel.expanded && !priv->source_sel.handler_id) { |
898 |
/* re-adjust from puller top to content top */ |
/* re-adjust from puller top to content top */ |
899 |
if(OSD_S_Y < 0) |
if(OSD_S_Y < 0) |
900 |
y += OSD_S_EXP_H - OSD_S_PH; |
y += OSD_S_EXP_H - OSD_S_PH; |
904 |
y > 0 && |
y > 0 && |
905 |
y < OSD_S_EXP_H) { |
y < OSD_S_EXP_H) { |
906 |
|
|
907 |
int step = (priv->height - 2*OSD_TEXT_BORDER) |
int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) |
908 |
/ OSM_GPS_MAP_SOURCE_LAST; |
/ OSM_GPS_MAP_SOURCE_LAST; |
909 |
|
|
910 |
y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP; |
y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP; |
911 |
y /= step; |
y /= step; |
912 |
y += 1; |
y += 1; |
913 |
|
|
914 |
gint old = 0; |
if(down) { |
915 |
g_object_get(osd->widget, "map-source", &old, NULL); |
gint old = 0; |
916 |
|
g_object_get(osd->widget, "map-source", &old, NULL); |
917 |
if(y > OSM_GPS_MAP_SOURCE_NULL && |
|
918 |
y <= OSM_GPS_MAP_SOURCE_LAST && |
if(y > OSM_GPS_MAP_SOURCE_NULL && |
919 |
old != y) { |
y <= OSM_GPS_MAP_SOURCE_LAST && |
920 |
g_object_set(osd->widget, "map-source", y, NULL); |
old != y) { |
921 |
|
g_object_set(osd->widget, "map-source", y, NULL); |
922 |
osd_render_source_sel(osd); |
|
923 |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
osd_render_source_sel(osd, TRUE); |
924 |
|
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
925 |
|
} |
926 |
} |
} |
927 |
|
|
928 |
/* return "clicked in OSD background" to prevent further */ |
/* return "clicked in OSD background" to prevent further */ |
936 |
#endif // OSD_SOURCE_SEL |
#endif // OSD_SOURCE_SEL |
937 |
|
|
938 |
static osd_button_t |
static osd_button_t |
939 |
osd_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
940 |
osd_button_t but = OSD_NONE; |
osd_button_t but = OSD_NONE; |
941 |
|
|
942 |
|
#ifdef OSD_BALLOON |
943 |
|
if(down) { |
944 |
|
/* needed to handle balloons that are created at click */ |
945 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
946 |
|
priv->balloon.just_created = FALSE; |
947 |
|
} |
948 |
|
#endif |
949 |
|
|
950 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
951 |
/* the source selection area is handles internally */ |
/* the source selection area is handles internally */ |
952 |
but = osd_source_check(osd, x, y); |
but = osd_source_check(osd, down, x, y); |
|
if(but != OSD_NONE) |
|
|
return but; |
|
953 |
#endif |
#endif |
954 |
|
|
955 |
x -= OSD_X; |
if(but == OSD_NONE) { |
956 |
y -= OSD_Y; |
x -= OSD_X; |
957 |
|
y -= OSD_Y; |
958 |
if(OSD_X < 0) |
|
959 |
x -= (osd->widget->allocation.width - OSD_W); |
if(OSD_X < 0) |
960 |
|
x -= (osd->widget->allocation.width - OSD_W); |
961 |
if(OSD_Y < 0) |
|
962 |
y -= (osd->widget->allocation.height - OSD_H); |
if(OSD_Y < 0) |
963 |
|
y -= (osd->widget->allocation.height - OSD_H); |
964 |
/* first do a rough test for the OSD area. */ |
|
965 |
/* this is just to avoid an unnecessary detailed test */ |
/* first do a rough test for the OSD area. */ |
966 |
if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) { |
/* this is just to avoid an unnecessary detailed test */ |
967 |
|
if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) { |
968 |
#ifndef OSD_NO_DPAD |
#ifndef OSD_NO_DPAD |
969 |
but = osd_check_dpad(x, y); |
but = osd_check_dpad(x, y); |
970 |
#endif |
#endif |
971 |
|
} |
972 |
|
|
973 |
if(but == OSD_NONE) |
if(but == OSD_NONE) |
974 |
but = osd_check_zoom(x, y); |
but = osd_check_zoom(x, y); |
975 |
} |
} |
976 |
|
|
977 |
|
#ifdef OSD_BALLOON |
978 |
|
if(but == OSD_NONE) { |
979 |
|
/* check if user clicked into balloon */ |
980 |
|
if(osd_balloon_check(osd, down, x, y)) |
981 |
|
but = OSD_BG; |
982 |
|
} |
983 |
|
#endif |
984 |
|
|
985 |
return but; |
return but; |
986 |
} |
} |
987 |
|
|
1132 |
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
1133 |
|
|
1134 |
/* check if position has changed enough to require redraw */ |
/* check if position has changed enough to require redraw */ |
1135 |
if(!isnan(priv->coo_lat) && !isnan(priv->coo_lon)) |
if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon)) |
1136 |
if((fabsf(lat - priv->coo_lat) < 1/60000) && /* 1/60000 == 1/1000 minute */ |
/* 1/60000 == 1/1000 minute */ |
1137 |
(fabsf(lon - priv->coo_lon) < 1/60000)) |
if((fabsf(lat - priv->coordinates.lat) < 1/60000) && |
1138 |
|
(fabsf(lon - priv->coordinates.lon) < 1/60000)) |
1139 |
return; |
return; |
1140 |
|
|
1141 |
priv->coo_lat = lat; |
priv->coordinates.lat = lat; |
1142 |
priv->coo_lon = lon; |
priv->coordinates.lon = lon; |
1143 |
|
|
1144 |
/* first fill with light transparency */ |
/* first fill with transparency */ |
1145 |
cairo_t *cr = cairo_create(priv->coordinates); |
cairo_t *cr = cairo_create(priv->coordinates.surface); |
1146 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1147 |
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); |
// cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); |
1148 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
1149 |
cairo_paint(cr); |
cairo_paint(cr); |
1150 |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1151 |
|
|
1230 |
{ |
{ |
1231 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1232 |
|
|
1233 |
|
if(priv->crosshair.rendered) |
1234 |
|
return; |
1235 |
|
|
1236 |
|
priv->crosshair.rendered = TRUE; |
1237 |
|
|
1238 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1239 |
cairo_t *cr = cairo_create(priv->crosshair); |
cairo_t *cr = cairo_create(priv->crosshair.surface); |
1240 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1241 |
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); |
|
1242 |
cairo_paint(cr); |
cairo_paint(cr); |
1243 |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1244 |
|
|
1279 |
/* this only needs to be rendered if the zoom has changed */ |
/* this only needs to be rendered if the zoom has changed */ |
1280 |
gint zoom; |
gint zoom; |
1281 |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
1282 |
if(zoom == priv->scale_zoom) |
if(zoom == priv->scale.zoom) |
1283 |
return; |
return; |
1284 |
|
|
1285 |
priv->scale_zoom = zoom; |
priv->scale.zoom = zoom; |
1286 |
|
|
1287 |
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)); |
1288 |
|
|
1289 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1290 |
cairo_t *cr = cairo_create(priv->scale); |
cairo_t *cr = cairo_create(priv->scale.surface); |
1291 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1292 |
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); |
1293 |
// 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); |
1415 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
1416 |
priv->controls.gps_enabled = (osd->cb != NULL); |
priv->controls.gps_enabled = (osd->cb != NULL); |
1417 |
#endif |
#endif |
1418 |
|
priv->controls.rendered = TRUE; |
1419 |
|
|
1420 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
1421 |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
1500 |
static void |
static void |
1501 |
osd_render(osm_gps_map_osd_t *osd) |
osd_render(osm_gps_map_osd_t *osd) |
1502 |
{ |
{ |
1503 |
|
/* this function is actually called pretty often since the */ |
1504 |
|
/* OSD contents may have changed (due to a coordinate/zoom change). */ |
1505 |
|
/* The different OSD parts have to make sure that they don't */ |
1506 |
|
/* render unneccessarily often and thus waste CPU power */ |
1507 |
|
|
1508 |
osd_render_controls(osd); |
osd_render_controls(osd); |
1509 |
|
|
1510 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1511 |
osd_render_source_sel(osd); |
osd_render_source_sel(osd, FALSE); |
1512 |
#endif |
#endif |
1513 |
|
|
1514 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1543 |
|
|
1544 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1545 |
/* the initial OSD state is alway not-expanded */ |
/* the initial OSD state is alway not-expanded */ |
1546 |
priv->map_source = |
priv->source_sel.surface = |
1547 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1548 |
OSD_S_W+2, OSD_S_H+2); |
OSD_S_W+2, OSD_S_H+2); |
1549 |
|
priv->source_sel.rendered = FALSE; |
1550 |
#endif |
#endif |
1551 |
|
|
1552 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1553 |
priv->scale = |
priv->scale.surface = |
1554 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1555 |
OSD_SCALE_W, OSD_SCALE_H); |
OSD_SCALE_W, OSD_SCALE_H); |
1556 |
priv->scale_zoom = -1; |
priv->scale.zoom = -1; |
1557 |
#endif |
#endif |
1558 |
|
|
1559 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
1560 |
priv->crosshair = |
priv->crosshair.surface = |
1561 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1562 |
OSD_CROSSHAIR_W, OSD_CROSSHAIR_H); |
OSD_CROSSHAIR_W, OSD_CROSSHAIR_H); |
1563 |
|
priv->crosshair.rendered = FALSE; |
1564 |
#endif |
#endif |
1565 |
|
|
1566 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1567 |
priv->coordinates = |
priv->coordinates.surface = |
1568 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1569 |
OSD_COORDINATES_W, OSD_COORDINATES_H); |
OSD_COORDINATES_W, OSD_COORDINATES_H); |
1570 |
|
|
1571 |
priv->coo_lat = priv->coo_lon = OSM_GPS_MAP_INVALID; |
priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID; |
1572 |
#endif |
#endif |
1573 |
|
|
1574 |
/* ... and render it */ |
/* ... and render it */ |
1578 |
// now draw this onto the original context |
// now draw this onto the original context |
1579 |
cairo_t *cr = gdk_cairo_create(drawable); |
cairo_t *cr = gdk_cairo_create(drawable); |
1580 |
|
|
1581 |
int x, y; |
gint x, y; |
1582 |
|
|
1583 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1584 |
x = OSD_X; |
x = OSD_X; |
1586 |
if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W; |
if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W; |
1587 |
if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H; |
if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H; |
1588 |
|
|
1589 |
cairo_set_source_surface(cr, priv->scale, x, y); |
cairo_set_source_surface(cr, priv->scale.surface, x, y); |
1590 |
cairo_paint(cr); |
cairo_paint(cr); |
1591 |
#endif |
#endif |
1592 |
|
|
1594 |
x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2; |
x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2; |
1595 |
y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2; |
y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2; |
1596 |
|
|
1597 |
cairo_set_source_surface(cr, priv->crosshair, x, y); |
cairo_set_source_surface(cr, priv->crosshair.surface, x, y); |
1598 |
cairo_paint(cr); |
cairo_paint(cr); |
1599 |
#endif |
#endif |
1600 |
|
|
1604 |
if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W; |
if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W; |
1605 |
if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H; |
if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H; |
1606 |
|
|
1607 |
cairo_set_source_surface(cr, priv->coordinates, x, y); |
cairo_set_source_surface(cr, priv->coordinates.surface, x, y); |
1608 |
cairo_paint(cr); |
cairo_paint(cr); |
1609 |
#endif |
#endif |
1610 |
|
|
1611 |
|
#ifdef OSD_BALLOON |
1612 |
|
if(priv->balloon.surface) { |
1613 |
|
|
1614 |
|
/* convert given lat lon into screen coordinates */ |
1615 |
|
gint x, y; |
1616 |
|
osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget), |
1617 |
|
priv->balloon.lat, priv->balloon.lon, |
1618 |
|
&x, &y); |
1619 |
|
|
1620 |
|
/* check if balloon needs to be rerendered */ |
1621 |
|
osd_render_balloon(osd); |
1622 |
|
|
1623 |
|
cairo_set_source_surface(cr, priv->balloon.surface, |
1624 |
|
x + priv->balloon.offset_x, |
1625 |
|
y + priv->balloon.offset_y); |
1626 |
|
cairo_paint(cr); |
1627 |
|
} |
1628 |
|
#endif |
1629 |
|
|
1630 |
x = OSD_X; |
x = OSD_X; |
1631 |
if(x < 0) |
if(x < 0) |
1632 |
x += osd->widget->allocation.width - OSD_W; |
x += osd->widget->allocation.width - OSD_W; |
1639 |
cairo_paint(cr); |
cairo_paint(cr); |
1640 |
|
|
1641 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1642 |
if(!priv->handler_id) { |
if(!priv->source_sel.handler_id) { |
1643 |
/* the OSD source selection is not being animated */ |
/* the OSD source selection is not being animated */ |
1644 |
if(!priv->expanded) |
if(!priv->source_sel.expanded) |
1645 |
x = osd->widget->allocation.width - OSD_S_W; |
x = osd->widget->allocation.width - OSD_S_W; |
1646 |
else |
else |
1647 |
x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
1648 |
} else |
} else |
1649 |
x = priv->shift; |
x = priv->source_sel.shift; |
1650 |
|
|
1651 |
y = OSD_S_Y; |
y = OSD_S_Y; |
1652 |
if(OSD_S_Y < 0) { |
if(OSD_S_Y < 0) { |
1653 |
if(!priv->expanded) |
if(!priv->source_sel.expanded) |
1654 |
y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y; |
y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y; |
1655 |
else |
else |
1656 |
y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y; |
y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y; |
1657 |
} |
} |
1658 |
|
|
1659 |
cairo_set_source_surface(cr, priv->map_source, x, y); |
cairo_set_source_surface(cr, priv->source_sel.surface, x, y); |
1660 |
cairo_paint(cr); |
cairo_paint(cr); |
1661 |
#endif |
#endif |
1662 |
|
|
1672 |
cairo_surface_destroy(priv->controls.surface); |
cairo_surface_destroy(priv->controls.surface); |
1673 |
|
|
1674 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1675 |
if(priv->handler_id) |
if(priv->source_sel.handler_id) |
1676 |
gtk_timeout_remove(priv->handler_id); |
gtk_timeout_remove(priv->source_sel.handler_id); |
1677 |
|
|
1678 |
if (priv->map_source) |
if (priv->source_sel.surface) |
1679 |
cairo_surface_destroy(priv->map_source); |
cairo_surface_destroy(priv->source_sel.surface); |
1680 |
#endif |
#endif |
1681 |
|
|
1682 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1683 |
if (priv->scale) |
if (priv->scale.surface) |
1684 |
cairo_surface_destroy(priv->scale); |
cairo_surface_destroy(priv->scale.surface); |
1685 |
#endif |
#endif |
1686 |
|
|
1687 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
1688 |
if (priv->crosshair) |
if (priv->crosshair.surface) |
1689 |
cairo_surface_destroy(priv->crosshair); |
cairo_surface_destroy(priv->crosshair.surface); |
1690 |
#endif |
#endif |
1691 |
|
|
1692 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1693 |
if (priv->coordinates) |
if (priv->coordinates.surface) |
1694 |
cairo_surface_destroy(priv->coordinates); |
cairo_surface_destroy(priv->coordinates.surface); |
1695 |
|
#endif |
1696 |
|
|
1697 |
|
#ifdef OSD_BALLOON |
1698 |
|
if (priv->balloon.surface) |
1699 |
|
cairo_surface_destroy(priv->balloon.surface); |
1700 |
#endif |
#endif |
1701 |
|
|
1702 |
g_free(priv); |
g_free(priv); |
1707 |
{ |
{ |
1708 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1709 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1710 |
return (priv->handler_id != 0); |
return (priv->source_sel.handler_id != 0); |
1711 |
#else |
#else |
1712 |
return FALSE; |
return FALSE; |
1713 |
#endif |
#endif |
1734 |
{ |
{ |
1735 |
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); |
1736 |
|
|
1737 |
|
#ifdef OSD_BALLOON |
1738 |
|
priv->balloon.lat = OSM_GPS_MAP_INVALID; |
1739 |
|
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
1740 |
|
#endif |
1741 |
|
|
1742 |
osd_classic.priv = priv; |
osd_classic.priv = priv; |
1743 |
|
|
1744 |
osm_gps_map_register_osd(map, &osd_classic); |
osm_gps_map_register_osd(map, &osd_classic); |
1768 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1769 |
g_return_val_if_fail (osd, OSD_NONE); |
g_return_val_if_fail (osd, OSD_NONE); |
1770 |
|
|
1771 |
return osd_check(osd, x, y); |
return osd_check(osd, TRUE, x, y); |
1772 |
} |
} |