[gimp/goat-invasion] app: move the GTK-free cairo utility functions to core/gimp-cairo.[ch]



commit dd9441bf495af391bce79d99a949434fce181cb6
Author: Michael Natterer <mitch gimp org>
Date:   Tue Apr 10 12:09:37 2012 +0200

    app: move the GTK-free cairo utility functions to core/gimp-cairo.[ch]

 app/core/Makefile.am                           |    2 +
 app/core/core-types.h                          |   12 ++
 app/core/gimp-cairo.c                          |  136 ++++++++++++++
 app/{widgets/gimpcairo.h => core/gimp-cairo.h} |    9 +-
 app/display/gimpcanvasarc.c                    |    2 +-
 app/display/gimpcanvasboundary.c               |    3 +-
 app/display/gimpcanvascursor.c                 |    2 +-
 app/display/gimpcanvashandle.c                 |    2 +-
 app/display/gimpdisplayshell-callbacks.c       |    2 +-
 app/display/gimpdisplayshell-draw.c            |    3 +-
 app/display/gimpdisplayshell-selection.c       |    3 +-
 app/display/gimpdisplayshell-style.c           |    3 +-
 app/widgets/Makefile.am                        |    2 -
 app/widgets/gimpcairo-wilber.c                 |   99 ++++++++++-
 app/widgets/gimpcairo-wilber.h                 |   17 +-
 app/widgets/gimpcairo.c                        |  232 ------------------------
 app/widgets/gimptoolbox.c                      |    2 +-
 app/widgets/widgets-types.h                    |   13 --
 18 files changed, 270 insertions(+), 274 deletions(-)
---
diff --git a/app/core/Makefile.am b/app/core/Makefile.am
index d137309..d769be5 100644
--- a/app/core/Makefile.am
+++ b/app/core/Makefile.am
@@ -23,6 +23,8 @@ libappcore_a_sources = \
 	gimp.h					\
 	gimp-apply-operation.c			\
 	gimp-apply-operation.h			\
+	gimp-cairo.c				\
+	gimp-cairo.h				\
 	gimp-contexts.c				\
 	gimp-contexts.h				\
 	gimp-edit.c				\
diff --git a/app/core/core-types.h b/app/core/core-types.h
index 6deace2..b2945b9 100644
--- a/app/core/core-types.h
+++ b/app/core/core-types.h
@@ -233,6 +233,18 @@ struct _GimpCoords
   gdouble direction;
 };
 
+/*  temp hack as replacement for GdkSegment  */
+
+typedef struct _GimpSegment GimpSegment;
+
+struct _GimpSegment
+{
+  gint x1;
+  gint y1;
+  gint x2;
+  gint y2;
+};
+
 
 #include "gegl/gimp-gegl-types.h"
 #include "paint/paint-types.h"
