[gegl/soc-2012-editor: 8/36] Added method to add a new node to the widget with a specified title, list of inputs, and list of out



commit 5f3ea6eb56dde63d8720c68006864433786664b2
Author: Isaac Wagner <isaacbw src gnome org>
Date:   Wed Jun 13 14:19:25 2012 -0400

    Added method to add a new node to the widget with a specified title, list of inputs, and list of outputs

 bin/editor/gegl-node-widget.c |  113 +++++++++++++++++++++--------------------
 bin/editor/gegl-node-widget.h |   11 ++++
 2 files changed, 68 insertions(+), 56 deletions(-)
---
diff --git a/bin/editor/gegl-node-widget.c b/bin/editor/gegl-node-widget.c
index 424afe8..f81cede 100644
--- a/bin/editor/gegl-node-widget.c
+++ b/bin/editor/gegl-node-widget.c
@@ -519,73 +519,74 @@ gegl_node_widget_init(GeglNodeWidget* self)
   self->dragged_pad = NULL;
   self->resized_node = NULL;
 
-  EditorNode* node = new_editor_node(NULL);
+  gchar *inputs[2];
+  inputs[0] = "Input1";
+  inputs[1] = "Input2";
 
-  NodePad* input = malloc(sizeof(NodePad));
-  input->next = NULL;
-  input->connected = NULL;
-  input->name = "In";
-  input->node = node;
-
-  NodePad* input2 = malloc(sizeof(NodePad));
-  input2->next = NULL;
-  input2->connected = NULL;
-  input2->name = "Mask";
-  input2->node = node;
-
-  input->next = input2;
-  node->inputs = input;
-
-  NodePad* output = malloc(sizeof(NodePad));
-  output->next = NULL;
-  output->connected = NULL;
-  output->name = "Out";
-  output->node = node;
-
-  node->outputs = output;
-
-  self->first_node = node;
+  gegl_node_widget_add_node(self, "New Node", 2, inputs, 2, inputs);
+}
 
-  node = new_editor_node(NULL);
+GtkWidget* 
+gegl_node_widget_new ( void )
+{
+  return g_object_new (GEGL_TYPE_NODE_WIDGET, NULL);
+}
 
-  input = malloc(sizeof(NodePad));
-  input->next = NULL;
-  input->connected = NULL;
-  input->name = "In";
-  input->node = node;
+gint	
+gegl_node_widget_add_node(GeglNodeWidget* self, gchar* title, gint ninputs, gchar** inputs, gint noutputs, gchar** outputs)
+{
+  EditorNode* node = new_editor_node(gegl_node_widget_last_node(self));
 
-  input2 = malloc(sizeof(NodePad));
-  input2->next = NULL;
-  input2->connected = NULL;
-  input2->name = "Mask";
-  input2->node = node;
+  if(self->first_node == NULL)
+    self->first_node = node;
+  /*  else
+      gegl_node_widget_last_node(self)->next = node;*/
 
-  input->next = input2;
-  node->inputs = input;
+  int i;
+  NodePad* pad;
+  NodePad* last_pad;
+  for(i = 0, last_pad = NULL; i < ninputs; i++)
+    {
+      pad = malloc(sizeof(NodePad));
+      if(node->inputs == NULL)
+	node->inputs = pad;
 
-  output = malloc(sizeof(NodePad));
-  output->next = NULL;
-  output->connected = NULL;
-  output->name = "Out";
-  output->node = node;
+      pad->next = NULL;
+      pad->connected = NULL;
+      pad->name = inputs[i];
+      pad->node = node;
 
-  node->outputs = output;
+      if(last_pad != NULL)
+	last_pad->next = pad;
+      
+      last_pad = pad;
+    }
 
-  self->first_node->next = node;
-  node->x = 200;
+  for(i = 0, last_pad = NULL; i < noutputs; i++)
+    {
+      pad = malloc(sizeof(NodePad));
+      if(node->outputs == NULL)
+	node->outputs = pad;
 
-  connect_pads(self->first_node->inputs, node->outputs);
+      pad->next = NULL;
+      pad->connected = NULL;
+      pad->name = outputs[i];
+      pad->node = node;
 
-  /*   = new_editor_node(self->first_node);
-       node->x = 50;
-       node = new_editor_node(node);
-       node->x = 100;
-       node->y = 14;*/
+      if(last_pad != NULL)
+	last_pad->next = pad;
+      
+      last_pad = pad;
+    }
+  //repeat for outputs
 }
 
-GtkWidget* 
-gegl_node_widget_new ( void )
+EditorNode* gegl_node_widget_last_node(GeglNodeWidget* self)
 {
-  return g_object_new (GEGL_TYPE_NODE_WIDGET, NULL);
-}
+  if(self->first_node == NULL)
+    return NULL;
 
+  EditorNode* node;
+  for(node = self->first_node; node->next != NULL; node = node->next);
+  return node;
+}
diff --git a/bin/editor/gegl-node-widget.h b/bin/editor/gegl-node-widget.h
index a803c02..9ebe58c 100644
--- a/bin/editor/gegl-node-widget.h
+++ b/bin/editor/gegl-node-widget.h
@@ -19,6 +19,7 @@ typedef struct _GeglNodeWidgetClass	GeglNodeWidgetClass;
 
 typedef struct _EditorNode	EditorNode;
 typedef struct _NodePad		NodePad;
+typedef struct _PadConnection   PadConnection;
 
 struct _NodePad
 {
@@ -28,6 +29,12 @@ struct _NodePad
   EditorNode*	 node;
 };
 
+struct _PadConnection
+{
+  
+};
+
+
 struct _EditorNode
 {
   gint		 x, y, width, height;
@@ -63,4 +70,8 @@ struct _GeglNodeWidgetClass
 GType		gegl_node_widget_get_type(void);
 GtkWidget*	gegl_node_widget_new(void);
 
+//public methods
+gint	gegl_node_widget_add_node(GeglNodeWidget* self, gchar* title, gint ninputs, gchar** inputs, gint noutputs, gchar** outputs);
+EditorNode* gegl_node_widget_last_node(GeglNodeWidget* self);
+
 #endif



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