[gegl/soc-2012-editor] Started working on layer functions
- From: Isaac Wagner <isaacbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/soc-2012-editor] Started working on layer functions
- Date: Wed, 13 Jun 2012 20:29:37 +0000 (UTC)
commit 0322ab8211061a56a6696f87fc31c024a3020a7c
Author: Isaac Wagner <isaacbw src gnome org>
Date: Wed Jun 13 15:24:24 2012 -0400
Started working on layer functions
bin/editor/build | 2 +-
bin/editor/gegl-editor-layer.c | 16 ++++
bin/editor/gegl-editor-layer.h | 31 +++++++
bin/editor/gegl-editor.c | 10 ++-
bin/editor/gegl-node-widget.c | 180 ++++++++++++++++++++-------------------
bin/editor/gegl-node-widget.h | 18 +++--
6 files changed, 158 insertions(+), 99 deletions(-)
---
diff --git a/bin/editor/build b/bin/editor/build
index ec9e060..602f294 100755
--- a/bin/editor/build
+++ b/bin/editor/build
@@ -1 +1 @@
-gcc gegl-editor.c gegl-node-widget.c -o editor `pkg-config --cflags --libs gtk+-2.0` -I/usr/local/include/gegl-0.1/ -I/usr/local/include/babl-0.1/
\ No newline at end of file
+gcc gegl-editor.c gegl-editor-layer.c gegl-node-widget.c -o editor `pkg-config --cflags --libs gtk+-2.0` -I/usr/local/include/gegl-0.1/ -I/usr/local/include/babl-0.1/
\ No newline at end of file
diff --git a/bin/editor/gegl-editor-layer.c b/bin/editor/gegl-editor-layer.c
new file mode 100644
index 0000000..48faf4e
--- /dev/null
+++ b/bin/editor/gegl-editor-layer.c
@@ -0,0 +1,16 @@
+#include "gegl-editor-layer.h"
+
+GeglEditorLayer*
+layer_create(GeglEditor* editor, GeglEditor* gegl)
+{
+ GeglEditorLayer* layer = malloc(sizeof(GeglEditorLayer));
+ layer->editor = editor;
+ layer->gegl = gegl;
+ return layer;
+}
+
+void
+layer_add_gegl_op(GeglEditorLayer* layer, GeglOperation* node)
+{
+ gegl_editor_add_node(layer->editor, gegl_operation_get_name(operation), 0, NULL, 0, NULL);
+}
diff --git a/bin/editor/gegl-editor-layer.h b/bin/editor/gegl-editor-layer.h
new file mode 100644
index 0000000..4e8eea6
--- /dev/null
+++ b/bin/editor/gegl-editor-layer.h
@@ -0,0 +1,31 @@
+#ifndef __EDITORLAYER_H__
+#define __EDITORLAYER_H__
+
+#include "gegl-node-widget.h"
+#include <gegl.h>
+typedef struct _GeglOperation GeglOperation;
+#include <operation/gegl-operation.h>
+
+/*
+Creates and removes connections between pads in the Gegl graph
+as they are created and removed by the user in the editor widget
+Note: only one layer can be safely used per editor widget
+The user should not link, unlink, add, or remove any operations outside of the layer interface
+*/
+typedef struct _GeglEditorLayer GeglEditorLayer;
+
+struct _GeglEditorLayer
+{
+ GeglEditor *editor;
+ GeglNode *gegl;
+};
+
+/*
+Editor and gegl graph should both be empty, but properly initialized
+*/
+GeglEditorLayer* layer_create(GeglEditor* editor, GeglEditor* gegl);
+void layer_add_gegl_op(GeglEditorLayer* layer, GeglOperation* op);
+//void layer_remove_gegl_node(GeglNode* node);
+//link, unlink
+
+#endif
diff --git a/bin/editor/gegl-editor.c b/bin/editor/gegl-editor.c
index 28438eb..c60a287 100644
--- a/bin/editor/gegl-editor.c
+++ b/bin/editor/gegl-editor.c
@@ -4,7 +4,7 @@
#include <gegl.h>
#include "gegl-node-widget.h"
-
+#include "gegl-editor-layer.h"
gint
main (gint argc,
@@ -26,12 +26,16 @@ main (gint argc,
gtk_widget_show(window);
GeglEditor* node_editor = GEGL_EDITOR(editor);
- gchar *inputs[2];
+ /*gchar *inputs[2];
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);
+ gegl_editor_set_node_position(node_editor, my_node, 100, 0);*/
+ gegl_init(&argc, &argv);
+ GeglNode *gegl = gegl_node_new();
+ GeglEditorLayer* layer = layer_create(node_editor, gegl);
gtk_main();
diff --git a/bin/editor/gegl-node-widget.c b/bin/editor/gegl-node-widget.c
index a60b04b..4502149 100644
--- a/bin/editor/gegl-node-widget.c
+++ b/bin/editor/gegl-node-widget.c
@@ -10,7 +10,7 @@ enum {
static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
static void
-gegl_editor_set_property (GObject *object,
+gegl_editor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
@@ -26,7 +26,7 @@ gegl_editor_set_property (GObject *object,
}
static void
-gegl_editor_get_property (GObject *object,
+gegl_editor_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
@@ -42,13 +42,13 @@ gegl_editor_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 = 100;
+ EditorNode* node = malloc(sizeof(EditorNode));
+ node->next = NULL;
+ node->x = node->y = 0;
+ node->width = node->height = 100;
if(prev != NULL)
- prev->next = node;
- node->title = "New Node";
+ prev->next = node;
+ node->title = "New Node";
node->inputs = NULL;
node->outputs = NULL;
@@ -56,8 +56,8 @@ EditorNode* new_editor_node(EditorNode* prev) {
return node;
}
-EditorNode* gegl_editor_last_node(GeglEditor* self);
-EditorNode* gegl_editor_get_node(GeglEditor* self, gint id);
+EditorNode* gegl_editor_last_node(GeglEditor* self);
+EditorNode* gegl_editor_get_node(GeglEditor* self, gint id);
void
connect_pads(NodePad* a, NodePad* b)
@@ -69,13 +69,13 @@ connect_pads(NodePad* a, NodePad* b)
NodePad*
get_pad_at(gint px, gint py, GeglEditor* editor)
{
- NodePad* result = NULL;
+ NodePad* result = NULL;
- EditorNode* node = editor->first_node;
+ EditorNode* node = editor->first_node;
for(;node != NULL; node = node->next)
{
- gint x, y;
- gint width, height;
+ gint x, y;
+ gint width, height;
if(node == editor->dragged_node)
{
@@ -88,44 +88,45 @@ get_pad_at(gint px, gint py, GeglEditor* editor)
y = node->y;
}
- //TODO: be more intelligent about minimum size (should be based on number of inputs/outputs so that they all fit properly)
+ /*TODO: be more intelligent about minimum size (should be based on number of
+ inputs/outputs and pad label sizes so that they all fit properly)*/
if(node->width < 100)
- node->width = 100;
+ node->width = 100;
if(node->height < 50)
node->height = 50;
if(node == editor->resized_node)
{
- width = node->width+editor->px-editor->dx;
+ width = node->width+editor->px-editor->dx;
height = node->height+editor->py-editor->dy;
}
else
{
- width = node->width;
+ width = node->width;
height = node->height;
}
if(width < 100)
- width = 100;
+ width = 100;
if(height < 50)
height = 50;
- gint title_height = node->title_height;
+ gint title_height = node->title_height;
- int i = 0;
- NodePad* pad = node->inputs;
+ int i = 0;
+ NodePad* pad = node->inputs;
for(;pad!=NULL;pad = pad->next, i++)
{
if(px > x && py > y+(title_height)+10+20*i && px < x+10 && py < y+(title_height)+20+20*i)
result = pad;
}
- i = 0;
+ i = 0;
pad = node->outputs;
for(;pad!=NULL;pad = pad->next, i++)
{
- if(px > x+width-10 && px < x+width &&
- py > y+(title_height)+10+20*i &&
+ if(px > x+width-10 && px < x+width &&
+ py > y+(title_height)+10+20*i &&
py < y+(title_height)+20+20*i)
result = pad;
}
@@ -140,17 +141,17 @@ get_pad_position_input(NodePad* pad, gint* x, gint* y, cairo_t* cr, GeglEditor*
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size(cr, 12);
- cairo_text_extents_t te;
+ cairo_text_extents_t te;
cairo_text_extents(cr, pad->node->title, &te);
- gint title_height = te.height+5;
+ gint title_height = te.height+5;
- int i = 0;
- NodePad* _pad = pad->node->inputs;
+ int i = 0;
+ NodePad* _pad = pad->node->inputs;
for(;_pad!=NULL;_pad = _pad->next, i++)
{
if(_pad == pad)
{
- gint node_x, node_y;
+ gint node_x, node_y;
if(pad->node == editor->dragged_node)
{
@@ -173,8 +174,8 @@ get_pad_position_input(NodePad* pad, gint* x, gint* y, cairo_t* cr, GeglEditor*
static void
draw_node(EditorNode* node, cairo_t *cr, GeglEditor* editor)
{
- gint x, y;
- gint width, height;
+ gint x, y;
+ gint width, height;
if(node == editor->dragged_node)
{
@@ -189,23 +190,23 @@ draw_node(EditorNode* node, cairo_t *cr, GeglEditor* editor)
//TODO: be more intelligent about minimum size (should be based on number of inputs/outputs so that they all fit properly)
if(node->width < 100)
- node->width = 100;
+ node->width = 100;
if(node->height < 50)
node->height = 50;
if(node == editor->resized_node)
{
- width = node->width+editor->px-editor->dx;
+ width = node->width+editor->px-editor->dx;
height = node->height+editor->py-editor->dy;
}
else
{
- width = node->width;
+ width = node->width;
height = node->height;
}
if(width < 100)
- width = 100;
+ width = 100;
if(height < 50)
height = 50;
@@ -223,13 +224,13 @@ draw_node(EditorNode* node, cairo_t *cr, GeglEditor* editor)
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size(cr, 12);
- cairo_font_extents_t fe;
+ cairo_font_extents_t fe;
cairo_font_extents(cr, &fe);
- cairo_text_extents_t te;
+ cairo_text_extents_t te;
cairo_text_extents(cr, node->title, &te);
- gint title_height = te.height+5;
- node->title_height = title_height;
+ gint title_height = te.height+5;
+ node->title_height = title_height;
//draw the line separating the title
cairo_move_to(cr, x, y+te.height+5);
@@ -253,8 +254,8 @@ draw_node(EditorNode* node, cairo_t *cr, GeglEditor* editor)
cairo_stroke(cr);
- int i = 0;
- NodePad* pad = node->inputs;
+ int i = 0;
+ NodePad* pad = node->inputs;
for(;pad!=NULL;pad = pad->next, i++)
{
cairo_text_extents(cr, pad->name, &te);
@@ -268,7 +269,7 @@ draw_node(EditorNode* node, cairo_t *cr, GeglEditor* editor)
cairo_show_text(cr, pad->name);
}
- i = 0;
+ i = 0;
pad = node->outputs;
for(;pad!=NULL;pad = pad->next, i++)
{
@@ -290,11 +291,11 @@ draw_node(EditorNode* node, cairo_t *cr, GeglEditor* editor)
//TODO: render all connections underneath all nodes
if(pad->connected)
{
- gint fx, fy;
+ gint fx, fy;
fx = x+width-5;
fy = y+(title_height)+15+20*i;
- gint tx, ty;
+ gint tx, ty;
get_pad_position_input(pad->connected, &tx, &ty, cr, editor);
@@ -312,11 +313,11 @@ draw_node(EditorNode* node, cairo_t *cr, GeglEditor* editor)
}
else if(pad == editor->dragged_pad)
{
- gint fx, fy;
+ gint fx, fy;
fx = x+width-5;
fy = y+(title_height)+15+20*i;
- gint tx = editor->px, ty = editor->py;
+ gint tx = editor->px, ty = editor->py;
cairo_move_to(cr, fx, fy);
//if(tx - fx > 200)
@@ -341,7 +342,7 @@ gegl_editor_draw(GtkWidget *widget, cairo_t *cr)
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_paint(cr);
- EditorNode* node = editor->first_node;
+ EditorNode* node = editor->first_node;
for(;node != NULL; node = node->next)
{
draw_node(node, cr, editor);
@@ -368,8 +369,8 @@ static gboolean
gegl_editor_motion(GtkWidget* widget, GdkEventMotion* event)
{
GeglEditor* editor = GEGL_EDITOR(widget);
- editor->px = (gint)event->x;
- editor->py = (gint)event->y;
+ editor->px = (gint)event->x;
+ editor->py = (gint)event->y;
/* redraw */
gtk_widget_queue_draw(widget);
@@ -381,33 +382,33 @@ gegl_editor_motion(GtkWidget* widget, GdkEventMotion* event)
static gboolean
gegl_editor_button_press(GtkWidget* widget, GdkEventButton* event)
{
- GeglEditor* editor = GEGL_EDITOR(widget);
+ GeglEditor* editor = GEGL_EDITOR(widget);
//TODO: check which mouse button was pressed
editor->left_mouse_down = TRUE;
- editor->dx = editor->px;
- editor->dy = editor->py;
+ editor->dx = editor->px;
+ editor->dy = editor->py;
editor->dragged_pad = NULL;
- NodePad* pad = get_pad_at(editor->px, editor->py, editor);
+ NodePad* pad = get_pad_at(editor->px, editor->py, editor);
if(pad)
{
- editor->dragged_pad = pad;
+ editor->dragged_pad = pad;
if(pad->connected) {
pad->connected->connected = NULL;
- pad->connected = NULL;
+ pad->connected = NULL;
}
}
else
{
- EditorNode* node = editor->first_node;
- EditorNode* focus = NULL;
+ 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 &&
+ if(editor->px > node->x && editor->px < node->x+node->width &&
editor->py > node->y && editor->py < node->y+node->height)
{
- if(editor->px >= node->x+node->width-15 &&
+ 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;
@@ -430,7 +431,7 @@ gegl_editor_button_press(GtkWidget* widget, GdkEventButton* event)
editor->first_node = focus->next;
}
- EditorNode* node = editor->first_node;
+ EditorNode* node = editor->first_node;
for(;node->next != NULL; node = node->next)
{
@@ -441,7 +442,7 @@ gegl_editor_button_press(GtkWidget* widget, GdkEventButton* event)
}
focus->next = NULL;
- node->next = focus;
+ node->next = focus;
}
}
@@ -462,19 +463,19 @@ gegl_editor_button_release(GtkWidget* widget, GdkEventButton* event)
{
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->width += editor->px-editor->dx;
editor->resized_node->height += editor->py-editor->dy;
- editor->resized_node = NULL;
+ editor->resized_node = NULL;
}
if(editor->dragged_pad)
{
- NodePad* pad = get_pad_at(editor->px, editor->py, editor);
+ NodePad* pad = get_pad_at(editor->px, editor->py, editor);
if(pad && pad != editor->dragged_pad) {
connect_pads(pad, editor->dragged_pad);
}
@@ -497,7 +498,7 @@ gegl_editor_class_init(GeglEditorClass *klass)
#endif
widget_class->motion_notify_event = gegl_editor_motion;
widget_class->button_press_event = gegl_editor_button_press;
- widget_class->button_release_event = gegl_editor_button_release;
+ widget_class->button_release_event = gegl_editor_button_release;
}
@@ -510,11 +511,14 @@ gegl_editor_init(GeglEditor* self)
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK );
- self->first_node = NULL;
- self->dragged_node = NULL;
- self->dragged_pad = NULL;
- self->resized_node = NULL;
- self->next_id = 1; //0 reserved for non-existent node
+ self->first_node = NULL;
+ self->dragged_node = NULL;
+ self->dragged_pad = NULL;
+ self->resized_node = NULL;
+ self->connectedPads = NULL;
+ self->disconnectedPads = NULL;
+
+ self->next_id = 1; //0 reserved for non-existent node
}
GtkWidget*
@@ -526,28 +530,28 @@ gegl_editor_new ( void )
gint
gegl_editor_add_node(GeglEditor* self, gchar* title, gint ninputs, gchar** inputs, gint noutputs, gchar** outputs)
{
- EditorNode* node = new_editor_node(gegl_editor_last_node(self));
+ EditorNode* node = new_editor_node(gegl_editor_last_node(self));
if(self->first_node == NULL)
self->first_node = node;
node->id = self->next_id++;
- int i;
- NodePad* pad;
- NodePad* last_pad;
+ int i;
+ NodePad* pad;
+ NodePad* last_pad;
//add inputs to node
for(i = 0, last_pad = NULL; i < ninputs; i++)
{
- pad = malloc(sizeof(NodePad));
+ pad = malloc(sizeof(NodePad));
if(node->inputs == NULL)
node->inputs = pad;
- pad->next = NULL;
+ pad->next = NULL;
pad->connected = NULL;
- pad->name = inputs[i];
- pad->node = node;
+ pad->name = inputs[i];
+ pad->node = node;
if(last_pad != NULL)
last_pad->next = pad;
@@ -558,14 +562,14 @@ gegl_editor_add_node(GeglEditor* self, gchar* title, gint ninputs, gchar** input
//add outputs to node
for(i = 0, last_pad = NULL; i < noutputs; i++)
{
- pad = malloc(sizeof(NodePad));
+ pad = malloc(sizeof(NodePad));
if(node->outputs == NULL)
node->outputs = pad;
- pad->next = NULL;
+ pad->next = NULL;
pad->connected = NULL;
- pad->name = outputs[i];
- pad->node = node;
+ pad->name = outputs[i];
+ pad->node = node;
if(last_pad != NULL)
last_pad->next = pad;
@@ -578,9 +582,9 @@ gegl_editor_add_node(GeglEditor* self, gchar* title, gint ninputs, gchar** input
void gegl_editor_set_node_position(GeglEditor* self, gint id, gint x, gint y)
{
- EditorNode* node = gegl_editor_get_node(self, id);
+ EditorNode* node = gegl_editor_get_node(self, id);
if(node == NULL)
- return; //generate an error
+ return; //generate an error
node->x = x;
node->y = y;
@@ -591,14 +595,14 @@ EditorNode* gegl_editor_last_node(GeglEditor* self)
if(self->first_node == NULL)
return NULL;
- EditorNode* node;
+ EditorNode* node;
for(node = self->first_node; node->next != NULL; node = node->next);
return node;
}
EditorNode* gegl_editor_get_node(GeglEditor* self, gint id)
{
- EditorNode* node;
+ EditorNode* node;
for(node = self->first_node; node != NULL; node = node->next)
if(node->id == id)
return node;
diff --git a/bin/editor/gegl-node-widget.h b/bin/editor/gegl-node-widget.h
index 8c6fbdb..aef38ba 100644
--- a/bin/editor/gegl-node-widget.h
+++ b/bin/editor/gegl-node-widget.h
@@ -7,14 +7,14 @@
#include <glib-object.h>
#include <stdlib.h>
-#define GEGL_TYPE_EDITOR (gegl_editor_get_type())
-#define GEGL_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, GEGL_TYPE_EDITOR, GeglEditor))
-#define GEGL_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, GEGL_TYPE_EDITOR, GeglEditorClass))
+#define GEGL_TYPE_EDITOR (gegl_editor_get_type())
+#define GEGL_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, GEGL_TYPE_EDITOR, GeglEditor))
+#define GEGL_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, GEGL_TYPE_EDITOR, GeglEditorClass))
#define GEGL_IS_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE(obj, GEGL_TYPE_EDITOR))
#define GEGL_IS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GEGL_TYPE_EDITOR))
-#define GEGL_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GEGL_TYPE_EDITOR, NodeWidgetClass))
+#define GEGL_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GEGL_TYPE_EDITOR, NodeWidgetClass))
-typedef struct _GeglEditor GeglEditor;
+typedef struct _GeglEditor GeglEditor;
typedef struct _GeglEditorClass GeglEditorClass;
typedef struct _EditorNode EditorNode;
@@ -52,10 +52,14 @@ struct _GeglEditor
{
GtkDrawingArea parent;
+ /* public */
+ gint (*connectedPads) (GeglEditor* self, gint from, gchar* output, gint to, gchar* input);
+ gint (*disconnectedPads) (GeglEditor* self, gint from, gchar* output, gint to, gchar* input);
+
/* private */
gint px, py; //current mouse coordinates
gint dx, dy; //last mouse coordinates when mouse button pressed
- gint next_id;
+ gint next_id;
gboolean left_mouse_down; //if left mouse button is pressed
EditorNode* first_node;
EditorNode* dragged_node;
@@ -73,6 +77,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);
-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]