diff --git a/app/core/gimp-cairo.c b/app/core/gimp-cairo.c
new file mode 100644
index 0000000..3bcdd93
--- /dev/null
+++ b/app/core/gimp-cairo.c
@@ -0,0 +1,136 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimp-cairo.c
+ * Copyright (C) 2010-2012  Michael Natterer <mitch gimp org>
+ *
+ * Some code here is based on code from librsvg that was originally
+ * written by Raph Levien <raph artofcode com> for Gill.
+ *
+ * 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/>.
+ */
+
+#include "config.h"
+
+#include <cairo.h>
+#include <gegl.h>
+
+#include "libgimpcolor/gimpcolor.h"
+
+#include "core-types.h"
+
+#include "gimp-cairo.h"
+
+
+static cairo_user_data_key_t surface_data_key = { 0, };
+
+
+cairo_pattern_t *
+gimp_cairo_stipple_pattern_create (const GimpRGB *fg,
+                                   const GimpRGB *bg,
+                                   gint           index)
+{
+  cairo_surface_t *surface;
+  cairo_pattern_t *pattern;
+  guchar          *data;
+  guchar          *d;
+  guchar           fg_r, fg_g, fg_b, fg_a;
+  guchar           bg_r, bg_g, bg_b, bg_a;
+  gint             x, y;
+
+  g_return_val_if_fail (fg != NULL, NULL);
+  g_return_val_if_fail (bg != NULL, NULL);
+
+  data = g_malloc (8 * 8 * 4);
+
+  gimp_rgba_get_uchar (fg, &fg_r, &fg_g, &fg_b, &fg_a);
+  gimp_rgba_get_uchar (bg, &bg_r, &bg_g, &bg_b, &bg_a);
+
+  d = data;
+
+  for (y = 0; y < 8; y++)
+    {
+      for (x = 0; x < 8; x++)
+        {
+          if ((x + y + index) % 8 >= 4)
+            GIMP_CAIRO_ARGB32_SET_PIXEL (d, fg_r, fg_g, fg_b, fg_a);
+          else
+            GIMP_CAIRO_ARGB32_SET_PIXEL (d, bg_r, bg_g, bg_b, bg_a);
+
+          d += 4;
+        }
+    }
+
+  surface = cairo_image_surface_create_for_data (data,
+                                                 CAIRO_FORMAT_ARGB32,
+                                                 8, 8, 8 * 4);
+  cairo_surface_set_user_data (surface, &surface_data_key,
+                               data, (cairo_destroy_func_t) g_free);
+
+  pattern = cairo_pattern_create_for_surface (surface);
+  cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
+
+  cairo_surface_destroy (surface);
+
+  return pattern;
+}
+
+void
+gimp_cairo_add_arc (cairo_t *cr,
+                    gdouble  center_x,
+                    gdouble  center_y,
+                    gdouble  radius,
+                    gdouble  start_angle,
+                    gdouble  slice_angle)
+{
+  g_return_if_fail (cr != NULL);
+
+  if (slice_angle >= 0)
+    {
+      cairo_arc_negative (cr, center_x, center_y, radius,
+                          - start_angle,
+                          - start_angle - slice_angle);
+    }
+  else
+    {
+      cairo_arc (cr, center_x, center_y, radius,
+                 - start_angle,
+                 - start_angle - slice_angle);
+    }
+}
+
+void
+gimp_cairo_add_segments (cairo_t     *cr,
+                         GimpSegment *segs,
+                         gint         n_segs)
+{
+  gint i;
+
+  g_return_if_fail (cr != NULL);
+  g_return_if_fail (segs != NULL && n_segs > 0);
+
+  for (i = 0; i < n_segs; i++)
+    {
+      if (segs[i].x1 == segs[i].x2)
+        {
+          cairo_move_to (cr, segs[i].x1 + 0.5, segs[i].y1 + 0.5);
+          cairo_line_to (cr, segs[i].x2 + 0.5, segs[i].y2 - 0.5);
+        }
+      else
+        {
+          cairo_move_to (cr, segs[i].x1 + 0.5, segs[i].y1 + 0.5);
+          cairo_line_to (cr, segs[i].x2 - 0.5, segs[i].y2 + 0.5);
+        }
+    }
+}
diff --git a/app/widgets/gimpcairo.h b/app/core/gimp-cairo.h
similarity index 83%
rename from app/widgets/gimpcairo.h
rename to app/core/gimp-cairo.h
index f7080a2..140369d 100644
--- a/app/widgets/gimpcairo.h
+++ b/app/core/gimp-cairo.h
@@ -1,8 +1,8 @@
 /* GIMP - The GNU Image Manipulation Program
  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  *
- * gimpcairo.h
- * Copyright (C) 2010  Michael Natterer <mitch gimp org>
+ * gimp-cairo.h
+ * Copyright (C) 2010-2012  Michael Natterer <mitch gimp org>
  *
  * Some code here is based on code from librsvg that was originally
  * written by Raph Levien <raph artofcode com> for Gill.
@@ -39,10 +39,5 @@ void              gimp_cairo_add_segments           (cairo_t       *cr,
                                                      GimpSegment   *segs,
                                                      gint           n_segs);
 
-void              gimp_cairo_draw_toolbox_wilber    (GtkWidget     *widget,
-                                                     cairo_t       *cr);
-void              gimp_cairo_draw_drop_wilber       (GtkWidget     *widget,
-                                                     cairo_t       *cr);
-
 
 #endif /* __GIMP_CAIRO_H__ */
