[gimp] app: Add "No erasing effect" parameter to MyPaint brush



commit 32280a170b2a109c0d60de14fa96561d094dd7b0
Author: shark0r <b91502038 ntu edu tw>
Date:   Wed Jan 3 02:18:02 2018 +0100

    app: Add "No erasing effect" parameter to MyPaint brush
    
    Last and unrelated patch of bug #785001.

 app/paint/gimpmybrushcore.c        |    3 ++-
 app/paint/gimpmybrushoptions.c     |   16 +++++++++++++++-
 app/paint/gimpmybrushoptions.h     |    1 +
 app/paint/gimpmybrushsurface.c     |   17 ++++++++++++-----
 app/paint/gimpmybrushsurface.h     |   11 ++++++-----
 app/tools/gimpmybrushoptions-gui.c |    5 +++++
 6 files changed, 41 insertions(+), 12 deletions(-)
---
diff --git a/app/paint/gimpmybrushcore.c b/app/paint/gimpmybrushcore.c
index d0931a5..eb65057 100644
--- a/app/paint/gimpmybrushcore.c
+++ b/app/paint/gimpmybrushcore.c
@@ -218,7 +218,8 @@ gimp_mybrush_core_paint (GimpPaintCore    *paint_core,
                                   gimp_drawable_get_active_mask (drawable),
                                   paint_core->mask_buffer,
                                   paint_core->mask_x_offset,
-                                  paint_core->mask_y_offset);
+                                  paint_core->mask_y_offset,
+                                  GIMP_MYBRUSH_OPTIONS (paint_options));
 
       gimp_mybrush_core_create_brushes (mybrush, drawable, paint_options, sym);
 
diff --git a/app/paint/gimpmybrushoptions.c b/app/paint/gimpmybrushoptions.c
index fbbd191..d6955b0 100644
--- a/app/paint/gimpmybrushoptions.c
+++ b/app/paint/gimpmybrushoptions.c
@@ -40,7 +40,8 @@ enum
   PROP_RADIUS,
   PROP_OPAQUE,
   PROP_HARDNESS,
-  PROP_ERASER
+  PROP_ERASER,
+  PROP_NO_ERASING
 };
 
 
@@ -107,6 +108,13 @@ gimp_mybrush_options_class_init (GimpMybrushOptionsClass *klass)
                             NULL,
                             FALSE,
                             GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_NO_ERASING,
+                            "no-erasing",
+                            _("No erasing effect"),
+                            _("Never decrease alpha of existing pixels"),
+                            FALSE,
+                            GIMP_PARAM_STATIC_STRINGS);
 }
 
 static void
@@ -144,6 +152,9 @@ gimp_mybrush_options_set_property (GObject      *object,
     case PROP_ERASER:
       options->eraser = g_value_get_boolean (value);
       break;
+    case PROP_NO_ERASING:
+      options->no_erasing = g_value_get_boolean (value);
+      break;
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -173,6 +184,9 @@ gimp_mybrush_options_get_property (GObject    *object,
     case PROP_ERASER:
       g_value_set_boolean (value, options->eraser);
       break;
+    case PROP_NO_ERASING:
+      g_value_set_boolean (value, options->no_erasing);
+      break;
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
diff --git a/app/paint/gimpmybrushoptions.h b/app/paint/gimpmybrushoptions.h
index fcf9931..c4a8aa3 100644
--- a/app/paint/gimpmybrushoptions.h
+++ b/app/paint/gimpmybrushoptions.h
@@ -40,6 +40,7 @@ struct _GimpMybrushOptions
   gdouble           opaque;
   gdouble           hardness;
   gboolean          eraser;
+  gboolean          no_erasing;
 };
 
 struct _GimpMybrushOptionsClass
diff --git a/app/paint/gimpmybrushsurface.c b/app/paint/gimpmybrushsurface.c
index 63c0441..add4277 100644
--- a/app/paint/gimpmybrushsurface.c
+++ b/app/paint/gimpmybrushsurface.c
@@ -29,6 +29,7 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include "libgimpcolor/gimpcolor.h"
 
+#include "gimpmybrushoptions.h"
 #include "gimpmybrushsurface.h"
 
 
@@ -41,6 +42,7 @@ struct _GimpMybrushSurface
   gint        paint_mask_y;
   GeglRectangle dirty;
   GimpComponentMask component_mask;
+  GimpMybrushOptions *options;
 };
 
 /* --- Taken from mypaint-tiled-surface.c --- */
