[gegl/soc-2012-editor] Will blit the contents of a node onto a thumbnail preview in the graphic. Pretty messy right now.



commit 0a0d4d50deed49a6e2f9ed7edab56096591cf902
Author: Isaac Wagner <isaacbw src gnome org>
Date:   Fri Jun 15 13:55:06 2012 -0400

    Will blit the contents of a node onto a thumbnail preview in the graphic. Pretty messy right now.

 bin/editor/gegl-editor-layer.c |   48 ++++++++++++++++++++++++++++++--
 bin/editor/gegl-editor.c       |   18 ++++++++++-
 bin/editor/gegl-node-widget.c  |   60 ++++++++++++++++++++++++++++++++-------
 bin/editor/gegl-node-widget.h  |   19 ++++++++----
 4 files changed, 122 insertions(+), 23 deletions(-)
---
diff --git a/bin/editor/gegl-editor-layer.c b/bin/editor/gegl-editor-layer.c
index a96f93e..5c9986c 100644
--- a/bin/editor/gegl-editor-layer.c
+++ b/bin/editor/gegl-editor-layer.c
@@ -1,12 +1,53 @@
 #include "gegl-editor-layer.h"
 
+void refresh_images(GeglEditorLayer* self)
+{
+  GSList*	pair = self->pairs;
+  for(;pair != NULL; pair = pair->next)
+    {
+      node_id_pair	*data = pair->data;
+
+      /*      if(node->image != NULL)
+	      cairo_surface_destroy(node->image);	//TODO: only destory if it has changed*/
+
+      const Babl	*cairo_argb32 = babl_format("cairo-ARGB32");
+
+      const GeglRectangle	roi = gegl_node_get_bounding_box(GEGL_NODE(data->node));
+      if(roi.width == 0 || roi.height == 0)
+	{
+	  g_print("Empty rectangle: %s\n", gegl_node_get_operation(GEGL_NODE(data->node)));
+	  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);
+
+      //make buffer in memory
+      gegl_node_blit(GEGL_NODE(data->node),
+		     1.0,
+		     &roi,
+		     cairo_argb32,
+		     buf,
+		     GEGL_AUTO_ROWSTRIDE,
+		     GEGL_BLIT_CACHE);
+
+      cairo_surface_t*	image = 
+	cairo_image_surface_create_for_data(buf, CAIRO_FORMAT_ARGB32, 
+				      roi.width, roi.height, 
+				      stride);
+      gegl_editor_set_node_image(self->editor, data->id, image);
+    }
+}
+
 gint layer_connected_pads (gpointer host, GeglEditor* editor, gint from, gchar* output, gint to, gchar* input)
 {
-  GeglEditorLayer*	layer = (GeglEditorLayer*)host;
+  GeglEditorLayer*	self = (GeglEditorLayer*)host;
 
   GeglNode*	from_node = NULL;
   GeglNode*	to_node	  = NULL;
-  GSList*	pair	  = layer->pairs;
+  GSList*	pair	  = self->pairs;
   for(;pair != NULL; pair = pair->next)
     {
       node_id_pair*	data = pair->data;
@@ -20,9 +61,10 @@ gint layer_connected_pads (gpointer host, GeglEditor* editor, gint from, gchar*
   
   g_assert(from_node != NULL && to_node != NULL);
   g_assert(from_node != to_node);
-  gboolean success = gegl_node_connect_to(from_node, output, to_node, input);
+  gboolean	success = gegl_node_connect_to(from_node, output, to_node, input);
   g_print("connected: %s(%s) to %s(%s), %i\n", gegl_node_get_operation(from_node), output,
 	  gegl_node_get_operation(to_node), input, success);  
+  refresh_images(self);
 }
 
 gint layer_disconnected_pads (gpointer host, GeglEditor* editor, gint from, gchar* output, gint to, gchar* input)
diff --git a/bin/editor/gegl-editor.c b/bin/editor/gegl-editor.c
index df5872f..0a2ec43 100644
--- a/bin/editor/gegl-editor.c
+++ b/bin/editor/gegl-editor.c
@@ -62,10 +62,24 @@ main (gint	  argc,
   layer_add_gegl_node(layer, display);
 
   GeglNode *over       = gegl_node_new_child (gegl,
-                                 "operation", "gegl:over",
-                                 NULL);
+					      "operation", "gegl:over",
+					      NULL);
   layer_add_gegl_node(layer, over);
 
+  GeglNode *load = gegl_node_new_child(gegl,
+				       "operation", "gegl:load",
+				       "path", "./surfer.png",
+				       NULL);
+  layer_add_gegl_node(layer, load);
+
+  GeglNode *text = gegl_node_new_child(gegl,
+				       "operation", "gegl:text",
+				       "size", 10.0,
+				       "color", gegl_color_new("rgb(1.0,1.0,1.0)"),
+				       "text", "Hello world!",
+				       NULL);
+  layer_add_gegl_node(layer, text);
+
 
   gtk_main();
   
diff --git a/bin/editor/gegl-node-widget.c b/bin/editor/gegl-node-widget.c
index 234f79c..c18ac25 100644
--- a/bin/editor/gegl-node-widget.c
+++ b/bin/editor/gegl-node-widget.c
@@ -53,6 +53,9 @@ EditorNode* new_editor_node(EditorNode* prev) {
   node->inputs	= NULL;
   node->outputs = NULL;
 
+  node->image	   = NULL;
+  node->show_image = FALSE;
+
   return node;
 }
 
@@ -253,7 +256,6 @@ draw_node(EditorNode* node, cairo_t *cr, GeglEditor* editor)
   cairo_line_to(cr, x+width, y+height-15);
   cairo_stroke(cr);
 
-
   int		i   = 0;
   NodePad*	pad = node->inputs;
   for(;pad!=NULL;pad = pad->next, i++)
@@ -267,7 +269,7 @@ draw_node(EditorNode* node, cairo_t *cr, GeglEditor* editor)
       cairo_set_source_rgb(cr, 0, 0, 0);
       cairo_move_to(cr, x+12.5, y+(title_height)+10+20*i+te.height/2+5);
       cairo_show_text(cr, pad->name);
-    }
+    }				//end of inputs
 
   i   = 0;
   pad = node->outputs;