diff --git a/app/display/gimpcanvasarc.c b/app/display/gimpcanvasarc.c
index bdf4d80..5d76bc0 100644
--- a/app/display/gimpcanvasarc.c
+++ b/app/display/gimpcanvasarc.c
@@ -28,7 +28,7 @@
 
 #include "display-types.h"
 
-#include "widgets/gimpcairo.h"
+#include "core/gimp-cairo.h"
 
 #include "gimpcanvasarc.h"
 #include "gimpdisplayshell.h"
diff --git a/app/display/gimpcanvasboundary.c b/app/display/gimpcanvasboundary.c
index e3aa9e9..3075003 100644
--- a/app/display/gimpcanvasboundary.c
+++ b/app/display/gimpcanvasboundary.c
@@ -28,11 +28,10 @@
 
 #include "display-types.h"
 
+#include "core/gimp-cairo.h"
 #include "core/gimpboundary.h"
 #include "core/gimpparamspecs.h"
 
-#include "widgets/gimpcairo.h"
-
 #include "gimpcanvasboundary.h"
 #include "gimpdisplayshell.h"
 #include "gimpdisplayshell-transform.h"
diff --git a/app/display/gimpcanvascursor.c b/app/display/gimpcanvascursor.c
index 577f5c2..5e2c3e1 100644
--- a/app/display/gimpcanvascursor.c
+++ b/app/display/gimpcanvascursor.c
@@ -28,7 +28,7 @@
 
 #include "display-types.h"
 
-#include "widgets/gimpcairo.h"
+#include "core/gimp-cairo.h"
 
 #include "gimpcanvascursor.h"
 #include "gimpdisplayshell.h"
diff --git a/app/display/gimpcanvashandle.c b/app/display/gimpcanvashandle.c
index 45ad673..2aca51b 100644
--- a/app/display/gimpcanvashandle.c
+++ b/app/display/gimpcanvashandle.c
@@ -28,7 +28,7 @@
 
 #include "display-types.h"
 
-#include "widgets/gimpcairo.h"
+#include "core/gimp-cairo.h"
 
 #include "gimpcanvashandle.h"
 #include "gimpcanvasitem-utils.h"
diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c
index 1a2ea7e..e8cf44d 100644
--- a/app/display/gimpdisplayshell-callbacks.c
+++ b/app/display/gimpdisplayshell-callbacks.c
@@ -29,7 +29,7 @@
 #include "core/gimpimage.h"
 #include "core/gimpimage-quick-mask.h"
 
-#include "widgets/gimpcairo.h"
+#include "widgets/gimpcairo-wilber.h"
 #include "widgets/gimpuimanager.h"
 
 #include "gimpcanvasitem.h"
diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c
index 6e0e971..5466631 100644
--- a/app/display/gimpdisplayshell-draw.c
+++ b/app/display/gimpdisplayshell-draw.c
@@ -27,13 +27,12 @@
 
 #include "display-types.h"
 
+#include "core/gimp-cairo.h"
 #include "core/gimpdrawable.h"
 #include "core/gimpimage.h"
 #include "core/gimppickable.h"
 #include "core/gimpprojection.h"
 
-#include "widgets/gimpcairo.h"
-
 #include "gimpcanvas.h"
 #include "gimpcanvaspath.h"
 #include "gimpdisplay.h"
