gegl r2672 - in trunk: . operations/external operations/workshop



Author: ok
Date: Thu Oct 30 23:05:26 2008
New Revision: 2672
URL: http://svn.gnome.org/viewvc/gegl?rev=2672&view=rev

Log:
* operations/workshop/stroke.c: moded ..
* operations/external/stroke.c: .. here and added cairo based
hitdetection (for fixed/max linewidth).
* operations/external/Makefile.am: added new file.


Added:
   trunk/operations/external/stroke.c   (contents, props changed)
      - copied, changed from r2667, /trunk/operations/workshop/stroke.c
Removed:
   trunk/operations/workshop/stroke.c
Modified:
   trunk/ChangeLog
   trunk/operations/external/Makefile.am

Modified: trunk/operations/external/Makefile.am
==============================================================================
--- trunk/operations/external/Makefile.am	(original)
+++ trunk/operations/external/Makefile.am	Thu Oct 30 23:05:26 2008
@@ -15,7 +15,10 @@
 fill_la_SOURCES = fill.c
 fill_la_LIBADD = $(op_libs) $(CAIRO_LIBS)
 fill_la_CFLAGS = $(CAIRO_CFLAGS)
-ops += fill.la
+stroke_la_SOURCES = stroke.c
+stroke_la_LIBADD = $(op_libs) $(CAIRO_LIBS)
+stroke_la_CFLAGS = $(CAIRO_CFLAGS)
+ops += fill.la stroke.la
 endif
 
 if HAVE_PNG

Copied: trunk/operations/external/stroke.c (from r2667, /trunk/operations/workshop/stroke.c)
==============================================================================
--- /trunk/operations/workshop/stroke.c	(original)
+++ trunk/operations/external/stroke.c	Thu Oct 30 23:05:26 2008
@@ -46,6 +46,7 @@
                           gpointer userdata);
 
 #include "gegl-chant.h"
+#include <cairo/cairo.h>
 
 
 static void path_changed (GeglPath *path,
@@ -108,6 +109,61 @@
 }
 
 
+static void foreach_cairo (const GeglPathItem *knot,
+                           gpointer              cr)
+{
+  switch (knot->type)
+    {
+      case 'M':
+        cairo_move_to (cr, knot->point[0].x, knot->point[0].y);
+        break;
+      case 'L':
+        cairo_line_to (cr, knot->point[0].x, knot->point[0].y);
+        break;
+      case 'C':
+        cairo_curve_to (cr, knot->point[0].x, knot->point[0].y,
+                            knot->point[1].x, knot->point[1].y,
+                            knot->point[2].x, knot->point[2].y);
+        break;
+      case 'z':
+        cairo_close_path (cr);
+        break;
+      default:
+        g_print ("%s uh?:%c\n", G_STRLOC, knot->type);
+    }
+}
+
+static void gegl_path_cairo_play (GeglPath *path,
+                                    cairo_t *cr)
+{
+  gegl_path_foreach_flat (path, foreach_cairo, cr);
+}
+
+static GeglNode *detect (GeglOperation *operation,
+                         gint           x,
+                         gint           y)
+{
+  GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
+  cairo_t *cr;
+  cairo_surface_t *surface;
+  gchar *data = "     ";
+  gboolean result;
+
+  surface = cairo_image_surface_create_for_data ((guchar*)data,
+                                                 CAIRO_FORMAT_ARGB32,
+                                                 1,1,4);
+  cr = cairo_create (surface);
+  gegl_path_cairo_play (o->path, cr);
+  cairo_set_line_width (cr, o->linewidth);
+  result = cairo_in_stroke (cr, x, y);
+  cairo_destroy (cr);
+
+  if (result)
+    return operation->node;
+
+  return NULL;
+}
+
 static void
 gegl_chant_class_init (GeglChantClass *klass)
 {
@@ -120,6 +176,7 @@
   source_class->process = process;
   operation_class->get_bounding_box = get_bounding_box;
   operation_class->prepare = prepare;
+  operation_class->detect = detect;
 
   operation_class->name        = "gegl:stroke";
   operation_class->categories  = "render";



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