49 |
|
|
50 |
#define EXTRA_BORDER (TILESIZE / 2) |
#define EXTRA_BORDER (TILESIZE / 2) |
51 |
|
|
52 |
|
#define OSM_GPS_MAP_SCROLL_STEP 10 |
53 |
|
|
54 |
|
/* any defined key enables key support */ |
55 |
|
#if (defined(OSM_GPS_MAP_KEY_FULLSCREEN) || \ |
56 |
|
defined(OSM_GPS_MAP_KEY_ZOOMIN) || \ |
57 |
|
defined(OSM_GPS_MAP_KEY_ZOOMOUT) || \ |
58 |
|
defined(OSM_GPS_MAP_KEY_UP) || \ |
59 |
|
defined(OSM_GPS_MAP_KEY_DOWN) || \ |
60 |
|
defined(OSM_GPS_MAP_KEY_LEFT) || \ |
61 |
|
defined(OSM_GPS_MAP_KEY_RIGHT)) |
62 |
|
#define OSM_GPS_MAP_KEYS |
63 |
|
#endif |
64 |
|
|
65 |
|
#ifdef OSM_GPS_MAP_KEYS |
66 |
|
#include <gdk/gdkkeysyms.h> |
67 |
|
#endif |
68 |
|
|
69 |
struct _OsmGpsMapPrivate |
struct _OsmGpsMapPrivate |
70 |
{ |
{ |
71 |
GHashTable *tile_queue; |
GHashTable *tile_queue; |
133 |
GdkPixmap *dbuf_pixmap; |
GdkPixmap *dbuf_pixmap; |
134 |
#endif |
#endif |
135 |
#endif |
#endif |
136 |
|
|
137 |
|
#ifdef OSM_GPS_MAP_KEY_FULLSCREEN |
138 |
|
gboolean fullscreen; |
139 |
|
#endif |
140 |
|
|
141 |
//additional images or tracks added to the map |
//additional images or tracks added to the map |
142 |
GSList *tracks; |
GSList *tracks; |
1491 |
priv->idle_map_redraw = g_idle_add ((GSourceFunc)osm_gps_map_map_redraw, map); |
priv->idle_map_redraw = g_idle_add ((GSourceFunc)osm_gps_map_map_redraw, map); |
1492 |
} |
} |
1493 |
|
|
1494 |
|
#ifdef OSM_GPS_MAP_KEYS |
1495 |
|
static gboolean |
1496 |
|
on_window_key_press(GtkWidget *widget, |
1497 |
|
GdkEventKey *event, OsmGpsMapPrivate *priv) { |
1498 |
|
gboolean handled = FALSE; |
1499 |
|
int step = GTK_WIDGET(widget)->allocation.width/OSM_GPS_MAP_SCROLL_STEP; |
1500 |
|
|
1501 |
|
printf("key event with keyval %x\n", event->keyval); |
1502 |
|
|
1503 |
|
// the map handles some keys on its own ... |
1504 |
|
switch(event->keyval) { |
1505 |
|
#ifdef OSM_GPS_MAP_KEY_FULLSCREEN |
1506 |
|
case OSM_GPS_MAP_KEY_FULLSCREEN: { |
1507 |
|
GtkWidget *toplevel = gtk_widget_get_toplevel(GTK_WIDGET(widget)); |
1508 |
|
if(!priv->fullscreen) |
1509 |
|
gtk_window_fullscreen(GTK_WINDOW(toplevel)); |
1510 |
|
else |
1511 |
|
gtk_window_unfullscreen(GTK_WINDOW(toplevel)); |
1512 |
|
|
1513 |
|
priv->fullscreen = !priv->fullscreen; |
1514 |
|
handled = TRUE; |
1515 |
|
} break; |
1516 |
|
#endif |
1517 |
|
|
1518 |
|
#ifdef OSM_GPS_MAP_KEY_ZOOMIN |
1519 |
|
case OSM_GPS_MAP_KEY_ZOOMIN: |
1520 |
|
osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom+1); |
1521 |
|
handled = TRUE; |
1522 |
|
break; |
1523 |
|
#endif |
1524 |
|
|
1525 |
|
#ifdef OSM_GPS_MAP_KEY_ZOOMOUT |
1526 |
|
case OSM_GPS_MAP_KEY_ZOOMOUT: |
1527 |
|
osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom-1); |
1528 |
|
handled = TRUE; |
1529 |
|
break; |
1530 |
|
#endif |
1531 |
|
|
1532 |
|
#ifdef OSM_GPS_MAP_KEY_UP |
1533 |
|
case OSM_GPS_MAP_KEY_UP: |
1534 |
|
priv->map_y -= step; |
1535 |
|
priv->center_coord_set = FALSE; |
1536 |
|
osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); |
1537 |
|
handled = TRUE; |
1538 |
|
break; |
1539 |
|
#endif |
1540 |
|
|
1541 |
|
#ifdef OSM_GPS_MAP_KEY_DOWN |
1542 |
|
case OSM_GPS_MAP_KEY_DOWN: |
1543 |
|
priv->map_y += step; |
1544 |
|
priv->center_coord_set = FALSE; |
1545 |
|
osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); |
1546 |
|
handled = TRUE; |
1547 |
|
break; |
1548 |
|
#endif |
1549 |
|
|
1550 |
|
#ifdef OSM_GPS_MAP_KEY_LEFT |
1551 |
|
case OSM_GPS_MAP_KEY_LEFT: |
1552 |
|
priv->map_x -= step; |
1553 |
|
priv->center_coord_set = FALSE; |
1554 |
|
osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); |
1555 |
|
handled = TRUE; |
1556 |
|
break; |
1557 |
|
#endif |
1558 |
|
|
1559 |
|
#ifdef OSM_GPS_MAP_KEY_RIGHT |
1560 |
|
case OSM_GPS_MAP_KEY_RIGHT: |
1561 |
|
priv->map_x += step; |
1562 |
|
priv->center_coord_set = FALSE; |
1563 |
|
osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); |
1564 |
|
handled = TRUE; |
1565 |
|
break; |
1566 |
|
#endif |
1567 |
|
|
1568 |
|
default: |
1569 |
|
printf("unhandled key event with keyval %x\n", event->keyval); |
1570 |
|
break; |
1571 |
|
} |
1572 |
|
|
1573 |
|
return handled; |
1574 |
|
} |
1575 |
|
#endif |
1576 |
|
|
1577 |
static void |
static void |
1578 |
osm_gps_map_init (OsmGpsMap *object) |
osm_gps_map_init (OsmGpsMap *object) |
1579 |
{ |
{ |
1598 |
priv->osd = NULL; |
priv->osd = NULL; |
1599 |
#endif |
#endif |
1600 |
|
|
1601 |
|
#ifdef OSM_GPS_MAP_BUTTON_FULLSCREEN |
1602 |
|
priv->fullscreen = FALSE; |
1603 |
|
#endif |
1604 |
|
|
1605 |
priv->tracks = NULL; |
priv->tracks = NULL; |
1606 |
priv->images = NULL; |
priv->images = NULL; |
1607 |
|
|
1646 |
GTK_WIDGET_SET_FLAGS (object, GTK_CAN_FOCUS); |
GTK_WIDGET_SET_FLAGS (object, GTK_CAN_FOCUS); |
1647 |
|
|
1648 |
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK, my_log_handler, NULL); |
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK, my_log_handler, NULL); |
|
} |
|
1649 |
|
|
1650 |
#ifndef G_CHECKSUM_MD5 |
#ifdef OSM_GPS_MAP_KEYS |
1651 |
/* simple hash algorithm hack if md5 is not present */ |
// GtkWidget *toplevel = gtk_widget_get_toplevel(GTK_WIDGET(object)); |
1652 |
static char *simple_hash(char *str) { |
g_signal_connect(G_OBJECT(object), "key_press_event", |
1653 |
union { |
G_CALLBACK(on_window_key_press), priv); |
|
char str[4]; |
|
|
gulong val; |
|
|
} hash = { .val = 0x55555555 }; |
|
|
|
|
|
while(*str) { |
|
|
hash.str[(int)str & 3] ^= *str; |
|
|
str++; |
|
|
} |
|
|
return g_strdup_printf("%08lX", hash.val); |
|
|
} |
|
1654 |
#endif |
#endif |
1655 |
|
} |
1656 |
|
|
1657 |
static GObject * |
static GObject * |
1658 |
osm_gps_map_constructor (GType gtype, guint n_properties, GObjectConstructParam *properties) |
osm_gps_map_constructor (GType gtype, guint n_properties, GObjectConstructParam *properties) |
1692 |
} |
} |
1693 |
|
|
1694 |
if (!priv->cache_dir_is_full_path) { |
if (!priv->cache_dir_is_full_path) { |
1695 |
#ifdef G_CHECKSUM_MD5 |
const char *fname = osm_gps_map_source_get_friendly_name(priv->map_source); |
1696 |
char *md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->repo_uri, -1); |
if(!fname) fname = "_unknown_"; |
|
#else |
|
|
char *md5 = simple_hash(priv->repo_uri); |
|
|
#endif |
|
1697 |
|
|
1698 |
if (priv->cache_dir) { |
if (priv->cache_dir) { |
1699 |
char *old = priv->cache_dir; |
char *old = priv->cache_dir; |
1700 |
//the new cachedir is the given cache dir + the md5 of the repo_uri |
//the new cachedir is the given cache dir + the md5 of the repo_uri |
1701 |
priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, md5); |
priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, fname); |
1702 |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir); |
1703 |
g_free(old); |
g_free(old); |
1704 |
} else { |
} else { |
1705 |
//the new cachedir is the current dir + the md5 of the repo_uri |
//the new cachedir is the current dir + the md5 of the repo_uri |
1706 |
priv->cache_dir = g_strdup(md5); |
priv->cache_dir = g_strdup(fname); |
1707 |
} |
} |
|
|
|
|
g_free(md5); |
|
1708 |
} |
} |
1709 |
|
|
1710 |
inspect_map_uri(map); |
inspect_map_uri(map); |
1987 |
#endif |
#endif |
1988 |
|
|
1989 |
#ifdef ENABLE_OSD |
#ifdef ENABLE_OSD |
|
#define SCROLL_STEP 10 |
|
|
|
|
1990 |
/* pressed inside OSD control? */ |
/* pressed inside OSD control? */ |
1991 |
if(priv->osd) { |
if(priv->osd) { |
1992 |
osd_button_t but = priv->osd->check(event->x, event->y); |
osd_button_t but = priv->osd->check(priv->osd, event->x, event->y); |
1993 |
if(but != OSD_NONE) |
if(but != OSD_NONE) |
1994 |
{ |
{ |
1995 |
|
int step = GTK_WIDGET(widget)->allocation.width/OSM_GPS_MAP_SCROLL_STEP; |
1996 |
priv->drag_counter = -1; |
priv->drag_counter = -1; |
1997 |
|
|
1998 |
switch(but) { |
switch(but) { |
1999 |
case OSD_UP: |
case OSD_UP: |
2000 |
priv->map_y -= GTK_WIDGET(widget)->allocation.height/SCROLL_STEP; |
priv->map_y -= step; |
2001 |
priv->center_coord_set = FALSE; |
priv->center_coord_set = FALSE; |
2002 |
|
osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); |
2003 |
break; |
break; |
2004 |
|
|
2005 |
case OSD_DOWN: |
case OSD_DOWN: |
2006 |
priv->map_y += GTK_WIDGET(widget)->allocation.height/SCROLL_STEP; |
priv->map_y += step; |
2007 |
priv->center_coord_set = FALSE; |
priv->center_coord_set = FALSE; |
2008 |
|
osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); |
2009 |
break; |
break; |
2010 |
|
|
2011 |
case OSD_LEFT: |
case OSD_LEFT: |
2012 |
priv->map_x -= GTK_WIDGET(widget)->allocation.width/SCROLL_STEP; |
priv->map_x -= step; |
2013 |
priv->center_coord_set = FALSE; |
priv->center_coord_set = FALSE; |
2014 |
|
osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); |
2015 |
break; |
break; |
2016 |
|
|
2017 |
case OSD_RIGHT: |
case OSD_RIGHT: |
2018 |
priv->map_x += GTK_WIDGET(widget)->allocation.width/SCROLL_STEP; |
priv->map_x += step; |
2019 |
priv->center_coord_set = FALSE; |
priv->center_coord_set = FALSE; |
2020 |
|
osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); |
2021 |
break; |
break; |
2022 |
|
|
2023 |
case OSD_IN: |
case OSD_IN: |
2035 |
break; |
break; |
2036 |
} |
} |
2037 |
|
|
|
osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); |
|
|
|
|
2038 |
return FALSE; |
return FALSE; |
2039 |
} |
} |
2040 |
} |
} |