diff --git a/app/display/gimpdisplayshell-selection.c b/app/display/gimpdisplayshell-selection.c
index d66211d..b6e1885 100644
--- a/app/display/gimpdisplayshell-selection.c
+++ b/app/display/gimpdisplayshell-selection.c
@@ -25,12 +25,11 @@
 #include "config/gimpdisplayconfig.h"
 
 #include "core/gimp.h"
+#include "core/gimp-cairo.h"
 #include "core/gimpboundary.h"
 #include "core/gimpchannel.h"
 #include "core/gimpimage.h"
 
-#include "widgets/gimpcairo.h"
-
 #include "gimpdisplay.h"
 #include "gimpdisplayshell.h"
 #include "gimpdisplayshell-appearance.h"
diff --git a/app/display/gimpdisplayshell-style.c b/app/display/gimpdisplayshell-style.c
index c17004c..91b87ce 100644
--- a/app/display/gimpdisplayshell-style.c
+++ b/app/display/gimpdisplayshell-style.c
@@ -28,11 +28,10 @@
 
 #include "display-types.h"
 
+#include "core/gimp-cairo.h"
 #include "core/gimpgrid.h"
 #include "core/gimplayer.h"
 
-#include "widgets/gimpcairo.h"
-
 #include "gimpdisplayshell.h"
 #include "gimpdisplayshell-style.h"
 
diff --git a/app/widgets/Makefile.am b/app/widgets/Makefile.am
index 55dacc5..ee09090 100644
--- a/app/widgets/Makefile.am
+++ b/app/widgets/Makefile.am
@@ -39,8 +39,6 @@ libappwidgets_a_sources = \
 	gimpbrushselect.h		\
 	gimpbufferview.c		\
 	gimpbufferview.h		\
-	gimpcairo.c			\
-	gimpcairo.h			\
 	gimpcairo-wilber.c		\
 	gimpcairo-wilber.h		\
 	gimpcellrendererdashes.c	\
diff --git a/app/widgets/gimpcairo-wilber.c b/app/widgets/gimpcairo-wilber.c
index 62fe06f..883ccc6 100644
--- a/app/widgets/gimpcairo-wilber.c
+++ b/app/widgets/gimpcairo-wilber.c
@@ -29,7 +29,104 @@
 
 #include "libgimpmath/gimpmath.h"
 
