[gegl-gtk] GeglGtkView: Add explicit public API



commit faf8935186cd47201352ba1cbb2278612dab1c12
Author: Jon Nordby <jononor gmail com>
Date:   Tue Sep 20 20:59:25 2011 +0200

    GeglGtkView: Add explicit public API

 examples/gegl-gtk-basic.c |    2 +-
 examples/gegl-gtk-paint.c |    2 +-
 gegl-gtk/gegl-gtk-view.c  |  154 +++++++++++++++++++++++++++++++++++---------
 gegl-gtk/gegl-gtk-view.h  |   17 +++++
 4 files changed, 141 insertions(+), 34 deletions(-)
---
diff --git a/examples/gegl-gtk-basic.c b/examples/gegl-gtk-basic.c
index 1d970c2..2498432 100644
--- a/examples/gegl-gtk-basic.c
+++ b/examples/gegl-gtk-basic.c
@@ -53,7 +53,7 @@ main (gint    argc,
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title (GTK_WINDOW (window), "GEGL-GTK basic example");
 
-  view = g_object_new (GEGL_GTK_TYPE_VIEW, "node", node, NULL);
+  view = gegl_gtk_view_new_for_node(node);
   gtk_container_add (GTK_CONTAINER (window), view);
 
   g_signal_connect (window, "destroy", 
diff --git a/examples/gegl-gtk-paint.c b/examples/gegl-gtk-paint.c
index efa7cf2..2dbad93 100644
--- a/examples/gegl-gtk-paint.c
+++ b/examples/gegl-gtk-paint.c
@@ -165,7 +165,7 @@ main (gint    argc,
 
     gegl_node_link_many (loadbuf, out, NULL);
 
-    view = g_object_new (GEGL_GTK_TYPE_VIEW, "node", out, NULL);
+    view = gegl_gtk_view_new_for_node(out);
     top  = loadbuf;
   }
 
diff --git a/gegl-gtk/gegl-gtk-view.c b/gegl-gtk/gegl-gtk-view.c
index ec68a8e..d47b5a2 100644
--- a/gegl-gtk/gegl-gtk-view.c
+++ b/gegl-gtk/gegl-gtk-view.c
@@ -238,43 +238,19 @@ set_property (GObject      *gobject,
   switch (property_id)
     {
     case PROP_NODE:
-      if (priv->node)
-        {
-          g_object_unref (priv->node);
-        }
-
-      if (g_value_get_object (value))
-        {
-          priv->node = GEGL_NODE (g_value_dup_object (value));
-
-          g_signal_connect_object (priv->node, "computed",
-                                   G_CALLBACK (computed_event),
-                                   self, 0);
-          g_signal_connect_object (priv->node, "invalidated",
-                                   G_CALLBACK (invalidated_event),
-                                   self, 0);
-          gegl_gtk_view_repaint (self);
-        }
-      else
-
-        {
-          priv->node = NULL;
-        }
+      gegl_gtk_view_set_node(self, GEGL_NODE(g_value_get_object(value)));
       break;
     case PROP_X:
-      priv->x = g_value_get_int (value);
-      gtk_widget_queue_draw (GTK_WIDGET (self));
+      gegl_gtk_view_set_x(self, g_value_get_int(value));
       break;
     case PROP_BLOCK:
       priv->block = g_value_get_boolean (value);
       break;
     case PROP_Y:
-      priv->y = g_value_get_int (value);
-      gtk_widget_queue_draw (GTK_WIDGET (self));
+      gegl_gtk_view_set_y(self, g_value_get_int(value));
       break;
     case PROP_SCALE:
-      priv->scale = g_value_get_double (value);
-      gtk_widget_queue_draw (GTK_WIDGET (self));
+      gegl_gtk_view_set_scale(self, g_value_get_double(value));
       break;
     default:
 
@@ -295,19 +271,19 @@ get_property (GObject      *gobject,
   switch (property_id)
     {
     case PROP_NODE:
-      g_value_set_object (value, priv->node);
+      g_value_set_object (value, gegl_gtk_view_get_node(self));
       break;
     case PROP_X:
-      g_value_set_int (value, priv->x);
+      g_value_set_int (value, gegl_gtk_view_get_x(self));
       break;
     case PROP_BLOCK:
       g_value_set_boolean (value, priv->block);
       break;
     case PROP_Y:
-      g_value_set_int (value, priv->y);
+      g_value_set_int (value, gegl_gtk_view_get_y(self));
       break;
     case PROP_SCALE:
-      g_value_set_double (value, priv->scale);
+      g_value_set_double (value, gegl_gtk_view_get_scale(self));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
@@ -441,3 +417,117 @@ gegl_gtk_view_repaint (GeglGtkView *view)
   if (priv->processor)
     gegl_processor_set_rectangle (priv->processor, &roi);
 }
+
+
+GeglGtkView *
+gegl_gtk_view_new()
+{
+    return GEGL_GTK_VIEW(g_object_new (GEGL_GTK_TYPE_VIEW, NULL));
+}
+
+GeglGtkView *
+gegl_gtk_view_new_for_node(GeglNode *node)
+{
+    GeglGtkView *view = gegl_gtk_view_new();
+    gegl_gtk_view_set_node(view, node);
+    return view;
+}
+
+
+void
+gegl_gtk_view_set_node(GeglGtkView *self, GeglNode *node)
+{
+    GeglGtkViewPrivate *priv = GEGL_GTK_VIEW_GET_PRIVATE (self);
+
+    if (priv->node == node)
+        return;
+
+    if (priv->node)
+        g_object_unref (priv->node);
+
+    if (node) {
+        g_object_ref (node);
+        priv->node = node;
+
+        g_signal_connect_object (priv->node, "computed",
+                               G_CALLBACK (computed_event),
+                               self, 0);
+        g_signal_connect_object (priv->node, "invalidated",
+                               G_CALLBACK (invalidated_event),
+                               self, 0);
+
+        gegl_gtk_view_repaint (self);
+
+    } else
+        priv->node = NULL;
+
+}
+
+/**
+ * gegl_gtk_view_get_node:
+ *
+ * Returns: (transfer none): The #GeglNode this widget displays
+ */
+GeglNode *
+gegl_gtk_view_get_node(GeglGtkView *self)
+{
+    GeglGtkViewPrivate *priv = GEGL_GTK_VIEW_GET_PRIVATE (self);
+    return priv->node;
+}
+
+void
+gegl_gtk_view_set_scale(GeglGtkView *self, float scale)
+{
+    GeglGtkViewPrivate *priv = GEGL_GTK_VIEW_GET_PRIVATE(self);
+
+    if (priv->scale == scale)
+        return;
+
+    priv->scale = scale;
+    gtk_widget_queue_draw(GTK_WIDGET (self));
+}
+
+float
+gegl_gtk_view_get_scale(GeglGtkView *self)
+{
+    GeglGtkViewPrivate *priv = GEGL_GTK_VIEW_GET_PRIVATE(self);
+    return priv->scale;
+}
+
+void
+gegl_gtk_view_set_x(GeglGtkView *self, int x)
+{
+    GeglGtkViewPrivate *priv = GEGL_GTK_VIEW_GET_PRIVATE(self);
+
+    if (priv->x == x)
+        return;
+
+    priv->x = x;
+    gtk_widget_queue_draw(GTK_WIDGET (self));
+}
+
+int
+gegl_gtk_view_get_x(GeglGtkView *self)
+{
+    GeglGtkViewPrivate *priv = GEGL_GTK_VIEW_GET_PRIVATE(self);
+    return priv->x;
+}
+
+void
+gegl_gtk_view_set_y(GeglGtkView *self, int y)
+{
+    GeglGtkViewPrivate *priv = GEGL_GTK_VIEW_GET_PRIVATE(self);
+
+    if (priv->y == y)
+        return;
+
+    priv->y = y;
+    gtk_widget_queue_draw(GTK_WIDGET (self));
+}
+
+int
+gegl_gtk_view_get_y(GeglGtkView *self)
+{
+    GeglGtkViewPrivate *priv = GEGL_GTK_VIEW_GET_PRIVATE(self);
+    return priv->y;
+}
diff --git a/gegl-gtk/gegl-gtk-view.h b/gegl-gtk/gegl-gtk-view.h
index fe9efd0..c6aa818 100644
--- a/gegl-gtk/gegl-gtk-view.h
+++ b/gegl-gtk/gegl-gtk-view.h
@@ -20,6 +20,7 @@
 #define __GEGL_GTK_VIEW_H__
 
 #include <gtk/gtk.h>
+#include <gegl.h>
 
 G_BEGIN_DECLS
 
@@ -46,6 +47,22 @@ struct _GeglGtkViewClass
 
 GType           gegl_gtk_view_get_type      (void) G_GNUC_CONST;
 
+
+GeglGtkView *gegl_gtk_view_new(void);
+GeglGtkView *gegl_gtk_view_new_for_node(GeglNode *node);
+
+void gegl_gtk_view_set_node(GeglGtkView *self, GeglNode *node);
+GeglNode *gegl_gtk_view_get_node(GeglGtkView *self);
+
+void gegl_gtk_view_set_scale(GeglGtkView *self, float scale);
+float gegl_gtk_view_get_scale(GeglGtkView *self);
+
+void gegl_gtk_view_set_x(GeglGtkView *self, int x);
+int gegl_gtk_view_get_x(GeglGtkView *self);
+
+void gegl_gtk_view_set_y(GeglGtkView *self, int y);
+int gegl_gtk_view_get_y(GeglGtkView *self);
+
 G_END_DECLS
 
 #endif /* __GEGL_GTK_VIEW_H__ */



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