[gegl/soc-2012-editor: 15/24] Added dummy menu to Gtk+ shell
- From: Isaac Wagner <isaacbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/soc-2012-editor: 15/24] Added dummy menu to Gtk+ shell
- Date: Thu, 28 Jun 2012 14:03:29 +0000 (UTC)
commit 7d44bf290c92dcb6649c482f1d15463d26760dbd
Author: Isaac Wagner <isaacbw src gnome org>
Date: Wed Jun 13 18:20:10 2012 -0400
Added dummy menu to Gtk+ shell
bin/editor/build | 2 +-
bin/editor/gegl-editor-layer.c | 59 ++++++++++++++++++++++++++-------------
bin/editor/gegl-editor-layer.h | 2 +-
bin/editor/gegl-editor.c | 46 +++++++++++++++++++++++--------
bin/editor/gegl-node-widget.c | 10 ++++---
5 files changed, 81 insertions(+), 38 deletions(-)
---
diff --git a/bin/editor/build b/bin/editor/build
index fb8f0fa..be012b5 100755
--- a/bin/editor/build
+++ b/bin/editor/build
@@ -1 +1 @@
-gcc -g 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.2/ -I/usr/local/include/babl-0.1/ -lgegl-0.2
\ No newline at end of file
+gcc -g gegl-editor.c gegl-editor-layer.c gegl-node-widget.c -o editor `pkg-config --cflags --libs gtk+-2.0 gthread-2.0` -I/usr/local/include/gegl-0.2/ -I/usr/local/include/babl-0.1/ -lgegl-0.2
\ No newline at end of file
diff --git a/bin/editor/gegl-editor-layer.c b/bin/editor/gegl-editor-layer.c
index 7e89174..a96f93e 100644
--- a/bin/editor/gegl-editor-layer.c
+++ b/bin/editor/gegl-editor-layer.c
@@ -2,13 +2,32 @@
gint layer_connected_pads (gpointer host, GeglEditor* editor, gint from, gchar* output, gint to, gchar* input)
{
- GeglEditorLayer* layer = (GeglEditorLayer*)host;
- g_print("connected: %s to %s\n", output, input);
+ GeglEditorLayer* layer = (GeglEditorLayer*)host;
+
+ GeglNode* from_node = NULL;
+ GeglNode* to_node = NULL;
+ GSList* pair = layer->pairs;
+ for(;pair != NULL; pair = pair->next)
+ {
+ node_id_pair* data = pair->data;
+ if(data->id == from)
+ from_node = data->node;
+ if(data->id == to)
+ to_node = data->node;
+ if(from_node != NULL && to_node != NULL)
+ break;
+ }
+
+ 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);
+ 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);
}
gint layer_disconnected_pads (gpointer host, GeglEditor* editor, gint from, gchar* output, gint to, gchar* input)
{
- GeglEditorLayer* layer = (GeglEditorLayer*)host;
+ GeglEditorLayer* layer = (GeglEditorLayer*)host;
g_print("disconnected: %s to %s\n", output, input);
}
//gint (*disconnectedPads) (gpointer host, GeglEditor* editor, gint from, gchar* output, gint to, gchar* input)
@@ -16,13 +35,13 @@ gint layer_disconnected_pads (gpointer host, GeglEditor* editor, gint from, gcha
GeglEditorLayer*
layer_create(GeglEditor* editor, GeglNode* gegl)
{
- GeglEditorLayer* layer = malloc(sizeof(GeglEditorLayer));
- editor->host = (gpointer)layer;
- editor->connectedPads = layer_connected_pads;
- editor->disconnectedPads = layer_disconnected_pads;
- layer->editor = editor;
- layer->gegl = gegl;
- layer->pairs = NULL;
+ GeglEditorLayer* layer = malloc(sizeof(GeglEditorLayer));
+ editor->host = (gpointer)layer;
+ editor->connectedPads = layer_connected_pads;
+ editor->disconnectedPads = layer_disconnected_pads;
+ layer->editor = editor;
+ layer->gegl = gegl;
+ layer->pairs = NULL;
return layer;
}
@@ -31,29 +50,29 @@ layer_add_gegl_node(GeglEditorLayer* layer, GeglNode* node)
{
//get input pads
//gegl_pad_is_output
- GSList *pads = gegl_node_get_input_pads(node);
- guint num_inputs = g_slist_length(pads);
- gchar** inputs = malloc(sizeof(gchar*)*num_inputs);
- int i;
+ GSList *pads = gegl_node_get_input_pads(node);
+ guint num_inputs = g_slist_length(pads);
+ gchar** inputs = malloc(sizeof(gchar*)*num_inputs);
+ int i;
for(i = 0; pads != NULL; pads = pads->next, i++)
{
inputs[i] = gegl_pad_get_name(pads->data);
}
- gint id;
+ gint id;
if(gegl_node_get_pad(node, "output") == NULL)
{
id = gegl_editor_add_node(layer->editor, gegl_node_get_operation(node), num_inputs, inputs, 0, NULL);
}
else
{
- gchar* output = "output";
+ gchar* output = "output";
gchar* outputs[] = {output};
- id = gegl_editor_add_node(layer->editor, gegl_node_get_operation(node), num_inputs, inputs, 1, outputs);
+ id = gegl_editor_add_node(layer->editor, gegl_node_get_operation(node), num_inputs, inputs, 1, outputs);
}
node_id_pair* new_pair = malloc(sizeof(node_id_pair));
- new_pair->node = node;
- new_pair->id = id;
- g_slist_append(layer->pairs, new_pair);
+ new_pair->node = node;
+ new_pair->id = id;
+ layer->pairs = g_slist_append(layer->pairs, new_pair);
}
diff --git a/bin/editor/gegl-editor-layer.h b/bin/editor/gegl-editor-layer.h
index 14059e8..8f23a6c 100644
--- a/bin/editor/gegl-editor-layer.h
+++ b/bin/editor/gegl-editor-layer.h
@@ -1,7 +1,7 @@
#ifndef __EDITORLAYER_H__
#define __EDITORLAYER_H__
-#include "gegl-node-widget.h"
+#include "gegl-node-widget.h"
#include <gegl.h>
#include <glib.h>
diff --git a/bin/editor/gegl-editor.c b/bin/editor/gegl-editor.c
index 34b9044..df5872f 100644
--- a/bin/editor/gegl-editor.c
+++ b/bin/editor/gegl-editor.c
@@ -10,30 +10,51 @@ gint
main (gint argc,
gchar **argv)
{
- GtkWidget *window;
- GtkWidget *editor;
-
gtk_init(&argc, &argv);
+ GtkWidget *window;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
+
+ GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
+ gtk_widget_show(vbox);
+ gtk_container_add(GTK_CONTAINER(window), vbox);
+
+
+ //create the menubar
+ GtkWidget *menubar;
+ GtkWidget *process_menu;
+ GtkWidget *process;
+ GtkWidget *process_all;
+ menubar = gtk_menu_bar_new();
+ process_menu = gtk_menu_new();
+
+ process = gtk_menu_item_new_with_label("Process");
+ process_all = gtk_menu_item_new_with_label("All");
+
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(process), process_menu);
+ gtk_menu_shell_append(GTK_MENU_SHELL(process_menu), process_all);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menubar), process);
+
+ gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
+ // gtk_widget_show(menubar);
+
+ GtkWidget *editor;
editor = gegl_editor_new ();
- gtk_container_add(GTK_CONTAINER(window), editor);
+ // gtk_container_add(GTK_CONTAINER(vbox), editor);
+ gtk_box_pack_start(GTK_BOX(vbox), editor, TRUE, TRUE, 0);
g_signal_connect (window, "destroy", G_CALLBACK( gtk_main_quit), NULL);
- gtk_widget_show(editor);
- gtk_widget_show(window);
+ // gtk_widget_show(editor);
+ gtk_widget_show_all(window);
GeglEditor* node_editor = GEGL_EDITOR(editor);
- /*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_init(&argc, &argv);
+
+ //add some samples nodes
GeglNode *gegl = gegl_node_new();
GeglEditorLayer* layer = layer_create(node_editor, gegl);
@@ -45,6 +66,7 @@ main (gint argc,
NULL);
layer_add_gegl_node(layer, over);
+
gtk_main();
return 0;
diff --git a/bin/editor/gegl-node-widget.c b/bin/editor/gegl-node-widget.c
index 84240b7..234f79c 100644
--- a/bin/editor/gegl-node-widget.c
+++ b/bin/editor/gegl-node-widget.c
@@ -50,7 +50,7 @@ EditorNode* new_editor_node(EditorNode* prev) {
prev->next = node;
node->title = "New Node";
- node->inputs = NULL;
+ node->inputs = NULL;
node->outputs = NULL;
return node;
@@ -382,8 +382,9 @@ gegl_editor_motion(GtkWidget* widget, GdkEventMotion* event)
static gboolean
gegl_editor_button_press(GtkWidget* widget, GdkEventButton* event)
{
- GeglEditor* editor = GEGL_EDITOR(widget);
- //TODO: check which mouse button was pressed
+ GeglEditor* editor = GEGL_EDITOR(widget);
+
+ //TODO: check which mouse button was pressed rather than assume it was the left button
editor->left_mouse_down = TRUE;
editor->dx = editor->px;
editor->dy = editor->py;
@@ -458,6 +459,7 @@ gegl_editor_button_press(GtkWidget* widget, GdkEventButton* event)
static gboolean
gegl_editor_button_release(GtkWidget* widget, GdkEventButton* event)
{
+ //TODO: only allow outputs to be connected to inputs (not inputs to inputs or outputs to outputs)
GeglEditor* editor = GEGL_EDITOR(widget);
/* TODO: check which mouse button was released instead of assuming it's the left one */
@@ -543,7 +545,7 @@ gegl_editor_add_node(GeglEditor* self, gchar* title, gint ninputs, gchar** input
if(self->first_node == NULL)
self->first_node = node;
- node->id = self->next_id++;
+ node->id = self->next_id++;
node->title = title;
int i;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]