-#include <gimpcairo-wilber.h>
+#include "widgets-types.h"
+
+#include "gimpcairo-wilber.h"
+
+
+void
+gimp_cairo_draw_toolbox_wilber (GtkWidget *widget,
+                                cairo_t   *cr)
+{
+  GtkStyle     *style;
+  GtkStateType  state;
+  GtkAllocation allocation;
+  gdouble       wilber_width;
+  gdouble       wilber_height;
+  gdouble       factor;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (cr != NULL);
+
+  style = gtk_widget_get_style (widget);
+  state = gtk_widget_get_state (widget);
+
+  gtk_widget_get_allocation (widget, &allocation);
+
+  gimp_cairo_wilber_get_size (cr, &wilber_width, &wilber_height);
+
+  factor = allocation.width / wilber_width * 0.9;
+
+  if (! gtk_widget_get_has_window (widget))
+    cairo_translate (cr, allocation.x, allocation.y);
+
+  cairo_scale (cr, factor, factor);
+
+  gimp_cairo_wilber (cr,
+                     (allocation.width  / factor - wilber_width)  / 2.0,
+                     (allocation.height / factor - wilber_height) / 2.0);
+
+  cairo_set_source_rgba (cr,
+                         style->fg[state].red   / 65535.0,
+                         style->fg[state].green / 65535.0,
+                         style->fg[state].blue  / 65535.0,
+                         0.10);
+  cairo_fill (cr);
+}
+
+void
+gimp_cairo_draw_drop_wilber (GtkWidget *widget,
+                             cairo_t   *cr)
+{
+  GtkStyle     *style;
+  GtkStateType  state;
+  GtkAllocation allocation;
+  gdouble       wilber_width;
+  gdouble       wilber_height;
+  gdouble       width;
+  gdouble       height;
+  gdouble       side;
+  gdouble       factor;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (cr != NULL);
+
+  style  = gtk_widget_get_style (widget);
+  state  = gtk_widget_get_state (widget);
+
+  gtk_widget_get_allocation (widget, &allocation);
+
+  gimp_cairo_wilber_get_size (cr, &wilber_width, &wilber_height);
+
+  wilber_width  /= 2;
+  wilber_height /= 2;
+
+  side = MIN (MIN (allocation.width, allocation.height),
+              MAX (allocation.width, allocation.height) / 2);
+
+  width  = MAX (wilber_width,  side);
+  height = MAX (wilber_height, side);
+
+  factor = MIN (width / wilber_width, height / wilber_height);
+
+  if (! gtk_widget_get_has_window (widget))
+    cairo_translate (cr, allocation.x, allocation.y);
+
+  cairo_scale (cr, factor, factor);
+
+  /*  magic factors depend on the image used, everything else is generic
+   */
+  gimp_cairo_wilber (cr,
+                     - wilber_width * 0.6,
+                     allocation.height / factor - wilber_height * 1.1);
+
+  cairo_set_source_rgba (cr,
+                         style->fg[state].red   / 65535.0,
+                         style->fg[state].green / 65535.0,
+                         style->fg[state].blue  / 65535.0,
+                         0.15);
+  cairo_fill (cr);
+}
 
 
 /* This string is a path description as found in SVG files.  You can
diff --git a/app/widgets/gimpcairo-wilber.h b/app/widgets/gimpcairo-wilber.h
index bc31992..44d3d24 100644
--- a/app/widgets/gimpcairo-wilber.h
+++ b/app/widgets/gimpcairo-wilber.h
@@ -25,12 +25,17 @@
 #define __GIMP_CAIRO_WILBER_H__
 
 
-void  gimp_cairo_wilber          (cairo_t *cr,
-                                  gdouble  x,
-                                  gdouble  y);
-void  gimp_cairo_wilber_get_size (cairo_t *cr,
-                                  gdouble *width,
-                                  gdouble *height);
+void  gimp_cairo_draw_toolbox_wilber    (GtkWidget *widget,
+                                         cairo_t   *cr);
+void  gimp_cairo_draw_drop_wilber       (GtkWidget *widget,
+                                         cairo_t   *cr);
+
+void  gimp_cairo_wilber                 (cairo_t   *cr,
+                                         gdouble    x,
+                                         gdouble    y);
+void  gimp_cairo_wilber_get_size        (cairo_t   *cr,
+                                         gdouble   *width,
+                                         gdouble   *height);
 
 
 #endif /* __GIMP_CAIRO_WILBER_H__ */
diff --git a/app/widgets/gimptoolbox.c b/app/widgets/gimptoolbox.c
index 00f4057..772ca3f 100644
--- a/app/widgets/gimptoolbox.c
+++ b/app/widgets/gimptoolbox.c
@@ -37,7 +37,7 @@
 #include "file/file-open.h"
 #include "file/file-utils.h"
 
-#include "gimpcairo.h"
+#include "gimpcairo-wilber.h"
 #include "gimpdevices.h"
 #include "gimpdialogfactory.h"
 #include "gimpdockwindow.h"
diff --git a/app/widgets/widgets-types.h b/app/widgets/widgets-types.h
index 0df8469..76719c4 100644
--- a/app/widgets/widgets-types.h
+++ b/app/widgets/widgets-types.h
@@ -281,17 +281,4 @@ typedef gboolean    (* GimpPanedBoxDroppedFunc)      (GtkWidget         *source,
                                                       gpointer           data);
 
 
-/*  temp hack as replacement for GdkSegment  */
-
-typedef struct _GimpSegment GimpSegment;
-
-struct _GimpSegment
-{
-  gint x1;
-  gint y1;
-  gint x2;
-  gint y2;
-};
-
-
 #endif /* __WIDGETS_TYPES_H__ */



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