[gimp] app: add gimp_fill_options_set_by_fill_type()



commit 9fa832c5aaa82030e3f3472018b2e7b8c5f5dbce
Author: Michael Natterer <mitch gimp org>
Date:   Tue Mar 8 01:51:10 2016 +0100

    app: add gimp_fill_options_set_by_fill_type()
    
    which sets color, pattern and fill style on a GimpFillOptions, based
    on a context and a GimpFillType.

 app/core/gimpfilloptions.c |   67 ++++++++++++++++++++++++++++++++++++++++++++
 app/core/gimpfilloptions.h |   13 ++++++--
 2 files changed, 76 insertions(+), 4 deletions(-)
---
diff --git a/app/core/gimpfilloptions.c b/app/core/gimpfilloptions.c
index 7f30b0a..9fd0434 100644
--- a/app/core/gimpfilloptions.c
+++ b/app/core/gimpfilloptions.c
@@ -20,15 +20,18 @@
 
 #include "config.h"
 
+#include <cairo.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
+#include "libgimpcolor/gimpcolor.h"
 #include "libgimpconfig/gimpconfig.h"
 
 #include "core-types.h"
 
 #include "gimp.h"
+#include "gimperror.h"
 #include "gimpfilloptions.h"
 #include "gimpviewable.h"
 
@@ -212,3 +215,67 @@ gimp_fill_options_get_antialias (GimpFillOptions *options)
 
   return GET_PRIVATE (options)->antialias;
 }
+
+gboolean
+gimp_fill_options_set_by_fill_type (GimpFillOptions  *options,
+                                    GimpContext      *context,
+                                    GimpFillType      fill_type,
+                                    GError          **error)
+{
+  GimpRGB color;
+
+  g_return_val_if_fail (GIMP_IS_FILL_OPTIONS (options), FALSE);
+  g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  switch (fill_type)
+    {
+    case GIMP_FILL_FOREGROUND:
+      gimp_context_get_foreground (context, &color);
+      break;
+
+    case GIMP_FILL_BACKGROUND:
+      gimp_context_get_background (context, &color);
+      break;
+
+    case GIMP_FILL_WHITE:
+      gimp_rgba_set (&color, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE);
+      break;
+
+    case GIMP_FILL_TRANSPARENT:
+      gimp_context_get_background (context, &color);
+      gimp_context_set_paint_mode (GIMP_CONTEXT (options), GIMP_ERASE_MODE);
+      break;
+
+    case GIMP_FILL_PATTERN:
+      {
+        GimpPattern *pattern = gimp_context_get_pattern (context);
+
+        if (! pattern)
+          {
+            g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
+                                 _("No patterns available for this operation."));
+            return FALSE;
+          }
+
+        g_object_set (options,
+                      "style", GIMP_FILL_STYLE_PATTERN,
+                      NULL);
+        gimp_context_set_pattern (GIMP_CONTEXT (options), pattern);
+
+        return TRUE;
+      }
+      break;
+
+    default:
+      g_warning ("%s: invalid fill_type %d", G_STRFUNC, fill_type);
+      return FALSE;
+    }
+
+  g_object_set (options,
+                "style", GIMP_FILL_STYLE_SOLID,
+                NULL);
+  gimp_context_set_foreground (GIMP_CONTEXT (options), &color);
+
+  return TRUE;
+}
diff --git a/app/core/gimpfilloptions.h b/app/core/gimpfilloptions.h
index 31e72c2..729bc6b 100644
--- a/app/core/gimpfilloptions.h
+++ b/app/core/gimpfilloptions.h
@@ -46,12 +46,17 @@ struct _GimpFillOptionsClass
 };
 
 
-GType             gimp_fill_options_get_type      (void) G_GNUC_CONST;
+GType             gimp_fill_options_get_type         (void) G_GNUC_CONST;
 
-GimpFillOptions * gimp_fill_options_new           (Gimp *gimp);
+GimpFillOptions * gimp_fill_options_new              (Gimp             *gimp);
 
-GimpFillStyle     gimp_fill_options_get_style     (GimpFillOptions *options);
-gboolean          gimp_fill_options_get_antialias (GimpFillOptions *options);
+GimpFillStyle     gimp_fill_options_get_style        (GimpFillOptions  *options);
+gboolean          gimp_fill_options_get_antialias    (GimpFillOptions  *options);
+
+gboolean          gimp_fill_options_set_by_fill_type (GimpFillOptions  *options,
+                                                      GimpContext      *context,
+                                                      GimpFillType      fill_type,
+                                                      GError          **error);
 
 
 #endif /* __GIMP_FILL_OPTIONS_H__ */


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