[gimp] app: mypaint: Add a toggle to change between erase & paint mode



commit 677b1f2d82ebe8712fb181efffd88afc0c7f68f2
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Mon Dec 28 15:24:46 2015 -0800

    app: mypaint: Add a toggle to change between erase & paint mode

 app/core/gimpmybrush-load.c        |    4 ++++
 app/core/gimpmybrush-private.h     |    1 +
 app/core/gimpmybrush.c             |    9 +++++++++
 app/core/gimpmybrush.h             |    1 +
 app/paint/gimpmybrushcore.c        |    3 +++
 app/paint/gimpmybrushoptions.c     |   14 +++++++++++++-
 app/paint/gimpmybrushoptions.h     |    1 +
 app/tools/gimpmybrushoptions-gui.c |    6 ++++++
 8 files changed, 38 insertions(+), 1 deletions(-)
---
diff --git a/app/core/gimpmybrush-load.c b/app/core/gimpmybrush-load.c
index 83ef4ce..4131319 100644
--- a/app/core/gimpmybrush-load.c
+++ b/app/core/gimpmybrush-load.c
@@ -138,6 +138,10 @@ gimp_mybrush_load (GimpContext   *context,
     mypaint_brush_get_base_value (mypaint_brush,
                                   MYPAINT_BRUSH_SETTING_HARDNESS);
 
+  brush->priv->eraser =
+    mypaint_brush_get_base_value (mypaint_brush,
+                                  MYPAINT_BRUSH_SETTING_ERASER) > 0.5f;
+
   mypaint_brush_unref (mypaint_brush);
 
   return g_list_prepend (NULL, brush);
diff --git a/app/core/gimpmybrush-private.h b/app/core/gimpmybrush-private.h
index f3e9f46..cfe880d 100644
--- a/app/core/gimpmybrush-private.h
+++ b/app/core/gimpmybrush-private.h
@@ -27,6 +27,7 @@ struct _GimpMybrushPrivate
   gdouble  radius;
   gdouble  opaque;
   gdouble  hardness;
+  gboolean eraser;
 };
 
 
diff --git a/app/core/gimpmybrush.c b/app/core/gimpmybrush.c
index 8bf6eb4..635fe1f 100644
--- a/app/core/gimpmybrush.c
+++ b/app/core/gimpmybrush.c
@@ -103,6 +103,7 @@ gimp_mybrush_init (GimpMybrush *brush)
   brush->priv->radius   = 1.0;
   brush->priv->opaque   = 1.0;
   brush->priv->hardness = 1.0;
+  brush->priv->eraser   = FALSE;
 }
 
 static void
@@ -259,3 +260,11 @@ gimp_mybrush_get_hardness (GimpMybrush *brush)
 
   return brush->priv->hardness;
 }
+
+gboolean
+gimp_mybrush_get_is_eraser (GimpMybrush *brush)
+{
+  g_return_val_if_fail (GIMP_IS_MYBRUSH (brush), FALSE);
+
+  return brush->priv->eraser;
+}
diff --git a/app/core/gimpmybrush.h b/app/core/gimpmybrush.h
index fc91a3b..bf1d82a 100644
--- a/app/core/gimpmybrush.h
+++ b/app/core/gimpmybrush.h
@@ -59,6 +59,7 @@ const gchar * gimp_mybrush_get_brush_json (GimpMybrush *brush);
 gdouble       gimp_mybrush_get_radius     (GimpMybrush *brush);
 gdouble       gimp_mybrush_get_opaque     (GimpMybrush *brush);
 gdouble       gimp_mybrush_get_hardness   (GimpMybrush *brush);
+gboolean      gimp_mybrush_get_is_eraser  (GimpMybrush *brush);
 
 
 #endif /* __GIMP_MYBRUSH_H__ */
