[gegl/soc-2012-editor: 18/24] Added code to print out a list of properties and their types whenever a new node is selected.



commit edfbd482205b922609666abe92bd8c872b0df258
Author: Isaac Wagner <isaacbw src gnome org>
Date:   Sun Jun 17 19:14:39 2012 -0400

    Added code to print out a list of properties and their types whenever a new node is selected.

 bin/editor/gegl-editor-layer.c |   41 ++++++++++++++++++++++++++++++++++++---
 bin/editor/gegl-editor.c       |    2 +
 bin/editor/gegl-node-widget.c  |   15 +++++++++++--
 bin/editor/gegl-node-widget.h  |    9 +++++--
 4 files changed, 57 insertions(+), 10 deletions(-)
---
diff --git a/bin/editor/gegl-editor-layer.c b/bin/editor/gegl-editor-layer.c
index 5c9986c..4396e1d 100644
--- a/bin/editor/gegl-editor-layer.c
+++ b/bin/editor/gegl-editor-layer.c
@@ -16,13 +16,13 @@ void refresh_images(GeglEditorLayer* self)
       if(roi.width == 0 || roi.height == 0)
 	{
 	  g_print("Empty rectangle: %s\n", gegl_node_get_operation(GEGL_NODE(data->node)));
-	  continue; //skip
+	  continue;		//skip
 	}
 
       gegl_editor_show_node_image(self->editor, data->id);
 
-      gint stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, roi.width);
-      guchar* buf = malloc(stride*roi.height);
+      gint	stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, roi.width);
+      guchar*	buf    = malloc(stride*roi.height);
 
       //make buffer in memory
       gegl_node_blit(GEGL_NODE(data->node),
@@ -71,8 +71,40 @@ gint layer_disconnected_pads (gpointer host, GeglEditor* editor, gint from, gcha
 {
   GeglEditorLayer*	layer = (GeglEditorLayer*)host;
   g_print("disconnected: %s to %s\n", output, input);
+  //TODO: disconnect in GEGL as well
 }
-//gint (*disconnectedPads) (gpointer host, GeglEditor* editor, gint from, gchar* output, gint to, gchar* input)
+
+gint layer_node_selected (gpointer host, GeglEditor* editor, gint node_id)
+{
+  GeglEditorLayer*	self = (GeglEditorLayer*)host;
+  GeglNode*		node = NULL;
+  GSList*		pair = self->pairs;
+  for(;pair != NULL; pair = pair->next)
+    {
+      node_id_pair*	data = pair->data;
+      if(data->id == node_id)
+	{
+	  node = data->node;
+	  break;
+	}
+    }
+
+  g_assert(node != NULL);
+
+  g_print("selected: %s\n", gegl_node_get_operation(node));
+
+  guint n_props;
+  GParamSpec** properties = gegl_operation_list_properties(gegl_node_get_operation(node), &n_props);
+  int i;
+  for(i = 0; i < n_props; i++)
+    {
+      GParamSpec* prop = properties[i];
+      g_print("%s (%s)\n", prop->name, g_type_name(prop->value_type));
+    }
+}
+
+/*  gint (*nodeSelected) (gpointer host, GeglEditor* editor, gint node);
+    gint (*nodeDeselected) (gpointer host, GeglEditor* editor, gint node);*/
 
 GeglEditorLayer*	
 layer_create(GeglEditor* editor, GeglNode* gegl)
@@ -81,6 +113,7 @@ layer_create(GeglEditor* editor, GeglNode* gegl)
   editor->host		      = (gpointer)layer;
   editor->connectedPads	      = layer_connected_pads;
   editor->disconnectedPads    = layer_disconnected_pads;
+  editor->nodeSelected	      = layer_node_selected;
   layer->editor		      = editor;
   layer->gegl		      = gegl;
   layer->pairs		      = NULL;
diff --git a/bin/editor/gegl-editor.c b/bin/editor/gegl-editor.c
index cacc11b..0fa4e28 100644
--- a/bin/editor/gegl-editor.c
+++ b/bin/editor/gegl-editor.c
@@ -125,6 +125,8 @@ main (gint	  argc,
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
+  g_print("%s\n", G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(load)));
+  
   gtk_main();
   
   return 0;
diff --git a/bin/editor/gegl-node-widget.c b/bin/editor/gegl-node-widget.c
index c18ac25..7e1f134 100644
--- a/bin/editor/gegl-node-widget.c
+++ b/bin/editor/gegl-node-widget.c
@@ -218,7 +218,7 @@ draw_node(EditorNode* node, cairo_t *cr, GeglEditor* editor)
   cairo_set_source_rgb(cr, 1, 1, 1);
   cairo_fill_preserve(cr);
 
-  cairo_set_line_width(cr, 1);
+  cairo_set_line_width(cr, (editor->selected_node == node) ? 3 : 1);
   cairo_set_source_rgb(cr, 0, 0, 0);
   cairo_stroke(cr);
 
@@ -426,7 +426,7 @@ gegl_editor_button_press(GtkWidget* widget, GdkEventButton* event)
 	pad->connected->connected = NULL;
 	pad->connected		  = NULL;
       }
-    }
+    } //end if(pad)
   else
     {
       EditorNode*	node  = editor->first_node;
@@ -472,7 +472,16 @@ gegl_editor_button_press(GtkWidget* widget, GdkEventButton* event)
 	  focus->next = NULL;
 	  node->next  = focus;
 	}
-    }
+
+      if(editor->selected_node && editor->selected_node != focus && editor->nodeDeselected)
+	editor->nodeDeselected(editor->host, editor, editor->selected_node->id);
+
+      if(focus && editor->selected_node != focus && editor->nodeSelected)
+	editor->nodeSelected(editor->host, editor, focus->id);
+
+      editor->selected_node = focus;
+
+    }//end if(pad) else
 
   gtk_widget_queue_draw(widget);
 
diff --git a/bin/editor/gegl-node-widget.h b/bin/editor/gegl-node-widget.h
index b5ff6af..b869d20 100644
--- a/bin/editor/gegl-node-widget.h
+++ b/bin/editor/gegl-node-widget.h
@@ -57,6 +57,8 @@ struct _GeglEditor
   /* public */
   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);
+  gint (*nodeSelected) (gpointer host, GeglEditor* editor, gint node);
+  gint (*nodeDeselected) (gpointer host, GeglEditor* editor, gint node);
 
   /* private */
   gint		px, py;		//current mouse coordinates
@@ -68,6 +70,7 @@ struct _GeglEditor
   EditorNode*	resized_node;
   NodePad*	dragged_pad;
   gpointer	host;		//sent back through callbacks. Can really be whatever
+  EditorNode*	selected_node;	//TODO: allow multiple nodes to be selected at once
 };
 
 struct _GeglEditorClass
@@ -81,8 +84,8 @@ GtkWidget*	gegl_editor_new(void);
 //public methods
 gint	gegl_editor_add_node(GeglEditor* self, gchar* title, gint ninputs, gchar** inputs, gint noutputs, gchar** outputs);
 void	gegl_editor_set_node_position(GeglEditor* self, gint node, gint x, gint y);
-void gegl_editor_show_node_image(GeglEditor* self, gint node);
-void gegl_editor_hide_node_image(GeglEditor* self, gint node);
-void gegl_editor_set_node_image(GeglEditor* self, gint node, cairo_surface_t* image);
+void	gegl_editor_show_node_image(GeglEditor* self, gint node);
+void	gegl_editor_hide_node_image(GeglEditor* self, gint node);
+void	gegl_editor_set_node_image(GeglEditor* self, gint node, cairo_surface_t* image);
 
 #endif



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