22 |
#include <math.h> // M_PI |
#include <math.h> // M_PI |
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 USE_CAIRO |
#ifndef USE_CAIRO |
29 |
#error "OSD control display lacks a non-cairo implementation!" |
#error "OSD control display lacks a non-cairo implementation!" |
38 |
typedef struct { |
typedef struct { |
39 |
/* the offscreen representation of the OSD */ |
/* the offscreen representation of the OSD */ |
40 |
cairo_surface_t *overlay; |
cairo_surface_t *overlay; |
|
|
|
|
GdkColor bg, fg, da; |
|
|
|
|
41 |
} osd_priv_t; |
} osd_priv_t; |
42 |
|
|
43 |
/* position and extent of bounding box */ |
/* position and extent of bounding box */ |
44 |
|
#ifndef OSD_X |
45 |
#define OSD_X (10) |
#define OSD_X (10) |
46 |
|
#endif |
47 |
|
|
48 |
|
#ifndef OSD_Y |
49 |
#define OSD_Y (10) |
#define OSD_Y (10) |
50 |
|
#endif |
51 |
|
|
52 |
/* parameters of the direction shape */ |
/* parameters of the direction shape */ |
53 |
#ifndef OSM_GPS_MAP_OSD_DIAMETER |
#ifndef OSD_DIAMETER |
54 |
#define D_RAD (30) // diameter of dpad |
#define D_RAD (30) // diameter of dpad |
55 |
#else |
#else |
56 |
#define D_RAD (OSM_GPS_MAP_OSD_DIAMETER) |
#define D_RAD (OSD_DIAMETER) |
57 |
#endif |
#endif |
58 |
#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 |
59 |
#define D_LEN (D_RAD/4) // length of arrow |
#define D_LEN (D_RAD/4) // length of arrow |
70 |
#define OSD_SHADOW (0) |
#define OSD_SHADOW (0) |
71 |
#endif |
#endif |
72 |
|
|
73 |
|
/* normally the GPS button is in the center of the dpad. if there's */ |
74 |
|
/* no dpad it will go into the zoom area */ |
75 |
|
#if defined(OSD_GPS_BUTTON) && defined(OSD_NO_DPAD) |
76 |
|
#define Z_GPS 1 |
77 |
|
#else |
78 |
|
#define Z_GPS 0 |
79 |
|
#endif |
80 |
|
|
81 |
/* total width and height of controls incl. shadow */ |
/* total width and height of controls incl. shadow */ |
82 |
#define OSD_W (2*D_RAD + OSD_SHADOW) |
#define OSD_W (2*D_RAD + OSD_SHADOW + Z_GPS * 2 * Z_RAD) |
83 |
|
#if !Z_GPS |
84 |
#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) |
85 |
|
#else |
86 |
|
#define OSD_H (2*Z_RAD + OSD_SHADOW) |
87 |
|
#endif |
88 |
|
|
89 |
#ifdef OSD_SHADOW_ENABLE |
#ifdef OSD_SHADOW_ENABLE |
90 |
#define OSD_LBL_SHADOW (OSD_SHADOW/2) |
#define OSD_LBL_SHADOW (OSD_SHADOW/2) |
91 |
#endif |
#endif |
92 |
|
|
93 |
#define Z_TOP (2 * D_RAD + Z_STEP) |
#define Z_TOP ((1-Z_GPS) * (2 * D_RAD + Z_STEP)) |
94 |
|
|
95 |
#define Z_MID (Z_TOP + Z_RAD) |
#define Z_MID (Z_TOP + Z_RAD) |
96 |
#define Z_BOT (Z_MID + Z_RAD) |
#define Z_BOT (Z_MID + Z_RAD) |
97 |
#define Z_LEFT (Z_RAD) |
#define Z_LEFT (Z_RAD) |
98 |
#define Z_RIGHT (2 * D_RAD - Z_RAD) |
#define Z_RIGHT (2 * D_RAD - Z_RAD + Z_GPS * 2 * Z_RAD) |
99 |
|
#define Z_CENTER ((Z_RIGHT + Z_LEFT)/2) |
100 |
|
|
101 |
/* create the cairo shape used for the zoom buttons */ |
/* create the cairo shape used for the zoom buttons */ |
102 |
static void |
static void |
130 |
osm_gps_map_osd_check_dpad(gint x, gint y) |
osm_gps_map_osd_check_dpad(gint x, gint y) |
131 |
{ |
{ |
132 |
/* within entire dpad circle */ |
/* within entire dpad circle */ |
133 |
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)) |
134 |
{ |
{ |
135 |
/* convert into position relative to dpads centre */ |
/* convert into position relative to dpads centre */ |
136 |
x -= (OSD_X + D_RAD); |
x -= D_RAD; |
137 |
y -= (OSD_Y + D_RAD); |
y -= D_RAD; |
138 |
|
|
139 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
140 |
/* check for dpad center goes here! */ |
/* check for dpad center goes here! */ |
163 |
/* check whether x/y is within the zoom pads */ |
/* check whether x/y is within the zoom pads */ |
164 |
static osd_button_t |
static osd_button_t |
165 |
osm_gps_map_osd_check_zoom(gint x, gint y) { |
osm_gps_map_osd_check_zoom(gint x, gint y) { |
166 |
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) { |
167 |
|
|
168 |
/* within circle around (-) label */ |
/* within circle around (-) label */ |
169 |
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) |
|
170 |
return OSD_OUT; |
return OSD_OUT; |
171 |
|
|
172 |
/* within circle around (+) label */ |
/* within circle around (+) label */ |
173 |
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)) |
174 |
return OSD_IN; |
return OSD_IN; |
175 |
|
|
176 |
|
#if Z_GPS == 1 |
177 |
|
/* within square around center */ |
178 |
|
if( x > Z_CENTER - Z_RAD && x < Z_CENTER + Z_RAD) |
179 |
|
return OSD_GPS; |
180 |
|
#endif |
181 |
|
|
182 |
|
/* between center of (-) button and center of entire zoom control area */ |
183 |
|
if(x > OSD_LEFT && x < D_RAD) |
184 |
|
return OSD_OUT; |
185 |
|
|
186 |
/* between center of (+) button and center of entire zoom control area */ |
/* between center of (+) button and center of entire zoom control area */ |
187 |
if(x < OSD_RIGHT && x > OSD_X + D_RAD) |
if(x < OSD_RIGHT && x > D_RAD) |
188 |
return OSD_IN; |
return OSD_IN; |
189 |
} |
} |
190 |
|
|
192 |
} |
} |
193 |
|
|
194 |
static osd_button_t |
static osd_button_t |
195 |
osm_gps_map_osd_check(gint x, gint y) { |
osm_gps_map_osd_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
196 |
osd_button_t but = OSD_NONE; |
osd_button_t but = OSD_NONE; |
197 |
|
|
198 |
|
x -= OSD_X; |
199 |
|
y -= OSD_Y; |
200 |
|
|
201 |
|
if(OSD_X < 0) |
202 |
|
x -= (osd->widget->allocation.width - OSD_W); |
203 |
|
|
204 |
|
if(OSD_Y < 0) |
205 |
|
y -= (osd->widget->allocation.height - OSD_H); |
206 |
|
|
207 |
/* first do a rough test for the OSD area. */ |
/* first do a rough test for the OSD area. */ |
208 |
/* this is just to avoid an unnecessary detailed test */ |
/* this is just to avoid an unnecessary detailed test */ |
209 |
if(x > OSD_X && x < OSD_X + OSD_W && |
if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) { |
|
y > OSD_Y && y < OSD_Y + OSD_H) { |
|
210 |
#ifndef OSD_NO_DPAD |
#ifndef OSD_NO_DPAD |
211 |
but = osm_gps_map_osd_check_dpad(x, y); |
but = osm_gps_map_osd_check_dpad(x, y); |
212 |
#endif |
#endif |
277 |
|
|
278 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
279 |
/* draw the satellite dish icon in the center of the dpad */ |
/* draw the satellite dish icon in the center of the dpad */ |
280 |
#define GPS_V0 (D_RAD/8) |
#define GPS_V0 (D_RAD/7) |
281 |
#define GPS_V1 (D_RAD/10) |
#define GPS_V1 (D_RAD/10) |
282 |
#define GPS_V2 (D_RAD/5) |
#define GPS_V2 (D_RAD/5) |
283 |
|
|
284 |
/* draw a satellite receiver dish */ |
/* draw a satellite receiver dish */ |
285 |
|
/* this is either drawn in the center of the dpad (if present) */ |
286 |
|
/* or in the middle of the zoom area */ |
287 |
static void |
static void |
288 |
osm_gps_map_osd_dpad_gps(cairo_t *cr, gint x, gint y) { |
osm_gps_map_osd_dpad_gps(cairo_t *cr, gint x, gint y) { |
289 |
/* move reference to dpad center */ |
/* move reference to dpad center */ |
290 |
x += D_RAD; |
x += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD * 3; |
291 |
y += D_RAD + GPS_V0; |
y += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD + GPS_V0; |
292 |
|
|
293 |
cairo_move_to (cr, x-GPS_V0, y+GPS_V0); |
cairo_move_to (cr, x-GPS_V0, y+GPS_V0); |
294 |
cairo_rel_line_to (cr, +GPS_V0, -GPS_V0); |
cairo_rel_line_to (cr, +GPS_V0, -GPS_V0); |
357 |
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); |
358 |
cairo_paint(cr); |
cairo_paint(cr); |
359 |
|
|
360 |
|
#ifndef OSD_COLOR |
361 |
|
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
362 |
|
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
363 |
|
GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE]; |
364 |
|
#endif |
365 |
|
|
366 |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
367 |
|
|
368 |
/* --------- draw zoom and dpad shape shadow ----------- */ |
/* --------- draw zoom and dpad shape shadow ----------- */ |
381 |
|
|
382 |
osm_gps_map_osd_zoom_shape(cr, x, y); |
osm_gps_map_osd_zoom_shape(cr, x, y); |
383 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
384 |
osm_gps_map_osd_shape(cr, &priv->bg, &priv->fg); |
osm_gps_map_osd_shape(cr, &bg, &fg); |
385 |
#else |
#else |
386 |
osm_gps_map_osd_shape(cr); |
osm_gps_map_osd_shape(cr); |
387 |
#endif |
#endif |
388 |
#ifndef OSD_NO_DPAD |
#ifndef OSD_NO_DPAD |
389 |
osm_gps_map_osd_dpad_shape(cr, x, y); |
osm_gps_map_osd_dpad_shape(cr, x, y); |
390 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
391 |
osm_gps_map_osd_shape(cr, &priv->bg, &priv->fg); |
osm_gps_map_osd_shape(cr, &bg, &fg); |
392 |
#else |
#else |
393 |
osm_gps_map_osd_shape(cr); |
osm_gps_map_osd_shape(cr); |
394 |
#endif |
#endif |
413 |
osm_gps_map_osd_dpad_labels(cr, x, y); |
osm_gps_map_osd_dpad_labels(cr, x, y); |
414 |
#endif |
#endif |
415 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
416 |
osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE, &priv->fg, &priv->da); |
osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE, &fg, &da); |
417 |
#else |
#else |
418 |
osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE); |
osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE); |
419 |
#endif |
#endif |
420 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
421 |
osm_gps_map_osd_dpad_gps(cr, x, y); |
osm_gps_map_osd_dpad_gps(cr, x, y); |
422 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
423 |
osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL, &priv->fg, &priv->da); |
osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL, &fg, &da); |
424 |
#else |
#else |
425 |
osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL); |
osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL); |
426 |
#endif |
#endif |
446 |
|
|
447 |
// now draw this onto the original context |
// now draw this onto the original context |
448 |
cairo_t *cr = gdk_cairo_create(drawable); |
cairo_t *cr = gdk_cairo_create(drawable); |
449 |
cairo_set_source_surface(cr, priv->overlay, OSD_X, OSD_Y); |
|
450 |
|
int x = OSD_X, y = OSD_Y; |
451 |
|
if(OSD_X < 0) |
452 |
|
x = osd->widget->allocation.width - OSD_W + OSD_X; |
453 |
|
|
454 |
|
if(OSD_Y < 0) |
455 |
|
y = osd->widget->allocation.height - OSD_H + OSD_Y; |
456 |
|
|
457 |
|
cairo_set_source_surface(cr, priv->overlay, x, y); |
458 |
cairo_paint(cr); |
cairo_paint(cr); |
459 |
cairo_destroy(cr); |
cairo_destroy(cr); |
460 |
} |
} |
490 |
|
|
491 |
osd_classic.priv = priv; |
osd_classic.priv = priv; |
492 |
|
|
|
/* 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]; |
|
|
|
|
493 |
osm_gps_map_register_osd(map, &osd_classic); |
osm_gps_map_register_osd(map, &osd_classic); |
494 |
} |
} |
495 |
|
|