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

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

revision 66 by harbaum, Wed Aug 19 20:03:28 2009 UTC revision 68 by harbaum, Thu Aug 20 09:54:10 2009 UTC
# Line 113  struct _OsmGpsMapPrivate Line 113  struct _OsmGpsMapPrivate
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;
# Line 1663  osm_gps_map_osd_labels_shadow(cairo_t *c Line 1664  osm_gps_map_osd_labels_shadow(cairo_t *c
1664  }  }
1665    
1666  static void  static void
1667  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;  
1668    
1669      /* create backup of background */      /* first fill with transparency */
1670      gdk_draw_drawable(priv->osd.backup,      cairo_t *cr = cairo_create(priv->osd.overlay);
         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);  
   
     /* fill with transparency */  
     {  
     cairo_t *cr = cairo_create(surface);  
1671      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1672      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);
1673      cairo_paint(cr);      cairo_paint(cr);
     cairo_destroy(cr);  
     }  
 #endif  
1674    
1675        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
 #ifdef USE_CAIRO  
     //    cairo_t *cr = cairo_create(surface);  
     cairo_t *cr = gdk_cairo_create(priv->pixmap);  
1676    
1677      /* --------- draw zoom and dpad shape shadow ----------- */      /* --------- draw zoom and dpad shape shadow ----------- */
1678        gint x = 0, y = 0;
1679    
1680      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);
1681      osm_gps_map_osd_shape_shadow(cr);      osm_gps_map_osd_shape_shadow(cr);
# Line 1733  osm_gps_map_osd_draw_controls (OsmGpsMap Line 1704  osm_gps_map_osd_draw_controls (OsmGpsMap
1704      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);
1705    
1706      cairo_destroy(cr);      cairo_destroy(cr);
1707    }
1708    
1709    static void
1710    osm_gps_map_osd_draw_controls (OsmGpsMap *map, gint xoffset, gint yoffset)
1711    {
1712        OsmGpsMapPrivate *priv = map->priv;
1713    
1714        /* backup previous contents */
1715        if(!priv->osd.backup)
1716            priv->osd.backup = gdk_pixmap_new(priv->pixmap, OSD_W+2, OSD_H+2, -1);
1717    
1718        gint x = OSD_X + EXTRA_BORDER + xoffset;
1719        gint y = OSD_Y + EXTRA_BORDER + yoffset;
1720    
1721        /* create backup of background */
1722        gdk_draw_drawable(priv->osd.backup,
1723            GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],
1724                          priv->pixmap, x-1, y-1, 0, 0, OSD_W+2, OSD_H+2);
1725    
1726        priv->osd.backup_x = x-1;
1727        priv->osd.backup_y = y-1;
1728    
1729    
1730    #ifdef USE_CAIRO
1731        /* OSD itself uses some off-screen rendering, so check if the */
1732        /* offscreen buffer is present and create it if not */
1733        if(!priv->osd.overlay) {
1734            /* create overlay ... */
1735            priv->osd.overlay =
1736                cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H);
1737            /* ... and render it */
1738            osm_gps_map_osd_render(priv);
1739        }
1740    
1741        // now draw this onto the original context
1742        cairo_t *cr = gdk_cairo_create(priv->pixmap);
1743        cairo_set_source_surface(cr, priv->osd.overlay, x, y);
1744        cairo_paint(cr);
1745        cairo_destroy(cr);
1746    
1747  #else  #else
1748  #warning "OSD control display lacks a non-cairo implementation!"  #warning "OSD control display lacks a non-cairo implementation!"
1749  #endif  #endif
# Line 1831  osm_gps_map_init (OsmGpsMap *object) Line 1841  osm_gps_map_init (OsmGpsMap *object)
1841    
1842  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
1843      priv->osd.backup = NULL;      priv->osd.backup = NULL;
1844        priv->osd.overlay = NULL;
1845      priv->osd.cb = NULL;      priv->osd.cb = NULL;
1846  #endif  #endif
1847    
# Line 2000  osm_gps_map_dispose (GObject *object) Line 2011  osm_gps_map_dispose (GObject *object)
2011  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
2012      if (priv->osd.backup)      if (priv->osd.backup)
2013          g_object_unref(priv->osd.backup);          g_object_unref(priv->osd.backup);
2014    
2015        if (priv->osd.overlay)
2016             cairo_surface_destroy(priv->osd.overlay);
2017  #endif  #endif
2018    
2019      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);
# Line 2329  osm_gps_map_button_release (GtkWidget *w Line 2343  osm_gps_map_button_release (GtkWidget *w
2343  }  }
2344    
2345  static gboolean  static gboolean
2346    osm_gps_map_expose (GtkWidget *widget, GdkEventExpose  *event);
2347    
2348    static gboolean
2349  osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion  *event)  osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion  *event)
2350  {  {
2351      int x, y;      int x, y;
# Line 2357  osm_gps_map_motion_notify (GtkWidget *wi Line 2374  osm_gps_map_motion_notify (GtkWidget *wi
2374      if (priv->drag_counter < 6)      if (priv->drag_counter < 6)
2375          return FALSE;          return FALSE;
2376    
2377    #ifdef USE_MAEMO
2378        /* reduce update frequency on maemo to keep screen update fluid */
2379        static guint32 last_time = 0;
2380    
2381        if(event->time - last_time < 100) return FALSE;
2382        last_time = event->time;
2383    #endif
2384    
2385      priv->dragging = TRUE;      priv->dragging = TRUE;
2386    
2387      if (priv->map_auto_center)      if (priv->map_auto_center)
# Line 2375  osm_gps_map_motion_notify (GtkWidget *wi Line 2400  osm_gps_map_motion_notify (GtkWidget *wi
2400                                     -priv->drag_mouse_dy);                                     -priv->drag_mouse_dy);
2401  #endif  #endif
2402    
2403        osm_gps_map_expose (widget, NULL);
2404    
2405    
2406        return FALSE;
2407    }
2408    
2409    static gboolean
2410    osm_gps_map_configure (GtkWidget *widget, GdkEventConfigure *event)
2411    {
2412        OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2413    
2414        /* create pixmap */
2415        if (priv->pixmap)
2416            g_object_unref (priv->pixmap);
2417    
2418        priv->pixmap = gdk_pixmap_new (
2419                                       widget->window,
2420                                       widget->allocation.width + EXTRA_BORDER * 2,
2421                                       widget->allocation.height + EXTRA_BORDER * 2,
2422                                       -1);
2423    
2424        /* and gc, used for clipping (I think......) */
2425        if(priv->gc_map)
2426            g_object_unref(priv->gc_map);
2427    
2428        priv->gc_map = gdk_gc_new(priv->pixmap);
2429    
2430        osm_gps_map_map_redraw(OSM_GPS_MAP(widget));
2431    
2432        return FALSE;
2433    }
2434    
2435    static gboolean
2436    osm_gps_map_expose (GtkWidget *widget, GdkEventExpose  *event)
2437    {
2438        OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2439    
2440      gdk_draw_drawable (      gdk_draw_drawable (
2441                         widget->window,                         widget->window,
2442                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2443                         priv->pixmap,                         priv->pixmap,
2444                         0,0,                         0,0,
2445                         priv->drag_mouse_dx - EXTRA_BORDER, priv->drag_mouse_dy - EXTRA_BORDER,                         priv->drag_mouse_dx - EXTRA_BORDER,
2446                           priv->drag_mouse_dy - EXTRA_BORDER,
2447                         -1,-1);                         -1,-1);
2448    
2449      //Paint white outside of the map if dragging. Its less      //Paint white outside of the map if dragging. Its less
# Line 2424  osm_gps_map_motion_notify (GtkWidget *wi Line 2487  osm_gps_map_motion_notify (GtkWidget *wi
2487                              widget->allocation.width,                              widget->allocation.width,
2488                              -priv->drag_mouse_dy - EXTRA_BORDER);                              -priv->drag_mouse_dy - EXTRA_BORDER);
2489      }      }
2490    #if 0
2491      return FALSE;      if(!priv->dragging)
2492  }          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 (  
2493                         widget->window,                         widget->window,
2494                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2495                         priv->pixmap,                         priv->pixmap,
# Line 2467  osm_gps_map_expose (GtkWidget *widget, G Line 2497  osm_gps_map_expose (GtkWidget *widget, G
2497                         event->area.y + EXTRA_BORDER,                         event->area.y + EXTRA_BORDER,
2498                         event->area.x, event->area.y,                         event->area.x, event->area.y,
2499                         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);  
     }  
2500  #endif  #endif
   
2501      return FALSE;      return FALSE;
2502  }  }
2503    
# Line 3298  void osm_gps_map_osd_enable_gps (OsmGpsM Line 3317  void osm_gps_map_osd_enable_gps (OsmGpsM
3317      priv->osd.cb = cb;      priv->osd.cb = cb;
3318      priv->osd.data = data;      priv->osd.data = data;
3319    
3320        /* this may have changed the state of the gps button */
3321        /* we thus re-render the overlay */
3322        osm_gps_map_osd_render(priv);
3323    
3324      osm_gps_map_map_redraw_idle(map);      osm_gps_map_map_redraw_idle(map);
3325  }  }
3326  #endif  #endif

Legend:
Removed from v.66  
changed lines
  Added in v.68