Commit 269ab384 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

app/tools/Makefile.am app/tools/tools-types.h new GimpPaintTool subclass

2006-08-15  Michael Natterer  <mitch@gimp.org>

	* app/tools/Makefile.am
	* app/tools/tools-types.h
	* app/tools/gimpbrushtool.[ch]: new GimpPaintTool subclass which
	completely handles brush outline drawing.

	* app/tools/gimppainttool.[ch]: removed all brush stuff here.

	* app/tools/gimpclonetool.[ch]
	* app/tools/gimpconvolvetool.[ch]
	* app/tools/gimpdodgeburntool.[ch]
	* app/tools/gimperasertool.[ch]
	* app/tools/gimppaintbrushtool.[ch]
	* app/tools/gimpsmudgetool.[ch]: derive from GimpBrushTool.

	* app/tools/gimpinktool.c: removed now obsolete cursor_update()
	implementation.
parent 02156f9a
2006-08-15 Michael Natterer <mitch@gimp.org>
* app/tools/Makefile.am
* app/tools/tools-types.h
* app/tools/gimpbrushtool.[ch]: new GimpPaintTool subclass which
completely handles brush outline drawing.
* app/tools/gimppainttool.[ch]: removed all brush stuff here.
* app/tools/gimpclonetool.[ch]
* app/tools/gimpconvolvetool.[ch]
* app/tools/gimpdodgeburntool.[ch]
* app/tools/gimperasertool.[ch]
* app/tools/gimppaintbrushtool.[ch]
* app/tools/gimpsmudgetool.[ch]: derive from GimpBrushTool.
* app/tools/gimpinktool.c: removed now obsolete cursor_update()
implementation.
2006-08-15 Michael Natterer <mitch@gimp.org>
 
