[gegl/soc-2012-editor: 4/24] Can resize nodes and the last node to be moved or resized is moved to the top (might get rid of resi



commit 54702995123fe9e0994877f6a4248e028ffe58e5
Author: Isaac Wagner <isaacbw src gnome org>
Date:   Tue Jun 5 22:52:20 2012 -0400

    Can resize nodes and the last node to be moved or resized is moved to the top (might get rid of resizing... not sure how useful it will be)

 bin/editor/gegl-node-widget.c |  178 ++++++++++++++++++++++++++++++++--------
 bin/editor/gegl-node-widget.h |    5 +-
 2 files changed, 145 insertions(+), 38 deletions(-)
---
diff --git a/bin/editor/gegl-node-widget.c b/bin/editor/gegl-node-widget.c
index fce95fb..24d7d1e 100644
--- a/bin/editor/gegl-node-widget.c
+++ b/bin/editor/gegl-node-widget.c
@@ -41,41 +41,112 @@ gegl_node_widget_get_property (GObject	*object,
     }
 }
 
+EditorNode* new_editor_node(EditorNode* prev) {
+  EditorNode* node = malloc(sizeof(EditorNode));
+  node->next = NULL;
+  node->x = node->y = 0;
+  node->width = node->height = 75;
+  if(prev != NULL)
+    prev->next = node;
+  node->title = "Empty Node";
+  return node;
+}
+
+EditorNode* top_node(EditorNode* first)
+{
+  EditorNode* node = first;
+  while(node->next != NULL) node = node->next;
+  return node;
+}
+
+static void
+draw_node(EditorNode* node, cairo_t *cr, GeglNodeWidget* editor)
+{
+  gint x, y;
+  gint width, height;
+
+  if(node == editor->dragged_node)
+    {
+      x = node->x+editor->px-editor->dx;
+      y = node->y+editor->py-editor->dy;
+    }
+  else
+    {
+      x = node->x;
+      y = node->y;
+    }
+
+  if(node == editor->resized_node)
+    {
+      width = node->width+editor->px-editor->dx;
+      height = node->height+editor->py-editor->dy;
+    }
+  else
+    {
+      width = node->width;
+      height = node->height;
+    }
+
+  if(width < 50)
+    width = 50;
+  if(height < 50)
+    height = 50;
+
+  cairo_rectangle(cr, x, y, width, height);
+
+  cairo_set_source_rgb(cr, 1, 1, 1);
+  cairo_fill_preserve(cr);
+
+  cairo_set_line_width(cr, 1);
+  cairo_set_source_rgb(cr, 0, 0, 0);
+  cairo_stroke(cr);
+
+
+  cairo_select_font_face(cr, "Georgia",
+			 CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+  cairo_set_font_size(cr, 12);
+
+  cairo_font_extents_t fe;
+  cairo_font_extents(cr, &fe);
+
+  cairo_text_extents_t te;
+  cairo_text_extents(cr, node->title, &te);
+
+  //draw the line separating the title
+  cairo_move_to(cr, x, y+te.height+5);
+  cairo_line_to(cr, x+width, y+te.height+5);
+  cairo_stroke(cr);
+
+  //setup the clip for the title text
+  cairo_rectangle(cr, x, y, width, te.height+5);
+  cairo_clip(cr);
+
+  //draw the text
+  cairo_move_to (cr, x-te.x_bearing +2.5,
+		 y - te.y_bearing +2.5);
+  cairo_show_text (cr, node->title);
+
+  //get rid of the clip
+  cairo_reset_clip(cr);
+
+  cairo_move_to(cr, x+width-15, y+height);
+  cairo_line_to(cr, x+width, y+height-15);
+  cairo_stroke(cr);
+}
+
 static gboolean
 gegl_node_widget_draw(GtkWidget *widget, cairo_t *cr)
 {
   GeglNodeWidget*	editor = GEGL_NODE_WIDGET(widget);
 
-  cairo_set_source_rgb(cr, 0, 0, 0);
+  cairo_set_source_rgb(cr, 1, 1, 1);
   cairo_paint(cr);
 
-
-
   EditorNode* node = editor->first_node;
   for(;node != NULL; node = node->next)
     {
-      cairo_set_source_rgb(cr, 1, 1, 1);
-
-      /*if(editor->px > node->x && editor->px < node->x+node->width &&
-	 editor->py > node->y && editor->py < node->y+node->height) 
-	{
-	  cairo_set_source_rgb(cr, 1, 0, 0);
-	  }*/
-
-      if(node == editor->dragged_node)
-	{
-	  cairo_rectangle(cr, node->x+editor->px-editor->dx, node->y+editor->py-editor->dy, node->width, node->height);
-	}
-      else
-	{
-	  cairo_rectangle(cr, node->x, node->y, node->width, node->height);
-	}
-
-      cairo_fill(cr);
+      draw_node(node, cr, editor);
     }
-  /*  cairo_arc(cr, editor->px, editor->py, 30, 0, 2*3.14159);
-
-  cairo_stroke(cr);*/
 
   return FALSE;
 }
@@ -116,15 +187,51 @@ gegl_node_widget_button_press(GtkWidget* widget, GdkEventButton* event)
   editor->dy = editor->py;
 
   EditorNode* node = editor->first_node;
+  EditorNode* focus = NULL;
   for(;node != NULL; node = node->next)
     {
       if(editor->px > node->x && editor->px < node->x+node->width &&
 	 editor->py > node->y && editor->py < node->y+node->height) 
 	{
-	  editor->dragged_node = node;
+	  if(editor->px >= node->x+node->width-15 &&
+	     editor->py >= node->y+node->height-15+(node->x+node->width-editor->px))
+	    {
+	      editor->dragged_node = NULL;
+	      editor->resized_node = node;
+	    }
+	  else
+	    {
+	      editor->resized_node = NULL;
+	      editor->dragged_node = node;
+	    }
+
+	  focus = node;
+	}
+    }
+
+  if(focus && focus->next != NULL)
+    {
+      if(focus == editor->first_node)
+	{
+	  editor->first_node = focus->next;
+	}
+
+      EditorNode* node = editor->first_node;
+
+      for(;node->next != NULL; node = node->next)
+	{
+	  if(node->next == focus)
+	    {
+	      node->next = focus->next;
+	    }
 	}
+
+      focus->next = NULL;
+      node->next = focus;
     }
 
+  gtk_widget_queue_draw(widget);
+
   return FALSE;
 }
 
