19 |
|
|
20 |
#include "config.h" |
#include "config.h" |
21 |
#include <stdlib.h> // abs |
#include <stdlib.h> // abs |
22 |
#include <math.h> // M_PI |
#include <math.h> // M_PI/cos() |
23 |
|
|
24 |
/* parameters that can be overwritten from the config file: */ |
/* parameters that can be overwritten from the config file: */ |
25 |
/* OSM_GPS_MAP_OSD_DIAMETER */ |
/* OSD_DIAMETER */ |
26 |
|
/* OSD_X, OSD_Y */ |
27 |
|
|
28 |
|
#define OSD_SCALE |
29 |
|
|
30 |
|
#define OSD_SCALE_W 100 |
31 |
|
#define OSD_SCALE_H 20 |
32 |
|
|
33 |
#ifndef USE_CAIRO |
#ifndef USE_CAIRO |
34 |
#error "OSD control display lacks a non-cairo implementation!" |
#error "OSD control display lacks a non-cairo implementation!" |
44 |
/* the offscreen representation of the OSD */ |
/* the offscreen representation of the OSD */ |
45 |
cairo_surface_t *overlay; |
cairo_surface_t *overlay; |
46 |
|
|
47 |
GdkColor bg, fg, da; |
#ifdef OSD_SCALE |
48 |
|
cairo_surface_t *scale; |
49 |
|
#endif |
50 |
|
|
51 |
|
#ifdef OSD_SOURCE_SEL |
52 |
|
/* values to handle the "source" menu */ |
53 |
|
cairo_surface_t *map_source; |
54 |
|
gboolean expanded; |
55 |
|
gint shift, dir, count; |
56 |
|
gint handler_id; |
57 |
|
gint width, height; |
58 |
|
#endif |
59 |
|
|
60 |
} osd_priv_t; |
} osd_priv_t; |
61 |
|
|
62 |
/* position and extent of bounding box */ |
/* position and extent of bounding box */ |
63 |
|
#ifndef OSD_X |
64 |
#define OSD_X (10) |
#define OSD_X (10) |
65 |
|
#endif |
66 |
|
|
67 |
|
#ifndef OSD_Y |
68 |
#define OSD_Y (10) |
#define OSD_Y (10) |
69 |
|
#endif |
70 |
|
|
71 |
/* parameters of the direction shape */ |
/* parameters of the direction shape */ |
72 |
#ifndef OSM_GPS_MAP_OSD_DIAMETER |
#ifndef OSD_DIAMETER |
73 |
#define D_RAD (30) // diameter of dpad |
#define D_RAD (30) // diameter of dpad |
74 |
#else |
#else |
75 |
#define D_RAD (OSM_GPS_MAP_OSD_DIAMETER) |
#define D_RAD (OSD_DIAMETER) |
76 |
#endif |
#endif |
77 |
#define D_TIP (4*D_RAD/5) // distance of arrow tip from dpad center |
#define D_TIP (4*D_RAD/5) // distance of arrow tip from dpad center |
78 |
#define D_LEN (D_RAD/4) // length of arrow |
#define D_LEN (D_RAD/4) // length of arrow |
89 |
#define OSD_SHADOW (0) |
#define OSD_SHADOW (0) |
90 |
#endif |
#endif |
91 |
|
|
92 |
|
/* normally the GPS button is in the center of the dpad. if there's */ |
93 |
|
/* no dpad it will go into the zoom area */ |
94 |
|
#if defined(OSD_GPS_BUTTON) && defined(OSD_NO_DPAD) |
95 |
|
#define Z_GPS 1 |
96 |
|
#else |
97 |
|
#define Z_GPS 0 |
98 |
|
#endif |
99 |
|
|
100 |
/* total width and height of controls incl. shadow */ |
/* total width and height of controls incl. shadow */ |
101 |
#define OSD_W (2*D_RAD + OSD_SHADOW) |
#define OSD_W (2*D_RAD + OSD_SHADOW + Z_GPS * 2 * Z_RAD) |
102 |
|
#if !Z_GPS |
103 |
#define OSD_H (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW) |
#define OSD_H (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW) |
104 |
|
#else |
105 |
|
#define OSD_H (2*Z_RAD + OSD_SHADOW) |
106 |
|
#endif |
107 |
|
|
108 |
#ifdef OSD_SHADOW_ENABLE |
#ifdef OSD_SHADOW_ENABLE |
109 |
#define OSD_LBL_SHADOW (OSD_SHADOW/2) |
#define OSD_LBL_SHADOW (OSD_SHADOW/2) |
110 |
#endif |
#endif |
111 |
|
|
112 |
#define Z_TOP (2 * D_RAD + Z_STEP) |
#define Z_TOP ((1-Z_GPS) * (2 * D_RAD + Z_STEP)) |
113 |
|
|
114 |
#define Z_MID (Z_TOP + Z_RAD) |
#define Z_MID (Z_TOP + Z_RAD) |
115 |
#define Z_BOT (Z_MID + Z_RAD) |
#define Z_BOT (Z_MID + Z_RAD) |
116 |
#define Z_LEFT (Z_RAD) |
#define Z_LEFT (Z_RAD) |
117 |
#define Z_RIGHT (2 * D_RAD - Z_RAD) |
#define Z_RIGHT (2 * D_RAD - Z_RAD + Z_GPS * 2 * Z_RAD) |
118 |
|
#define Z_CENTER ((Z_RIGHT + Z_LEFT)/2) |
119 |
|
|
120 |
/* create the cairo shape used for the zoom buttons */ |
/* create the cairo shape used for the zoom buttons */ |
121 |
static void |
static void |
122 |
osm_gps_map_osd_zoom_shape(cairo_t *cr, gint x, gint y) |
osd_zoom_shape(cairo_t *cr, gint x, gint y) |
123 |
{ |
{ |
124 |
cairo_move_to (cr, x+Z_LEFT, y+Z_TOP); |
cairo_move_to (cr, x+Z_LEFT, y+Z_TOP); |
125 |
cairo_line_to (cr, x+Z_RIGHT, y+Z_TOP); |
cairo_line_to (cr, x+Z_RIGHT, y+Z_TOP); |
128 |
cairo_arc (cr, x+Z_LEFT, y+Z_MID, Z_RAD, M_PI/2, -M_PI/2); |
cairo_arc (cr, x+Z_LEFT, y+Z_MID, Z_RAD, M_PI/2, -M_PI/2); |
129 |
} |
} |
130 |
|
|
131 |
|
/* ------------------- color/shadow functions ----------------- */ |
132 |
|
|
133 |
|
#ifndef OSD_COLOR |
134 |
|
/* if no color has been specified we just use the gdks default colors */ |
135 |
|
static void |
136 |
|
osd_labels(cairo_t *cr, gint width, gboolean enabled, |
137 |
|
GdkColor *fg, GdkColor *disabled) { |
138 |
|
if(enabled) gdk_cairo_set_source_color(cr, fg); |
139 |
|
else gdk_cairo_set_source_color(cr, disabled); |
140 |
|
cairo_set_line_width (cr, width); |
141 |
|
} |
142 |
|
#else |
143 |
|
static void |
144 |
|
osd_labels(cairo_t *cr, gint width, gboolean enabled) { |
145 |
|
if(enabled) cairo_set_source_rgb (cr, OSD_COLOR); |
146 |
|
else cairo_set_source_rgb (cr, OSD_COLOR_DISABLED); |
147 |
|
cairo_set_line_width (cr, width); |
148 |
|
} |
149 |
|
#endif |
150 |
|
|
151 |
|
#ifdef OSD_SHADOW_ENABLE |
152 |
|
static void |
153 |
|
osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) { |
154 |
|
cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15); |
155 |
|
cairo_set_line_width (cr, width); |
156 |
|
} |
157 |
|
#endif |
158 |
|
|
159 |
#ifndef OSD_NO_DPAD |
#ifndef OSD_NO_DPAD |
160 |
/* create the cairo shape used for the dpad */ |
/* create the cairo shape used for the dpad */ |
161 |
static void |
static void |
162 |
osm_gps_map_osd_dpad_shape(cairo_t *cr, gint x, gint y) |
osd_dpad_shape(cairo_t *cr, gint x, gint y) |
163 |
{ |
{ |
164 |
cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI); |
cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI); |
165 |
} |
} |
166 |
#endif |
#endif |
167 |
|
|
168 |
|
#ifdef OSD_SHADOW_ENABLE |
169 |
|
static void |
170 |
|
osd_shape_shadow(cairo_t *cr) { |
171 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 0.2); |
172 |
|
cairo_fill (cr); |
173 |
|
cairo_stroke (cr); |
174 |
|
} |
175 |
|
#endif |
176 |
|
|
177 |
|
#ifndef OSD_COLOR |
178 |
|
/* if no color has been specified we just use the gdks default colors */ |
179 |
|
static void |
180 |
|
osd_shape(cairo_t *cr, GdkColor *bg, GdkColor *fg) { |
181 |
|
gdk_cairo_set_source_color(cr, bg); |
182 |
|
cairo_fill_preserve (cr); |
183 |
|
gdk_cairo_set_source_color(cr, fg); |
184 |
|
cairo_set_line_width (cr, 1); |
185 |
|
cairo_stroke (cr); |
186 |
|
} |
187 |
|
#else |
188 |
|
static void |
189 |
|
osd_shape(cairo_t *cr) { |
190 |
|
cairo_set_source_rgb (cr, OSD_COLOR_BG); |
191 |
|
cairo_fill_preserve (cr); |
192 |
|
cairo_set_source_rgb (cr, OSD_COLOR); |
193 |
|
cairo_set_line_width (cr, 1); |
194 |
|
cairo_stroke (cr); |
195 |
|
} |
196 |
|
#endif |
197 |
|
|
198 |
|
|
199 |
static gboolean |
static gboolean |
200 |
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) |
201 |
{ |
{ |
205 |
#ifndef OSD_NO_DPAD |
#ifndef OSD_NO_DPAD |
206 |
/* check whether x/y is within the dpad */ |
/* check whether x/y is within the dpad */ |
207 |
static osd_button_t |
static osd_button_t |
208 |
osm_gps_map_osd_check_dpad(gint x, gint y) |
osd_check_dpad(gint x, gint y) |
209 |
{ |
{ |
210 |
/* within entire dpad circle */ |
/* within entire dpad circle */ |
211 |
if( osm_gps_map_in_circle(x, y, OSD_X + D_RAD, OSD_Y + D_RAD, D_RAD)) |
if( osm_gps_map_in_circle(x, y, D_RAD, D_RAD, D_RAD)) |
212 |
{ |
{ |
213 |
/* convert into position relative to dpads centre */ |
/* convert into position relative to dpads centre */ |
214 |
x -= (OSD_X + D_RAD); |
x -= D_RAD; |
215 |
y -= (OSD_Y + D_RAD); |
y -= D_RAD; |
216 |
|
|
217 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
218 |
/* check for dpad center goes here! */ |
/* check for dpad center goes here! */ |
240 |
|
|
241 |
/* check whether x/y is within the zoom pads */ |
/* check whether x/y is within the zoom pads */ |
242 |
static osd_button_t |
static osd_button_t |
243 |
osm_gps_map_osd_check_zoom(gint x, gint y) { |
osd_check_zoom(gint x, gint y) { |
244 |
if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < (OSD_Y+Z_BOT)) { |
if( x > 0 && x < OSD_W && y > Z_TOP && y < Z_BOT) { |
245 |
|
|
246 |
/* within circle around (-) label */ |
/* within circle around (-) label */ |
247 |
if( osm_gps_map_in_circle(x, y, OSD_X + Z_LEFT, OSD_Y + Z_MID, Z_RAD)) |
if( osm_gps_map_in_circle(x, y, Z_LEFT, Z_MID, Z_RAD)) |
|
return OSD_OUT; |
|
|
|
|
|
/* between center of (-) button and center of entire zoom control area */ |
|
|
if(x > OSD_LEFT && x < OSD_X + D_RAD) |
|
248 |
return OSD_OUT; |
return OSD_OUT; |
249 |
|
|
250 |
/* within circle around (+) label */ |
/* within circle around (+) label */ |
251 |
if( osm_gps_map_in_circle(x, y, OSD_X + Z_RIGHT, OSD_Y + Z_MID, Z_RAD)) |
if( osm_gps_map_in_circle(x, y, Z_RIGHT, Z_MID, Z_RAD)) |
252 |
return OSD_IN; |
return OSD_IN; |
253 |
|
|
254 |
|
#if Z_GPS == 1 |
255 |
|
/* within square around center */ |
256 |
|
if( x > Z_CENTER - Z_RAD && x < Z_CENTER + Z_RAD) |
257 |
|
return OSD_GPS; |
258 |
|
#endif |
259 |
|
|
260 |
|
/* between center of (-) button and center of entire zoom control area */ |
261 |
|
if(x > OSD_LEFT && x < D_RAD) |
262 |
|
return OSD_OUT; |
263 |
|
|
264 |
/* between center of (+) button and center of entire zoom control area */ |
/* between center of (+) button and center of entire zoom control area */ |
265 |
if(x < OSD_RIGHT && x > OSD_X + D_RAD) |
if(x < OSD_RIGHT && x > D_RAD) |
266 |
return OSD_IN; |
return OSD_IN; |
267 |
} |
} |
268 |
|
|
269 |
return OSD_NONE; |
return OSD_NONE; |
270 |
} |
} |
271 |
|
|
272 |
static osd_button_t |
#ifdef OSD_SOURCE_SEL |
|
osm_gps_map_osd_check(gint x, gint y) { |
|
|
osd_button_t but = OSD_NONE; |
|
273 |
|
|
274 |
/* first do a rough test for the OSD area. */ |
/* place source selection at right border */ |
275 |
/* this is just to avoid an unnecessary detailed test */ |
#define OSD_S_RAD (Z_RAD) |
276 |
if(x > OSD_X && x < OSD_X + OSD_W && |
#define OSD_S_X (-OSD_X) |
277 |
y > OSD_Y && y < OSD_Y + OSD_H) { |
#define OSD_S_Y (OSD_Y) |
278 |
#ifndef OSD_NO_DPAD |
#define OSD_S_PW (2 * Z_RAD) |
279 |
but = osm_gps_map_osd_check_dpad(x, y); |
#define OSD_S_W (OSD_S_PW) |
280 |
|
#define OSD_S_PH (2 * Z_RAD) |
281 |
|
#define OSD_S_H (OSD_S_PH + OSD_SHADOW) |
282 |
|
|
283 |
|
/* size of usable area when expanded */ |
284 |
|
#define OSD_S_AREA_W (priv->width) |
285 |
|
#define OSD_S_AREA_H (priv->height) |
286 |
|
#define OSD_S_EXP_W (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW) |
287 |
|
#define OSD_S_EXP_H (OSD_S_AREA_H + OSD_SHADOW) |
288 |
|
|
289 |
|
/* internal value to draw the arrow on the "puller" */ |
290 |
|
#define OSD_S_D0 (OSD_S_RAD/2) |
291 |
|
#ifndef OSD_FONT_SIZE |
292 |
|
#define OSD_FONT_SIZE 16.0 |
293 |
#endif |
#endif |
294 |
|
#define OSD_TEXT_BORDER (OSD_FONT_SIZE/2) |
295 |
|
#define OSD_TEXT_SKIP (OSD_FONT_SIZE/8) |
296 |
|
|
297 |
if(but == OSD_NONE) |
/* draw the shape of the source selection OSD, either only the puller (not expanded) */ |
298 |
but = osm_gps_map_osd_check_zoom(x, y); |
/* or the entire menu incl. the puller (expanded) */ |
299 |
|
static void |
300 |
|
osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) { |
301 |
|
if(!priv->expanded) { |
302 |
|
/* just draw the puller */ |
303 |
|
cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH); |
304 |
|
cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); |
305 |
|
cairo_line_to (cr, x + OSD_S_PW, y); |
306 |
|
} else { |
307 |
|
/* draw the puller and the area itself */ |
308 |
|
cairo_move_to (cr, x + OSD_S_PW + OSD_S_AREA_W, y + OSD_S_AREA_H); |
309 |
|
cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_AREA_H); |
310 |
|
if(OSD_S_Y > 0) { |
311 |
|
cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_PH); |
312 |
|
cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); |
313 |
|
} else { |
314 |
|
cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_AREA_H-OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); |
315 |
|
cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_AREA_H - OSD_S_PH); |
316 |
|
cairo_line_to (cr, x + OSD_S_PW, y); |
317 |
|
} |
318 |
|
cairo_line_to (cr, x + OSD_S_PW + OSD_S_AREA_W, y); |
319 |
|
cairo_close_path (cr); |
320 |
} |
} |
321 |
|
} |
322 |
|
|
323 |
return but; |
static void |
324 |
|
osd_source_content(osm_gps_map_osd_t *osd, cairo_t *cr, gint offset) { |
325 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
326 |
|
|
327 |
|
int py = offset + OSD_S_RAD - OSD_S_D0; |
328 |
|
|
329 |
|
if(!priv->expanded) { |
330 |
|
/* draw the "puller" open (<) arrow */ |
331 |
|
cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py); |
332 |
|
cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); |
333 |
|
cairo_rel_line_to (cr, +OSD_S_D0, +OSD_S_D0); |
334 |
|
} else { |
335 |
|
if(OSD_S_Y < 0) |
336 |
|
py += OSD_S_AREA_H - OSD_S_PH; |
337 |
|
|
338 |
|
/* draw the "puller" close (>) arrow */ |
339 |
|
cairo_move_to (cr, offset + OSD_S_RAD - OSD_S_D0/2, py); |
340 |
|
cairo_rel_line_to (cr, +OSD_S_D0, +OSD_S_D0); |
341 |
|
cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); |
342 |
|
cairo_stroke(cr); |
343 |
|
|
344 |
|
/* don't draw a shadow for the text content */ |
345 |
|
if(offset == 1) { |
346 |
|
gint source; |
347 |
|
g_object_get(osd->widget, "map-source", &source, NULL); |
348 |
|
|
349 |
|
cairo_select_font_face (cr, "Sans", |
350 |
|
CAIRO_FONT_SLANT_NORMAL, |
351 |
|
CAIRO_FONT_WEIGHT_BOLD); |
352 |
|
cairo_set_font_size (cr, OSD_FONT_SIZE); |
353 |
|
|
354 |
|
int i, step = (priv->height - 2*OSD_TEXT_BORDER) / |
355 |
|
OSM_GPS_MAP_SOURCE_LAST; |
356 |
|
for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) { |
357 |
|
cairo_text_extents_t extents; |
358 |
|
const char *src = osm_gps_map_source_get_friendly_name(i); |
359 |
|
cairo_text_extents (cr, src, &extents); |
360 |
|
|
361 |
|
int x = offset + OSD_S_PW + OSD_TEXT_BORDER; |
362 |
|
int y = offset + step * (i-1) + OSD_TEXT_BORDER; |
363 |
|
|
364 |
|
/* draw filled rectangle if selected */ |
365 |
|
if(source == i) { |
366 |
|
cairo_rectangle(cr, x - OSD_TEXT_BORDER/2, |
367 |
|
y - OSD_TEXT_SKIP, |
368 |
|
priv->width - OSD_TEXT_BORDER, |
369 |
|
step + OSD_TEXT_SKIP); |
370 |
|
cairo_fill(cr); |
371 |
|
|
372 |
|
/* temprarily draw with background color */ |
373 |
|
#ifndef OSD_COLOR |
374 |
|
GdkColor bg = osd->widget->style->bg[GTK_STATE_NORMAL]; |
375 |
|
gdk_cairo_set_source_color(cr, &bg); |
376 |
|
#else |
377 |
|
cairo_set_source_rgb (cr, OSD_COLOR_BG); |
378 |
|
#endif |
379 |
|
} |
380 |
|
|
381 |
|
cairo_move_to (cr, x, y + OSD_TEXT_SKIP - extents.y_bearing); |
382 |
|
cairo_show_text (cr, src); |
383 |
|
|
384 |
|
/* restore color */ |
385 |
|
if(source == i) { |
386 |
|
#ifndef OSD_COLOR |
387 |
|
GdkColor fg = osd->widget->style->fg[GTK_STATE_NORMAL]; |
388 |
|
gdk_cairo_set_source_color(cr, &fg); |
389 |
|
#else |
390 |
|
cairo_set_source_rgb (cr, OSD_COLOR); |
391 |
|
#endif |
392 |
|
} |
393 |
|
} |
394 |
|
} |
395 |
|
} |
396 |
} |
} |
397 |
|
|
398 |
|
static void |
399 |
|
osd_render_source_sel(osm_gps_map_osd_t *osd) { |
400 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
401 |
|
|
402 |
|
#ifndef OSD_COLOR |
403 |
|
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
404 |
|
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
405 |
|
GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE]; |
406 |
|
#endif |
407 |
|
|
408 |
|
/* draw source selector */ |
409 |
|
cairo_t *cr = cairo_create(priv->map_source); |
410 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
411 |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
412 |
|
cairo_paint(cr); |
413 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
414 |
|
|
415 |
#ifdef OSD_SHADOW_ENABLE |
#ifdef OSD_SHADOW_ENABLE |
416 |
static void |
osd_source_shape(priv, cr, 1+OSD_SHADOW, 1+OSD_SHADOW); |
417 |
osm_gps_map_osd_shape_shadow(cairo_t *cr) { |
osd_shape_shadow(cr); |
|
cairo_set_source_rgba (cr, 0, 0, 0, 0.2); |
|
|
cairo_fill (cr); |
|
|
cairo_stroke (cr); |
|
|
} |
|
418 |
#endif |
#endif |
419 |
|
|
420 |
|
osd_source_shape(priv, cr, 1, 1); |
421 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
422 |
/* if no color has been specified we just use the gdks default colors */ |
osd_shape(cr, &bg, &fg); |
423 |
static void |
#else |
424 |
osm_gps_map_osd_shape(cairo_t *cr, GdkColor *bg, GdkColor *fg) { |
osd_shape(cr); |
425 |
gdk_cairo_set_source_color(cr, bg); |
#endif |
426 |
cairo_fill_preserve (cr); |
|
427 |
gdk_cairo_set_source_color(cr, fg); |
#ifdef OSD_SHADOW_ENABLE |
428 |
cairo_set_line_width (cr, 1); |
osd_labels_shadow(cr, Z_RAD/3, TRUE); |
429 |
|
osd_source_content(osd, cr, 1+OSD_LBL_SHADOW); |
430 |
cairo_stroke (cr); |
cairo_stroke (cr); |
431 |
} |
#endif |
432 |
|
#ifndef OSD_COLOR |
433 |
|
osd_labels(cr, Z_RAD/3, TRUE, &fg, &da); |
434 |
#else |
#else |
435 |
static void |
osd_labels(cr, Z_RAD/3, TRUE); |
436 |
osm_gps_map_osd_shape(cairo_t *cr) { |
#endif |
437 |
cairo_set_source_rgb (cr, OSD_COLOR_BG); |
osd_source_content(osd, cr, 1); |
|
cairo_fill_preserve (cr); |
|
|
cairo_set_source_rgb (cr, OSD_COLOR); |
|
|
cairo_set_line_width (cr, 1); |
|
438 |
cairo_stroke (cr); |
cairo_stroke (cr); |
439 |
|
|
440 |
|
cairo_destroy(cr); |
441 |
} |
} |
442 |
|
|
443 |
|
/* re-allocate the buffer used to draw the menu. This is used */ |
444 |
|
/* to collapse/expand the buffer */ |
445 |
|
static void |
446 |
|
osd_source_reallocate(osm_gps_map_osd_t *osd) { |
447 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
448 |
|
|
449 |
|
/* re-allocate offscreen bitmap */ |
450 |
|
g_assert (priv->map_source); |
451 |
|
|
452 |
|
int w = OSD_S_W, h = OSD_S_H; |
453 |
|
if(priv->expanded) { |
454 |
|
/* ... and right of it the waypoint id */ |
455 |
|
cairo_text_extents_t extents; |
456 |
|
|
457 |
|
/* determine content size */ |
458 |
|
cairo_t *cr = cairo_create(priv->map_source); |
459 |
|
cairo_select_font_face (cr, "Sans", |
460 |
|
CAIRO_FONT_SLANT_NORMAL, |
461 |
|
CAIRO_FONT_WEIGHT_BOLD); |
462 |
|
cairo_set_font_size (cr, OSD_FONT_SIZE); |
463 |
|
|
464 |
|
/* calculate menu size */ |
465 |
|
int i, max_h = 0, max_w = 0; |
466 |
|
for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) { |
467 |
|
const char *src = osm_gps_map_source_get_friendly_name(i); |
468 |
|
cairo_text_extents (cr, src, &extents); |
469 |
|
|
470 |
|
if(extents.width > max_w) max_w = extents.width; |
471 |
|
if(extents.height > max_h) max_h = extents.height; |
472 |
|
} |
473 |
|
cairo_destroy(cr); |
474 |
|
|
475 |
|
priv->width = max_w + 2*OSD_TEXT_BORDER; |
476 |
|
priv->height = OSM_GPS_MAP_SOURCE_LAST * |
477 |
|
(max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER; |
478 |
|
|
479 |
|
w = OSD_S_EXP_W; |
480 |
|
h = OSD_S_EXP_H; |
481 |
|
} |
482 |
|
|
483 |
|
cairo_surface_destroy(priv->map_source); |
484 |
|
priv->map_source = |
485 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
486 |
|
|
487 |
|
osd_render_source_sel(osd); |
488 |
|
} |
489 |
|
|
490 |
|
#define OSD_HZ 15 |
491 |
|
#define OSD_TIME 500 |
492 |
|
|
493 |
|
static gboolean osd_source_animate(gpointer data) { |
494 |
|
osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data; |
495 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
496 |
|
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
497 |
|
gboolean done = FALSE; |
498 |
|
priv->count += priv->dir; |
499 |
|
|
500 |
|
/* shifting in */ |
501 |
|
if(priv->dir < 0) { |
502 |
|
if(priv->count <= 0) { |
503 |
|
priv->count = 0; |
504 |
|
done = TRUE; |
505 |
|
} |
506 |
|
} else { |
507 |
|
if(priv->count >= 1000) { |
508 |
|
priv->expanded = FALSE; |
509 |
|
osd_source_reallocate(osd); |
510 |
|
|
511 |
|
priv->count = 1000; |
512 |
|
done = TRUE; |
513 |
|
} |
514 |
|
} |
515 |
|
|
516 |
|
|
517 |
|
/* count runs linearly from 0 to 1000, map this nicely onto a position */ |
518 |
|
|
519 |
|
/* nicer sinoid mapping */ |
520 |
|
float m = 0.5-cos(priv->count * M_PI / 1000.0)/2; |
521 |
|
priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
522 |
|
m * diff; |
523 |
|
|
524 |
|
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
525 |
|
|
526 |
|
if(done) |
527 |
|
priv->handler_id = 0; |
528 |
|
|
529 |
|
return !done; |
530 |
|
} |
531 |
|
|
532 |
|
/* switch between expand and collapse mode of source selection */ |
533 |
|
static void |
534 |
|
osd_source_toggle(osm_gps_map_osd_t *osd) |
535 |
|
{ |
536 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
537 |
|
|
538 |
|
/* ignore clicks while animation is running */ |
539 |
|
if(priv->handler_id) |
540 |
|
return; |
541 |
|
|
542 |
|
/* expand immediately, collapse is handle at the end of the collapse animation */ |
543 |
|
if(!priv->expanded) { |
544 |
|
priv->expanded = TRUE; |
545 |
|
osd_source_reallocate(osd); |
546 |
|
|
547 |
|
priv->count = 1000; |
548 |
|
priv->shift = osd->widget->allocation.width - OSD_S_W; |
549 |
|
priv->dir = -1000/OSD_HZ; |
550 |
|
} else { |
551 |
|
priv->count = 0; |
552 |
|
priv->shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
553 |
|
priv->dir = +1000/OSD_HZ; |
554 |
|
} |
555 |
|
|
556 |
|
priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd); |
557 |
|
} |
558 |
|
|
559 |
|
/* check if the user clicked inside the source selection area */ |
560 |
|
static osd_button_t |
561 |
|
osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
562 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
563 |
|
|
564 |
|
if(!priv->expanded) |
565 |
|
x -= osd->widget->allocation.width - OSD_S_W; |
566 |
|
else |
567 |
|
x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
568 |
|
|
569 |
|
if(OSD_S_Y > 0) |
570 |
|
y -= OSD_S_Y; |
571 |
|
else |
572 |
|
y -= osd->widget->allocation.height - OSD_S_PH + OSD_S_Y; |
573 |
|
|
574 |
|
/* within square around puller? */ |
575 |
|
if(y > 0 && y < OSD_S_PH && x > 0 && x < OSD_S_PW) { |
576 |
|
/* really within puller shape? */ |
577 |
|
if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) { |
578 |
|
/* expand source selector */ |
579 |
|
osd_source_toggle(osd); |
580 |
|
|
581 |
|
/* tell upper layers that user clicked some background element */ |
582 |
|
/* of the OSD */ |
583 |
|
return OSD_BG; |
584 |
|
} |
585 |
|
} |
586 |
|
|
587 |
|
/* check for clicks into data area */ |
588 |
|
if(priv->expanded && !priv->handler_id) { |
589 |
|
/* re-adjust from puller top to content top */ |
590 |
|
if(OSD_S_Y < 0) |
591 |
|
y += OSD_S_EXP_H - OSD_S_PH; |
592 |
|
|
593 |
|
if(x > OSD_S_PW && |
594 |
|
x < OSD_S_PW + OSD_S_EXP_W && |
595 |
|
y > 0 && |
596 |
|
y < OSD_S_EXP_H) { |
597 |
|
|
598 |
|
int step = (priv->height - 2*OSD_TEXT_BORDER) |
599 |
|
/ OSM_GPS_MAP_SOURCE_LAST; |
600 |
|
|
601 |
|
y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP; |
602 |
|
y /= step; |
603 |
|
y += 1; |
604 |
|
|
605 |
|
gint old = 0; |
606 |
|
g_object_get(osd->widget, "map-source", &old, NULL); |
607 |
|
|
608 |
|
if(y > OSM_GPS_MAP_SOURCE_NULL && |
609 |
|
y <= OSM_GPS_MAP_SOURCE_LAST && |
610 |
|
old != y) { |
611 |
|
g_object_set(osd->widget, "map-source", y, NULL); |
612 |
|
|
613 |
|
osd_render_source_sel(osd); |
614 |
|
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
615 |
|
} |
616 |
|
|
617 |
|
/* return "clicked in OSD background" to prevent further */ |
618 |
|
/* processing by application */ |
619 |
|
return OSD_BG; |
620 |
|
} |
621 |
|
} |
622 |
|
|
623 |
|
return OSD_NONE; |
624 |
|
} |
625 |
|
#endif // OSD_SOURCE_SEL |
626 |
|
|
627 |
|
static osd_button_t |
628 |
|
osd_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
629 |
|
osd_button_t but = OSD_NONE; |
630 |
|
|
631 |
|
#ifdef OSD_SOURCE_SEL |
632 |
|
/* the source selection area is handles internally */ |
633 |
|
but = osd_source_check(osd, x, y); |
634 |
|
if(but != OSD_NONE) |
635 |
|
return but; |
636 |
|
#endif |
637 |
|
|
638 |
|
x -= OSD_X; |
639 |
|
y -= OSD_Y; |
640 |
|
|
641 |
|
if(OSD_X < 0) |
642 |
|
x -= (osd->widget->allocation.width - OSD_W); |
643 |
|
|
644 |
|
if(OSD_Y < 0) |
645 |
|
y -= (osd->widget->allocation.height - OSD_H); |
646 |
|
|
647 |
|
/* first do a rough test for the OSD area. */ |
648 |
|
/* this is just to avoid an unnecessary detailed test */ |
649 |
|
if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) { |
650 |
|
#ifndef OSD_NO_DPAD |
651 |
|
but = osd_check_dpad(x, y); |
652 |
#endif |
#endif |
653 |
|
|
654 |
|
if(but == OSD_NONE) |
655 |
|
but = osd_check_zoom(x, y); |
656 |
|
} |
657 |
|
|
658 |
|
return but; |
659 |
|
} |
660 |
|
|
661 |
#ifndef OSD_NO_DPAD |
#ifndef OSD_NO_DPAD |
662 |
static void |
static void |
663 |
osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) { |
osd_dpad_labels(cairo_t *cr, gint x, gint y) { |
664 |
/* move reference to dpad center */ |
/* move reference to dpad center */ |
665 |
x += D_RAD; |
x += D_RAD; |
666 |
y += D_RAD; |
y += D_RAD; |
687 |
|
|
688 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
689 |
/* draw the satellite dish icon in the center of the dpad */ |
/* draw the satellite dish icon in the center of the dpad */ |
690 |
#define GPS_V0 (D_RAD/8) |
#define GPS_V0 (D_RAD/7) |
691 |
#define GPS_V1 (D_RAD/10) |
#define GPS_V1 (D_RAD/10) |
692 |
#define GPS_V2 (D_RAD/5) |
#define GPS_V2 (D_RAD/5) |
693 |
|
|
694 |
/* draw a satellite receiver dish */ |
/* draw a satellite receiver dish */ |
695 |
|
/* this is either drawn in the center of the dpad (if present) */ |
696 |
|
/* or in the middle of the zoom area */ |
697 |
static void |
static void |
698 |
osm_gps_map_osd_dpad_gps(cairo_t *cr, gint x, gint y) { |
osd_dpad_gps(cairo_t *cr, gint x, gint y) { |
699 |
/* move reference to dpad center */ |
/* move reference to dpad center */ |
700 |
x += D_RAD; |
x += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD * 3; |
701 |
y += D_RAD + GPS_V0; |
y += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD + GPS_V0; |
702 |
|
|
703 |
cairo_move_to (cr, x-GPS_V0, y+GPS_V0); |
cairo_move_to (cr, x-GPS_V0, y+GPS_V0); |
704 |
cairo_rel_line_to (cr, +GPS_V0, -GPS_V0); |
cairo_rel_line_to (cr, +GPS_V0, -GPS_V0); |
718 |
#define Z_LEN (2*Z_RAD/3) |
#define Z_LEN (2*Z_RAD/3) |
719 |
|
|
720 |
static void |
static void |
721 |
osm_gps_map_osd_zoom_labels(cairo_t *cr, gint x, gint y) { |
osd_zoom_labels(cairo_t *cr, gint x, gint y) { |
722 |
cairo_move_to (cr, x + Z_LEFT - Z_LEN, y + Z_MID); |
cairo_move_to (cr, x + Z_LEFT - Z_LEN, y + Z_MID); |
723 |
cairo_line_to (cr, x + Z_LEFT + Z_LEN, y + Z_MID); |
cairo_line_to (cr, x + Z_LEFT + Z_LEN, y + Z_MID); |
724 |
|
|
728 |
cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); |
cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); |
729 |
} |
} |
730 |
|
|
731 |
#ifndef OSD_COLOR |
static char * |
732 |
/* if no color has been specified we just use the gdks default colors */ |
dist_str_metric(int dist) |
733 |
static void |
{ |
734 |
osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled, |
if(dist<1000) |
735 |
GdkColor *fg, GdkColor *disabled) { |
return g_strdup_printf("%u m", dist); |
736 |
if(enabled) gdk_cairo_set_source_color(cr, fg); |
|
737 |
else gdk_cairo_set_source_color(cr, disabled); |
return g_strdup_printf("%u km", dist/1000); |
|
cairo_set_line_width (cr, width); |
|
|
cairo_stroke (cr); |
|
738 |
} |
} |
739 |
#else |
|
740 |
static void |
static void |
741 |
osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) { |
osd_render_scale(osm_gps_map_osd_t *osd) |
742 |
if(enabled) cairo_set_source_rgb (cr, OSD_COLOR); |
{ |
743 |
else cairo_set_source_rgb (cr, OSD_COLOR_DISABLED); |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
744 |
cairo_set_line_width (cr, width); |
float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget)); |
|
cairo_stroke (cr); |
|
|
} |
|
|
#endif |
|
745 |
|
|
746 |
#ifdef OSD_SHADOW_ENABLE |
/* first fill with transparency */ |
747 |
static void |
cairo_t *cr = cairo_create(priv->scale); |
748 |
osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) { |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
749 |
cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15); |
// cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
750 |
cairo_set_line_width (cr, width); |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
751 |
cairo_stroke (cr); |
cairo_paint(cr); |
752 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
753 |
|
|
754 |
|
/* determine the size of the scale width in meters */ |
755 |
|
float width = (OSD_SCALE_W-2) * m_per_pix; |
756 |
|
printf("width = %f meters\n", width); |
757 |
|
|
758 |
|
/* scale this to useful values */ |
759 |
|
int exp = logf(width)*M_LOG10E; |
760 |
|
int mant = width/pow(10,exp); |
761 |
|
printf("mant = %d, exp = %d \n", mant, exp); |
762 |
|
|
763 |
|
int width_metric = mant * pow(10,exp); |
764 |
|
char *dist_str = dist_str_metric(width_metric); |
765 |
|
width_metric /= m_per_pix; |
766 |
|
printf("metric scale width = %d pixels: %s\n", width_metric, dist_str); |
767 |
|
|
768 |
|
int font_size = 12; |
769 |
|
|
770 |
|
cairo_select_font_face (cr, "Sans", |
771 |
|
CAIRO_FONT_SLANT_NORMAL, |
772 |
|
CAIRO_FONT_WEIGHT_BOLD); |
773 |
|
cairo_set_font_size (cr, font_size); |
774 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); |
775 |
|
|
776 |
|
cairo_text_extents_t extents; |
777 |
|
cairo_text_extents (cr, dist_str, &extents); |
778 |
|
|
779 |
|
cairo_move_to (cr, font_size/3, font_size); |
780 |
|
cairo_show_text (cr, dist_str); |
781 |
|
|
782 |
|
printf("height = %f, bearing = %f\n", extents.height, extents.y_bearing); |
783 |
|
|
784 |
|
/* draw white line */ |
785 |
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
786 |
|
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); |
787 |
|
cairo_set_line_width (cr, 3); |
788 |
|
cairo_move_to (cr, 2, 2*font_size/3); |
789 |
|
cairo_rel_line_to (cr, 0, 2*font_size/3); |
790 |
|
cairo_rel_line_to (cr, width_metric, 0); |
791 |
|
cairo_rel_line_to (cr, 0, -2*font_size/3); |
792 |
|
cairo_stroke(cr); |
793 |
|
|
794 |
|
/* draw black line */ |
795 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); |
796 |
|
cairo_set_line_width (cr, 2); |
797 |
|
cairo_move_to (cr, 2, 2*font_size/3); |
798 |
|
cairo_rel_line_to (cr, 0, 2*font_size/3); |
799 |
|
cairo_rel_line_to (cr, width_metric, 0); |
800 |
|
cairo_rel_line_to (cr, 0, -2*font_size/3); |
801 |
|
cairo_stroke(cr); |
802 |
|
|
803 |
|
/* xyz */ |
804 |
|
|
805 |
|
cairo_destroy(cr); |
806 |
} |
} |
|
#endif |
|
807 |
|
|
808 |
static void |
static void |
809 |
osm_gps_map_osd_render(osm_gps_map_osd_t *osd) { |
osd_render(osm_gps_map_osd_t *osd) |
810 |
|
{ |
811 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
812 |
|
|
813 |
|
#ifndef OSD_COLOR |
814 |
|
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
815 |
|
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
816 |
|
GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE]; |
817 |
|
#endif |
818 |
|
|
819 |
/* first fill with transparency */ |
/* first fill with transparency */ |
820 |
cairo_t *cr = cairo_create(priv->overlay); |
cairo_t *cr = cairo_create(priv->overlay); |
821 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
822 |
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); |
823 |
cairo_paint(cr); |
cairo_paint(cr); |
|
|
|
824 |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
825 |
|
|
826 |
/* --------- draw zoom and dpad shape shadow ----------- */ |
/* --------- draw zoom and dpad shape shadow ----------- */ |
|
gint x = 0, y = 0; |
|
|
|
|
827 |
#ifdef OSD_SHADOW_ENABLE |
#ifdef OSD_SHADOW_ENABLE |
828 |
osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW); |
osd_zoom_shape(cr, 1+OSD_SHADOW, 1+OSD_SHADOW); |
829 |
osm_gps_map_osd_shape_shadow(cr); |
osd_shape_shadow(cr); |
830 |
#ifndef OSD_NO_DPAD |
#ifndef OSD_NO_DPAD |
831 |
osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW); |
osd_dpad_shape(cr, 1+OSD_SHADOW, 1+OSD_SHADOW); |
832 |
osm_gps_map_osd_shape_shadow(cr); |
osd_shape_shadow(cr); |
833 |
#endif |
#endif |
834 |
#endif |
#endif |
835 |
|
|
836 |
/* --------- draw zoom and dpad shape ----------- */ |
/* --------- draw zoom and dpad shape ----------- */ |
837 |
|
|
838 |
osm_gps_map_osd_zoom_shape(cr, x, y); |
osd_zoom_shape(cr, 1, 1); |
839 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
840 |
osm_gps_map_osd_shape(cr, &priv->bg, &priv->fg); |
osd_shape(cr, &bg, &fg); |
841 |
#else |
#else |
842 |
osm_gps_map_osd_shape(cr); |
osd_shape(cr); |
843 |
#endif |
#endif |
844 |
#ifndef OSD_NO_DPAD |
#ifndef OSD_NO_DPAD |
845 |
osm_gps_map_osd_dpad_shape(cr, x, y); |
osd_dpad_shape(cr, 1, 1); |
846 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
847 |
osm_gps_map_osd_shape(cr, &priv->bg, &priv->fg); |
osd_shape(cr, &bg, &fg); |
848 |
#else |
#else |
849 |
osm_gps_map_osd_shape(cr); |
osd_shape(cr); |
850 |
#endif |
#endif |
851 |
#endif |
#endif |
852 |
|
|
853 |
/* --------- draw zoom and dpad labels --------- */ |
/* --------- draw zoom and dpad labels --------- */ |
854 |
|
|
855 |
#ifdef OSD_SHADOW_ENABLE |
#ifdef OSD_SHADOW_ENABLE |
856 |
osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
osd_labels_shadow(cr, Z_RAD/3, TRUE); |
857 |
|
osd_zoom_labels(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW); |
858 |
#ifndef OSD_NO_DPAD |
#ifndef OSD_NO_DPAD |
859 |
osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
osd_dpad_labels(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW); |
860 |
#endif |
#endif |
861 |
osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE); |
cairo_stroke(cr); |
862 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
863 |
osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL); |
864 |
osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL); |
osd_dpad_gps(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW); |
865 |
|
cairo_stroke(cr); |
866 |
#endif |
#endif |
867 |
#endif |
#endif |
868 |
|
|
|
osm_gps_map_osd_zoom_labels(cr, x, y); |
|
|
#ifndef OSD_NO_DPAD |
|
|
osm_gps_map_osd_dpad_labels(cr, x, y); |
|
|
#endif |
|
869 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
870 |
osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE, &priv->fg, &priv->da); |
osd_labels(cr, Z_RAD/3, TRUE, &fg, &da); |
871 |
#else |
#else |
872 |
osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE); |
osd_labels(cr, Z_RAD/3, TRUE); |
873 |
#endif |
#endif |
874 |
#ifdef OSD_GPS_BUTTON |
osd_zoom_labels(cr, 1, 1); |
875 |
osm_gps_map_osd_dpad_gps(cr, x, y); |
#ifndef OSD_NO_DPAD |
876 |
|
osd_dpad_labels(cr, 1, 1); |
877 |
|
#endif |
878 |
|
cairo_stroke(cr); |
879 |
|
|
880 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
881 |
osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL, &priv->fg, &priv->da); |
osd_labels(cr, Z_RAD/6, osd->cb != NULL, &fg, &da); |
882 |
#else |
#else |
883 |
osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL); |
osd_labels(cr, Z_RAD/6, osd->cb != NULL); |
884 |
#endif |
#endif |
885 |
|
#ifdef OSD_GPS_BUTTON |
886 |
|
osd_dpad_gps(cr, 1, 1); |
887 |
#endif |
#endif |
888 |
|
cairo_stroke(cr); |
889 |
|
|
890 |
cairo_destroy(cr); |
cairo_destroy(cr); |
891 |
|
|
892 |
|
#ifdef OSD_SOURCE_SEL |
893 |
|
osd_render_source_sel(osd); |
894 |
|
#endif |
895 |
|
|
896 |
|
#ifdef OSD_SCALE |
897 |
|
osd_render_scale(osd); |
898 |
|
#endif |
899 |
} |
} |
900 |
|
|
901 |
static void |
static void |
902 |
osm_gps_map_osd_draw(osm_gps_map_osd_t *osd, GdkDrawable *drawable) |
osd_draw(osm_gps_map_osd_t *osd, GdkDrawable *drawable) |
903 |
{ |
{ |
904 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
905 |
|
|
908 |
if(!priv->overlay) { |
if(!priv->overlay) { |
909 |
/* create overlay ... */ |
/* create overlay ... */ |
910 |
priv->overlay = |
priv->overlay = |
911 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H); |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2); |
912 |
|
|
913 |
|
#ifdef OSD_SOURCE_SEL |
914 |
|
/* the initial OSD state is alway not-expanded */ |
915 |
|
priv->map_source = |
916 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
917 |
|
OSD_S_W+2, OSD_S_H+2); |
918 |
|
#endif |
919 |
|
|
920 |
|
#ifdef OSD_SCALE |
921 |
|
priv->scale = |
922 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
923 |
|
OSD_SCALE_W+2, OSD_SCALE_H+2); |
924 |
|
#endif |
925 |
|
|
926 |
/* ... and render it */ |
/* ... and render it */ |
927 |
osm_gps_map_osd_render(osd); |
osd_render(osd); |
928 |
} |
} |
929 |
|
|
930 |
// now draw this onto the original context |
// now draw this onto the original context |
931 |
cairo_t *cr = gdk_cairo_create(drawable); |
cairo_t *cr = gdk_cairo_create(drawable); |
932 |
cairo_set_source_surface(cr, priv->overlay, OSD_X, OSD_Y); |
|
933 |
|
int x = OSD_X, y = OSD_Y; |
934 |
|
if(OSD_X < 0) |
935 |
|
x = osd->widget->allocation.width - OSD_W + OSD_X; |
936 |
|
|
937 |
|
if(OSD_Y < 0) |
938 |
|
y = osd->widget->allocation.height - OSD_H + OSD_Y; |
939 |
|
|
940 |
|
cairo_set_source_surface(cr, priv->overlay, x, y); |
941 |
|
cairo_paint(cr); |
942 |
|
|
943 |
|
#ifdef OSD_SOURCE_SEL |
944 |
|
if(!priv->handler_id) { |
945 |
|
/* the OSD source selection is not being animated */ |
946 |
|
if(!priv->expanded) |
947 |
|
x = osd->widget->allocation.width - OSD_S_W; |
948 |
|
else |
949 |
|
x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
950 |
|
} else |
951 |
|
x = priv->shift; |
952 |
|
|
953 |
|
y = OSD_S_Y; |
954 |
|
if(OSD_S_Y < 0) { |
955 |
|
if(!priv->expanded) |
956 |
|
y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y; |
957 |
|
else |
958 |
|
y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y; |
959 |
|
} |
960 |
|
|
961 |
|
cairo_set_source_surface(cr, priv->map_source, x, y); |
962 |
|
cairo_paint(cr); |
963 |
|
#endif |
964 |
|
|
965 |
|
#ifdef OSD_SCALE |
966 |
|
x = OSD_X; |
967 |
|
y = -OSD_Y; |
968 |
|
if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W; |
969 |
|
if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H; |
970 |
|
|
971 |
|
cairo_set_source_surface(cr, priv->scale, x, y); |
972 |
cairo_paint(cr); |
cairo_paint(cr); |
973 |
|
#endif |
974 |
|
|
975 |
cairo_destroy(cr); |
cairo_destroy(cr); |
976 |
} |
} |
977 |
|
|
978 |
static void |
static void |
979 |
osm_gps_map_osd_free(osm_gps_map_osd_t *osd) |
osd_free(osm_gps_map_osd_t *osd) |
980 |
{ |
{ |
981 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
982 |
|
|
983 |
if (priv->overlay) |
if (priv->overlay) |
984 |
cairo_surface_destroy(priv->overlay); |
cairo_surface_destroy(priv->overlay); |
985 |
|
|
986 |
|
#ifdef OSD_SOURCE_SEL |
987 |
|
if(priv->handler_id) |
988 |
|
gtk_timeout_remove(priv->handler_id); |
989 |
|
|
990 |
|
if (priv->map_source) |
991 |
|
cairo_surface_destroy(priv->map_source); |
992 |
|
#endif |
993 |
|
|
994 |
|
#ifdef OSD_SCALE |
995 |
|
if (priv->scale) |
996 |
|
cairo_surface_destroy(priv->scale); |
997 |
|
#endif |
998 |
|
|
999 |
g_free(priv); |
g_free(priv); |
1000 |
} |
} |
1001 |
|
|
1002 |
|
static gboolean |
1003 |
|
osd_busy(osm_gps_map_osd_t *osd) |
1004 |
|
{ |
1005 |
|
#ifdef OSD_SOURCE_SEL |
1006 |
|
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1007 |
|
return (priv->handler_id != 0); |
1008 |
|
#else |
1009 |
|
return FALSE; |
1010 |
|
#endif |
1011 |
|
} |
1012 |
|
|
1013 |
static osm_gps_map_osd_t osd_classic = { |
static osm_gps_map_osd_t osd_classic = { |
1014 |
.draw = osm_gps_map_osd_draw, |
.widget = NULL, |
1015 |
.check = osm_gps_map_osd_check, |
|
1016 |
.render = osm_gps_map_osd_render, |
.draw = osd_draw, |
1017 |
.free = osm_gps_map_osd_free, |
.check = osd_check, |
1018 |
|
.render = osd_render, |
1019 |
|
.free = osd_free, |
1020 |
|
.busy = osd_busy, |
1021 |
|
|
1022 |
.cb = NULL, |
.cb = NULL, |
1023 |
.data = NULL, |
.data = NULL, |
1033 |
|
|
1034 |
osd_classic.priv = priv; |
osd_classic.priv = priv; |
1035 |
|
|
|
/* extract style info from the widget */ |
|
|
priv->bg = GTK_WIDGET(map)->style->bg[GTK_STATE_NORMAL]; |
|
|
priv->fg = GTK_WIDGET(map)->style->fg[GTK_STATE_NORMAL]; |
|
|
priv->da = GTK_WIDGET(map)->style->fg[GTK_STATE_INSENSITIVE]; |
|
|
|
|
1036 |
osm_gps_map_register_osd(map, &osd_classic); |
osm_gps_map_register_osd(map, &osd_classic); |
1037 |
} |
} |
1038 |
|
|
1042 |
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, |
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, |
1043 |
gpointer data) { |
gpointer data) { |
1044 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
|
|
|
1045 |
g_return_if_fail (osd); |
g_return_if_fail (osd); |
1046 |
|
|
1047 |
osd->cb = cb; |
osd->cb = cb; |
1054 |
osm_gps_map_redraw(map); |
osm_gps_map_redraw(map); |
1055 |
} |
} |
1056 |
#endif |
#endif |
1057 |
|
|
1058 |
|
osd_button_t |
1059 |
|
osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) { |
1060 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1061 |
|
g_return_val_if_fail (osd, OSD_NONE); |
1062 |
|
|
1063 |
|
return osd_check(osd, x, y); |
1064 |
|
} |