[gimp] app: add new files gimpdisplayshell-style.[ch]



commit 002003a2ea6c96ab9547a8418bd067698ecc3655
Author: Michael Natterer <mitch gimp org>
Date:   Wed Aug 11 23:47:46 2010 +0200

    app: add new files gimpdisplayshell-style.[ch]
    
    which contains functions to set styles on a cairo_t.

 app/display/Makefile.am              |    2 +
 app/display/gimpdisplayshell-draw.c  |   78 +-----------------------
 app/display/gimpdisplayshell-style.c |  106 ++++++++++++++++++++++++++++++++++
 app/display/gimpdisplayshell-style.h |   30 ++++++++++
 4 files changed, 142 insertions(+), 74 deletions(-)
---
diff --git a/app/display/Makefile.am b/app/display/Makefile.am
index 987c995..2cf3aac 100644
--- a/app/display/Makefile.am
+++ b/app/display/Makefile.am
@@ -71,6 +71,8 @@ libappdisplay_a_sources = \
 	gimpdisplayshell-scroll.h		\
 	gimpdisplayshell-selection.c		\
 	gimpdisplayshell-selection.h		\
+	gimpdisplayshell-style.c		\
+	gimpdisplayshell-style.h		\
 	gimpdisplayshell-title.c		\
 	gimpdisplayshell-title.h		\
 	gimpdisplayshell-transform.c		\
diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c
index 2f9b50f..e6f4b19 100644
--- a/app/display/gimpdisplayshell-draw.c
+++ b/app/display/gimpdisplayshell-draw.c
@@ -21,7 +21,6 @@
 #include <gtk/gtk.h>
 
 #include "libgimpbase/gimpbase.h"
-#include "libgimpcolor/gimpcolor.h"
 #include "libgimpmath/gimpmath.h"
 #include "libgimpwidgets/gimpwidgets.h"
 
@@ -52,17 +51,15 @@
 #include "gimpdisplayshell-render.h"
 #include "gimpdisplayshell-scale.h"
 #include "gimpdisplayshell-scroll.h"
+#include "gimpdisplayshell-style.h"
 #include "gimpdisplayshell-transform.h"
 
 
 /*  local function prototypes  */
 
-static void    gimp_display_shell_set_grid_style (GimpDisplayShell *shell,
-                                                  GimpGrid         *grid,
-                                                  cairo_t          *cr);
-static GdkGC * gimp_display_shell_get_pen_gc     (GimpDisplayShell *shell,
-                                                  GimpContext      *context,
-                                                  GimpActiveColor   active);
+static GdkGC * gimp_display_shell_get_pen_gc (GimpDisplayShell *shell,
+                                              GimpContext      *context,
+                                              GimpActiveColor   active);
 
 
 /*  public functions  */
