113 |
//the osd controls |
//the osd controls |
114 |
struct { |
struct { |
115 |
GdkPixmap *backup; |
GdkPixmap *backup; |
116 |
|
cairo_surface_t *overlay; |
117 |
gint backup_x, backup_y; |
gint backup_x, backup_y; |
118 |
OsmGpsMapOsdGpsCallback cb; |
OsmGpsMapOsdGpsCallback cb; |
119 |
gpointer data; |
gpointer data; |
1476 |
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); |
1477 |
} |
} |
1478 |
|
|
|
typedef enum { |
|
|
OSD_NONE = 0, |
|
|
OSD_BG, |
|
|
OSD_UP, |
|
|
OSD_DOWN, |
|
|
OSD_LEFT, |
|
|
OSD_RIGHT, |
|
|
OSD_IN, |
|
|
OSD_OUT, |
|
|
OSD_GPS |
|
|
} osd_button_t; |
|
|
|
|
1479 |
static gboolean |
static gboolean |
1480 |
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) |
1481 |
{ |
{ |
1539 |
return OSD_NONE; |
return OSD_NONE; |
1540 |
} |
} |
1541 |
|
|
1542 |
static osd_button_t |
osd_button_t |
1543 |
osm_gps_map_osd_check(gint x, gint y) { |
osm_gps_map_osd_check(gint x, gint y) { |
1544 |
osd_button_t but = OSD_NONE; |
osd_button_t but = OSD_NONE; |
1545 |
|
|
1652 |
} |
} |
1653 |
|
|
1654 |
static void |
static void |
1655 |
osm_gps_map_osd_draw_controls (OsmGpsMap *map, gint xoffset, gint yoffset) |
osm_gps_map_osd_render(OsmGpsMapPrivate *priv) { |
|
{ |
|
|
OsmGpsMapPrivate *priv = map->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; |
|
|
|
|
|
#if 0 |
|
|
/* create pixbuf for osd */ |
|
|
if(!priv->osd.pixbuf) |
|
|
priv->osd.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, |
|
|
TRUE, 8, OSD_W, OSD_H); |
|
|
cairo_surface_t *surface = |
|
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H); |
|
1656 |
|
|
1657 |
/* fill with transparency */ |
/* first fill with transparency */ |
1658 |
{ |
cairo_t *cr = cairo_create(priv->osd.overlay); |
|
cairo_t *cr = cairo_create(surface); |
|
1659 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1660 |
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); |
1661 |
cairo_paint(cr); |
cairo_paint(cr); |
|
cairo_destroy(cr); |
|
|
} |
|
|
#endif |
|
1662 |
|
|
1663 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
|
#ifdef USE_CAIRO |
|
|
// cairo_t *cr = cairo_create(surface); |
|
|
cairo_t *cr = gdk_cairo_create(priv->pixmap); |
|
1664 |
|
|
1665 |
/* --------- draw zoom and dpad shape shadow ----------- */ |
/* --------- draw zoom and dpad shape shadow ----------- */ |
1666 |
|
gint x = 0, y = 0; |
1667 |
|
|
1668 |
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); |
1669 |
osm_gps_map_osd_shape_shadow(cr); |
osm_gps_map_osd_shape_shadow(cr); |
1692 |
osm_gps_map_osd_labels(cr, Z_RAD/6, priv->osd.cb != NULL); |
osm_gps_map_osd_labels(cr, Z_RAD/6, priv->osd.cb != NULL); |
1693 |
|
|
1694 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1695 |
|
} |
1696 |
|
|
1697 |
|
static void |
1698 |
|
osm_gps_map_osd_draw_controls (OsmGpsMap *map, gint xoffset, gint yoffset) |
1699 |
|
{ |
1700 |
|
OsmGpsMapPrivate *priv = map->priv; |
1701 |
|
|
1702 |
|
/* backup previous contents */ |
1703 |
|
if(!priv->osd.backup) |
1704 |
|
priv->osd.backup = gdk_pixmap_new(priv->pixmap, OSD_W+2, OSD_H+2, -1); |
1705 |
|
|
1706 |
|
gint x = OSD_X + EXTRA_BORDER + xoffset; |
1707 |
|
gint y = OSD_Y + EXTRA_BORDER + yoffset; |
1708 |
|
|
1709 |
|
/* create backup of background */ |
1710 |
|
gdk_draw_drawable(priv->osd.backup, |
1711 |
|
GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))], |
1712 |
|
priv->pixmap, x-1, y-1, 0, 0, OSD_W+2, OSD_H+2); |
1713 |
|
|
1714 |
|
priv->osd.backup_x = x-1; |
1715 |
|
priv->osd.backup_y = y-1; |
1716 |
|
|
1717 |
|
|
1718 |
|
#ifdef USE_CAIRO |
1719 |
|
/* OSD itself uses some off-screen rendering, so check if the */ |
1720 |
|
/* offscreen buffer is present and create it if not */ |
1721 |
|
if(!priv->osd.overlay) { |
1722 |
|
/* create overlay ... */ |
1723 |
|
priv->osd.overlay = |
1724 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H); |
1725 |
|
/* ... and render it */ |
1726 |
|
osm_gps_map_osd_render(priv); |
1727 |
|
} |
1728 |
|
|
1729 |
|
// now draw this onto the original context |
1730 |
|
cairo_t *cr = gdk_cairo_create(priv->pixmap); |
1731 |
|
cairo_set_source_surface(cr, priv->osd.overlay, x, y); |
1732 |
|
cairo_paint(cr); |
1733 |
|
cairo_destroy(cr); |
1734 |
|
|
1735 |
#else |
#else |
1736 |
#warning "OSD control display lacks a non-cairo implementation!" |
#warning "OSD control display lacks a non-cairo implementation!" |
1737 |
#endif |
#endif |
1829 |
|
|
1830 |
#ifdef ENABLE_OSD |
#ifdef ENABLE_OSD |
1831 |
priv->osd.backup = NULL; |
priv->osd.backup = NULL; |
1832 |
|
priv->osd.overlay = NULL; |
1833 |
priv->osd.cb = NULL; |
priv->osd.cb = NULL; |
1834 |
#endif |
#endif |
1835 |
|
|
1999 |
#ifdef ENABLE_OSD |
#ifdef ENABLE_OSD |
2000 |
if (priv->osd.backup) |
if (priv->osd.backup) |
2001 |
g_object_unref(priv->osd.backup); |
g_object_unref(priv->osd.backup); |
2002 |
|
|
2003 |
|
if (priv->osd.overlay) |
2004 |
|
cairo_surface_destroy(priv->osd.overlay); |
2005 |
#endif |
#endif |
2006 |
|
|
2007 |
G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object); |
G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object); |
2331 |
} |
} |
2332 |
|
|
2333 |
static gboolean |
static gboolean |
2334 |
|
osm_gps_map_expose (GtkWidget *widget, GdkEventExpose *event); |
2335 |
|
|
2336 |
|
static gboolean |
2337 |
osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion *event) |
osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion *event) |
2338 |
{ |
{ |
2339 |
int x, y; |
int x, y; |
2362 |
if (priv->drag_counter < 6) |
if (priv->drag_counter < 6) |
2363 |
return FALSE; |
return FALSE; |
2364 |
|
|
2365 |
|
#ifdef USE_MAEMO |
2366 |
|
/* reduce update frequency on maemo to keep screen update fluid */ |
2367 |
|
static guint32 last_time = 0; |
2368 |
|
|
2369 |
|
if(event->time - last_time < 100) return FALSE; |
2370 |
|
last_time = event->time; |
2371 |
|
#endif |
2372 |
|
|
2373 |
priv->dragging = TRUE; |
priv->dragging = TRUE; |
2374 |
|
|
2375 |
if (priv->map_auto_center) |
if (priv->map_auto_center) |
2388 |
-priv->drag_mouse_dy); |
-priv->drag_mouse_dy); |
2389 |
#endif |
#endif |
2390 |
|
|
2391 |
|
osm_gps_map_expose (widget, NULL); |
2392 |
|
|
2393 |
|
|
2394 |
|
return FALSE; |
2395 |
|
} |
2396 |
|
|
2397 |
|
static gboolean |
2398 |
|
osm_gps_map_configure (GtkWidget *widget, GdkEventConfigure *event) |
2399 |
|
{ |
2400 |
|
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
2401 |
|
|
2402 |
|
/* create pixmap */ |
2403 |
|
if (priv->pixmap) |
2404 |
|
g_object_unref (priv->pixmap); |
2405 |
|
|
2406 |
|
priv->pixmap = gdk_pixmap_new ( |
2407 |
|
widget->window, |
2408 |
|
widget->allocation.width + EXTRA_BORDER * 2, |
2409 |
|
widget->allocation.height + EXTRA_BORDER * 2, |
2410 |
|
-1); |
2411 |
|
|
2412 |
|
/* and gc, used for clipping (I think......) */ |
2413 |
|
if(priv->gc_map) |
2414 |
|
g_object_unref(priv->gc_map); |
2415 |
|
|
2416 |
|
priv->gc_map = gdk_gc_new(priv->pixmap); |
2417 |
|
|
2418 |
|
osm_gps_map_map_redraw(OSM_GPS_MAP(widget)); |
2419 |
|
|
2420 |
|
return FALSE; |
2421 |
|
} |
2422 |
|
|
2423 |
|
static gboolean |
2424 |
|
osm_gps_map_expose (GtkWidget *widget, GdkEventExpose *event) |
2425 |
|
{ |
2426 |
|
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
2427 |
|
|
2428 |
gdk_draw_drawable ( |
gdk_draw_drawable ( |
2429 |
widget->window, |
widget->window, |
2430 |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
2431 |
priv->pixmap, |
priv->pixmap, |
2432 |
0,0, |
0,0, |
2433 |
priv->drag_mouse_dx - EXTRA_BORDER, priv->drag_mouse_dy - EXTRA_BORDER, |
priv->drag_mouse_dx - EXTRA_BORDER, |
2434 |
|
priv->drag_mouse_dy - EXTRA_BORDER, |
2435 |
-1,-1); |
-1,-1); |
2436 |
|
|
2437 |
//Paint white outside of the map if dragging. Its less |
//Paint white outside of the map if dragging. Its less |
2475 |
widget->allocation.width, |
widget->allocation.width, |
2476 |
-priv->drag_mouse_dy - EXTRA_BORDER); |
-priv->drag_mouse_dy - EXTRA_BORDER); |
2477 |
} |
} |
2478 |
|
#if 0 |
2479 |
return FALSE; |
if(!priv->dragging) |
2480 |
} |
gdk_draw_drawable ( |
|
|
|
|
static gboolean |
|
|
osm_gps_map_configure (GtkWidget *widget, GdkEventConfigure *event) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
|
|
|
|
|
/* create pixmap */ |
|
|
if (priv->pixmap) |
|
|
g_object_unref (priv->pixmap); |
|
|
|
|
|
priv->pixmap = gdk_pixmap_new ( |
|
|
widget->window, |
|
|
widget->allocation.width + EXTRA_BORDER * 2, |
|
|
widget->allocation.height + EXTRA_BORDER * 2, |
|
|
-1); |
|
|
|
|
|
/* and gc, used for clipping (I think......) */ |
|
|
if(priv->gc_map) |
|
|
g_object_unref(priv->gc_map); |
|
|
|
|
|
priv->gc_map = gdk_gc_new(priv->pixmap); |
|
|
|
|
|
osm_gps_map_map_redraw(OSM_GPS_MAP(widget)); |
|
|
|
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
static gboolean |
|
|
osm_gps_map_expose (GtkWidget *widget, GdkEventExpose *event) |
|
|
{ |
|
|
OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); |
|
|
|
|
|
gdk_draw_drawable ( |
|
2481 |
widget->window, |
widget->window, |
2482 |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
2483 |
priv->pixmap, |
priv->pixmap, |
2485 |
event->area.y + EXTRA_BORDER, |
event->area.y + EXTRA_BORDER, |
2486 |
event->area.x, event->area.y, |
event->area.x, event->area.y, |
2487 |
event->area.width, event->area.height); |
event->area.width, event->area.height); |
|
|
|
|
#ifdef ENABLE_OSD_OVL |
|
|
/* TODO: intersect with area */ |
|
|
if (priv->osd.pixbuf) |
|
|
{ |
|
|
// gdk_draw_drawable (widget->window, |
|
|
// widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
|
|
// priv->osd.pixbuf, 0, 0, |
|
|
// OSD_X, OSD_Y, OSD_W, OSD_H); |
|
|
} |
|
2488 |
#endif |
#endif |
|
|
|
2489 |
return FALSE; |
return FALSE; |
2490 |
} |
} |
2491 |
|
|
3305 |
priv->osd.cb = cb; |
priv->osd.cb = cb; |
3306 |
priv->osd.data = data; |
priv->osd.data = data; |
3307 |
|
|
3308 |
|
/* this may have changed the state of the gps button */ |
3309 |
|
/* we thus re-render the overlay */ |
3310 |
|
osm_gps_map_osd_render(priv); |
3311 |
|
|
3312 |
osm_gps_map_map_redraw_idle(map); |
osm_gps_map_map_redraw_idle(map); |
3313 |
} |
} |
3314 |
#endif |
#endif |