@@ -320,19 +322,40 @@ draw_node(EditorNode* node, cairo_t *cr, GeglEditor* editor)
 	  gint	tx = editor->px, ty = editor->py;
 
 	  cairo_move_to(cr, fx, fy);
-	  //if(tx - fx > 200)
-	    cairo_curve_to(cr, (fx+tx)/2, fy,
-			   (fx+tx)/2, ty,
-			   tx, ty);
-	  /* else
-	    cairo_curve_to(cr, fx+100, fy,
-			   tx-100, ty,
-			   tx, ty);*/
+	  cairo_curve_to(cr, (fx+tx)/2, fy,
+			 (fx+tx)/2, ty,
+			 tx, ty);
+
 	  cairo_stroke(cr);
 
 	}
+    }				//end of outputs
+
+  if(node->show_image)
+    {
+      g_assert(node->image != NULL);
+      {
+	//	node->image = cairo_image_surface_create_from_png("surfer.png");
+	cairo_reset_clip(cr);
+	gdouble w, h, mw, mh;
+	w = (gdouble)cairo_image_surface_get_width(node->image);
+	h = (gdouble)cairo_image_surface_get_height(node->image);
+
+	mw = width;
+	mh = height - 50;
+	gdouble scale;
+	if(mw/w < mh/h)
+	  scale = mw/w;
+	else
+	  scale = mh/h;
+	cairo_scale(cr, scale, scale);
+	cairo_set_source_surface(cr, node->image, (x/scale)+(mw-w*scale)/2.0/scale, (y+height-h*scale)/scale);
+	cairo_paint(cr);
+	//	cairo_surface_destroy(node->image);
+	cairo_scale(cr, 1.0/scale, 1.0/scale);
+      }
     }
-}
+}				//end of draw_node
 
 static gboolean
 gegl_editor_draw(GtkWidget *widget, cairo_t *cr)
@@ -619,3 +642,18 @@ EditorNode* gegl_editor_get_node(GeglEditor* self, gint id)
       return node;
   return NULL;
 }
+
+void gegl_editor_show_node_image(GeglEditor* self, gint node)
+{
+  gegl_editor_get_node(self, node)->show_image = TRUE;
+}
+
+void gegl_editor_hide_node_image(GeglEditor* self, gint node)
+{
+  gegl_editor_get_node(self, node)->show_image = FALSE;
+}
+
+void gegl_editor_set_node_image(GeglEditor* self, gint node, cairo_surface_t* image)
+{
+  gegl_editor_get_node(self, node)->image = image;
+}
diff --git a/bin/editor/gegl-node-widget.h b/bin/editor/gegl-node-widget.h
index 6c26b9c..b5ff6af 100644
--- a/bin/editor/gegl-node-widget.h
+++ b/bin/editor/gegl-node-widget.h
@@ -37,12 +37,14 @@ struct _PadConnection
 
 struct _EditorNode
 {
-  gint		 id, x, y, width, height;
-  gchar*	 title;
-  gint		 title_height;
-  EditorNode	*next;
-  NodePad*	 inputs;
-  NodePad*	 outputs;
+  gint			 id, x, y, width, height;
+  gchar*		 title;
+  gint			 title_height;
+  EditorNode		*next;
+  NodePad*		 inputs;
+  NodePad*		 outputs;
+  gboolean		 show_image;
+  cairo_surface_t	*image;
 };
 
 EditorNode*	new_editor_node(EditorNode* prev);
@@ -65,7 +67,7 @@ struct _GeglEditor
   EditorNode*	dragged_node;
   EditorNode*	resized_node;
   NodePad*	dragged_pad;
-  gpointer host; //sent back through callbacks. Can really be whatever
+  gpointer	host;		//sent back through callbacks. Can really be whatever
 };
 
 struct _GeglEditorClass
@@ -79,5 +81,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);
 
 #endif



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