[gegl/soc-2012-editor: 14/24] Made node dis/connection callbacks functional



commit 39b2d3a87228605daf506173036c1477a8290852
Author: Isaac Wagner <isaacbw src gnome org>
Date:   Wed Jun 13 17:17:45 2012 -0400

    Made node dis/connection callbacks functional

 bin/editor/gegl-editor-layer.c |   31 +++++++++++++++++++++++++++----
 bin/editor/gegl-editor-layer.h |    8 ++++++++
 bin/editor/gegl-node-widget.c  |    8 ++++++++
 bin/editor/gegl-node-widget.h  |    5 +++--
 4 files changed, 46 insertions(+), 6 deletions(-)
---
diff --git a/bin/editor/gegl-editor-layer.c b/bin/editor/gegl-editor-layer.c
index d2c06ea..7e89174 100644
--- a/bin/editor/gegl-editor-layer.c
+++ b/bin/editor/gegl-editor-layer.c
@@ -1,15 +1,32 @@
 #include "gegl-editor-layer.h"
 
+gint layer_connected_pads (gpointer host, GeglEditor* editor, gint from, gchar* output, gint to, gchar* input)
+{
+  GeglEditorLayer* layer = (GeglEditorLayer*)host;
+  g_print("connected: %s to %s\n", output, input);
+}
+
+gint layer_disconnected_pads (gpointer host, GeglEditor* editor, gint from, gchar* output, gint to, gchar* input)
+{
+  GeglEditorLayer* layer = (GeglEditorLayer*)host;
+  g_print("disconnected: %s to %s\n", output, input);
+}
+//gint (*disconnectedPads) (gpointer host, GeglEditor* editor, gint from, gchar* output, gint to, gchar* input)
+
 GeglEditorLayer*	
 layer_create(GeglEditor* editor, GeglNode* gegl)
 {
   GeglEditorLayer* layer = malloc(sizeof(GeglEditorLayer));
+  editor->host = (gpointer)layer;
+  editor->connectedPads = layer_connected_pads;
+  editor->disconnectedPads = layer_disconnected_pads;
   layer->editor = editor;
   layer->gegl = gegl;
+  layer->pairs = NULL;
   return layer;
 }
 
-void			
+void
 layer_add_gegl_node(GeglEditorLayer* layer, GeglNode* node)
 {
   //get input pads
@@ -23,14 +40,20 @@ layer_add_gegl_node(GeglEditorLayer* layer, GeglNode* node)
       inputs[i] = gegl_pad_get_name(pads->data);
     }
 
+  gint id;
   if(gegl_node_get_pad(node, "output") == NULL)
     {
-      gegl_editor_add_node(layer->editor, gegl_node_get_operation(node), num_inputs, inputs, 0, NULL);
+      id = gegl_editor_add_node(layer->editor, gegl_node_get_operation(node), num_inputs, inputs, 0, NULL);
     }
   else
     {
       gchar* output = "output";
-      gchar** outputs[1] = {output};
-      gegl_editor_add_node(layer->editor, gegl_node_get_operation(node), num_inputs, inputs, 1, outputs);
+      gchar* outputs[] = {output};
+      id = gegl_editor_add_node(layer->editor, gegl_node_get_operation(node), num_inputs, inputs, 1, outputs);
     }
+
+  node_id_pair* new_pair = malloc(sizeof(node_id_pair));
+  new_pair->node = node;
+  new_pair->id = id;
+  g_slist_append(layer->pairs, new_pair);
 }
diff --git a/bin/editor/gegl-editor-layer.h b/bin/editor/gegl-editor-layer.h
index 8ee8a22..14059e8 100644
--- a/bin/editor/gegl-editor-layer.h
+++ b/bin/editor/gegl-editor-layer.h
@@ -3,6 +3,7 @@
 
 #include "gegl-node-widget.h"
 #include <gegl.h>
+#include <glib.h>
 
 /*	
 Creates and removes connections between pads in the Gegl graph 
@@ -12,10 +13,17 @@ The user should not link, unlink, add, or remove any operations outside of the l
 */
 typedef struct _GeglEditorLayer GeglEditorLayer;
 
+typedef struct _node_id_pair
+{
+  GeglNode*	node;
+  gint		id;
+} node_id_pair;
+
 struct _GeglEditorLayer
 {
   GeglEditor	*editor;
   GeglNode	*gegl;
+  GSList	*pairs;
 };
 
 /* 
diff --git a/bin/editor/gegl-node-widget.c b/bin/editor/gegl-node-widget.c
index e378a34..84240b7 100644
--- a/bin/editor/gegl-node-widget.c
+++ b/bin/editor/gegl-node-widget.c
@@ -395,6 +395,10 @@ gegl_editor_button_press(GtkWidget* widget, GdkEventButton* event)
     {
       editor->dragged_pad	  = pad;
       if(pad->connected) {
+	if(editor->disconnectedPads != NULL)
+	  editor->disconnectedPads(editor->host, editor, 
+				pad->connected->node->id, pad->connected->name,
+				pad->node->id, pad->name);
 	pad->connected->connected = NULL;
 	pad->connected		  = NULL;
       }
@@ -478,6 +482,10 @@ gegl_editor_button_release(GtkWidget* widget, GdkEventButton* event)
       NodePad*	pad = get_pad_at(editor->px, editor->py, editor);
       if(pad && pad != editor->dragged_pad) {
 	connect_pads(pad, editor->dragged_pad);
+	if(editor->connectedPads != NULL)
+	  editor->connectedPads(editor->host, editor, 
+				editor->dragged_pad->node->id, editor->dragged_pad->name,
+				pad->node->id, pad->name);
       }
       editor->dragged_pad = NULL;
     }
diff --git a/bin/editor/gegl-node-widget.h b/bin/editor/gegl-node-widget.h
index aef38ba..6c26b9c 100644
--- a/bin/editor/gegl-node-widget.h
+++ b/bin/editor/gegl-node-widget.h
@@ -53,8 +53,8 @@ struct _GeglEditor
   GtkDrawingArea	parent;
 
   /* public */
-  gint (*connectedPads) (GeglEditor* self, gint from, gchar* output, gint to, gchar* input);
-  gint (*disconnectedPads) (GeglEditor* self, gint from, gchar* output, gint to, gchar* input);
+  gint (*connectedPads) (gpointer host, GeglEditor* editor, gint from, gchar* output, gint to, gchar* input);
+  gint (*disconnectedPads) (gpointer host, GeglEditor* editor, gint from, gchar* output, gint to, gchar* input);
 
   /* private */
   gint		px, py;		//current mouse coordinates
@@ -65,6 +65,7 @@ struct _GeglEditor
   EditorNode*	dragged_node;
   EditorNode*	resized_node;
   NodePad*	dragged_pad;
+  gpointer host; //sent back through callbacks. Can really be whatever
 };
 
 struct _GeglEditorClass



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