@@ -690,73 +687,6 @@ gimp_display_shell_draw_area (GimpDisplayShell *shell,
 
 /*  private functions  */
 
-static void
-gimp_display_shell_set_grid_style (GimpDisplayShell *shell,
-                                   GimpGrid         *grid,
-                                   cairo_t          *cr)
-{
-  cairo_set_line_width (cr, 1.0);
-
-  switch (grid->style)
-    {
-    case GIMP_GRID_ON_OFF_DASH:
-    case GIMP_GRID_DOUBLE_DASH:
-      {
-        guchar *data = g_malloc0 (8 * 8 * 4);
-        guchar  fg_r, fg_g, fg_b, fg_a;
-        guchar  bg_r, bg_g, bg_b, bg_a;
-        gint    x, y;
-        guchar *d;
-        cairo_surface_t *surface;
-        static cairo_user_data_key_t data_key;
-
-        gimp_rgba_get_uchar (&grid->fgcolor, &fg_r, &fg_g, &fg_b, &fg_a);
-
-        if (grid->style == GIMP_GRID_DOUBLE_DASH)
-          gimp_rgba_get_uchar (&grid->bgcolor, &bg_r, &bg_g, &bg_b, &bg_a);
-        else
-          bg_r = bg_g = bg_b = bg_a = 0;
-
-        d = data;
-
-        for (y = 0; y < 8; y++)
-          {
-            for (x = 0; x < 8; x++)
-              {
-                if ((y < 4 && x < 4) || (y >= 4 && x >= 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, &data_key,
-                                     data, (cairo_destroy_func_t) g_free);
-
-        cairo_set_source_surface (cr, surface, 0, 0);
-        cairo_surface_destroy (surface);
-
-        cairo_pattern_set_extend (cairo_get_source (cr),
-                                  CAIRO_EXTEND_REPEAT);
-      }
-      break;
-
-    case GIMP_GRID_DOTS:
-    case GIMP_GRID_INTERSECTIONS:
-    case GIMP_GRID_SOLID:
-      cairo_set_source_rgb (cr,
-                            grid->fgcolor.r,
-                            grid->fgcolor.g,
-                            grid->fgcolor.b);
-      break;
-    }
-}
-
 static GdkGC *
 gimp_display_shell_get_pen_gc (GimpDisplayShell *shell,
                                GimpContext      *context,
diff --git a/app/display/gimpdisplayshell-style.c b/app/display/gimpdisplayshell-style.c
new file mode 100644
index 0000000..094d1dc
--- /dev/null
+++ b/app/display/gimpdisplayshell-style.c
@@ -0,0 +1,106 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpdisplayshell-style.c
+ * Copyright (C) 2010  Michael Natterer <mitch gimp org>
+ *
+ * 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 <gegl.h>
+#include <gtk/gtk.h>
+
+#include "libgimpcolor/gimpcolor.h"
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "display-types.h"
+
+#include "core/gimpgrid.h"
+
+#include "gimpdisplayshell.h"
+#include "gimpdisplayshell-style.h"
+
+
+void
+gimp_display_shell_set_grid_style (GimpDisplayShell *shell,
+                                   GimpGrid         *grid,
+                                   cairo_t          *cr)
+{
+  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
+  g_return_if_fail (GIMP_IS_GRID (grid));
+  g_return_if_fail (cr != NULL);
+
+  cairo_set_line_width (cr, 1.0);
+
+  switch (grid->style)
+    {
+    case GIMP_GRID_ON_OFF_DASH:
+    case GIMP_GRID_DOUBLE_DASH:
+      {
+        guchar *data = g_malloc0 (8 * 8 * 4);
+        guchar  fg_r, fg_g, fg_b, fg_a;
+        guchar  bg_r, bg_g, bg_b, bg_a;
+        gint    x, y;
+        guchar *d;
+        cairo_surface_t *surface;
+        static cairo_user_data_key_t data_key;
+
+        gimp_rgba_get_uchar (&grid->fgcolor, &fg_r, &fg_g, &fg_b, &fg_a);
+
+        if (grid->style == GIMP_GRID_DOUBLE_DASH)
+          gimp_rgba_get_uchar (&grid->bgcolor, &bg_r, &bg_g, &bg_b, &bg_a);
+        else
+          bg_r = bg_g = bg_b = bg_a = 0;
+
+        d = data;
+
+        for (y = 0; y < 8; y++)
+          {
+            for (x = 0; x < 8; x++)
+              {
+                if ((y < 4 && x < 4) || (y >= 4 && x >= 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, &data_key,
+                                     data, (cairo_destroy_func_t) g_free);
+
+        cairo_set_source_surface (cr, surface, 0, 0);
+        cairo_surface_destroy (surface);
+
+        cairo_pattern_set_extend (cairo_get_source (cr),
+                                  CAIRO_EXTEND_REPEAT);
+      }
+      break;
+
+    case GIMP_GRID_DOTS:
+    case GIMP_GRID_INTERSECTIONS:
+    case GIMP_GRID_SOLID:
+      cairo_set_source_rgb (cr,
+                            grid->fgcolor.r,
+                            grid->fgcolor.g,
+                            grid->fgcolor.b);
+      break;
+    }
+}
diff --git a/app/display/gimpdisplayshell-style.h b/app/display/gimpdisplayshell-style.h
new file mode 100644
index 0000000..02de456
--- /dev/null
+++ b/app/display/gimpdisplayshell-style.h
@@ -0,0 +1,30 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpdisplayshell-style.h
+ * Copyright (C) 2010  Michael Natterer <mitch gimp org>
+ *
+ * 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/>.
+ */
+
+#ifndef __GIMP_DISPLAY_SHELL_STYLE_H__
+#define __GIMP_DISPLAY_SHELL_STYLE_H__
+
+
+void   gimp_display_shell_set_grid_style (GimpDisplayShell *shell,
+                                          GimpGrid         *grid,
+                                          cairo_t          *cr);
+
+
+#endif /* __GIMP_DISPLAY_SHELL_STYLE_H__ */



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