gegl r2299 - in trunk: . examples



Author: ok
Date: Sat May 17 13:39:53 2008
New Revision: 2299
URL: http://svn.gnome.org/viewvc/gegl?rev=2299&view=rev

Log:
* Makefile.am: added examples subdir.
* configure.ac: added examples/Makefile.am
* examples/: new dir.
* examples/Makefile.am: added a make file with wildcards that builds,
dists and cleans .c files, each .c file in the dir turns into an
executable.
* examples/gegl-paint.c: a tiny drawing app.


Added:
   trunk/examples/
   trunk/examples/Makefile.am
   trunk/examples/gegl-paint.c
Modified:
   trunk/ChangeLog
   trunk/Makefile.am
   trunk/configure.ac

Modified: trunk/Makefile.am
==============================================================================
--- trunk/Makefile.am	(original)
+++ trunk/Makefile.am	Sat May 17 13:39:53 2008
@@ -1,11 +1,16 @@
 AUTOMAKE_OPTIONS = dist-bzip2
 
-SUBDIRS= gegl operations bin tools
+SUBDIRS=\
+	gegl \
+	operations \
+	bin \
+	tools \
+	examples
+
 if ENABLE_DOCS
 SUBDIRS+= docs
 endif
 
-
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = gegl.pc
 
@@ -34,4 +39,4 @@
 dist-hook: dist-check-w3m
 
 website: all
-	$(MAKE) -C docs website
+	$(MAKE) -C docs website
\ No newline at end of file

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Sat May 17 13:39:53 2008
@@ -831,6 +831,7 @@
 docs/index-static.txt
 docs/gallery/Makefile
 docs/gallery/data/Makefile
+examples/Makefile
 gegl.pc
 gegl-uninstalled.pc
 ])