* app/tools/gimpeditselectiontool.c (gimp_edit_selection_tool_start):
......
......@@ -24,6 +24,8 @@ libapptools_a_sources = \
gimpblendtool.h \
gimpbrightnesscontrasttool.c \
gimpbrightnesscontrasttool.h \
gimpbrushtool.c \
gimpbrushtool.h \
gimpbucketfilloptions.c \
gimpbucketfilloptions.h \
gimpbucketfilltool.c \
......
This diff is collapsed.
......@@ -16,52 +16,40 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_PAINT_TOOL_H__
#define __GIMP_PAINT_TOOL_H__
#ifndef __GIMP_BRUSH_TOOL_H__
#define __GIMP_BRUSH_TOOL_H__
#include "gimpcolortool.h"
#include "gimppainttool.h"
#define GIMP_TYPE_PAINT_TOOL (gimp_paint_tool_get_type ())
#define GIMP_PAINT_TOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_PAINT_TOOL, GimpPaintTool))
#define GIMP_PAINT_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PAINT_TOOL, GimpPaintToolClass))
#define GIMP_IS_PAINT_TOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_PAINT_TOOL))
#define GIMP_IS_PAINT_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PAINT_TOOL))
#define GIMP_PAINT_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_PAINT_TOOL, GimpPaintToolClass))
#define GIMP_TYPE_BRUSH_TOOL (gimp_brush_tool_get_type ())
#define GIMP_BRUSH_TOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_BRUSH_TOOL, GimpBrushTool))
#define GIMP_BRUSH_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_BRUSH_TOOL, GimpBrushToolClass))
#define GIMP_IS_BRUSH_TOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_BRUSH_TOOL))
#define GIMP_IS_BRUSH_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_BRUSH_TOOL))
#define GIMP_BRUSH_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_BRUSH_TOOL, GimpBrushToolClass))
typedef struct _GimpPaintToolClass GimpPaintToolClass;
typedef struct _GimpBrushToolClass GimpBrushToolClass;
struct _GimpPaintTool
struct _GimpBrushTool
{
GimpColorTool parent_instance;
GimpPaintTool parent_instance;
gboolean pick_colors; /* pick color if ctrl is pressed */
gboolean draw_line;
gboolean show_cursor;
gboolean draw_brush;
gdouble brush_x;
gdouble brush_y;
const gchar *status; /* status message */
const gchar *status_line; /* status message when drawing a line */
const gchar *status_ctrl; /* additional message for the ctrl modifier */
GimpPaintCore *core;
gboolean show_cursor;
gboolean draw_brush;
gdouble brush_x;
gdouble brush_y;
};
struct _GimpPaintToolClass
struct _GimpBrushToolClass
{
GimpColorToolClass parent_class;
GimpPaintToolClass parent_class;
};
GType gimp_paint_tool_get_type (void) G_GNUC_CONST;
void gimp_paint_tool_enable_color_picker (GimpPaintTool *tool,
GimpColorPickMode mode);
GType gimp_brush_tool_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_PAINT_TOOL_H__ */
#endif /* __GIMP_BRUSH_TOOL_H__ */
......@@ -86,7 +86,7 @@ static void gimp_clone_tool_draw (GimpDrawTool *draw_tool);
static GtkWidget * gimp_clone_options_gui (GimpToolOptions *tool_options);
G_DEFINE_TYPE (GimpCloneTool, gimp_clone_tool, GIMP_TYPE_PAINT_TOOL)
G_DEFINE_TYPE (GimpCloneTool, gimp_clone_tool, GIMP_TYPE_BRUSH_TOOL)
#define parent_class gimp_clone_tool_parent_class
......
......@@ -20,7 +20,7 @@
#define __GIMP_CLONE_TOOL_H__
#include "gimppainttool.h"
#include "gimpbrushtool.h"
#define GIMP_TYPE_CLONE_TOOL (gimp_clone_tool_get_type ())
......@@ -36,7 +36,7 @@ typedef struct _GimpCloneToolClass GimpCloneToolClass;
struct _GimpCloneTool
{
GimpPaintTool parent_instance;
GimpBrushTool parent_instance;
GimpDisplay *src_display;
gint src_x;
......@@ -45,7 +45,7 @@ struct _GimpCloneTool
struct _GimpCloneToolClass
{
GimpPaintToolClass parent_class;
GimpBrushToolClass parent_class;
};
......
......@@ -58,7 +58,7 @@ static void gimp_convolve_tool_status_update (GimpTool *tool,
static GtkWidget * gimp_convolve_options_gui (GimpToolOptions *options);
G_DEFINE_TYPE (GimpConvolveTool, gimp_convolve_tool, GIMP_TYPE_PAINT_TOOL)
G_DEFINE_TYPE (GimpConvolveTool, gimp_convolve_tool, GIMP_TYPE_BRUSH_TOOL)
#define parent_class gimp_convolve_tool_parent_class
......@@ -195,14 +195,12 @@ gimp_convolve_tool_status_update (GimpTool *tool,
static GtkWidget *
gimp_convolve_options_gui (GimpToolOptions *tool_options)
{
GObject *config;
GObject *config = G_OBJECT (tool_options);
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *frame;
gchar *str;
config = G_OBJECT (tool_options);
vbox = gimp_paint_options_gui (tool_options);
/* the type radio box */
......
......@@ -20,7 +20,7 @@
#define __GIMP_CONVOLVE_TOOL_H__
#include "gimppainttool.h"
#include "gimpbrushtool.h"
#define GIMP_TYPE_CONVOLVE_TOOL (gimp_convolve_tool_get_type ())
......@@ -36,12 +36,12 @@ typedef struct _GimpConvolveToolClass GimpConvolveToolClass;
struct _GimpConvolveTool
{
GimpPaintTool parent_instance;
GimpBrushTool parent_instance;
};
struct _GimpConvolveToolClass
{
GimpPaintToolClass parent_class;
GimpBrushToolClass parent_class;
};
......
......@@ -58,7 +58,7 @@ static void gimp_dodge_burn_tool_status_update (GimpTool *tool,
static GtkWidget * gimp_dodge_burn_options_gui (GimpToolOptions *tool_options);
G_DEFINE_TYPE (GimpDodgeBurnTool, gimp_dodge_burn_tool, GIMP_TYPE_PAINT_TOOL)
G_DEFINE_TYPE (GimpDodgeBurnTool, gimp_dodge_burn_tool, GIMP_TYPE_BRUSH_TOOL)
#define parent_class gimp_dodge_burn_tool_parent_class
......@@ -197,14 +197,12 @@ gimp_dodge_burn_tool_status_update (GimpTool *tool,
static GtkWidget *
gimp_dodge_burn_options_gui (GimpToolOptions *tool_options)
{
GObject *config;
GObject *config = G_OBJECT (tool_options);
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *frame;
gchar *str;
config = G_OBJECT (tool_options);
vbox = gimp_paint_options_gui (tool_options);
/* the type (dodge or burn) */
......
......@@ -20,7 +20,7 @@
#define __GIMP_DODGE_BURN_TOOL_H__
#include "gimppainttool.h"
#include "gimpbrushtool.h"
#define GIMP_TYPE_DODGE_BURN_TOOL (gimp_dodge_burn_tool_get_type ())
......@@ -35,12 +35,12 @@ typedef struct _GimpDodgeBurnToolClass GimpDodgeBurnToolClass;
struct _GimpDodgeBurnTool
{
GimpPaintTool parent_instance;
GimpBrushTool parent_instance;
};
struct _GimpDodgeBurnToolClass
{
GimpPaintToolClass parent_class;
GimpBrushToolClass parent_class;
};
......
......@@ -51,7 +51,7 @@ static void gimp_eraser_tool_cursor_update (GimpTool *tool,
static GtkWidget * gimp_eraser_options_gui (GimpToolOptions *tool_options);
G_DEFINE_TYPE (GimpEraserTool, gimp_eraser_tool, GIMP_TYPE_PAINT_TOOL)
G_DEFINE_TYPE (GimpEraserTool, gimp_eraser_tool, GIMP_TYPE_BRUSH_TOOL)
#define parent_class gimp_eraser_tool_parent_class
......@@ -143,13 +143,11 @@ gimp_eraser_tool_cursor_update (GimpTool *tool,
static GtkWidget *
gimp_eraser_options_gui (GimpToolOptions *tool_options)
{
GObject *config;
GObject *config = G_OBJECT (tool_options);
GtkWidget *vbox;
GtkWidget *button;
gchar *str;
config = G_OBJECT (tool_options);
vbox = gimp_paint_options_gui (tool_options);
/* the anti_erase toggle */
......
......@@ -20,7 +20,7 @@
#define __GIMP_ERASER_TOOL_H__
#include "gimppainttool.h"
#include "gimpbrushtool.h"
#define GIMP_TYPE_ERASER_TOOL (gimp_eraser_tool_get_type ())
......@@ -36,12 +36,12 @@ typedef struct _GimpEraserToolClass GimpEraserToolClass;
struct _GimpEraserTool
{
GimpPaintTool parent_instance;
GimpBrushTool parent_instance;
};
struct _GimpEraserToolClass
{
GimpPaintToolClass parent_class;
GimpBrushToolClass parent_class;
};
......
......@@ -35,12 +35,6 @@
#include "gimp-intl.h"
static void gimp_ink_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display);
G_DEFINE_TYPE (GimpInkTool, gimp_ink_tool, GIMP_TYPE_PAINT_TOOL)
#define parent_class gimp_ink_tool_parent_class
......@@ -69,9 +63,6 @@ gimp_ink_tool_register (GimpToolRegisterCallback callback,
static void
gimp_ink_tool_class_init (GimpInkToolClass *klass)
{
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
tool_class->cursor_update = gimp_ink_tool_cursor_update;
}
static void
......@@ -90,16 +81,3 @@ gimp_ink_tool_init (GimpInkTool *ink_tool)
gimp_paint_tool_enable_color_picker (GIMP_PAINT_TOOL (ink_tool),
GIMP_COLOR_PICK_MODE_FOREGROUND);
}
static void
gimp_ink_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display)
{
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
paint_tool->show_cursor = TRUE;
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
}
......@@ -35,7 +35,7 @@
#include "gimp-intl.h"
G_DEFINE_TYPE (GimpPaintbrushTool, gimp_paintbrush_tool, GIMP_TYPE_PAINT_TOOL)
G_DEFINE_TYPE (GimpPaintbrushTool, gimp_paintbrush_tool, GIMP_TYPE_BRUSH_TOOL)
void
......
......@@ -20,7 +20,7 @@
#define __GIMP_PAINTBRUSH_TOOL_H__
#include "gimppainttool.h"
#include "gimpbrushtool.h"
#define GIMP_TYPE_PAINTBRUSH_TOOL (gimp_paintbrush_tool_get_type ())
......@@ -36,12 +36,12 @@ typedef struct _GimpPaintbrushToolClass GimpPaintbrushToolClass;
struct _GimpPaintbrushTool
{
GimpPaintTool parent_instance;
GimpBrushTool parent_instance;
};
struct _GimpPaintbrushToolClass
{
GimpPaintToolClass parent_class;
GimpBrushToolClass parent_class;
};
......
......@@ -23,14 +23,7 @@
#include "tools-types.h"
#include "config/gimpdisplayconfig.h"
#include "base/boundary.h"
#include "base/pixel-region.h"
#include "base/temp-buf.h"
#include "core/gimp.h"
#include "core/gimpbrush.h"
#include "core/gimpcontainer.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
......@@ -39,7 +32,6 @@
#include "core/gimptoolinfo.h"
#include "core/gimpunit.h"
#include "paint/gimpbrushcore.h"
#include "paint/gimppaintcore.h"
#include "paint/gimppaintoptions.h"
......@@ -50,7 +42,6 @@
#include "display/gimpdisplayshell.h"
#include "gimpcoloroptions.h"
#include "gimpcolorpickertool.h"
#include "gimppainttool.h"
#include "gimptoolcontrol.h"
#include "tools-utils.h"
......@@ -58,7 +49,7 @@
#include "gimp-intl.h"
#define TARGET_SIZE 15
#define HANDLE_SIZE 15
#define STATUSBAR_SIZE 200
......@@ -67,7 +58,7 @@ static GObject * gimp_paint_tool_constructor (GType type,
GObjectConstructParam *params);
static void gimp_paint_tool_finalize (GObject *object);
static void gimp_paint_tool_control (GimpTool *tool,
static void gimp_paint_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display);
static void gimp_paint_tool_button_press (GimpTool *tool,
......@@ -95,26 +86,9 @@ static void gimp_paint_tool_oper_update (GimpTool *tool,
GdkModifierType state,
gboolean proximity,
GimpDisplay *display);
static void gimp_paint_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display);
static void gimp_paint_tool_draw (GimpDrawTool *draw_tool);
static void gimp_paint_tool_brush_changed (GimpContext *context,
GimpBrush *brush,
GimpPaintTool *paint_tool);
static void gimp_paint_tool_set_brush (GimpBrushCore *brush_core,
GimpBrush *brush,
GimpPaintTool *paint_tool);
static void gimp_paint_tool_set_brush_after(GimpBrushCore *brush_core,
GimpBrush *brush,
GimpPaintTool *paint_tool);
static void gimp_paint_tool_notify_brush (GimpDisplayConfig *config,
GParamSpec *pspec,
GimpPaintTool *paint_tool);
G_DEFINE_TYPE (GimpPaintTool, gimp_paint_tool, GIMP_TYPE_COLOR_TOOL)
......@@ -137,7 +111,6 @@ gimp_paint_tool_class_init (GimpPaintToolClass *klass)
tool_class->motion = gimp_paint_tool_motion;
tool_class->modifier_key = gimp_paint_tool_modifier_key;
tool_class->oper_update = gimp_paint_tool_oper_update;
tool_class->cursor_update = gimp_paint_tool_cursor_update;
draw_tool_class->draw = gimp_paint_tool_draw;
}
......@@ -151,14 +124,6 @@ gimp_paint_tool_init (GimpPaintTool *paint_tool)
GIMP_MOTION_MODE_EXACT);
gimp_tool_control_set_action_value_1 (tool->control,
"context/context-opacity-set");
gimp_tool_control_set_action_value_2 (tool->control,
"context/context-brush-radius-set");
gimp_tool_control_set_action_value_3 (tool->control,
"context/context-brush-aspect-set");
gimp_tool_control_set_action_value_4 (tool->control,
"context/context-brush-angle-set");
gimp_tool_control_set_action_object_1 (tool->control,
"context/context-brush-select-set");
paint_tool->pick_colors = FALSE;
paint_tool->draw_line = FALSE;
......@@ -167,11 +132,6 @@ gimp_paint_tool_init (GimpPaintTool *paint_tool)
paint_tool->status_line = _("Click to draw the line.");
paint_tool->status_ctrl = _("%s to pick a color");
paint_tool->show_cursor = TRUE;
paint_tool->draw_brush = TRUE;
paint_tool->brush_x = 0.0;
paint_tool->brush_y = 0.0;
paint_tool->core = NULL;
}
......@@ -190,38 +150,13 @@ gimp_paint_tool_constructor (GType type,
paint_tool = GIMP_PAINT_TOOL (object);
g_assert (GIMP_IS_TOOL_INFO (tool->tool_info));
paint_tool->show_cursor =
GIMP_DISPLAY_CONFIG (tool->tool_info->gimp->config)->show_paint_tool_cursor;
paint_tool->draw_brush =
GIMP_DISPLAY_CONFIG (tool->tool_info->gimp->config)->show_brush_outline;
g_signal_connect_object (tool->tool_info->gimp->config,
"notify::show-paint-tool-cursor",
G_CALLBACK (gimp_paint_tool_notify_brush),
paint_tool, 0);
g_signal_connect_object (tool->tool_info->gimp->config,
"notify::show-brush-outline",
G_CALLBACK (gimp_paint_tool_notify_brush),
paint_tool, 0);
g_assert (GIMP_IS_PAINT_INFO (tool->tool_info->paint_info));
g_assert (g_type_is_a (tool->tool_info->paint_info->paint_type,
GIMP_TYPE_PAINT_CORE));
paint_tool->core = g_object_new (tool->tool_info->paint_info->paint_type,
NULL);
if (GIMP_IS_BRUSH_CORE (paint_tool->core))
{
g_signal_connect_object (tool->tool_info->tool_options, "brush-changed",
G_CALLBACK (gimp_paint_tool_brush_changed),
paint_tool, 0);
g_signal_connect (paint_tool->core, "set-brush",
G_CALLBACK (gimp_paint_tool_set_brush),
paint_tool);
g_signal_connect_after (paint_tool->core, "set-brush",
G_CALLBACK (gimp_paint_tool_set_brush_after),
paint_tool);
}
return object;
}
......@@ -508,9 +443,6 @@ gimp_paint_tool_motion (GimpTool *tool,
gimp_projection_flush_now (display->image->projection);
gimp_display_flush_now (display);
paint_tool->brush_x = coords->x;
paint_tool->brush_y = coords->y;
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
}
......@@ -713,20 +645,6 @@ gimp_paint_tool_oper_update (GimpTool *tool,
paint_tool->draw_line = FALSE;
}
paint_tool->brush_x = coords->x;
paint_tool->brush_y = coords->y;
if (GIMP_IS_BRUSH_CORE (core))
{
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (core);
GimpBrush *brush;
brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));
if (brush_core->main_brush != brush)
gimp_brush_core_set_brush (brush_core, brush);
}
gimp_draw_tool_start (draw_tool, display);
}
......@@ -750,8 +668,8 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
GIMP_HANDLE_CROSS,
core->last_coords.x,
core->last_coords.y,
TARGET_SIZE,
TARGET_SIZE,
HANDLE_SIZE,
HANDLE_SIZE,
GTK_ANCHOR_CENTER,
TRUE);
......@@ -760,8 +678,8 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
GIMP_HANDLE_CROSS,
core->cur_coords.x,
core->cur_coords.y,
TARGET_SIZE,
TARGET_SIZE,
HANDLE_SIZE,
HANDLE_SIZE,
GTK_ANCHOR_CENTER,
TRUE);
......@@ -773,136 +691,7 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool)
core->cur_coords.y,
TRUE);
}
if (paint_tool->draw_brush && GIMP_IS_BRUSH_CORE (core))
{
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (core);
if (! brush_core->brush_bound_segs && brush_core->main_brush)
{
TempBuf *mask = gimp_brush_get_mask (brush_core->main_brush);
PixelRegion PR = { 0, };
BoundSeg *boundary;
gint num_groups;
pixel_region_init_temp_buf (&PR, mask,
0, 0, mask->width, mask->height);
boundary = boundary_find (&PR, BOUNDARY_WITHIN_BOUNDS,
0, 0, PR.w, PR.h,
0,
&brush_core->n_brush_bound_segs);
brush_core->brush_bound_segs =
boundary_sort (boundary, brush_core->n_brush_bound_segs,
&num_groups);
brush_core->n_brush_bound_segs += num_groups;
g_free (boundary);
brush_core->brush_bound_width = mask->width;
brush_core->brush_bound_height = mask->height;
}
if (brush_core->brush_bound_segs)
{
GimpTool *tool = GIMP_TOOL (draw_tool);
GimpPaintOptions *paint_options;
gdouble brush_x, brush_y;
paint_options = GIMP_PAINT_OPTIONS (tool->tool_info->tool_options);
brush_x = (paint_tool->brush_x -
((gdouble) brush_core->brush_bound_width / 2.0));
brush_y = (paint_tool->brush_y -
((gdouble) brush_core->brush_bound_height / 2.0));
if (gimp_paint_options_get_brush_mode (paint_options) == GIMP_BRUSH_HARD)
{
#define EPSILON 0.000001
/* Add EPSILON before rounding since e.g.
* (5.0 - 0.5) may end up at (4.499999999....)
* due to floating point fnords
*/
brush_x = RINT (brush_x + EPSILON);
brush_y = RINT (brush_y + EPSILON);
#undef EPSILON
}