[gegl/soc-2012-editor] Added node IDs and a function for externally setting the position of a node



commit 2fdf5c505ca6a5a8288c6ee14e98a124adaff2f6
Author: Isaac Wagner <isaacbw src gnome org>
Date:   Wed Jun 13 14:32:14 2012 -0400

    Added node IDs and a function for externally setting the position of a node

 bin/editor/gegl-editor.c      |    3 ++-
 bin/editor/gegl-node-widget.c |   38 +++++++++++++++++++++++++++++---------
 bin/editor/gegl-node-widget.h |    6 +++---
 3 files changed, 34 insertions(+), 13 deletions(-)
---
diff --git a/bin/editor/gegl-editor.c b/bin/editor/gegl-editor.c
index bece04a..28438eb 100644
--- a/bin/editor/gegl-editor.c
+++ b/bin/editor/gegl-editor.c
@@ -30,7 +30,8 @@ main (gint	  argc,
   inputs[0] = "Input1";
   inputs[1] = "Input2";
 
-  gegl_editor_add_node(node_editor, "New Node", 2, inputs, 2, inputs);
+  gint my_node = gegl_editor_add_node(node_editor, "New Node", 2, inputs, 2, inputs);
+  gegl_editor_set_node_position(node_editor, my_node, 100, 0);
 
   gtk_main();
   
diff --git a/bin/editor/gegl-node-widget.c b/bin/editor/gegl-node-widget.c
index a910c49..a60b04b 100644
--- a/bin/editor/gegl-node-widget.c
+++ b/bin/editor/gegl-node-widget.c
@@ -56,12 +56,8 @@ EditorNode* new_editor_node(EditorNode* prev) {
   return node;
 }
 
-EditorNode* top_node(EditorNode* first)
-{
-  EditorNode* node = first;
-  while(node->next != NULL) node = node->next;
-  return node;
-}
+EditorNode* gegl_editor_last_node(GeglEditor* self);
+EditorNode* gegl_editor_get_node(GeglEditor* self, gint id);
 
 void
 connect_pads(NodePad* a, NodePad* b)
@@ -518,8 +514,7 @@ gegl_editor_init(GeglEditor* self)
   self->dragged_node = NULL;
   self->dragged_pad = NULL;
   self->resized_node = NULL;
-
-
+  self->next_id = 1; //0 reserved for non-existent node
 }
 
 GtkWidget* 
@@ -536,9 +531,13 @@ gegl_editor_add_node(GeglEditor* self, gchar* title, gint ninputs, gchar** input
   if(self->first_node == NULL)
     self->first_node = node;
 
+  node->id = self->next_id++;
+
   int i;
   NodePad* pad;
   NodePad* last_pad;
+
+  //add inputs to node
   for(i = 0, last_pad = NULL; i < ninputs; i++)
     {
       pad = malloc(sizeof(NodePad));
@@ -556,6 +555,7 @@ gegl_editor_add_node(GeglEditor* self, gchar* title, gint ninputs, gchar** input
       last_pad = pad;
     }
 
+  //add outputs to node
   for(i = 0, last_pad = NULL; i < noutputs; i++)
     {
       pad = malloc(sizeof(NodePad));
@@ -572,7 +572,18 @@ gegl_editor_add_node(GeglEditor* self, gchar* title, gint ninputs, gchar** input
       
       last_pad = pad;
     }
-  //repeat for outputs
+  
+  return node->id;
+}
+
+void gegl_editor_set_node_position(GeglEditor* self, gint id, gint x, gint y)
+{
+  EditorNode* node = gegl_editor_get_node(self, id);
+  if(node == NULL)
+    return; //generate an error
+
+  node->x = x;
+  node->y = y;
 }
 
 EditorNode* gegl_editor_last_node(GeglEditor* self)
@@ -584,3 +595,12 @@ EditorNode* gegl_editor_last_node(GeglEditor* self)
   for(node = self->first_node; node->next != NULL; node = node->next);
   return node;
 }
+
+EditorNode* gegl_editor_get_node(GeglEditor* self, gint id)
+{
+  EditorNode* node;
+  for(node = self->first_node; node != NULL; node = node->next)
+    if(node->id == id)
+      return node;
+  return NULL;
+}
diff --git a/bin/editor/gegl-node-widget.h b/bin/editor/gegl-node-widget.h
index 12f3f3d..8c6fbdb 100644
--- a/bin/editor/gegl-node-widget.h
+++ b/bin/editor/gegl-node-widget.h
@@ -37,7 +37,7 @@ struct _PadConnection
 
 struct _EditorNode
 {
-  gint		 x, y, width, height;
+  gint		 id, x, y, width, height;
   gchar*	 title;
   gint		 title_height;
   EditorNode	*next;
@@ -55,6 +55,7 @@ struct _GeglEditor
   /* private */
   gint		px, py;		//current mouse coordinates
   gint		dx, dy;		//last mouse coordinates when mouse button pressed
+  gint next_id;
   gboolean	left_mouse_down;	//if left mouse button is pressed
   EditorNode*	first_node;
   EditorNode*	dragged_node;
@@ -72,7 +73,6 @@ GtkWidget*	gegl_editor_new(void);
 
 //public methods
 gint	gegl_editor_add_node(GeglEditor* self, gchar* title, gint ninputs, gchar** inputs, gint noutputs, gchar** outputs);
-EditorNode* gegl_editor_last_node(GeglEditor* self);
-//void gegl_editor_set_node_position(GeglEditor* self, gint node, gint x, gint y);
+void gegl_editor_set_node_position(GeglEditor* self, gint node, gint x, gint y);
 
 #endif



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