Diff of /trunk/src/osm-gps-map.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 74 by harbaum, Mon Aug 24 09:23:36 2009 UTC revision 75 by harbaum, Mon Aug 24 12:57:15 2009 UTC
# Line 112  struct _OsmGpsMapPrivate Line 112  struct _OsmGpsMapPrivate
112  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
113      //the osd controls (if present)      //the osd controls (if present)
114      osm_gps_map_osd_t *osd;      osm_gps_map_osd_t *osd;
115    #ifdef OSD_DOUBLE_BUFFER
116        GdkPixmap *dbuf_pixmap;
117    #endif
118  #endif  #endif
119    
120      //additional images or tracks added to the map      //additional images or tracks added to the map
# Line 1451  osm_gps_map_map_redraw (OsmGpsMap *map) Line 1454  osm_gps_map_map_redraw (OsmGpsMap *map)
1454      osm_gps_map_draw_balloon_int(map);      osm_gps_map_draw_balloon_int(map);
1455  #endif  #endif
1456    
 #ifdef ENABLE_OSD  
     if(priv->osd)  
         priv->osd->draw(priv->osd, EXTRA_BORDER, EXTRA_BORDER);  
 #endif  
   
1457      //osm_gps_map_osd_speed(map, 1.5);      //osm_gps_map_osd_speed(map, 1.5);
1458      osm_gps_map_purge_cache(map);      osm_gps_map_purge_cache(map);
1459      gtk_widget_queue_draw (GTK_WIDGET (map));      gtk_widget_queue_draw (GTK_WIDGET (map));
# Line 1662  osm_gps_map_dispose (GObject *object) Line 1660  osm_gps_map_dispose (GObject *object)
1660  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
1661      if(priv->osd)      if(priv->osd)
1662          priv->osd->free(priv->osd);          priv->osd->free(priv->osd);
1663    
1664    #ifdef OSD_DOUBLE_BUFFER
1665        if(priv->dbuf_pixmap)
1666            g_object_unref (priv->dbuf_pixmap);
1667    #endif
1668  #endif  #endif
1669    
1670      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);
# Line 2023  osm_gps_map_motion_notify (GtkWidget *wi Line 2026  osm_gps_map_motion_notify (GtkWidget *wi
2026      if (priv->drag_counter < 6)      if (priv->drag_counter < 6)
2027          return FALSE;          return FALSE;
2028    
2029  #ifdef USE_MAEMO  #ifdef OSM_GPS_MAP_REFRESH
2030      /* reduce update frequency on maemo to keep screen update fluid */      /* reduce update frequency on maemo to keep screen update fluid */
2031      static guint32 last_time = 0;      static guint32 last_time = 0;
2032    
2033      if(event->time - last_time < 100) return FALSE;      if(event->time - last_time < (1000/OSM_GPS_MAP_REFRESH)) return FALSE;
2034      last_time = event->time;      last_time = event->time;
2035  #endif  #endif
2036    
# Line 2039  osm_gps_map_motion_notify (GtkWidget *wi Line 2042  osm_gps_map_motion_notify (GtkWidget *wi
2042      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;
2043      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;
2044    
 #ifdef ENABLE_OSD  
     if(priv->osd) {  
         /* undo OSD */  
         priv->osd->restore (priv->osd);  
   
         /* draw new OSD */  
         priv->osd->draw (priv->osd,  
                          EXTRA_BORDER - priv->drag_mouse_dx,  
                          EXTRA_BORDER - priv->drag_mouse_dy);  
     }  
 #endif  
   
