gegl r2440 - in trunk: . examples



Author: martinn
Date: Sat Jun 14 11:52:44 2008
New Revision: 2440
URL: http://svn.gnome.org/viewvc/gegl?rev=2440&view=rev

Log:
2008-06-14  Martin Nordholts  <martinn svn gnome org>

	* examples/gegl-paint.c: Some cleanup.


Modified:
   trunk/ChangeLog
   trunk/examples/gegl-paint.c

Modified: trunk/examples/gegl-paint.c
==============================================================================
--- trunk/examples/gegl-paint.c	(original)
+++ trunk/examples/gegl-paint.c	Sat Jun 14 11:52:44 2008
@@ -28,8 +28,8 @@
 #define LINEWIDTH   60.0
 #define COLOR       "rgba(0.0,0.0,0.0,0.4)"
 
-GtkWidget *window;
-GtkWidget *view;
+GtkWidget         *window;
+GtkWidget         *view;
 static GeglBuffer *buffer   = NULL;
 static GeglNode   *gegl     = NULL;
 static GeglNode   *out      = NULL;
@@ -41,12 +41,11 @@
 static GeglNode   *stroke   = NULL;
 
 
-static gboolean  paint_press   (GtkWidget      *widget,
-                                       GdkEventButton *event)
+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);
@@ -67,65 +66,65 @@
 }
 
 
-static gboolean  paint_motion  (GtkWidget      *widget,
-                                       GdkEventMotion *event)
+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;
+        }
+
+      gegl_vector_line_to (vector,
+                           event->x,
+                           event->y);
       return TRUE;
     }
   return FALSE;
 }
 
 
-static gboolean  paint_release   (GtkWidget      *widget,
-                                         GdkEventButton *event)
+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;
+      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)
@@ -139,37 +138,38 @@
 
   /*gegl = gegl_node_new_from_xml ("<gegl><rectangle width='512' height='512' color='red'/></gegl>", NULL);*/
 
-  if (argv[1]==NULL)
+  if (argv[1] == NULL)
     {
       gchar *buf = NULL;
-      buffer = gegl_buffer_new (&(GeglRectangle){0,0,512,512},
+      buffer = gegl_buffer_new (&(GeglRectangle){0, 0, 512, 512},
                                 babl_format("RGBA float"));
-      buf = g_malloc(512*512);
-      memset (buf, 255, 512*512); /* FIXME: we need a babl_buffer_paint () */
+      buf    = g_malloc(512 * 512);
+      memset (buf, 255, 512 * 512); /* FIXME: we need a babl_buffer_paint () */
       gegl_buffer_set (buffer, NULL, babl_format ("Y' u8"), buf, 0);
       g_free (buf);
     }
   else
-    buffer = gegl_buffer_open (argv[1]);
-
+    {
+      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);
+  {
+    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;
-}
+    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);
+                      (GtkSignalFunc) paint_motion, NULL);
   gtk_signal_connect (GTK_OBJECT (view), "button-press-event",
-		      (GtkSignalFunc) paint_press, NULL);
+                      (GtkSignalFunc) paint_press, NULL);
   gtk_signal_connect (GTK_OBJECT (view), "button-release-event",
-		      (GtkSignalFunc) paint_release, NULL);
+                      (GtkSignalFunc) paint_release, NULL);
 
   gtk_widget_add_events (view, GDK_BUTTON_RELEASE_MASK);
 



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