From aa61c435475936286571bfa35decd08d78d822c1 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Sat, 8 Oct 2016 15:36:01 -0700 Subject: [PATCH] visualizer-view: fix selections when scrolling If we have a scrolled view, we might be a bit off on the selected range until this commit. This adjusts for the scrolled area and ensures that both ticks and selections land in the right place. --- lib/sp-visualizer-view.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/sp-visualizer-view.c b/lib/sp-visualizer-view.c index e73192f7..c39521de 100644 --- a/lib/sp-visualizer-view.c +++ b/lib/sp-visualizer-view.c @@ -95,10 +95,7 @@ get_time_from_coordinates (SpVisualizerView *self, { SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self); SpVisualizerRow *row1 = NULL; - GtkAdjustment *hadjustment; GtkAllocation alloc; - gdouble nsec_per_pixel; - gdouble value; gint64 begin_time; gint64 end_time; gint graph_width; @@ -121,18 +118,11 @@ get_time_from_coordinates (SpVisualizerView *self, if (!SP_IS_VISUALIZER_ROW (row1)) return 0; - hadjustment = gtk_scrolled_window_get_hadjustment (priv->scroller); - value = gtk_adjustment_get_value (hadjustment); - begin_time = sp_capture_reader_get_start_time (priv->reader); end_time = sp_capture_reader_get_end_time (priv->reader); - graph_width = _sp_visualizer_row_get_graph_width (row1); - nsec_per_pixel = (end_time - begin_time) / (gdouble)graph_width; - begin_time += value * nsec_per_pixel; - end_time = begin_time + (alloc.width * nsec_per_pixel); - return begin_time + ((end_time - begin_time) / (gdouble)alloc.width * x); + return begin_time + ((end_time - begin_time) * (x / (gdouble)graph_width)); } static gint @@ -203,16 +193,21 @@ static void sp_visualizer_view_update_ticks (SpVisualizerView *self) { SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self); + GtkAdjustment *hadjustment; GtkAllocation alloc; + gdouble value; gint64 begin_time; gint64 end_time; g_assert (SP_IS_VISUALIZER_VIEW (self)); + hadjustment = gtk_scrolled_window_get_hadjustment (priv->scroller); + value = gtk_adjustment_get_value (hadjustment); + gtk_widget_get_allocation (GTK_WIDGET (self), &alloc); - begin_time = get_time_from_coordinates (self, alloc.x, alloc.y); - end_time = get_time_from_coordinates (self, alloc.x + alloc.width, alloc.y); + begin_time = get_time_from_coordinates (self, alloc.x + value, alloc.y); + end_time = get_time_from_coordinates (self, alloc.x + value + alloc.width, alloc.y); sp_visualizer_ticks_set_time_range (priv->ticks, begin_time, end_time); }