2045      osm_gps_map_expose (widget, NULL);      osm_gps_map_expose (widget, NULL);
2046    
2047      return FALSE;      return FALSE;
# Line 2066  osm_gps_map_configure (GtkWidget *widget Line 2057  osm_gps_map_configure (GtkWidget *widget
2057          g_object_unref (priv->pixmap);          g_object_unref (priv->pixmap);
2058    
2059      priv->pixmap = gdk_pixmap_new (      priv->pixmap = gdk_pixmap_new (
2060                                     widget->window,                          widget->window,
2061                                     widget->allocation.width + EXTRA_BORDER * 2,                          widget->allocation.width + EXTRA_BORDER * 2,
2062                                     widget->allocation.height + EXTRA_BORDER * 2,                          widget->allocation.height + EXTRA_BORDER * 2,
2063                                     -1);                          -1);
2064    
2065  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
2066    
2067    #ifdef OSD_DOUBLE_BUFFER
2068        if (priv->dbuf_pixmap)
2069            g_object_unref (priv->dbuf_pixmap);
2070    
2071        priv->dbuf_pixmap = gdk_pixmap_new (
2072                            widget->window,
2073                            widget->allocation.width,
2074                            widget->allocation.height,
2075                            -1);
2076    #endif
2077    
2078      /* the osd needs some references to map internal objects */      /* the osd needs some references to map internal objects */
2079      if(priv->osd)      if(priv->osd)
     {  
         priv->osd->pixmap = priv->pixmap;  
2080          priv->osd->widget = widget;          priv->osd->widget = widget;
     }  