@@ -132,16 +239,23 @@ static gboolean
 gegl_node_widget_button_release(GtkWidget* widget, GdkEventButton* event)
 {
   GeglNodeWidget*	editor = GEGL_NODE_WIDGET(widget);
-  //TODO: check which mouse button was released
+
+  /* TODO: check which mouse button was released instead of assuming it's the left one */
   editor->left_mouse_down = FALSE;
 
   if(editor->dragged_node)
     {
       editor->dragged_node->x += editor->px-editor->dx;
       editor->dragged_node->y += editor->py-editor->dy;
+      editor->dragged_node = NULL;
     }
 
-  editor->dragged_node = NULL;
+  if(editor->resized_node)
+    {
+      editor->resized_node->width += editor->px-editor->dx;
+      editor->resized_node->height += editor->py-editor->dy;
+      editor->resized_node = NULL;
+    }
 
   return FALSE;
 }
@@ -172,6 +286,7 @@ gegl_node_widget_init(GeglNodeWidget* self)
 
   self->first_node = NULL;
   self->dragged_node = NULL;
+  self->resized_node = NULL;
 
   self->first_node = new_editor_node(NULL);
   EditorNode* node = new_editor_node(self->first_node);
@@ -187,12 +302,3 @@ gegl_node_widget_new ( void )
   return g_object_new (GEGL_TYPE_NODE_WIDGET, NULL);
 }
 
-EditorNode* new_editor_node(EditorNode* prev) {
-  EditorNode* node = malloc(sizeof(EditorNode));
-  node->next = NULL;
-  node->x = node->y = 0;
-  node->width = node->height = 25;
-  if(prev != NULL)
-    prev->next = node;
-  return node;
-}
diff --git a/bin/editor/gegl-node-widget.h b/bin/editor/gegl-node-widget.h
index 28dfd9a..17ce728 100644
--- a/bin/editor/gegl-node-widget.h
+++ b/bin/editor/gegl-node-widget.h
@@ -22,8 +22,8 @@ typedef struct _EditorNode EditorNode;
 struct _EditorNode
 {
   gint x, y, width, height;
-  gboolean dragging;
-  EditorNode* next;
+  gchar* title;
+  EditorNode *next;
 };
 
 EditorNode* new_editor_node(EditorNode* prev);
@@ -39,6 +39,7 @@ struct _GeglNodeWidget
   gboolean left_mouse_down; //if left mouse button is pressed
   EditorNode* first_node;
   EditorNode* dragged_node;
+  EditorNode* resized_node;
 };
 
 struct _GeglNodeWidgetClass



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