@@ -468,6 +470,9 @@ gimp_mypaint_surface_draw_dab (MyPaintSurface *base_surface,
                     }
                 }
 
+              if (surface->options->no_erasing)
+                a = MAX (a, pixel[ALPHA]);
+
               if (component_mask != GIMP_COMPONENT_MASK_ALL)
                 {
                   if (component_mask & GIMP_COMPONENT_MASK_RED)
@@ -526,11 +531,12 @@ gimp_mypaint_surface_destroy (MyPaintSurface *base_surface)
 }
 
 GimpMybrushSurface *
-gimp_mypaint_surface_new (GeglBuffer        *buffer,
-                          GimpComponentMask  component_mask,
-                          GeglBuffer        *paint_mask,
-                          gint               paint_mask_x,
-                          gint               paint_mask_y)
+gimp_mypaint_surface_new (GeglBuffer         *buffer,
+                          GimpComponentMask   component_mask,
+                          GeglBuffer         *paint_mask,
+                          gint                paint_mask_x,
+                          gint                paint_mask_y,
+                          GimpMybrushOptions *options)
 {
   GimpMybrushSurface *surface = g_malloc0 (sizeof (GimpMybrushSurface));
 
@@ -542,6 +548,7 @@ gimp_mypaint_surface_new (GeglBuffer        *buffer,
   surface->surface.end_atomic   = gimp_mypaint_surface_end_atomic;
   surface->surface.destroy      = gimp_mypaint_surface_destroy;
   surface->component_mask       = component_mask;
+  surface->options              = options;
   surface->buffer               = g_object_ref (buffer);
   if (paint_mask)
     surface->paint_mask         = g_object_ref (paint_mask);
diff --git a/app/paint/gimpmybrushsurface.h b/app/paint/gimpmybrushsurface.h
index bf9c49c..c3fc737 100644
--- a/app/paint/gimpmybrushsurface.h
+++ b/app/paint/gimpmybrushsurface.h
@@ -22,11 +22,12 @@
 typedef struct _GimpMybrushSurface GimpMybrushSurface;
 
 GimpMybrushSurface *
-gimp_mypaint_surface_new (GeglBuffer        *buffer,
-                          GimpComponentMask  component_mask,
-                          GeglBuffer        *paint_mask,
-                          gint               paint_mask_x,
-                          gint               paint_mask_y);
+gimp_mypaint_surface_new (GeglBuffer         *buffer,
+                          GimpComponentMask   component_mask,
+                          GeglBuffer         *paint_mask,
+                          gint                paint_mask_x,
+                          gint                paint_mask_y,
+                          GimpMybrushOptions *options);
 
 
 #endif  /*  __GIMP_MYBRUSH_SURFACE_H__  */
diff --git a/app/tools/gimpmybrushoptions-gui.c b/app/tools/gimpmybrushoptions-gui.c
index 8a8999d..358bd07 100644
--- a/app/tools/gimpmybrushoptions-gui.c
+++ b/app/tools/gimpmybrushoptions-gui.c
@@ -61,6 +61,11 @@ gimp_mybrush_options_gui (GimpToolOptions *tool_options)
   gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
   gtk_widget_show (scale);
 
+  /* no erasing */
+  scale = gimp_prop_check_button_new (config, "no-erasing", NULL);
+  gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
+  gtk_widget_show (scale);
+
   /* radius */
   scale = gimp_prop_spin_scale_new (config, "radius", NULL,
                                     0.1, 1.0, 2);


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