2081  #endif  #endif
2082    
2083      /* and gc, used for clipping (I think......) */      /* and gc, used for clipping (I think......) */
# Line 2096  osm_gps_map_expose (GtkWidget *widget, G Line 2096  osm_gps_map_expose (GtkWidget *widget, G
2096  {  {
2097      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2098    
2099      gdk_draw_drawable (  #if defined(ENABLE_OSD) && defined(OSD_DOUBLE_BUFFER)
2100                         widget->window,      GdkDrawable *drawable = priv->dbuf_pixmap;
2101    #else
2102        GdkDrawable *drawable = widget->window;
2103    #endif
2104    
2105        gdk_draw_drawable (drawable,
2106                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2107                         priv->pixmap,                         priv->pixmap,
2108                         0,0,                         0,0,
# Line 2108  osm_gps_map_expose (GtkWidget *widget, G Line 2113  osm_gps_map_expose (GtkWidget *widget, G
2113      //Paint white outside of the map if dragging. Its less      //Paint white outside of the map if dragging. Its less
2114      //ugly than painting the corrupted map      //ugly than painting the corrupted map
2115      if(priv->drag_mouse_dx>EXTRA_BORDER) {      if(priv->drag_mouse_dx>EXTRA_BORDER) {
2116          gdk_draw_rectangle (          gdk_draw_rectangle (drawable,
                             widget->window,  
2117                              widget->style->white_gc,                              widget->style->white_gc,
2118                              TRUE,                              TRUE,
2119                              0, 0,                              0, 0,
# Line 2118  osm_gps_map_expose (GtkWidget *widget, G Line 2122  osm_gps_map_expose (GtkWidget *widget, G
2122      }      }
2123      else if (-priv->drag_mouse_dx > EXTRA_BORDER)      else if (-priv->drag_mouse_dx > EXTRA_BORDER)
2124      {      {
2125          gdk_draw_rectangle (          gdk_draw_rectangle (drawable,
                             widget->window,  
2126                              widget->style->white_gc,                              widget->style->white_gc,
2127                              TRUE,                              TRUE,
2128                              priv->drag_mouse_dx + widget->allocation.width + EXTRA_BORDER, 0,                              priv->drag_mouse_dx + widget->allocation.width + EXTRA_BORDER, 0,
# Line 2128  osm_gps_map_expose (GtkWidget *widget, G Line 2131  osm_gps_map_expose (GtkWidget *widget, G
2131      }      }
2132    
2133      if (priv->drag_mouse_dy>EXTRA_BORDER) {      if (priv->drag_mouse_dy>EXTRA_BORDER) {
2134          gdk_draw_rectangle (          gdk_draw_rectangle (drawable,
                             widget->window,  
2135                              widget->style->white_gc,                              widget->style->white_gc,
2136                              TRUE,                              TRUE,
2137                              0, 0,                              0, 0,
# Line 2138  osm_gps_map_expose (GtkWidget *widget, G Line 2140  osm_gps_map_expose (GtkWidget *widget, G
2140      }      }
2141      else if (-priv->drag_mouse_dy > EXTRA_BORDER)      else if (-priv->drag_mouse_dy > EXTRA_BORDER)
2142      {      {
2143          gdk_draw_rectangle (          gdk_draw_rectangle (drawable,
                             widget->window,  
2144                              widget->style->white_gc,                              widget->style->white_gc,
2145                              TRUE,                              TRUE,
2146                              0, priv->drag_mouse_dy + widget->allocation.height + EXTRA_BORDER,                              0, priv->drag_mouse_dy + widget->allocation.height + EXTRA_BORDER,
2147                              widget->allocation.width,                              widget->allocation.width,
2148                              -priv->drag_mouse_dy - EXTRA_BORDER);                              -priv->drag_mouse_dy - EXTRA_BORDER);
2149      }      }
2150  #if 0  
2151      if(!priv->dragging)  #ifdef ENABLE_OSD
2152          gdk_draw_drawable (      /* draw new OSD */
2153                         widget->window,      if(priv->osd)
2154            priv->osd->draw (priv->osd, drawable);
2155    
2156    #ifdef OSD_DOUBLE_BUFFER
2157        gdk_draw_drawable (widget->window,
2158                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2159                         priv->pixmap,                         priv->dbuf_pixmap,
2160                         event->area.x + EXTRA_BORDER,                         0,0,0,0,-1,-1);
2161                         event->area.y + EXTRA_BORDER,  #endif
2162                         event->area.x, event->area.y,  
                        event->area.width, event->area.height);  
2163  #endif  #endif
2164    
2165      return FALSE;      return FALSE;
2166  }  }
2167    
# Line 2736  osm_gps_map_clear_images (OsmGpsMap *map Line 2741  osm_gps_map_clear_images (OsmGpsMap *map
2741  }  }
2742    
2743  void  void
 osm_gps_map_osd_speed (OsmGpsMap *map, float speed)  
 {  
     OsmGpsMapPrivate *priv;  
   
     PangoContext        *context = NULL;  
     PangoLayout     *layout  = NULL;  
     PangoFontDescription    *desc    = NULL;  
   
     GdkColor color;  
     GdkGC *gc;  
   
     gchar *buffer;  
     //static int x = 10, y = 10;  
     static int width = 0, height = 0;  
   
     g_return_if_fail (OSM_IS_GPS_MAP (map));  
     priv = map->priv;  
   
     buffer = g_strdup_printf("%.0f", speed);  
   
     /* pango initialisation */  
     context = gtk_widget_get_pango_context (GTK_WIDGET(map));  
     layout  = pango_layout_new (context);  
     desc    = pango_font_description_new();  
   
     pango_font_description_set_size (desc, 40 * PANGO_SCALE);  
     pango_layout_set_font_description (layout, desc);  
     pango_layout_set_text (layout, buffer, strlen(buffer));  
   
     gc = gdk_gc_new (GTK_WIDGET(map)->window);  
   
     color.red = (0 > 50) ? 0xffff : 0;  
     color.green = 0;  
     color.blue = 0;  
   
     gdk_gc_set_rgb_fg_color (gc, &color);  
   
     /* faster / less flicker alternative:*/  
     gdk_draw_drawable (  
                        GTK_WIDGET(map)->window,  
                        GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(map)],  
                        priv->pixmap,  
                        0,0,  
                        0,0,  
                        width+10,width+10);  
   
     gdk_draw_layout(GTK_WIDGET(map)->window,  
                     gc,  
                     0, 0,  
                     layout);  
   
     /* set width and height */  
     pango_layout_get_pixel_size(layout, &width, &height);  
   
     g_free(buffer);  
     pango_font_description_free (desc);  
     g_object_unref (layout);  
     g_object_unref (gc);  
 }  
   
 void  
2744  osm_gps_map_draw_gps (OsmGpsMap *map, float latitude, float longitude, float heading)  osm_gps_map_draw_gps (OsmGpsMap *map, float latitude, float longitude, float heading)
2745  {  {
2746      int pixel_x, pixel_y;      int pixel_x, pixel_y;

Legend:
Removed from v.74  
changed lines
  Added in v.75