35 |
|
|
36 |
//the osd controls |
//the osd controls |
37 |
typedef struct { |
typedef struct { |
38 |
GdkPixmap *backup; |
/* the offscreen representation of the OSD */ |
|
gint backup_x, backup_y; |
|
39 |
cairo_surface_t *overlay; |
cairo_surface_t *overlay; |
40 |
|
|
41 |
|
GdkColor bg, fg, da; |
42 |
|
|
43 |
} osd_priv_t; |
} osd_priv_t; |
44 |
|
|
45 |
/* position and extent of bounding box */ |
/* position and extent of bounding box */ |
46 |
#define OSD_X (10) |
#define OSD_X (10) |
47 |
#define OSD_Y (10) |
#define OSD_Y (10) |
48 |
|
|
|
#define OSD_COLOR 0.5, 0.5, 1 |
|
|
#define OSD_COLOR_DISABLED 0.8, 0.8, 0.8 |
|
|
|
|
49 |
/* parameters of the direction shape */ |
/* parameters of the direction shape */ |
50 |
#ifndef OSM_GPS_MAP_OSD_DIAMETER |
#ifndef OSM_GPS_MAP_OSD_DIAMETER |
51 |
#define D_RAD (30) // diameter of dpad |
#define D_RAD (30) // diameter of dpad |
60 |
#define Z_STEP (D_RAD/4) // distance between dpad and zoom |
#define Z_STEP (D_RAD/4) // distance between dpad and zoom |
61 |
#define Z_RAD (D_RAD/2) // radius of "caps" of zoom bar |
#define Z_RAD (D_RAD/2) // radius of "caps" of zoom bar |
62 |
|
|
63 |
|
#ifdef OSD_SHADOW_ENABLE |
64 |
/* shadow also depends on control size */ |
/* shadow also depends on control size */ |
65 |
#define OSD_SHADOW (D_RAD/6) |
#define OSD_SHADOW (D_RAD/6) |
66 |
|
#else |
67 |
|
#define OSD_SHADOW (0) |
68 |
|
#endif |
69 |
|
|
70 |
/* total width and height of controls incl. shadow */ |
/* total width and height of controls incl. shadow */ |
71 |
#define OSD_W (2*D_RAD + OSD_SHADOW) |
#define OSD_W (2*D_RAD + OSD_SHADOW) |
72 |
#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) |
73 |
|
|
74 |
|
#ifdef OSD_SHADOW_ENABLE |
75 |
#define OSD_LBL_SHADOW (OSD_SHADOW/2) |
#define OSD_LBL_SHADOW (OSD_SHADOW/2) |
76 |
|
#endif |
77 |
|
|
78 |
#define Z_TOP (2 * D_RAD + Z_STEP) |
#define Z_TOP (2 * D_RAD + Z_STEP) |
79 |
#define Z_MID (Z_TOP + Z_RAD) |
#define Z_MID (Z_TOP + Z_RAD) |
93 |
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); |
94 |
} |
} |
95 |
|
|
96 |
|
#ifndef OSD_NO_DPAD |
97 |
/* create the cairo shape used for the dpad */ |
/* create the cairo shape used for the dpad */ |
98 |
static void |
static void |
99 |
osm_gps_map_osd_dpad_shape(cairo_t *cr, gint x, gint y) |
osm_gps_map_osd_dpad_shape(cairo_t *cr, gint x, gint y) |
100 |
{ |
{ |
101 |
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); |
102 |
} |
} |
103 |
|
#endif |
104 |
|
|
105 |
static gboolean |
static gboolean |
106 |
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) |
108 |
return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad); |
return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad); |
109 |
} |
} |
110 |
|
|
111 |
|
#ifndef OSD_NO_DPAD |
112 |
/* check whether x/y is within the dpad */ |
/* check whether x/y is within the dpad */ |
113 |
static osd_button_t |
static osd_button_t |
114 |
osm_gps_map_osd_check_dpad(gint x, gint y) |
osm_gps_map_osd_check_dpad(gint x, gint y) |
120 |
x -= (OSD_X + D_RAD); |
x -= (OSD_X + D_RAD); |
121 |
y -= (OSD_Y + D_RAD); |
y -= (OSD_Y + D_RAD); |
122 |
|
|
123 |
|
#ifdef OSD_GPS_BUTTON |
124 |
/* check for dpad center goes here! */ |
/* check for dpad center goes here! */ |
125 |
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)) |
126 |
return OSD_GPS; |
return OSD_GPS; |
127 |
|
#endif |
128 |
|
|
129 |
if( y < 0 && abs(x) < abs(y)) |
if( y < 0 && abs(x) < abs(y)) |
130 |
return OSD_UP; |
return OSD_UP; |
142 |
} |
} |
143 |
return OSD_NONE; |
return OSD_NONE; |
144 |
} |
} |
145 |
|
#endif |
146 |
|
|
147 |
/* check whether x/y is within the zoom pads */ |
/* check whether x/y is within the zoom pads */ |
148 |
static osd_button_t |
static osd_button_t |
177 |
/* this is just to avoid an unnecessary detailed test */ |
/* this is just to avoid an unnecessary detailed test */ |
178 |
if(x > OSD_X && x < OSD_X + OSD_W && |
if(x > OSD_X && x < OSD_X + OSD_W && |
179 |
y > OSD_Y && y < OSD_Y + OSD_H) { |
y > OSD_Y && y < OSD_Y + OSD_H) { |
180 |
|
#ifndef OSD_NO_DPAD |
181 |
but = osm_gps_map_osd_check_dpad(x, y); |
but = osm_gps_map_osd_check_dpad(x, y); |
182 |
|
#endif |
183 |
|
|
184 |
if(but == OSD_NONE) |
if(but == OSD_NONE) |
185 |
but = osm_gps_map_osd_check_zoom(x, y); |
but = osm_gps_map_osd_check_zoom(x, y); |
188 |
return but; |
return but; |
189 |
} |
} |
190 |
|
|
191 |
|
#ifdef OSD_SHADOW_ENABLE |
192 |
static void |
static void |
193 |
osm_gps_map_osd_shape_shadow(cairo_t *cr) { |
osm_gps_map_osd_shape_shadow(cairo_t *cr) { |
194 |
cairo_set_source_rgba (cr, 0, 0, 0, 0.2); |
cairo_set_source_rgba (cr, 0, 0, 0, 0.2); |
195 |
cairo_fill (cr); |
cairo_fill (cr); |
196 |
cairo_stroke (cr); |
cairo_stroke (cr); |
197 |
} |
} |
198 |
|
#endif |
199 |
|
|
200 |
|
#ifndef OSD_COLOR |
201 |
|
/* if no color has been specified we just use the gdks default colors */ |
202 |
|
static void |
203 |
|
osm_gps_map_osd_shape(cairo_t *cr, GdkColor *bg, GdkColor *fg) { |
204 |
|
gdk_cairo_set_source_color(cr, bg); |
205 |
|
cairo_fill_preserve (cr); |
206 |
|
gdk_cairo_set_source_color(cr, fg); |
207 |
|
cairo_set_line_width (cr, 1); |
208 |
|
cairo_stroke (cr); |
209 |
|
} |
210 |
|
#else |
211 |
static void |
static void |
212 |
osm_gps_map_osd_shape(cairo_t *cr) { |
osm_gps_map_osd_shape(cairo_t *cr) { |
213 |
cairo_set_source_rgb (cr, 1, 1, 1); |
cairo_set_source_rgb (cr, OSD_COLOR_BG); |
214 |
cairo_fill_preserve (cr); |
cairo_fill_preserve (cr); |
215 |
cairo_set_source_rgb (cr, OSD_COLOR); |
cairo_set_source_rgb (cr, OSD_COLOR); |
216 |
cairo_set_line_width (cr, 1); |
cairo_set_line_width (cr, 1); |
217 |
cairo_stroke (cr); |
cairo_stroke (cr); |
218 |
} |
} |
219 |
|
#endif |
220 |
|
|
221 |
|
#ifndef OSD_NO_DPAD |
222 |
static void |
static void |
223 |
osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) { |
osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) { |
224 |
/* move reference to dpad center */ |
/* move reference to dpad center */ |
243 |
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]); |
244 |
} |
} |
245 |
} |
} |
246 |
|
#endif |
247 |
|
|
248 |
/* draw the sattelite dish icon in the center of the dpad */ |
#ifdef OSD_GPS_BUTTON |
249 |
|
/* draw the satellite dish icon in the center of the dpad */ |
250 |
#define GPS_V0 (D_RAD/8) |
#define GPS_V0 (D_RAD/8) |
251 |
#define GPS_V1 (D_RAD/10) |
#define GPS_V1 (D_RAD/10) |
252 |
#define GPS_V2 (D_RAD/5) |
#define GPS_V2 (D_RAD/5) |
271 |
cairo_move_to (cr, x, y-GPS_V2); |
cairo_move_to (cr, x, y-GPS_V2); |
272 |
cairo_rel_line_to (cr, +GPS_V1, -GPS_V1); |
cairo_rel_line_to (cr, +GPS_V1, -GPS_V1); |
273 |
} |
} |
274 |
|
#endif |
275 |
|
|
276 |
#define Z_LEN (2*Z_RAD/3) |
#define Z_LEN (2*Z_RAD/3) |
277 |
|
|
286 |
cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); |
cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); |
287 |
} |
} |
288 |
|
|
289 |
|
#ifndef OSD_COLOR |
290 |
|
/* if no color has been specified we just use the gdks default colors */ |
291 |
|
static void |
292 |
|
osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled, |
293 |
|
GdkColor *fg, GdkColor *disabled) { |
294 |
|
if(enabled) gdk_cairo_set_source_color(cr, fg); |
295 |
|
else gdk_cairo_set_source_color(cr, disabled); |
296 |
|
cairo_set_line_width (cr, width); |
297 |
|
cairo_stroke (cr); |
298 |
|
} |
299 |
|
#else |
300 |
static void |
static void |
301 |
osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) { |
osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) { |
302 |
if(enabled) cairo_set_source_rgb (cr, OSD_COLOR); |
if(enabled) cairo_set_source_rgb (cr, OSD_COLOR); |
304 |
cairo_set_line_width (cr, width); |
cairo_set_line_width (cr, width); |
305 |
cairo_stroke (cr); |
cairo_stroke (cr); |
306 |
} |
} |
307 |
|
#endif |
308 |
|
|
309 |
|
#ifdef OSD_SHADOW_ENABLE |
310 |
static void |
static void |
311 |
osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) { |
osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) { |
312 |
cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15); |
cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15); |
313 |
cairo_set_line_width (cr, width); |
cairo_set_line_width (cr, width); |
314 |
cairo_stroke (cr); |
cairo_stroke (cr); |
315 |
} |
} |
316 |
|
#endif |
317 |
|
|
318 |
static void |
static void |
319 |
osm_gps_map_osd_render(osm_gps_map_osd_t *osd) { |
osm_gps_map_osd_render(osm_gps_map_osd_t *osd) { |
330 |
/* --------- draw zoom and dpad shape shadow ----------- */ |
/* --------- draw zoom and dpad shape shadow ----------- */ |
331 |
gint x = 0, y = 0; |
gint x = 0, y = 0; |
332 |
|
|
333 |
|
#ifdef OSD_SHADOW_ENABLE |
334 |
osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW); |
osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW); |
335 |
osm_gps_map_osd_shape_shadow(cr); |
osm_gps_map_osd_shape_shadow(cr); |
336 |
|
#ifndef OSD_NO_DPAD |
337 |
osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW); |
osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW); |
338 |
osm_gps_map_osd_shape_shadow(cr); |
osm_gps_map_osd_shape_shadow(cr); |
339 |
|
#endif |
340 |
|
#endif |
341 |
|
|
342 |
/* --------- draw zoom and dpad shape ----------- */ |
/* --------- draw zoom and dpad shape ----------- */ |
343 |
|
|
344 |
osm_gps_map_osd_zoom_shape(cr, x, y); |
osm_gps_map_osd_zoom_shape(cr, x, y); |
345 |
|
#ifndef OSD_COLOR |
346 |
|
osm_gps_map_osd_shape(cr, &priv->bg, &priv->fg); |
347 |
|
#else |
348 |
osm_gps_map_osd_shape(cr); |
osm_gps_map_osd_shape(cr); |
349 |
|
#endif |
350 |
|
#ifndef OSD_NO_DPAD |
351 |
osm_gps_map_osd_dpad_shape(cr, x, y); |
osm_gps_map_osd_dpad_shape(cr, x, y); |
352 |
|
#ifndef OSD_COLOR |
353 |
|
osm_gps_map_osd_shape(cr, &priv->bg, &priv->fg); |
354 |
|
#else |
355 |
osm_gps_map_osd_shape(cr); |
osm_gps_map_osd_shape(cr); |
356 |
|
#endif |
357 |
|
#endif |
358 |
|
|
359 |
/* --------- draw zoom and dpad labels --------- */ |
/* --------- draw zoom and dpad labels --------- */ |
360 |
|
|
361 |
|
#ifdef OSD_SHADOW_ENABLE |
362 |
osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
363 |
|
#ifndef OSD_NO_DPAD |
364 |
osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
365 |
|
#endif |
366 |
osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE); |
osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE); |
367 |
|
#ifdef OSD_GPS_BUTTON |
368 |
osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); |
369 |
osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL); |
osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL); |
370 |
|
#endif |
371 |
|
#endif |
372 |
|
|
373 |
osm_gps_map_osd_zoom_labels(cr, x, y); |
osm_gps_map_osd_zoom_labels(cr, x, y); |
374 |
|
#ifndef OSD_NO_DPAD |
375 |
osm_gps_map_osd_dpad_labels(cr, x, y); |
osm_gps_map_osd_dpad_labels(cr, x, y); |
376 |
|
#endif |
377 |
|
#ifndef OSD_COLOR |
378 |
|
osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE, &priv->fg, &priv->da); |
379 |
|
#else |
380 |
osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE); |
osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE); |
381 |
|
#endif |
382 |
|
#ifdef OSD_GPS_BUTTON |
383 |
osm_gps_map_osd_dpad_gps(cr, x, y); |
osm_gps_map_osd_dpad_gps(cr, x, y); |
384 |
|
#ifndef OSD_COLOR |
385 |
|
osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL, &priv->fg, &priv->da); |
386 |
|
#else |
387 |
osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL); |
osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL); |
388 |
|
#endif |
389 |
|
#endif |
390 |
|
|
391 |
cairo_destroy(cr); |
cairo_destroy(cr); |
392 |
} |
} |
393 |
|
|
394 |
static void |
static void |
395 |
osm_gps_map_osd_draw(osm_gps_map_osd_t *osd, gint xoffset, gint yoffset) |
osm_gps_map_osd_draw(osm_gps_map_osd_t *osd, GdkDrawable *drawable) |
396 |
{ |
{ |
397 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
398 |
|
|
|
/* backup previous contents */ |
|
|
if(!priv->backup) |
|
|
priv->backup = gdk_pixmap_new(osd->pixmap, OSD_W+2, OSD_H+2, -1); |
|
|
|
|
|
gint x = OSD_X + xoffset; |
|
|
gint y = OSD_Y + yoffset; |
|
|
|
|
|
/* create backup of background */ |
|
|
gdk_draw_drawable(priv->backup, |
|
|
osd->widget->style->fg_gc[GTK_WIDGET_STATE(osd->widget)], |
|
|
osd->pixmap, x-1, y-1, 0, 0, OSD_W+2, OSD_H+2); |
|
|
|
|
|
priv->backup_x = x-1; |
|
|
priv->backup_y = y-1; |
|
|
|
|
399 |
/* OSD itself uses some off-screen rendering, so check if the */ |
/* OSD itself uses some off-screen rendering, so check if the */ |
400 |
/* offscreen buffer is present and create it if not */ |
/* offscreen buffer is present and create it if not */ |
401 |
if(!priv->overlay) { |
if(!priv->overlay) { |
407 |
} |
} |
408 |
|
|
409 |
// now draw this onto the original context |
// now draw this onto the original context |
410 |
cairo_t *cr = gdk_cairo_create(osd->pixmap); |
cairo_t *cr = gdk_cairo_create(drawable); |
411 |
cairo_set_source_surface(cr, priv->overlay, x, y); |
cairo_set_source_surface(cr, priv->overlay, OSD_X, OSD_Y); |
412 |
cairo_paint(cr); |
cairo_paint(cr); |
413 |
cairo_destroy(cr); |
cairo_destroy(cr); |
414 |
} |
} |
415 |
|
|
416 |
static void |
static void |
|
osm_gps_map_osd_restore (osm_gps_map_osd_t *osd) |
|
|
{ |
|
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
|
|
|
|
|
/* restore backup of previous contents */ |
|
|
if(priv->backup) { |
|
|
/* create backup of background */ |
|
|
gdk_draw_drawable(osd->pixmap, |
|
|
osd->widget->style->fg_gc[GTK_WIDGET_STATE(osd->widget)], |
|
|
priv->backup, 0, 0, |
|
|
priv->backup_x, priv->backup_y, OSD_W+2, OSD_H+2); |
|
|
} |
|
|
} |
|
|
|
|
|
static void |
|
417 |
osm_gps_map_osd_free(osm_gps_map_osd_t *osd) |
osm_gps_map_osd_free(osm_gps_map_osd_t *osd) |
418 |
{ |
{ |
419 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
420 |
|
|
|
if (priv->backup) |
|
|
g_object_unref(priv->backup); |
|
|
|
|
421 |
if (priv->overlay) |
if (priv->overlay) |
422 |
cairo_surface_destroy(priv->overlay); |
cairo_surface_destroy(priv->overlay); |
423 |
|
|
425 |
} |
} |
426 |
|
|
427 |
static osm_gps_map_osd_t osd_classic = { |
static osm_gps_map_osd_t osd_classic = { |
|
.restore = osm_gps_map_osd_restore, |
|
428 |
.draw = osm_gps_map_osd_draw, |
.draw = osm_gps_map_osd_draw, |
429 |
.check = osm_gps_map_osd_check, |
.check = osm_gps_map_osd_check, |
430 |
.render = osm_gps_map_osd_render, |
.render = osm_gps_map_osd_render, |
444 |
|
|
445 |
osd_classic.priv = priv; |
osd_classic.priv = priv; |
446 |
|
|
447 |
|
/* extract style info from the widget */ |
448 |
|
priv->bg = GTK_WIDGET(map)->style->bg[GTK_STATE_NORMAL]; |
449 |
|
priv->fg = GTK_WIDGET(map)->style->fg[GTK_STATE_NORMAL]; |
450 |
|
priv->da = GTK_WIDGET(map)->style->fg[GTK_STATE_INSENSITIVE]; |
451 |
|
|
452 |
osm_gps_map_register_osd(map, &osd_classic); |
osm_gps_map_register_osd(map, &osd_classic); |
453 |
} |
} |
454 |
|
|
455 |
|
#ifdef OSD_GPS_BUTTON |
456 |
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, gpointer data) { |
/* below are osd specific functions which aren't used by osm-gps-map */ |
457 |
|
/* but instead are to be used by the main application */ |
458 |
|
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, |
459 |
|
gpointer data) { |
460 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
461 |
|
|
462 |
g_return_if_fail (osd); |
g_return_if_fail (osd); |
470 |
|
|
471 |
osm_gps_map_redraw(map); |
osm_gps_map_redraw(map); |
472 |
} |
} |
473 |
|
#endif |