Added: trunk/examples/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/examples/Makefile.am	Sat May 17 13:39:53 2008
@@ -0,0 +1,27 @@
+#include $(top_srcdir)/operations/Makefile-common.am
+
+CFILES = $(wildcard $(srcdir)/*.c)
+bins   = $(subst $(srcdir)/,,$(CFILES:.c=))
+EXTRA_DIST = $(wildcard *.c)
+
+all-local: $(bins)
+
+clean-local:
+	rm -f *.lo $(bins)
+
+INCLUDES = \
+	-I$(top_builddir) \
+	-I$(top_srcdir)	-I$(top_srcdir)/gegl -I$(top_srcdir)/gegl/buffer \
+	-I$(top_srcdir)/gegl/property-types \
+	-I$(top_srcdir)/gegl/buffer \
+	-I$(top_srcdir)/gegl/operation \
+	-I$(top_srcdir)/gegl/module \
+	@DEP_CFLAGS@ @GTK_CFLAGS@ @BABL_CFLAGS@ @PNG_CFLAGS@
+
+AM_LDFLAGS =  \
+	../gegl/libgegl- GEGL_API_VERSION@.la \
+	@DEP_LIBS@ @GTK_LIBS@ @BABL_LIBS@ @PNG_LIBS@
+
+%: %.c $(GEGLHEADERS)
+	$(LIBTOOL) --mode=compile $(CC) $< -c -o $  lo $(INCLUDES) -DHAVE_CONFIG_H
+	$(LIBTOOL) --mode=link    $(CC) $  lo -o $@ $(AM_LDFLAGS)

Added: trunk/examples/gegl-paint.c
==============================================================================
--- (empty file)
+++ trunk/examples/gegl-paint.c	Sat May 17 13:39:53 2008
@@ -0,0 +1,192 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2003, 2004, 2006 Ãyvind KolÃs
+ */
+
+#include <string.h>
+#include "config.h"
+#include <glib.h>
+#include <gegl.h>
+#include <gtk/gtk.h>
+#include "../bin/gegl-view.h"
+#include "../bin/gegl-view.c"
+#include "property-types/gegl-vector.h"
+
+#define HARDNESS    0.8
+#define LINEWIDTH  23.0
+
+GtkWidget *window;
+GtkWidget *view;
+static GeglBuffer *buffer   = NULL;
+static GeglNode   *gegl     = NULL;
+static GeglNode   *out      = NULL;
+static GeglNode   *top      = NULL;
+static gboolean    pen_down = FALSE;
+static GeglVector *vector   = NULL;
+
+static GeglNode   *over     = NULL;
+static GeglNode   *stroke   = NULL;
+
+
+static gboolean  paint_press   (GtkWidget      *widget,
+                                       GdkEventButton *event)
+{
+  if (event->button == 1)
+    {
+
+      vector     = gegl_vector_new ();
+
+      over       = gegl_node_new_child (gegl, "operation", "over", NULL);
+      stroke     = gegl_node_new_child (gegl, "operation", "stroke",
+                                        "vector", vector,
+                                        "color", gegl_color_new ("rgba(1.0,0.5,0.5,0.4)"),
+                                        "linewidth", LINEWIDTH,
+                                        "hardness", HARDNESS,
+                                        NULL);
+      gegl_node_link_many (top, over, out, NULL);
+      gegl_node_connect_to (stroke, "output", over, "aux");
+
+      pen_down = TRUE;
+
+      return TRUE;
+    }
+  return FALSE;
+}
+
+
+static gboolean  paint_motion  (GtkWidget      *widget,
+                                       GdkEventMotion *event)
+{
+  if (event->state & GDK_BUTTON1_MASK)
+    {
+      if (!pen_down)
+        return TRUE;
+
+
+      gegl_vector_line_to (vector, event->x,
+                                   event->y);
+
+      return TRUE;
+    }
+  return FALSE;
+}
+
+
+static gboolean  paint_release   (GtkWidget      *widget,
+                                         GdkEventButton *event)
+{
+  if (event->button == 1)
+    {
+        gdouble x0,x1,y0,y1;
+
+        GeglProcessor *processor;
+        GeglNode *writebuf;
+        GeglRectangle roi;
+
+        gegl_vector_get_bounds (vector, &x0, &x1, &y0, &y1);
+
+        roi = (GeglRectangle){x0 - LINEWIDTH, y0 - LINEWIDTH,
+               x1-x0 + LINEWIDTH*2, y1-y0 + LINEWIDTH *2};
+
+        writebuf = gegl_node_new_child (gegl,
+                                        "operation", "write-buffer",
+                                        "buffer", buffer,
+                                        NULL);
+        gegl_node_link_many (over, writebuf, NULL);
+
+        processor = gegl_node_new_processor (writebuf, &roi);
+        while (gegl_processor_work (processor, NULL));
+        g_object_unref (processor);
+        g_object_unref (writebuf);
+
+        gegl_node_link_many (top, out, NULL);
+        g_object_unref (over);
+        g_object_unref (stroke);
+        over = NULL;
+        stroke = NULL;
+        pen_down = FALSE;
+
+      return TRUE;
+    }
+  return FALSE;
+}
+
+
+
+gint
+main (gint    argc,
+      gchar **argv)
+{
+
+  gtk_init (&argc, &argv);
+  gegl_init (&argc, &argv);
+
+  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  gtk_window_set_title (GTK_WINDOW (window), "GEGL painter");
+
+  /*gegl = gegl_node_new_from_xml ("<gegl><rectangle width='512' height='512' color='red'/></gegl>", NULL);*/
+
+  if (argv[1]==NULL)
+    {
+      gchar *buf = NULL;
+      buffer = gegl_buffer_new (&(GeglRectangle){0,0,512,512},
+                                babl_format("RGBA float"));
+      buf = g_malloc(512*512);
+      memset (buf, 255, 512*512);
+      gegl_buffer_set (buffer, NULL, babl_format ("Y' u8"), buf, 0);
+      g_free (buf);
+    }
+  else
+    buffer = gegl_buffer_open (argv[1]);
+
+
+  gegl = gegl_node_new ();
+
+{
+        GeglNode *loadbuf = gegl_node_new_child (gegl, "operation", "load-buffer", "buffer", buffer, NULL);
+   out = gegl_node_new_child (gegl, "operation", "nop", NULL);
+
+    gegl_node_link_many (loadbuf, out, NULL);
+
+  view = g_object_new (GEGL_TYPE_VIEW, "node", out, NULL);
+  top = loadbuf;
+}
+
+  gtk_signal_connect (GTK_OBJECT (view), "motion-notify-event",
+		      (GtkSignalFunc) paint_motion, NULL);
+  gtk_signal_connect (GTK_OBJECT (view), "button-press-event",
+		      (GtkSignalFunc) paint_press, NULL);
+  gtk_signal_connect (GTK_OBJECT (view), "button-release-event",
+		      (GtkSignalFunc) paint_release, NULL);
+
+  gtk_widget_add_events (view, GDK_BUTTON_RELEASE_MASK);
+
+
+  gtk_container_add (GTK_CONTAINER (window), view);
+  gtk_widget_set_size_request (view, 512, 512);
+
+  g_signal_connect (G_OBJECT (window), "delete-event",
+                    G_CALLBACK (gtk_main_quit), window);
+  gtk_widget_show_all (window);
+
+
+  gtk_main ();
+  g_object_unref (gegl);
+  gegl_buffer_destroy (buffer);
+
+
+  gegl_exit ();
+  return 0;
+}



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