diff --git a/app/paint/gimpmybrushcore.c b/app/paint/gimpmybrushcore.c
index 7238925..b29691e 100644
--- a/app/paint/gimpmybrushcore.c
+++ b/app/paint/gimpmybrushcore.c
@@ -219,6 +219,9 @@ gimp_mybrush_core_paint (GimpPaintCore    *paint_core,
       mypaint_brush_set_base_value (mybrush->private->brush,
                                     MYPAINT_BRUSH_SETTING_HARDNESS,
                                     options->hardness);
+      mypaint_brush_set_base_value (mybrush->private->brush,
+                                    MYPAINT_BRUSH_SETTING_ERASER,
+                                    options->eraser ? 1.0f : 0.0f);
 
       mypaint_brush_new_stroke (mybrush->private->brush);
       mybrush->private->last_time = -1;
diff --git a/app/paint/gimpmybrushoptions.c b/app/paint/gimpmybrushoptions.c
index bd6ba0d..1858eb7 100644
--- a/app/paint/gimpmybrushoptions.c
+++ b/app/paint/gimpmybrushoptions.c
@@ -39,7 +39,8 @@ enum
   PROP_0,
   PROP_RADIUS,
   PROP_OPAQUE,
-  PROP_HARDNESS
+  PROP_HARDNESS,
+  PROP_ERASER
 };
 
 
@@ -83,6 +84,10 @@ gimp_mybrush_options_class_init (GimpMybrushOptionsClass *klass)
                                    "hardness", NULL,
                                    0.0, 1.0, 1.0,
                                    GIMP_PARAM_STATIC_STRINGS);
+  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_ERASER,
+                                   "eraser", NULL,
+                                   FALSE,
+                                   GIMP_PARAM_STATIC_STRINGS);
 }
 
 static void
@@ -109,6 +114,9 @@ gimp_mybrush_options_set_property (GObject      *object,
     case PROP_OPAQUE:
       options->opaque = g_value_get_double (value);
       break;
+    case PROP_ERASER:
+      options->eraser = g_value_get_boolean (value);
+      break;
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -135,6 +143,9 @@ gimp_mybrush_options_get_property (GObject    *object,
     case PROP_HARDNESS:
       g_value_set_double (value, options->hardness);
       break;
+    case PROP_ERASER:
+      g_value_set_boolean (value, options->eraser);
+      break;
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -151,5 +162,6 @@ gimp_mybrush_options_mybrush_changed (GimpContext *context,
                   "radius",   gimp_mybrush_get_radius (brush),
                   "opaque",   gimp_mybrush_get_opaque (brush),
                   "hardness", gimp_mybrush_get_hardness (brush),
+                  "eraser",   gimp_mybrush_get_is_eraser (brush),
                   NULL);
 }
diff --git a/app/paint/gimpmybrushoptions.h b/app/paint/gimpmybrushoptions.h
index 12d8aed..fcf9931 100644
--- a/app/paint/gimpmybrushoptions.h
+++ b/app/paint/gimpmybrushoptions.h
@@ -39,6 +39,7 @@ struct _GimpMybrushOptions
   gdouble           radius;
   gdouble           opaque;
   gdouble           hardness;
+  gboolean          eraser;
 };
 
 struct _GimpMybrushOptionsClass
diff --git a/app/tools/gimpmybrushoptions-gui.c b/app/tools/gimpmybrushoptions-gui.c
index 109d0c4..ad66010 100644
--- a/app/tools/gimpmybrushoptions-gui.c
+++ b/app/tools/gimpmybrushoptions-gui.c
@@ -56,6 +56,12 @@ gimp_mybrush_options_gui (GimpToolOptions *tool_options)
   gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
   gtk_widget_show (button);
 
+  /* erase mode */
+  scale = gimp_prop_check_button_new (config, "eraser",
+                                    _("Erase with this brush"));
+  gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
+  gtk_widget_show (scale);
+
   /* radius */
   scale = gimp_prop_spin_scale_new (config, "radius",
                                     _("Radius"),


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