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