[sysprof/wip/visualizers] visualizer-selection: add visualizer helpers



commit 42b82f69c9f722d8521916f7bee62306debd2da4
Author: Christian Hergert <chergert redhat com>
Date:   Sat Oct 8 19:19:46 2016 -0700

    visualizer-selection: add visualizer helpers
    
    Adds a copy helper (for thread access) and a contains helper.

 lib/sp-visualizer-selection.c |   37 +++++++++++++++++++++++++++++++++++++
 lib/sp-visualizer-selection.h |    8 ++++++--
 2 files changed, 43 insertions(+), 2 deletions(-)
---
diff --git a/lib/sp-visualizer-selection.c b/lib/sp-visualizer-selection.c
index 062d480..d0c83d1 100644
--- a/lib/sp-visualizer-selection.c
+++ b/lib/sp-visualizer-selection.c
@@ -212,3 +212,40 @@ sp_visualizer_selection_unselect_all (SpVisualizerSelection *self)
       g_signal_emit (self, signals [CHANGED], 0);
     }
 }
+
+gboolean
+sp_visualizer_selection_contains (SpVisualizerSelection *self,
+                                  gint64                 time_at)
+{
+  if (self == NULL || self->ranges->len == 0)
+    return TRUE;
+
+  for (guint i = 0; i < self->ranges->len; i++)
+    {
+      const Range *range = &g_array_index (self->ranges, Range, i);
+
+      if (time_at >= range->begin && time_at <= range->end)
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
+SpVisualizerSelection *
+sp_visualizer_selection_copy (const SpVisualizerSelection *self)
+{
+  SpVisualizerSelection *copy;
+
+  if (self == NULL)
+    return NULL;
+
+  copy = g_object_new (SP_TYPE_VISUALIZER_SELECTION, NULL);
+
+  for (guint i = 0; i < self->ranges->len; i++)
+    {
+      Range range = g_array_index (self->ranges, Range, i);
+      g_array_append_val (copy->ranges, range);
+    }
+
+  return copy;
+}
diff --git a/lib/sp-visualizer-selection.h b/lib/sp-visualizer-selection.h
index 76a7867..56be994 100644
--- a/lib/sp-visualizer-selection.h
+++ b/lib/sp-visualizer-selection.h
@@ -19,13 +19,13 @@
 #ifndef SP_VISUALIZER_SELECTION_H
 #define SP_VISUALIZER_SELECTION_H
 
-#include <gtk/gtk.h>
+#include <glib-object.h>
 
 G_BEGIN_DECLS
 
 #define SP_TYPE_VISUALIZER_SELECTION (sp_visualizer_selection_get_type())
 
-G_DECLARE_FINAL_TYPE (SpVisualizerSelection, sp_visualizer_selection, SP, VISUALIZER_SELECTION, 
GtkDrawingArea)
+G_DECLARE_FINAL_TYPE (SpVisualizerSelection, sp_visualizer_selection, SP, VISUALIZER_SELECTION, GObject)
 
 typedef void (*SpVisualizerSelectionForeachFunc) (SpVisualizerSelection *self,
                                                   gint64                 begin_time,
@@ -33,6 +33,8 @@ typedef void (*SpVisualizerSelectionForeachFunc) (SpVisualizerSelection *self,
                                                   gpointer               user_data);
 
 gboolean sp_visualizer_selection_get_has_selection (SpVisualizerSelection            *self);
+gboolean sp_visualizer_selection_contains          (SpVisualizerSelection            *self,
+                                                    gint64                            time_at);
 void     sp_visualizer_selection_select_range      (SpVisualizerSelection            *self,
                                                     gint64                            begin_time,
                                                     gint64                            end_time);
@@ -43,6 +45,8 @@ void     sp_visualizer_selection_unselect_all      (SpVisualizerSelection
 void     sp_visualizer_selection_foreach           (SpVisualizerSelection            *self,
                                                     SpVisualizerSelectionForeachFunc  foreach_func,
                                                     gpointer                          user_data);
+SpVisualizerSelection *
+         sp_visualizer_selection_copy              (const SpVisualizerSelection      *self);
 
 G_END_DECLS
 


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