114 |
struct { |
struct { |
115 |
GdkPixmap *backup; |
GdkPixmap *backup; |
116 |
gint backup_x, backup_y; |
gint backup_x, backup_y; |
117 |
// GdkPixbuf *pixbuf; |
OsmGpsMapOsdGpsCallback cb; |
118 |
|
gpointer data; |
119 |
} osd; |
} osd; |
120 |
#endif |
#endif |
121 |
|
|
664 |
#define BALLOON_AREA_HEIGHT 75 |
#define BALLOON_AREA_HEIGHT 75 |
665 |
#endif |
#endif |
666 |
#ifndef BALLOON_CORNER_RADIUS |
#ifndef BALLOON_CORNER_RADIUS |
667 |
#define BALLOON_CORNER_RADIUS 20 |
#define BALLOON_CORNER_RADIUS 10 |
668 |
#endif |
#endif |
669 |
|
|
670 |
#define BALLOON_BORDER (BALLOON_CORNER_RADIUS/4) |
#define BALLOON_BORDER (BALLOON_CORNER_RADIUS/2) |
671 |
#define BALLOON_WIDTH (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER) |
#define BALLOON_WIDTH (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER) |
672 |
#define BALLOON_HEIGHT (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER) |
#define BALLOON_HEIGHT (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER) |
673 |
#define BALLOON_TRANSPARENCY 0.8 |
#define BALLOON_TRANSPARENCY 0.8 |
674 |
#define POINTER_HEIGHT 20 |
#define POINTER_HEIGHT 20 |
675 |
#define POINTER_FOOT_WIDTH 20 |
#define POINTER_FOOT_WIDTH 20 |
676 |
#define POINTER_OFFSET (BALLOON_CORNER_RADIUS*3/4) |
#define POINTER_OFFSET (BALLOON_CORNER_RADIUS*3/4) |
677 |
#define BALLOON_SHADOW 5 |
#define BALLOON_SHADOW (BALLOON_CORNER_RADIUS/2) |
678 |
#define BALLOON_SHADOW_TRANSPARENCY 0.2 |
#define BALLOON_SHADOW_TRANSPARENCY 0.2 |
679 |
|
|
680 |
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS/3) |
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) |
681 |
|
|
682 |
|
|
683 |
/* draw the bubble shape. this is used twice, once for the shape and once */ |
/* draw the bubble shape. this is used twice, once for the shape and once */ |
687 |
gboolean bottom, int px, int py, int px0, int px1) { |
gboolean bottom, int px, int py, int px0, int px1) { |
688 |
|
|
689 |
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
690 |
cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + BALLOON_CORNER_RADIUS, y0); |
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
691 |
|
BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2); |
692 |
if(!bottom) { |
if(!bottom) { |
693 |
/* insert top pointer */ |
/* insert top pointer */ |
694 |
cairo_line_to (cr, px1, y0); |
cairo_line_to (cr, px1, y0); |
697 |
} |
} |
698 |
|
|
699 |
cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0); |
cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0); |
700 |
cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + BALLOON_CORNER_RADIUS); |
cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
701 |
|
BALLOON_CORNER_RADIUS, -M_PI/2, 0); |
702 |
cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS); |
cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS); |
703 |
cairo_curve_to (cr, x1, y1, x1, y1, x1 - BALLOON_CORNER_RADIUS, y1); |
cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, |
704 |
|
BALLOON_CORNER_RADIUS, 0, M_PI/2); |
705 |
if(bottom) { |
if(bottom) { |
706 |
/* insert bottom pointer */ |
/* insert bottom pointer */ |
707 |
cairo_line_to (cr, px0, y1); |
cairo_line_to (cr, px0, y1); |
710 |
} |
} |
711 |
|
|
712 |
cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1); |
cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1); |
713 |
cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - BALLOON_CORNER_RADIUS); |
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, |
714 |
|
BALLOON_CORNER_RADIUS, M_PI/2, M_PI); |
715 |
|
|
716 |
cairo_close_path (cr); |
cairo_close_path (cr); |
717 |
} |
} |
802 |
cairo_stroke(cr); |
cairo_stroke(cr); |
803 |
|
|
804 |
cairo_set_source_rgba (cr, 1, 1, 1, 1.0); |
cairo_set_source_rgba (cr, 1, 1, 1, 1.0); |
805 |
cairo_set_line_width (cr, 3); |
cairo_set_line_width (cr, BALLOON_CORNER_RADIUS/3.3); |
806 |
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
807 |
cairo_move_to (cr, cx - crad/2, cy - crad/2); |
cairo_move_to (cr, cx - crad/2, cy - crad/2); |
808 |
cairo_line_to (cr, cx + crad/2, cy + crad/2); |
cairo_line_to (cr, cx + crad/2, cy + crad/2); |
1427 |
#define OSD_X (10) |
#define OSD_X (10) |
1428 |
#define OSD_Y (10) |
#define OSD_Y (10) |
1429 |
|
|
1430 |
#define OSD_COLOR 0.5, 0.5, 1 |
#define OSD_COLOR 0.5, 0.5, 1 |
1431 |
|
#define OSD_COLOR_DISABLED 0.8, 0.8, 0.8 |
1432 |
|
|
1433 |
/* parameters of the direction shape */ |
/* parameters of the direction shape */ |
1434 |
#define D_RAD (20) // diameter of dpad |
#ifndef OSM_GPS_MAP_OSD_DIAMETER |
1435 |
|
#define D_RAD (30) // diameter of dpad |
1436 |
|
#else |
1437 |
|
#define D_RAD (OSM_GPS_MAP_OSD_DIAMETER) |
1438 |
|
#endif |
1439 |
#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 |
1440 |
#define D_LEN (D_RAD/4) // length of arrow |
#define D_LEN (D_RAD/4) // length of arrow |
1441 |
#define D_WID (D_LEN) // width of arrow |
#define D_WID (D_LEN) // width of arrow |
1442 |
|
|
1443 |
/* parameters of the "zoom" pad */ |
/* parameters of the "zoom" pad */ |
1444 |
#define Z_STEP (-D_RAD/8) // distance between dpad and zoom |
#define Z_STEP (D_RAD/4) // distance between dpad and zoom |
1445 |
#define Z_RAD (D_RAD/2) // radius of "caps" of zoom bar |
#define Z_RAD (D_RAD/2) // radius of "caps" of zoom bar |
1446 |
|
|
1447 |
/* shadow also depends on control size */ |
/* shadow also depends on control size */ |
1448 |
#define OSD_SHADOW (D_RAD/8) |
#define OSD_SHADOW (D_RAD/6) |
1449 |
|
|
1450 |
/* total width and height of controls incl. shadow */ |
/* total width and height of controls incl. shadow */ |
1451 |
#define OSD_W (2*D_RAD + OSD_SHADOW) |
#define OSD_W (2*D_RAD + OSD_SHADOW) |
1505 |
y -= (OSD_Y + D_RAD); |
y -= (OSD_Y + D_RAD); |
1506 |
|
|
1507 |
/* check for dpad center goes here! */ |
/* check for dpad center goes here! */ |
1508 |
if( osm_gps_map_in_circle(x, y, OSD_X + D_RAD, OSD_Y + D_RAD, D_RAD/3)) |
if( osm_gps_map_in_circle(x, y, 0, 0, D_RAD/3)) |
1509 |
return OSD_GPS; |
return OSD_GPS; |
1510 |
|
|
1511 |
if( y < 0 && abs(x) < abs(y)) |
if( y < 0 && abs(x) < abs(y)) |
1528 |
/* check whether x/y is within the zoom pads */ |
/* check whether x/y is within the zoom pads */ |
1529 |
static osd_button_t |
static osd_button_t |
1530 |
osm_gps_map_osd_check_zoom(gint x, gint y) { |
osm_gps_map_osd_check_zoom(gint x, gint y) { |
1531 |
if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < Z_BOT) { |
if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < (OSD_Y+Z_BOT)) { |
1532 |
|
|
1533 |
/* within circle around (-) label */ |
/* within circle around (-) label */ |
1534 |
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, OSD_X + Z_LEFT, OSD_Y + Z_MID, Z_RAD)) |
1558 |
/* this is just to avoid an unnecessary detailed test */ |
/* this is just to avoid an unnecessary detailed test */ |
1559 |
if(x > OSD_X && x < OSD_X + OSD_W && |
if(x > OSD_X && x < OSD_X + OSD_W && |
1560 |
y > OSD_Y && y < OSD_Y + OSD_H) { |
y > OSD_Y && y < OSD_Y + OSD_H) { |
|
|
|
1561 |
but = osm_gps_map_osd_check_dpad(x, y); |
but = osm_gps_map_osd_check_dpad(x, y); |
1562 |
|
|
1563 |
if(but == OSD_NONE) |
if(but == OSD_NONE) |
1648 |
} |
} |
1649 |
|
|
1650 |
static void |
static void |
1651 |
osm_gps_map_osd_labels(cairo_t *cr, gint width) { |
osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) { |
1652 |
cairo_set_source_rgb (cr, OSD_COLOR); |
if(enabled) cairo_set_source_rgb (cr, OSD_COLOR); |
1653 |
|
else cairo_set_source_rgb (cr, OSD_COLOR_DISABLED); |
1654 |
cairo_set_line_width (cr, width); |
cairo_set_line_width (cr, width); |
1655 |
cairo_stroke (cr); |
cairo_stroke (cr); |
1656 |
} |
} |
1657 |
|
|
1658 |
static void |
static void |
1659 |
osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width) { |
osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) { |
1660 |
cairo_set_source_rgba (cr, 0, 0, 0, 0.2); |
cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15); |
1661 |
cairo_set_line_width (cr, width); |
cairo_set_line_width (cr, width); |
1662 |
cairo_stroke (cr); |
cairo_stroke (cr); |
1663 |
} |
} |
1722 |
|
|
1723 |
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); |
1724 |
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); |
1725 |
osm_gps_map_osd_labels_shadow(cr, Z_RAD/3); |
osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE); |
1726 |
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); |
1727 |
osm_gps_map_osd_labels_shadow(cr, Z_RAD/6); |
osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, priv->osd.cb != NULL); |
1728 |
|
|
1729 |
osm_gps_map_osd_zoom_labels(cr, x, y); |
osm_gps_map_osd_zoom_labels(cr, x, y); |
1730 |
osm_gps_map_osd_dpad_labels(cr, x, y); |
osm_gps_map_osd_dpad_labels(cr, x, y); |
1731 |
osm_gps_map_osd_labels(cr, Z_RAD/3); |
osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE); |
1732 |
osm_gps_map_osd_dpad_gps(cr, x, y); |
osm_gps_map_osd_dpad_gps(cr, x, y); |
1733 |
osm_gps_map_osd_labels(cr, Z_RAD/6); |
osm_gps_map_osd_labels(cr, Z_RAD/6, priv->osd.cb != NULL); |
1734 |
|
|
1735 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1736 |
|
|
1831 |
|
|
1832 |
#ifdef ENABLE_OSD |
#ifdef ENABLE_OSD |
1833 |
priv->osd.backup = NULL; |
priv->osd.backup = NULL; |
1834 |
|
priv->osd.cb = NULL; |
1835 |
#endif |
#endif |
1836 |
|
|
1837 |
priv->tracks = NULL; |
priv->tracks = NULL; |
2229 |
#endif |
#endif |
2230 |
|
|
2231 |
#ifdef ENABLE_OSD |
#ifdef ENABLE_OSD |
2232 |
/* also don't drag on clicks into the control OSD */ |
#define SCROLL_STEP 10 |
|
if(osm_gps_map_osd_check(event->x, event->y) != OSD_NONE) |
|
|
{ |
|
|
priv->drag_counter = -1; |
|
|
return FALSE; |
|
|
} |
|
|
#endif |
|
2233 |
|
|
2234 |
priv->drag_counter = 0; |
/* pressed inside OSD control? */ |
|
priv->drag_start_mouse_x = (int) event->x; |
|
|
priv->drag_start_mouse_y = (int) event->y; |
|
|
priv->drag_start_map_x = priv->map_x; |
|
|
priv->drag_start_map_y = priv->map_y; |
|
|
|
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
static gboolean |
|
|
osm_gps_map_button_release (GtkWidget *widget, GdkEventButton *event) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
|
|
|
|
|
#ifdef ENABLE_OSD |
|
|
/* released inside OSD control? */ |
|
2235 |
osd_button_t but = osm_gps_map_osd_check(event->x, event->y); |
osd_button_t but = osm_gps_map_osd_check(event->x, event->y); |
2236 |
if(but != OSD_NONE) |
if(but != OSD_NONE) |
2237 |
{ |
{ |
2238 |
|
priv->drag_counter = -1; |
2239 |
|
|
2240 |
switch(but) { |
switch(but) { |
2241 |
|
case OSD_GPS: |
2242 |
|
priv->osd.cb(priv->osd.data); |
2243 |
|
break; |
2244 |
|
|
2245 |
case OSD_UP: |
case OSD_UP: |
2246 |
priv->map_y -= GTK_WIDGET(widget)->allocation.height/4; |
priv->map_y -= GTK_WIDGET(widget)->allocation.height/SCROLL_STEP; |
2247 |
priv->center_coord_set = FALSE; |
priv->center_coord_set = FALSE; |
2248 |
break; |
break; |
2249 |
|
|
2250 |
case OSD_DOWN: |
case OSD_DOWN: |
2251 |
priv->map_y += GTK_WIDGET(widget)->allocation.height/4; |
priv->map_y += GTK_WIDGET(widget)->allocation.height/SCROLL_STEP; |
2252 |
priv->center_coord_set = FALSE; |
priv->center_coord_set = FALSE; |
2253 |
break; |
break; |
2254 |
|
|
2255 |
case OSD_LEFT: |
case OSD_LEFT: |
2256 |
priv->map_x -= GTK_WIDGET(widget)->allocation.width/4; |
priv->map_x -= GTK_WIDGET(widget)->allocation.width/SCROLL_STEP; |
2257 |
priv->center_coord_set = FALSE; |
priv->center_coord_set = FALSE; |
2258 |
break; |
break; |
2259 |
|
|
2260 |
case OSD_RIGHT: |
case OSD_RIGHT: |
2261 |
priv->map_x += GTK_WIDGET(widget)->allocation.width/4; |
priv->map_x += GTK_WIDGET(widget)->allocation.width/SCROLL_STEP; |
2262 |
priv->center_coord_set = FALSE; |
priv->center_coord_set = FALSE; |
2263 |
break; |
break; |
2264 |
|
|
2280 |
} |
} |
2281 |
#endif |
#endif |
2282 |
|
|
2283 |
|
priv->drag_counter = 0; |
2284 |
|
priv->drag_start_mouse_x = (int) event->x; |
2285 |
|
priv->drag_start_mouse_y = (int) event->y; |
2286 |
|
priv->drag_start_map_x = priv->map_x; |
2287 |
|
priv->drag_start_map_y = priv->map_y; |
2288 |
|
|
2289 |
|
return FALSE; |
2290 |
|
} |
2291 |
|
|
2292 |
|
static gboolean |
2293 |
|
osm_gps_map_button_release (GtkWidget *widget, GdkEventButton *event) |
2294 |
|
{ |
2295 |
|
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
2296 |
|
|
2297 |
#ifdef ENABLE_BALLOON |
#ifdef ENABLE_BALLOON |
2298 |
/* released inside the balloon? */ |
/* released inside the balloon? */ |
2299 |
if (osm_gps_map_in_balloon(priv, |
if (osm_gps_map_in_balloon(priv, |
2664 |
"radius of the gps point inner circle", |
"radius of the gps point inner circle", |
2665 |
0, /* minimum property value */ |
0, /* minimum property value */ |
2666 |
G_MAXINT, /* maximum property value */ |
G_MAXINT, /* maximum property value */ |
2667 |
5, |
10, |
2668 |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); |
2669 |
|
|
2670 |
g_object_class_install_property (object_class, |
g_object_class_install_property (object_class, |
3287 |
osm_gps_map_map_redraw_idle(map); |
osm_gps_map_map_redraw_idle(map); |
3288 |
} |
} |
3289 |
#endif |
#endif |
3290 |
|
|
3291 |
|
#ifdef ENABLE_OSD |
3292 |
|
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdGpsCallback cb, gpointer data) { |
3293 |
|
OsmGpsMapPrivate *priv; |
3294 |
|
|
3295 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
3296 |
|
priv = map->priv; |
3297 |
|
|
3298 |
|
priv->osd.cb = cb; |
3299 |
|
priv->osd.data = data; |
3300 |
|
|
3301 |
|
osm_gps_map_map_redraw_idle(map); |
3302 |
|
} |
3303 |
|
#endif |