[gimp/gimp-2-10] app: don't add fg color to history in GimpEraser
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] app: don't add fg color to history in GimpEraser
- Date: Wed, 29 May 2019 09:27:18 +0000 (UTC)
commit bf6489f727fa93a393154fc26c289cff27fdcb6f
Author: Ell <ell_se yahoo com>
Date: Wed May 29 04:25:38 2019 -0400
app: don't add fg color to history in GimpEraser
Add GimpPaintbrush::get_color_history_color() virtual function,
which should return the color to be added to the color history upon
painting, if any. The default implementation returns the
foreground color, when not using a pixmap brush or color-from-
gradient.
Override this function in GimpEraser, to return the background
color when the affected drawable has no alpha channel, instead of
overriding GimpPaintCore::paint() for this purpose. This avoids
erroneously adding both the background and foreground colors to the
history.
(cherry picked from commit 86f4d4d41d5c27677beb041d1fe8b2f32bf781e1)
app/paint/gimperaser.c | 81 +++++++++++++++++-----------------------------
app/paint/gimppaintbrush.c | 80 +++++++++++++++++++++++++++++----------------
app/paint/gimppaintbrush.h | 20 +++++++-----
3 files changed, 93 insertions(+), 88 deletions(-)
---
diff --git a/app/paint/gimperaser.c b/app/paint/gimperaser.c
index b360f18ca9..a8d72d1dae 100644
--- a/app/paint/gimperaser.c
+++ b/app/paint/gimperaser.c
@@ -38,27 +38,22 @@
#include "gimp-intl.h"
-static void gimp_eraser_paint (GimpPaintCore *paint_core,
- GimpDrawable *drawable,
- GimpPaintOptions *paint_options,
- GimpSymmetry *sym,
- GimpPaintState paint_state,
- guint32 time);
-
-static void gimp_eraser_get_paint_params (GimpPaintbrush *paintbrush,
- GimpDrawable *drawable,
- GimpPaintOptions *paint_options,
- GimpSymmetry *sym,
- GimpLayerMode *paint_mode,
- GimpPaintApplicationMode *paint_appl_mode,
- const GimpTempBuf **paint_pixmap,
- GimpRGB *paint_color);
+static gboolean gimp_eraser_get_color_history_color (GimpPaintbrush *paintbrush,
+ GimpDrawable *drawable,
+ GimpPaintOptions *paint_options,
+ GimpRGB *color);
+static void gimp_eraser_get_paint_params (GimpPaintbrush *paintbrush,
+ GimpDrawable *drawable,
+ GimpPaintOptions *paint_options,
+ GimpSymmetry *sym,
+ GimpLayerMode *paint_mode,
+ GimpPaintApplicationMode *paint_appl_mode,
+ const GimpTempBuf **paint_pixmap,
+ GimpRGB *paint_color);
G_DEFINE_TYPE (GimpEraser, gimp_eraser, GIMP_TYPE_PAINTBRUSH)
-#define parent_class gimp_eraser_parent_class
-
void
gimp_eraser_register (Gimp *gimp,
@@ -75,12 +70,10 @@ gimp_eraser_register (Gimp *gimp,
static void
gimp_eraser_class_init (GimpEraserClass *klass)
{
- GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
GimpPaintbrushClass *paintbrush_class = GIMP_PAINTBRUSH_CLASS (klass);
- paint_core_class->paint = gimp_eraser_paint;
-
- paintbrush_class->get_paint_params = gimp_eraser_get_paint_params;
+ paintbrush_class->get_color_history_color = gimp_eraser_get_color_history_color;
+ paintbrush_class->get_paint_params = gimp_eraser_get_paint_params;
}
static void
@@ -88,41 +81,25 @@ gimp_eraser_init (GimpEraser *eraser)
{
}
-static void
-gimp_eraser_paint (GimpPaintCore *paint_core,
- GimpDrawable *drawable,
- GimpPaintOptions *paint_options,
- GimpSymmetry *sym,
- GimpPaintState paint_state,
- guint32 time)
+static gboolean
+gimp_eraser_get_color_history_color (GimpPaintbrush *paintbrush,
+ GimpDrawable *drawable,
+ GimpPaintOptions *paint_options,
+ GimpRGB *color)
{
- switch (paint_state)
+ /* Erasing on a drawable without alpha is equivalent to
+ * drawing with background color. So let's save history.
+ */
+ if (! gimp_drawable_has_alpha (drawable))
{
- case GIMP_PAINT_STATE_INIT:
- {
- if (! gimp_drawable_has_alpha (drawable))
- {
- /* Erasing on a drawable without alpha is equivalent to
- * drawing with background color. So let's save history.
- */
- GimpContext *context = GIMP_CONTEXT (paint_options);
- GimpRGB background;
-
- gimp_context_get_background (context, &background);
- gimp_palettes_add_color_history (context->gimp,
- &background);
-
- }
- }
- break;
-
- default:
- break;
+ GimpContext *context = GIMP_CONTEXT (paint_options);
+
+ gimp_context_get_background (context, color);
+
+ return TRUE;
}
- GIMP_PAINT_CORE_CLASS (parent_class)->paint (paint_core, drawable,
- paint_options, sym,
- paint_state, time);
+ return FALSE;
}
static void
diff --git a/app/paint/gimppaintbrush.c b/app/paint/gimppaintbrush.c
index 1db8fea250..a4bbf387b4 100644
--- a/app/paint/gimppaintbrush.c
+++ b/app/paint/gimppaintbrush.c
@@ -46,21 +46,25 @@
#include "gimp-intl.h"
-static void gimp_paintbrush_paint (GimpPaintCore *paint_core,
- GimpDrawable *drawable,
- GimpPaintOptions *paint_options,
- GimpSymmetry *sym,
- GimpPaintState paint_state,
- guint32 time);
-
-static void gimp_paintbrush_real_get_paint_params (GimpPaintbrush *paintbrush,
- GimpDrawable *drawable,
- GimpPaintOptions *paint_options,
- GimpSymmetry *sym,
- GimpLayerMode *paint_mode,
- GimpPaintApplicationMode *paint_appl_mode,
- const GimpTempBuf **paint_pixmap,
- GimpRGB *paint_color);
+static void gimp_paintbrush_paint (GimpPaintCore *paint_core,
+ GimpDrawable *drawable,
+ GimpPaintOptions *paint_options,
+ GimpSymmetry *sym,
+ GimpPaintState paint_state,
+ guint32 time);
+
+static gboolean gimp_paintbrush_real_get_color_history_color (GimpPaintbrush *paintbrush,
+ GimpDrawable *drawable,
+ GimpPaintOptions *paint_options,
+ GimpRGB *color);
+static void gimp_paintbrush_real_get_paint_params (GimpPaintbrush *paintbrush,
+ GimpDrawable *drawable,
+ GimpPaintOptions *paint_options,
+ GimpSymmetry *sym,
+ GimpLayerMode *paint_mode,
+ GimpPaintApplicationMode *paint_appl_mode,
+ const GimpTempBuf **paint_pixmap,
+ GimpRGB *paint_color);
G_DEFINE_TYPE (GimpPaintbrush, gimp_paintbrush, GIMP_TYPE_BRUSH_CORE)
@@ -88,6 +92,7 @@ gimp_paintbrush_class_init (GimpPaintbrushClass *klass)
brush_core_class->handles_changing_brush = TRUE;
+ klass->get_color_history_color = gimp_paintbrush_real_get_color_history_color;
klass->get_paint_params = gimp_paintbrush_real_get_paint_params;
}
@@ -104,24 +109,21 @@ gimp_paintbrush_paint (GimpPaintCore *paint_core,
GimpPaintState paint_state,
guint32 time)
{
+ GimpPaintbrush *paintbrush = GIMP_PAINTBRUSH (paint_core);
+
switch (paint_state)
{
case GIMP_PAINT_STATE_INIT:
{
- GimpContext *context = GIMP_CONTEXT (paint_options);
- GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_core);
- GimpDynamics *dynamics = gimp_context_get_dynamics (context);
+ GimpRGB color;
- if (! gimp_dynamics_is_output_enabled (dynamics, GIMP_DYNAMICS_OUTPUT_COLOR) &&
- (! brush_core->brush || ! gimp_brush_get_pixmap (brush_core->brush)))
+ if (GIMP_PAINTBRUSH_GET_CLASS (paintbrush)->get_color_history_color &&
+ GIMP_PAINTBRUSH_GET_CLASS (paintbrush)->get_color_history_color (
+ paintbrush, drawable, paint_options, &color))
{
- /* We don't save gradient color history and pixmap brushes
- * have no color to save.
- */
- GimpRGB foreground;
+ GimpContext *context = GIMP_CONTEXT (paint_options);
- gimp_context_get_foreground (context, &foreground);
- gimp_palettes_add_color_history (context->gimp, &foreground);
+ gimp_palettes_add_color_history (context->gimp, &color);
}
}
break;
@@ -133,8 +135,6 @@ gimp_paintbrush_paint (GimpPaintCore *paint_core,
case GIMP_PAINT_STATE_FINISH:
{
- GimpPaintbrush *paintbrush = GIMP_PAINTBRUSH (paint_core);
-
if (paintbrush->paint_buffer)
{
g_object_remove_weak_pointer (
@@ -150,6 +150,30 @@ gimp_paintbrush_paint (GimpPaintCore *paint_core,
}
}
+static gboolean
+gimp_paintbrush_real_get_color_history_color (GimpPaintbrush *paintbrush,
+ GimpDrawable *drawable,
+ GimpPaintOptions *paint_options,
+ GimpRGB *color)
+{
+ GimpContext *context = GIMP_CONTEXT (paint_options);
+ GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paintbrush);
+ GimpDynamics *dynamics = gimp_context_get_dynamics (context);
+
+ /* We don't save gradient color history and pixmap brushes
+ * have no color to save.
+ */
+ if (gimp_dynamics_is_output_enabled (dynamics, GIMP_DYNAMICS_OUTPUT_COLOR) ||
+ (brush_core->brush && gimp_brush_get_pixmap (brush_core->brush)))
+ {
+ return FALSE;
+ }
+
+ gimp_context_get_foreground (context, color);
+
+ return TRUE;
+}
+
static void
gimp_paintbrush_real_get_paint_params (GimpPaintbrush *paintbrush,
GimpDrawable *drawable,
diff --git a/app/paint/gimppaintbrush.h b/app/paint/gimppaintbrush.h
index 0631439826..75ca7adf48 100644
--- a/app/paint/gimppaintbrush.h
+++ b/app/paint/gimppaintbrush.h
@@ -46,14 +46,18 @@ struct _GimpPaintbrushClass
GimpBrushCoreClass parent_class;
/* virtual functions */
- void (* get_paint_params) (GimpPaintbrush *paintbrush,
- GimpDrawable *drawable,
- GimpPaintOptions *paint_options,
- GimpSymmetry *sym,
- GimpLayerMode *paint_mode,
- GimpPaintApplicationMode *paint_appl_mode,
- const GimpTempBuf **paint_pixmap,
- GimpRGB *paint_color);
+ gboolean (* get_color_history_color) (GimpPaintbrush *paintbrush,
+ GimpDrawable *drawable,
+ GimpPaintOptions *paint_options,
+ GimpRGB *color);
+ void (* get_paint_params) (GimpPaintbrush *paintbrush,
+ GimpDrawable *drawable,
+ GimpPaintOptions *paint_options,
+ GimpSymmetry *sym,
+ GimpLayerMode *paint_mode,
+ GimpPaintApplicationMode *paint_appl_mode,
+ const GimpTempBuf **paint_pixmap,
+ GimpRGB *paint_color);
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]