[gimp] app: also move the "draw brush outline" logic from brush to paint tool
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: also move the "draw brush outline" logic from brush to paint tool
- Date: Sat, 12 Apr 2014 13:07:40 +0000 (UTC)
commit d897188e328fc8af86124282aea81e304c7b699c
Author: Michael Natterer <mitch gimp org>
Date: Sat Apr 12 15:03:15 2014 +0200
app: also move the "draw brush outline" logic from brush to paint tool
So all paint tools honor the setting.
Add GimpPaintTool::get_outline() which either returns an outline, or
calls gimp_paint_tool_set_draw_cursor() and implement it in
GimpBrushTool and GimpInkTool. Handle all brush/circle/fallback
drawing in gimp_paint_tool_draw().
app/config/gimprc-blurbs.h | 2 +-
app/tools/gimpbrushtool.c | 168 ++++++++++---------------------------------
app/tools/gimpbrushtool.h | 4 -
app/tools/gimpinktool.c | 21 ++++--
app/tools/gimppainttool.c | 64 +++++++++++++++--
app/tools/gimppainttool.h | 6 ++
6 files changed, 117 insertions(+), 148 deletions(-)
---
diff --git a/app/config/gimprc-blurbs.h b/app/config/gimprc-blurbs.h
index fb80ab2..f8b143f 100644
--- a/app/config/gimprc-blurbs.h
+++ b/app/config/gimprc-blurbs.h
@@ -312,7 +312,7 @@ N_("Save the tool options when GIMP exits.")
"This path will be searched for scripts when the Script-Fu plug-in is run."
#define SHOW_BRUSH_OUTLINE_BLURB \
-N_("When enabled, all brush-based paint tools will show a preview of the current " \
+N_("When enabled, all paint tools will show a preview of the current " \
"brush's outline.")
#define SHOW_HELP_BUTTON_BLURB \
diff --git a/app/tools/gimpbrushtool.c b/app/tools/gimpbrushtool.c
index 80311d8..f963b87 100644
--- a/app/tools/gimpbrushtool.c
+++ b/app/tools/gimpbrushtool.c
@@ -48,11 +48,6 @@
static void gimp_brush_tool_constructed (GObject *object);
-static void gimp_brush_tool_motion (GimpTool *tool,
- const GimpCoords *coords,
- guint32 time,
- GdkModifierType state,
- GimpDisplay *display);
static void gimp_brush_tool_oper_update (GimpTool *tool,
const GimpCoords *coords,
GdkModifierType state,
@@ -66,7 +61,11 @@ static void gimp_brush_tool_options_notify (GimpTool *tool,
GimpToolOptions *options,
const GParamSpec *pspec);
-static void gimp_brush_tool_draw (GimpDrawTool *draw_tool);
+static GimpCanvasItem *
+ gimp_brush_tool_get_outline (GimpPaintTool *paint_tool,
+ GimpDisplay *display,
+ gdouble x,
+ gdouble y);
static void gimp_brush_tool_brush_changed (GimpContext *context,
GimpBrush *brush,
@@ -74,9 +73,6 @@ static void gimp_brush_tool_brush_changed (GimpContext *context,
static void gimp_brush_tool_set_brush (GimpBrushCore *brush_core,
GimpBrush *brush,
GimpBrushTool *brush_tool);
-static void gimp_brush_tool_notify_brush (GimpDisplayConfig *config,
- GParamSpec *pspec,
- GimpBrushTool *brush_tool);
G_DEFINE_TYPE (GimpBrushTool, gimp_brush_tool, GIMP_TYPE_PAINT_TOOL)
@@ -87,18 +83,17 @@ G_DEFINE_TYPE (GimpBrushTool, gimp_brush_tool, GIMP_TYPE_PAINT_TOOL)
static void
gimp_brush_tool_class_init (GimpBrushToolClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
- GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
+ GimpPaintToolClass *paint_tool_class = GIMP_PAINT_TOOL_CLASS (klass);
- object_class->constructed = gimp_brush_tool_constructed;
+ object_class->constructed = gimp_brush_tool_constructed;
- tool_class->motion = gimp_brush_tool_motion;
- tool_class->oper_update = gimp_brush_tool_oper_update;
- tool_class->cursor_update = gimp_brush_tool_cursor_update;
- tool_class->options_notify = gimp_brush_tool_options_notify;
+ tool_class->oper_update = gimp_brush_tool_oper_update;
+ tool_class->cursor_update = gimp_brush_tool_cursor_update;
+ tool_class->options_notify = gimp_brush_tool_options_notify;
- draw_tool_class->draw = gimp_brush_tool_draw;
+ paint_tool_class->get_outline = gimp_brush_tool_get_outline;
}
static void
@@ -114,61 +109,25 @@ gimp_brush_tool_init (GimpBrushTool *brush_tool)
"context/context-brush-angle-set");
gimp_tool_control_set_action_object_1 (tool->control,
"context/context-brush-select-set");
-
- brush_tool->draw_brush = TRUE;
- brush_tool->brush_x = 0.0;
- brush_tool->brush_y = 0.0;
}
static void
gimp_brush_tool_constructed (GObject *object)
{
- GimpTool *tool = GIMP_TOOL (object);
- GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (object);
- GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (object);
- GimpDisplayConfig *display_config;
+ GimpTool *tool = GIMP_TOOL (object);
+ GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (object);
G_OBJECT_CLASS (parent_class)->constructed (object);
g_assert (GIMP_IS_BRUSH_CORE (paint_tool->core));
- display_config = GIMP_DISPLAY_CONFIG (tool->tool_info->gimp->config);
-
- brush_tool->draw_brush = display_config->show_brush_outline;
-
- g_signal_connect_object (display_config, "notify::show-brush-outline",
- G_CALLBACK (gimp_brush_tool_notify_brush),
- brush_tool, 0);
-
g_signal_connect_object (gimp_tool_get_options (tool), "brush-changed",
G_CALLBACK (gimp_brush_tool_brush_changed),
- brush_tool, 0);
+ paint_tool, 0);
g_signal_connect_object (paint_tool->core, "set-brush",
G_CALLBACK (gimp_brush_tool_set_brush),
- brush_tool, 0);
-}
-
-static void
-gimp_brush_tool_motion (GimpTool *tool,
- const GimpCoords *coords,
- guint32 time,
- GdkModifierType state,
- GimpDisplay *display)
-{
- GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (tool);
-
- gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
-
- GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, display);
-
- if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
- {
- brush_tool->brush_x = coords->x;
- brush_tool->brush_y = coords->y;
- }
-
- gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
+ paint_tool, 0);
}
static void
@@ -178,7 +137,6 @@ gimp_brush_tool_oper_update (GimpTool *tool,
gboolean proximity,
GimpDisplay *display)
{
- GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (tool);
GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (tool);
GimpDrawable *drawable;
@@ -196,9 +154,6 @@ gimp_brush_tool_oper_update (GimpTool *tool,
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_tool->core);
- brush_tool->brush_x = coords->x;
- brush_tool->brush_y = coords->y;
-
gimp_brush_core_set_brush (brush_core,
gimp_context_get_brush (context));
@@ -260,69 +215,36 @@ gimp_brush_tool_options_notify (GimpTool *tool,
}
}
-static void
-gimp_brush_tool_draw (GimpDrawTool *draw_tool)
+static GimpCanvasItem *
+gimp_brush_tool_get_outline (GimpPaintTool *paint_tool,
+ GimpDisplay *display,
+ gdouble x,
+ gdouble y)
{
- GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (draw_tool);
- GimpCanvasItem *item = NULL;
+ GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (paint_tool);
+ GimpCanvasItem *item;
- gimp_paint_tool_set_draw_circle (GIMP_PAINT_TOOL (brush_tool),
- FALSE, 0.0);
+ item = gimp_brush_tool_create_outline (brush_tool, display, x, y);
- if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (draw_tool)))
+ if (! item)
{
- item = gimp_brush_tool_create_outline (brush_tool,
- draw_tool->display,
- brush_tool->brush_x,
- brush_tool->brush_y);
+ GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_tool->core);
- if (! item)
+ if (brush_core->main_brush && brush_core->dynamics)
{
- GimpBrushCore *brush_core;
-
- brush_core = GIMP_BRUSH_CORE (GIMP_PAINT_TOOL (brush_tool)->core);
-
- if (brush_tool->draw_brush &&
- brush_core->main_brush &&
- brush_core->dynamics)
- {
- /* if an outline was expected, but got scaled away by
- * transform/dynamics, draw a circle in the "normal" size.
- */
- GimpPaintOptions *options;
-
- options = GIMP_PAINT_TOOL_GET_OPTIONS (brush_tool);
-
- gimp_paint_tool_set_draw_circle (GIMP_PAINT_TOOL (brush_tool),
- TRUE, options->brush_size);
- }
- else if (! GIMP_PAINT_TOOL (brush_tool)->show_cursor)
- {
- /* don't leave the user without any indication and draw
- * a fallback crosshair
- */
- GimpDisplayShell *shell;
-
- shell = gimp_display_get_shell (draw_tool->display);
-
- item = gimp_canvas_handle_new (shell,
- GIMP_HANDLE_CROSS,
- GIMP_HANDLE_ANCHOR_CENTER,
- brush_tool->brush_x,
- brush_tool->brush_y,
- GIMP_TOOL_HANDLE_SIZE_SMALL,
- GIMP_TOOL_HANDLE_SIZE_SMALL);
- }
- }
- }
+ /* if an outline was expected, but got scaled away by
+ * transform/dynamics, draw a circle in the "normal" size.
+ */
+ GimpPaintOptions *options;
- GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
+ options = GIMP_PAINT_TOOL_GET_OPTIONS (brush_tool);
- if (item)
- {
- gimp_draw_tool_add_item (draw_tool, item);
- g_object_unref (item);
+ gimp_paint_tool_set_draw_circle (paint_tool,
+ TRUE, options->brush_size);
+ }
}
+
+ return item;
}
GimpCanvasItem *
@@ -341,7 +263,7 @@ gimp_brush_tool_create_outline (GimpBrushTool *brush_tool,
g_return_val_if_fail (GIMP_IS_BRUSH_TOOL (brush_tool), NULL);
g_return_val_if_fail (GIMP_IS_DISPLAY (display), NULL);
- if (! brush_tool->draw_brush)
+ if (! GIMP_PAINT_TOOL (brush_tool)->draw_brush)
return NULL;
brush_core = GIMP_BRUSH_CORE (GIMP_PAINT_TOOL (brush_tool)->core);
@@ -418,15 +340,3 @@ gimp_brush_tool_set_brush (GimpBrushCore *brush_core,
gimp_draw_tool_resume (GIMP_DRAW_TOOL (brush_tool));
}
-
-static void
-gimp_brush_tool_notify_brush (GimpDisplayConfig *config,
- GParamSpec *pspec,
- GimpBrushTool *brush_tool)
-{
- gimp_draw_tool_pause (GIMP_DRAW_TOOL (brush_tool));
-
- brush_tool->draw_brush = config->show_brush_outline;
-
- gimp_draw_tool_resume (GIMP_DRAW_TOOL (brush_tool));
-}
diff --git a/app/tools/gimpbrushtool.h b/app/tools/gimpbrushtool.h
index 018db8e..79225f3 100644
--- a/app/tools/gimpbrushtool.h
+++ b/app/tools/gimpbrushtool.h
@@ -35,10 +35,6 @@ typedef struct _GimpBrushToolClass GimpBrushToolClass;
struct _GimpBrushTool
{
GimpPaintTool parent_instance;
-
- gboolean draw_brush;
- gdouble brush_x;
- gdouble brush_y;
};
struct _GimpBrushToolClass
diff --git a/app/tools/gimpinktool.c b/app/tools/gimpinktool.c
index 58474e5..4df6026 100644
--- a/app/tools/gimpinktool.c
+++ b/app/tools/gimpinktool.c
@@ -40,7 +40,10 @@ G_DEFINE_TYPE (GimpInkTool, gimp_ink_tool, GIMP_TYPE_PAINT_TOOL)
#define parent_class gimp_ink_tool_parent_class
-static void gimp_ink_tool_draw (GimpDrawTool *draw_tool);
+static GimpCanvasItem * gimp_ink_tool_get_outline (GimpPaintTool *paint_tool,
+ GimpDisplay *display,
+ gdouble x,
+ gdouble y);
void
@@ -66,9 +69,9 @@ gimp_ink_tool_register (GimpToolRegisterCallback callback,
static void
gimp_ink_tool_class_init (GimpInkToolClass *klass)
{
- GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
+ GimpPaintToolClass *paint_tool_class = GIMP_PAINT_TOOL_CLASS (klass);
- draw_tool_class->draw = gimp_ink_tool_draw;
+ paint_tool_class->get_outline = gimp_ink_tool_get_outline;
}
static void
@@ -88,14 +91,16 @@ gimp_ink_tool_init (GimpInkTool *ink_tool)
GIMP_COLOR_PICK_MODE_FOREGROUND);
}
-static void
-gimp_ink_tool_draw (GimpDrawTool *draw_tool)
+static GimpCanvasItem *
+gimp_ink_tool_get_outline (GimpPaintTool *paint_tool,
+ GimpDisplay *display,
+ gdouble x,
+ gdouble y)
{
- GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (draw_tool);
- GimpInkOptions *options = GIMP_INK_TOOL_GET_OPTIONS (draw_tool);
+ GimpInkOptions *options = GIMP_INK_TOOL_GET_OPTIONS (paint_tool);
gimp_paint_tool_set_draw_circle (paint_tool, TRUE,
options->size);
- GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
+ return NULL;
}
diff --git a/app/tools/gimppainttool.c b/app/tools/gimppainttool.c
index fe9cdb1..aec043a 100644
--- a/app/tools/gimppainttool.c
+++ b/app/tools/gimppainttool.c
@@ -93,6 +93,12 @@ static void gimp_paint_tool_oper_update (GimpTool *tool,
static void gimp_paint_tool_draw (GimpDrawTool *draw_tool);
+static GimpCanvasItem *
+ gimp_paint_tool_get_outline (GimpPaintTool *paint_tool,
+ GimpDisplay *display,
+ gdouble x,
+ gdouble y);
+
static void gimp_paint_tool_hard_notify (GimpPaintOptions *options,
const GParamSpec *pspec,
GimpTool *tool);
@@ -141,6 +147,7 @@ gimp_paint_tool_init (GimpPaintTool *paint_tool)
paint_tool->draw_line = FALSE;
paint_tool->show_cursor = TRUE;
+ paint_tool->draw_brush = TRUE;
paint_tool->draw_circle = FALSE;
paint_tool->circle_radius = 0.0;
@@ -182,10 +189,14 @@ gimp_paint_tool_constructed (GObject *object)
gimp_paint_tool_hard_notify (options, NULL, tool);
paint_tool->show_cursor = display_config->show_paint_tool_cursor;
+ paint_tool->draw_brush = display_config->show_brush_outline;
g_signal_connect_object (display_config, "notify::show-paint-tool-cursor",
G_CALLBACK (gimp_paint_tool_cursor_notify),
paint_tool, 0);
+ g_signal_connect_object (display_config, "notify::show-brush-outline",
+ G_CALLBACK (gimp_paint_tool_cursor_notify),
+ paint_tool, 0);
}
static void
@@ -722,11 +733,12 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
{
if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (draw_tool)))
{
- GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (draw_tool);
- GimpPaintCore *core = paint_tool->core;
- GimpImage *image = gimp_display_get_image (draw_tool->display);
- GimpDrawable *drawable = gimp_image_get_active_drawable (image);
- gint off_x, off_y;
+ GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (draw_tool);
+ GimpPaintCore *core = paint_tool->core;
+ GimpImage *image = gimp_display_get_image (draw_tool->display);
+ GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+ GimpCanvasItem *outline = NULL;
+ gint off_x, off_y;
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
@@ -759,7 +771,20 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
GIMP_HANDLE_ANCHOR_CENTER);
}
- if (paint_tool->draw_circle)
+ gimp_paint_tool_set_draw_circle (paint_tool, FALSE, 0.0);
+
+ if (paint_tool->draw_brush)
+ outline = gimp_paint_tool_get_outline (paint_tool,
+ draw_tool->display,
+ core->cur_coords.x + off_x,
+ core->cur_coords.y + off_y);
+
+ if (outline)
+ {
+ gimp_draw_tool_add_item (draw_tool, outline);
+ g_object_unref (outline);
+ }
+ else if (paint_tool->draw_circle)
{
gint size = MAX (3, paint_tool->circle_radius * 2);
@@ -770,11 +795,37 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
size, size,
GIMP_HANDLE_ANCHOR_CENTER);
}
+ else if (! paint_tool->show_cursor)
+ {
+ /* don't leave the user without any indication and draw
+ * a fallback crosshair
+ */
+ gimp_draw_tool_add_handle (draw_tool,
+ GIMP_HANDLE_CROSS,
+ core->cur_coords.x + off_x,
+ core->cur_coords.y + off_y,
+ GIMP_TOOL_HANDLE_SIZE_SMALL,
+ GIMP_TOOL_HANDLE_SIZE_SMALL,
+ GIMP_HANDLE_ANCHOR_CENTER);
+ }
}
GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
}
+static GimpCanvasItem *
+gimp_paint_tool_get_outline (GimpPaintTool *paint_tool,
+ GimpDisplay *display,
+ gdouble x,
+ gdouble y)
+{
+ if (GIMP_PAINT_TOOL_GET_CLASS (paint_tool)->get_outline)
+ return GIMP_PAINT_TOOL_GET_CLASS (paint_tool)->get_outline (paint_tool,
+ display, x, y);
+
+ return NULL;
+}
+
static void
gimp_paint_tool_hard_notify (GimpPaintOptions *options,
const GParamSpec *pspec,
@@ -794,6 +845,7 @@ gimp_paint_tool_cursor_notify (GimpDisplayConfig *config,
gimp_draw_tool_pause (GIMP_DRAW_TOOL (paint_tool));
paint_tool->show_cursor = config->show_paint_tool_cursor;
+ paint_tool->draw_brush = config->show_brush_outline;
gimp_draw_tool_resume (GIMP_DRAW_TOOL (paint_tool));
}
diff --git a/app/tools/gimppainttool.h b/app/tools/gimppainttool.h
index 61126b6..c7514d3 100644
--- a/app/tools/gimppainttool.h
+++ b/app/tools/gimppainttool.h
@@ -42,6 +42,7 @@ struct _GimpPaintTool
gboolean draw_line;
gboolean show_cursor;
+ gboolean draw_brush;
gboolean draw_circle;
gint circle_radius;
@@ -55,6 +56,11 @@ struct _GimpPaintTool
struct _GimpPaintToolClass
{
GimpColorToolClass parent_class;
+
+ GimpCanvasItem * (* get_outline) (GimpPaintTool *paint_tool,
+ GimpDisplay *display,
+ gdouble x,
+ gdouble y);
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]