[gnome-builder] realtime-graphs: try harder to not jump when resizing



commit ac65cfa4092f69b46f232cc73e68631bcfc23e70
Author: Christian Hergert <chergert redhat com>
Date:   Tue May 10 13:23:23 2016 +0300

    realtime-graphs: try harder to not jump when resizing
    
    We were resetting our x_offset when resizing the window, so things would
    appear to jump backwards. This tries to persist the offset in time and
    only apply the alloc.width multiplication when it comes time to render.
    
    This allows us to keep the x_offset between resizes, and therefore endup
    on the right offset even when destroying the surface.

 contrib/rg/rg-graph.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/contrib/rg/rg-graph.c b/contrib/rg/rg-graph.c
index 7176d39..fae62f5 100644
--- a/contrib/rg/rg-graph.c
+++ b/contrib/rg/rg-graph.c
@@ -29,7 +29,7 @@ typedef struct
   GPtrArray       *renderers;
   cairo_surface_t *surface;
   guint            tick_handler;
-  gint             x_offset;
+  gdouble          x_offset;
   guint            surface_dirty : 1;
 } RgGraphPrivate;
 
@@ -117,7 +117,7 @@ rg_graph_tick_cb (GtkWidget     *widget,
   gint64 frame_time;
   gint64 end_time;
   gint64 timespan;
-  gint x_offset;
+  gdouble x_offset;
 
   g_assert (RG_IS_GRAPH (self));
 
@@ -133,7 +133,7 @@ rg_graph_tick_cb (GtkWidget     *widget,
   frame_time = gdk_frame_clock_get_frame_time (frame_clock);
   end_time = rg_table_get_end_time (priv->table);
 
-  x_offset = -((frame_time - end_time) / (gdouble)timespan * alloc.width);
+  x_offset = -((frame_time - end_time) / (gdouble)timespan);
 
   if (x_offset != priv->x_offset)
     {
@@ -215,8 +215,6 @@ rg_graph_ensure_surface (RgGraph *self)
         }
 
       cairo_destroy (cr);
-
-      priv->x_offset = 0;
     }
 
   if (priv->tick_handler == 0)
@@ -249,7 +247,7 @@ rg_graph_draw (GtkWidget *widget,
   gtk_style_context_restore (style_context);
 
   cairo_save (cr);
-  cairo_set_source_surface (cr, priv->surface, priv->x_offset, 0);
+  cairo_set_source_surface (cr, priv->surface, priv->x_offset * alloc.width, 0);
   cairo_rectangle (cr, 0, 0, alloc.width, alloc.height);
   cairo_fill (cr);
   cairo_restore (cr);
@@ -280,9 +278,13 @@ static void
 rg_graph__table_changed (RgGraph *self,
                          RgTable *table)
 {
+  RgGraphPrivate *priv = rg_graph_get_instance_private (self);
+
   g_assert (RG_IS_GRAPH (self));
   g_assert (RG_IS_TABLE (table));
 
+  priv->x_offset = 0;
+
   rg_graph_clear_surface (self);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]