--- trunk/src/osm-gps-map.c 2009/09/15 13:52:04 112 +++ trunk/src/osm-gps-map.c 2009/10/28 11:50:37 147 @@ -149,6 +149,7 @@ int drag_start_mouse_y; int drag_start_map_x; int drag_start_map_y; + guint drag_expose; //for customizing the redering of the gps track int ui_gps_track_width; @@ -1247,6 +1248,12 @@ { OsmGpsMapPrivate *priv = map->priv; + /* on diablo the map comes up at 1x1 pixel size and */ + /* isn't really usable. ignore this */ + if((GTK_WIDGET(map)->allocation.width < 10) || + (GTK_WIDGET(map)->allocation.height < 10)) + return FALSE; + priv->idle_map_redraw = 0; /* don't redraw the entire map while the OSD is doing */ @@ -1546,6 +1553,9 @@ if (priv->idle_map_redraw != 0) g_source_remove (priv->idle_map_redraw); + if (priv->drag_expose != 0) + g_source_remove (priv->drag_expose); + g_free(priv->gps); #ifdef ENABLE_OSD @@ -1797,10 +1807,13 @@ #ifdef ENABLE_OSD /* pressed inside OSD control? */ if(priv->osd) { - osd_button_t but = priv->osd->check(priv->osd, event->x, event->y); + osd_button_t but = + priv->osd->check(priv->osd, TRUE, event->x, event->y); + if(but != OSD_NONE) { - int step = GTK_WIDGET(widget)->allocation.width/OSM_GPS_MAP_SCROLL_STEP; + int step = + GTK_WIDGET(widget)->allocation.width/OSM_GPS_MAP_SCROLL_STEP; priv->drag_counter = -1; switch(but) { @@ -1880,6 +1893,11 @@ osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget)); } +#ifdef ENABLE_OSD + /* pressed inside OSD control? */ + else if(priv->osd) + priv->osd->check(priv->osd, FALSE, event->x, event->y); +#endif #ifdef DRAG_DEBUG printf("dragging done\n"); @@ -1894,6 +1912,16 @@ osm_gps_map_expose (GtkWidget *widget, GdkEventExpose *event); static gboolean +osm_gps_map_map_expose (GtkWidget *widget) +{ + OsmGpsMapPrivate *priv = OSM_GPS_MAP(widget)->priv; + + priv->drag_expose = 0; + osm_gps_map_expose (widget, NULL); + return FALSE; +} + +static gboolean osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion *event) { int x, y; @@ -1916,19 +1944,14 @@ if (priv->drag_counter < 0) return FALSE; - priv->drag_counter++; - - // we havent dragged more than 6 pixels - if (priv->drag_counter < 6) + /* not yet dragged far enough? */ + if(!priv->drag_counter && + ( (x - priv->drag_start_mouse_x) * (x - priv->drag_start_mouse_x) + + (y - priv->drag_start_mouse_y) * (y - priv->drag_start_mouse_y) < + 10*10)) return FALSE; -#ifdef OSM_GPS_MAP_REFRESH - /* reduce update frequency on maemo to keep screen update fluid */ - static guint32 last_time = 0; - - if(event->time - last_time < (1000/OSM_GPS_MAP_REFRESH)) return FALSE; - last_time = event->time; -#endif + priv->drag_counter++; priv->dragging = TRUE; @@ -1938,7 +1961,10 @@ priv->drag_mouse_dx = x - priv->drag_start_mouse_x; priv->drag_mouse_dy = y - priv->drag_start_mouse_y; - osm_gps_map_expose (widget, NULL); + /* instead of redrawing directly just add an idle function */ + if (!priv->drag_expose) + priv->drag_expose = + g_idle_add ((GSourceFunc)osm_gps_map_map_expose, widget); return FALSE; } @@ -2769,9 +2795,11 @@ priv = map->priv; if (pixel_x) - *pixel_x = lon2pixel(priv->map_zoom, deg2rad(longitude)) - priv->map_x; + *pixel_x = lon2pixel(priv->map_zoom, deg2rad(longitude)) - + priv->map_x + priv->drag_mouse_dx; if (pixel_y) - *pixel_y = lat2pixel(priv->map_zoom, deg2rad(latitude)) - priv->map_y; + *pixel_y = lat2pixel(priv->map_zoom, deg2rad(latitude)) - + priv->map_y + priv->drag_mouse_dy; } void @@ -2814,12 +2842,16 @@ osm_gps_map_map_redraw_idle(map); } -osm_gps_map_osd_t *osm_gps_map_osd_get(OsmGpsMap *map) { +osm_gps_map_osd_t * +osm_gps_map_osd_get(OsmGpsMap *map) +{ g_return_val_if_fail (OSM_IS_GPS_MAP (map), NULL); return map->priv->osd; } -void osm_gps_map_register_osd(OsmGpsMap *map, osm_gps_map_osd_t *osd) { +void +osm_gps_map_register_osd(OsmGpsMap *map, osm_gps_map_osd_t *osd) +{ OsmGpsMapPrivate *priv; g_return_if_fail (OSM_IS_GPS_MAP (map)); @@ -2831,8 +2863,20 @@ } void -osm_gps_map_repaint (OsmGpsMap *map) { +osm_gps_map_repaint (OsmGpsMap *map) +{ osm_gps_map_expose (GTK_WIDGET(map), NULL); } +coord_t * +osm_gps_map_get_gps (OsmGpsMap *map) +{ + g_return_val_if_fail (OSM_IS_GPS_MAP (map), NULL); + + if(!map->priv->gps_valid) + return NULL; + + return map->priv->gps; +} + #endif