2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc
1999-09-01 Tor Lillqvist <tml@iki.fi>
* app/appenv.h
* libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI,
RINT(), ROUND() etc from app/appenv.h here, so plug-ins can
use them, too. Remove some commented-out old stuff in appenv.h.
* libgimp/gimp.h: Include gimpmath.h.
* libgimp/gimp.c (gimp_main): Win32: Don't install signal
handlers, we can't do anything useful in the handler ourselves
anyway (it would be nice to print out a backtrace, but that seems
pretty hard to do, even if not impossible). Let Windows inform the
user about the crash. If the plug-in was compiled with MSVC, and
the user also has it, she is offered a chance to start the
debugger automatically anyway.
* app/*several*.c: Include gimpmath.h for G_PI etc. Don't include
<math.h>, as gimpmath.h includes it.
* plug-ins/*/*many*.c: Include config.h. Don't include <math.h>.
Remove all the duplicated definitions of G_PI and rint(). Use
RINT() instead of rint().
* app/app_procs.[ch]: app_exit() takes a gboolean.
* app/batch.c
* app/commands.c
* app/interface.c: Call app_exit() with FALSE or TRUE.
* app/main.c (on_error): Call gimp_fatal_error. (main): Don't
install any signal handler on Win32 here, either.
* app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format
the message and call MessageBox with it. g_on_error_query doesn't
do anything useful on Win32, and printf'ing a message to stdout or
stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-11-10 21:20:33 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2003-08-20 01:20:05 +08:00
|
|
|
#include "config/gimpdisplayconfig.h"
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "core/gimp.h"
|
2003-08-20 02:04:40 +08:00
|
|
|
#include "core/gimpbrush.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2001-12-02 05:02:34 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2004-05-26 04:41:09 +08:00
|
|
|
#include "paint/gimpbrushcore.h"
|
2003-02-05 22:39:40 +08:00
|
|
|
#include "paint/gimppaintoptions.h"
|
2002-02-15 03:31:16 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2007-10-30 01:17:14 +08:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
|
2006-08-16 05:46:22 +08:00
|
|
|
#include "gimpbrushtool.h"
|
2003-04-16 00:05:52 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
2001-03-08 09:07:03 +08:00
|
|
|
|
1999-09-02 02:46:25 +08:00
|
|
|
|
2011-01-13 17:06:07 +08:00
|
|
|
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,
|
|
|
|
gboolean proximity,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_brush_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_brush_tool_options_notify (GimpTool *tool,
|
|
|
|
GimpToolOptions *options,
|
|
|
|
const GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gimp_brush_tool_draw (GimpDrawTool *draw_tool);
|
|
|
|
|
|
|
|
static void gimp_brush_tool_brush_changed (GimpContext *context,
|
|
|
|
GimpBrush *brush,
|
|
|
|
GimpBrushTool *brush_tool);
|
|
|
|
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);
|
2003-08-20 01:20:05 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-08-16 05:46:22 +08:00
|
|
|
G_DEFINE_TYPE (GimpBrushTool, gimp_brush_tool, GIMP_TYPE_PAINT_TOOL)
|
2001-02-28 03:18:01 +08:00
|
|
|
|
2006-08-16 05:46:22 +08:00
|
|
|
#define parent_class gimp_brush_tool_parent_class
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
static void
|
2006-08-16 05:46:22 +08:00
|
|
|
gimp_brush_tool_class_init (GimpBrushToolClass *klass)
|
2001-02-27 13:21:12 +08:00
|
|
|
{
|
2006-05-28 22:13:44 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
2001-02-28 03:18:01 +08:00
|
|
|
|
2011-01-13 17:06:07 +08:00
|
|
|
object_class->constructed = gimp_brush_tool_constructed;
|
2002-02-13 22:50:37 +08:00
|
|
|
|
2010-11-10 21:20:33 +08:00
|
|
|
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;
|
2001-02-28 03:18:01 +08:00
|
|
|
|
2011-01-13 17:06:07 +08:00
|
|
|
draw_tool_class->draw = gimp_brush_tool_draw;
|
2001-02-27 13:21:12 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
static void
|
2006-08-16 05:46:22 +08:00
|
|
|
gimp_brush_tool_init (GimpBrushTool *brush_tool)
|
2001-02-28 03:18:01 +08:00
|
|
|
{
|
2006-08-16 05:46:22 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (brush_tool);
|
2002-02-05 19:35:03 +08:00
|
|
|
|
2006-11-17 21:06:00 +08:00
|
|
|
gimp_tool_control_set_action_value_2 (tool->control,
|
2010-10-31 02:38:20 +08:00
|
|
|
"tools/tools-paint-brush-size-set");
|
2005-03-05 03:05:40 +08:00
|
|
|
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");
|
2002-06-17 01:13:39 +08:00
|
|
|
|
2006-08-16 05:46:22 +08:00
|
|
|
brush_tool->show_cursor = TRUE;
|
|
|
|
brush_tool->draw_brush = TRUE;
|
|
|
|
brush_tool->brush_x = 0.0;
|
|
|
|
brush_tool->brush_y = 0.0;
|
2003-08-31 00:41:35 +08:00
|
|
|
}
|
|
|
|
|
2011-01-13 17:06:07 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_tool_constructed (GObject *object)
|
2003-08-31 00:41:35 +08:00
|
|
|
{
|
2011-01-13 17:06:07 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (object);
|
|
|
|
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (object);
|
|
|
|
GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (object);
|
2007-05-17 02:47:47 +08:00
|
|
|
GimpDisplayConfig *display_config;
|
2003-08-31 00:41:35 +08:00
|
|
|
|
2011-01-13 17:06:07 +08:00
|
|
|
if (G_OBJECT_CLASS (parent_class)->constructed)
|
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2003-08-31 00:41:35 +08:00
|
|
|
|
2006-08-16 05:46:22 +08:00
|
|
|
g_assert (GIMP_IS_BRUSH_CORE (paint_tool->core));
|
2003-08-31 00:41:35 +08:00
|
|
|
|
2007-05-17 02:47:47 +08:00
|
|
|
display_config = GIMP_DISPLAY_CONFIG (tool->tool_info->gimp->config);
|
2003-08-20 01:20:05 +08:00
|
|
|
|
2007-05-17 02:47:47 +08:00
|
|
|
brush_tool->show_cursor = display_config->show_paint_tool_cursor;
|
|
|
|
brush_tool->draw_brush = display_config->show_brush_outline;
|
|
|
|
|
|
|
|
g_signal_connect_object (display_config, "notify::show-paint-tool-cursor",
|
2006-08-16 05:46:22 +08:00
|
|
|
G_CALLBACK (gimp_brush_tool_notify_brush),
|
|
|
|
brush_tool, 0);
|
2007-05-17 02:47:47 +08:00
|
|
|
g_signal_connect_object (display_config, "notify::show-brush-outline",
|
2006-08-16 05:46:22 +08:00
|
|
|
G_CALLBACK (gimp_brush_tool_notify_brush),
|
|
|
|
brush_tool, 0);
|
2003-08-31 00:41:35 +08:00
|
|
|
|
2006-09-06 02:25:31 +08:00
|
|
|
g_signal_connect_object (gimp_tool_get_options (tool), "brush-changed",
|
2006-08-16 05:46:22 +08:00
|
|
|
G_CALLBACK (gimp_brush_tool_brush_changed),
|
|
|
|
brush_tool, 0);
|
2009-04-26 01:53:09 +08:00
|
|
|
|
2011-04-04 06:01:30 +08:00
|
|
|
g_signal_connect_object (paint_tool->core, "set-brush",
|
|
|
|
G_CALLBACK (gimp_brush_tool_set_brush),
|
|
|
|
brush_tool, 0);
|
2002-02-13 22:50:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-11-01 23:17:36 +08:00
|
|
|
gimp_brush_tool_motion (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-08-16 05:46:22 +08:00
|
|
|
GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-09-13 19:04:49 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
1999-05-13 19:12:32 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, display);
|
2003-07-11 00:01:45 +08:00
|
|
|
|
2006-08-16 05:46:22 +08:00
|
|
|
if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
|
2003-06-05 23:43:49 +08:00
|
|
|
{
|
2006-08-16 05:46:22 +08:00
|
|
|
brush_tool->brush_x = coords->x;
|
|
|
|
brush_tool->brush_y = coords->y;
|
2003-06-05 23:43:49 +08:00
|
|
|
}
|
2010-03-20 02:21:42 +08:00
|
|
|
|
2006-09-13 19:04:49 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
2003-06-05 23:43:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-11-01 23:17:36 +08:00
|
|
|
gimp_brush_tool_oper_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
gboolean proximity,
|
|
|
|
GimpDisplay *display)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-09-06 02:25:31 +08:00
|
|
|
GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (tool);
|
|
|
|
GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (tool);
|
2011-03-31 01:18:29 +08:00
|
|
|
GimpDrawable *drawable;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-09-13 19:04:49 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
2000-03-05 08:06:11 +08:00
|
|
|
|
2006-08-16 05:46:22 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state,
|
|
|
|
proximity, display);
|
1999-05-15 08:02:47 +08:00
|
|
|
|
2011-03-31 01:18:29 +08:00
|
|
|
drawable = gimp_image_get_active_drawable (gimp_display_get_image (display));
|
|
|
|
|
|
|
|
if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)) &&
|
|
|
|
drawable && proximity)
|
2002-02-19 01:00:09 +08:00
|
|
|
{
|
2006-09-13 19:04:49 +08:00
|
|
|
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
|
|
|
|
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_tool->core);
|
|
|
|
GimpBrush *brush;
|
2010-03-15 08:20:13 +08:00
|
|
|
GimpDynamics *dynamics;
|
2006-08-16 05:46:22 +08:00
|
|
|
|
2006-09-13 19:04:49 +08:00
|
|
|
brush_tool->brush_x = coords->x;
|
|
|
|
brush_tool->brush_y = coords->y;
|
2004-06-23 20:19:28 +08:00
|
|
|
|
2006-09-13 19:04:49 +08:00
|
|
|
brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));
|
2004-06-23 20:19:28 +08:00
|
|
|
|
2006-09-13 19:04:49 +08:00
|
|
|
if (brush_core->main_brush != brush)
|
|
|
|
gimp_brush_core_set_brush (brush_core, brush);
|
2010-03-15 08:20:13 +08:00
|
|
|
|
|
|
|
dynamics = gimp_context_get_dynamics (GIMP_CONTEXT (paint_options));
|
|
|
|
|
|
|
|
if (brush_core->dynamics != dynamics)
|
|
|
|
gimp_brush_core_set_dynamics (brush_core, dynamics);
|
|
|
|
|
|
|
|
if (GIMP_BRUSH_CORE_GET_CLASS (brush_core)->handles_transforming_brush)
|
|
|
|
{
|
|
|
|
gimp_brush_core_eval_transform_dynamics (paint_tool->core,
|
2010-03-17 03:51:59 +08:00
|
|
|
drawable,
|
2010-03-15 08:20:13 +08:00
|
|
|
paint_options,
|
|
|
|
coords);
|
|
|
|
}
|
2002-02-05 01:43:01 +08:00
|
|
|
}
|
2010-03-20 02:21:42 +08:00
|
|
|
|
2006-09-13 19:04:49 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
2006-08-16 05:46:22 +08:00
|
|
|
}
|
2001-02-25 03:29:47 +08:00
|
|
|
|
2006-08-16 05:46:22 +08:00
|
|
|
static void
|
2008-11-01 23:17:36 +08:00
|
|
|
gimp_brush_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
2006-08-16 05:46:22 +08:00
|
|
|
{
|
|
|
|
GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (tool);
|
2011-03-25 03:20:24 +08:00
|
|
|
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (GIMP_PAINT_TOOL (brush_tool)->core);
|
2006-08-16 05:46:22 +08:00
|
|
|
|
2011-03-25 03:20:24 +08:00
|
|
|
if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
|
2006-09-12 22:24:10 +08:00
|
|
|
{
|
2011-03-25 03:20:24 +08:00
|
|
|
if (! brush_core->main_brush || ! brush_core->dynamics)
|
|
|
|
{
|
2011-03-31 01:18:29 +08:00
|
|
|
gimp_tool_set_cursor (tool, display,
|
|
|
|
gimp_tool_control_get_cursor (tool->control),
|
|
|
|
gimp_tool_control_get_tool_cursor (tool->control),
|
|
|
|
GIMP_CURSOR_MODIFIER_BAD);
|
|
|
|
return;
|
2011-03-25 03:20:24 +08:00
|
|
|
}
|
|
|
|
else if (! brush_tool->show_cursor &&
|
|
|
|
gimp_tool_control_get_cursor_modifier (tool->control) !=
|
|
|
|
GIMP_CURSOR_MODIFIER_BAD)
|
|
|
|
{
|
|
|
|
gimp_tool_set_cursor (tool, display,
|
|
|
|
GIMP_CURSOR_NONE,
|
|
|
|
GIMP_TOOL_CURSOR_NONE,
|
|
|
|
GIMP_CURSOR_MODIFIER_NONE);
|
|
|
|
return;
|
|
|
|
}
|
2006-09-12 22:24:10 +08:00
|
|
|
}
|
2011-03-25 03:20:24 +08:00
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2010-11-10 21:20:33 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_tool_options_notify (GimpTool *tool,
|
|
|
|
GimpToolOptions *options,
|
|
|
|
const GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec);
|
|
|
|
|
|
|
|
if (! strcmp (pspec->name, "brush-size") ||
|
|
|
|
! strcmp (pspec->name, "brush-angle") ||
|
|
|
|
! strcmp (pspec->name, "brush-aspect-ratio"))
|
|
|
|
{
|
|
|
|
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
|
|
|
|
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_tool->core);
|
|
|
|
|
|
|
|
gimp_brush_core_set_brush (brush_core, brush_core->main_brush);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
static void
|
2006-08-16 05:46:22 +08:00
|
|
|
gimp_brush_tool_draw (GimpDrawTool *draw_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-09-13 19:04:49 +08:00
|
|
|
GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (draw_tool);
|
|
|
|
|
2006-08-16 05:46:22 +08:00
|
|
|
GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
|
|
|
|
|
2006-09-13 19:04:49 +08:00
|
|
|
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (draw_tool)))
|
|
|
|
return;
|
|
|
|
|
2007-05-07 18:19:04 +08:00
|
|
|
gimp_brush_tool_draw_brush (brush_tool,
|
2007-10-30 01:17:14 +08:00
|
|
|
brush_tool->brush_x, brush_tool->brush_y,
|
|
|
|
! brush_tool->show_cursor);
|
2007-05-07 18:19:04 +08:00
|
|
|
}
|
2003-07-11 00:01:45 +08:00
|
|
|
|
2007-05-07 18:19:04 +08:00
|
|
|
void
|
|
|
|
gimp_brush_tool_draw_brush (GimpBrushTool *brush_tool,
|
|
|
|
gdouble x,
|
2007-10-30 01:17:14 +08:00
|
|
|
gdouble y,
|
|
|
|
gboolean draw_fallback)
|
2007-05-07 18:19:04 +08:00
|
|
|
{
|
|
|
|
GimpDrawTool *draw_tool;
|
|
|
|
GimpBrushCore *brush_core;
|
2007-10-30 01:17:14 +08:00
|
|
|
GimpPaintOptions *options;
|
2010-10-10 04:00:19 +08:00
|
|
|
GimpMatrix3 matrix;
|
2007-05-07 18:19:04 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_BRUSH_TOOL (brush_tool));
|
|
|
|
|
2010-03-20 02:22:56 +08:00
|
|
|
if (! brush_tool->draw_brush)
|
2007-05-07 18:19:04 +08:00
|
|
|
return;
|
|
|
|
|
2007-10-30 01:17:14 +08:00
|
|
|
draw_tool = GIMP_DRAW_TOOL (brush_tool);
|
|
|
|
brush_core = GIMP_BRUSH_CORE (GIMP_PAINT_TOOL (brush_tool)->core);
|
|
|
|
options = GIMP_PAINT_TOOL_GET_OPTIONS (brush_tool);
|
2007-05-07 18:19:04 +08:00
|
|
|
|
2011-03-25 03:20:24 +08:00
|
|
|
if (! brush_core->main_brush || ! brush_core->dynamics)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (! brush_core->brush_bound_segs)
|
2010-10-10 04:00:19 +08:00
|
|
|
gimp_brush_core_create_boundary (brush_core, options);
|
2003-07-14 22:50:41 +08:00
|
|
|
|
2010-10-10 04:00:19 +08:00
|
|
|
if (brush_core->brush_bound_segs &&
|
|
|
|
gimp_brush_core_get_transform (brush_core, &matrix))
|
2007-05-07 18:19:04 +08:00
|
|
|
{
|
2009-10-05 01:56:39 +08:00
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
|
2010-03-15 08:20:13 +08:00
|
|
|
gdouble width = brush_core->transformed_brush_bound_width;
|
|
|
|
gdouble height = brush_core->transformed_brush_bound_height;
|
2003-07-14 22:50:41 +08:00
|
|
|
|
2007-10-30 01:17:14 +08:00
|
|
|
/* don't draw the boundary if it becomes too small */
|
|
|
|
if (SCALEX (shell, width) > 4 && SCALEY (shell, height) > 4)
|
2007-05-07 18:19:04 +08:00
|
|
|
{
|
2007-10-30 01:17:14 +08:00
|
|
|
x -= width / 2.0;
|
|
|
|
y -= height / 2.0;
|
2003-07-17 00:19:16 +08:00
|
|
|
|
2007-10-30 01:17:14 +08:00
|
|
|
if (gimp_paint_options_get_brush_mode (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
|
|
|
|
*/
|
|
|
|
x = RINT (x + EPSILON);
|
|
|
|
y = RINT (y + EPSILON);
|
2003-07-17 00:19:16 +08:00
|
|
|
#undef EPSILON
|
2007-10-30 01:17:14 +08:00
|
|
|
}
|
2007-05-07 18:19:04 +08:00
|
|
|
|
2010-09-26 01:02:22 +08:00
|
|
|
gimp_draw_tool_add_boundary (draw_tool,
|
2010-09-27 04:26:57 +08:00
|
|
|
brush_core->brush_bound_segs,
|
|
|
|
brush_core->n_brush_bound_segs,
|
2010-10-10 04:00:19 +08:00
|
|
|
&matrix,
|
2010-09-26 01:02:22 +08:00
|
|
|
x, y);
|
2007-10-30 01:17:14 +08:00
|
|
|
}
|
2010-03-20 02:34:07 +08:00
|
|
|
else if (draw_fallback)
|
2007-10-30 01:17:14 +08:00
|
|
|
{
|
2010-09-26 01:02:22 +08:00
|
|
|
gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_CROSS,
|
|
|
|
x, y,
|
2010-10-19 02:13:09 +08:00
|
|
|
5, 5, GIMP_HANDLE_ANCHOR_CENTER);
|
2007-10-30 01:17:14 +08:00
|
|
|
}
|
2002-02-07 19:33:01 +08:00
|
|
|
}
|
2004-06-05 07:08:29 +08:00
|
|
|
}
|
|
|
|
|
2006-05-07 05:10:32 +08:00
|
|
|
static void
|
2006-08-16 05:46:22 +08:00
|
|
|
gimp_brush_tool_brush_changed (GimpContext *context,
|
2006-05-07 05:10:32 +08:00
|
|
|
GimpBrush *brush,
|
2006-08-16 05:46:22 +08:00
|
|
|
GimpBrushTool *brush_tool)
|
2006-05-07 05:10:32 +08:00
|
|
|
{
|
2006-08-16 05:46:22 +08:00
|
|
|
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (brush_tool);
|
2006-05-07 05:10:32 +08:00
|
|
|
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_tool->core);
|
|
|
|
|
|
|
|
if (brush_core->main_brush != brush)
|
|
|
|
gimp_brush_core_set_brush (brush_core, brush);
|
2010-03-17 03:51:59 +08:00
|
|
|
|
2006-05-07 05:10:32 +08:00
|
|
|
}
|
|
|
|
|
2004-06-23 20:19:28 +08:00
|
|
|
static void
|
2006-08-16 05:46:22 +08:00
|
|
|
gimp_brush_tool_set_brush (GimpBrushCore *brush_core,
|
2004-06-23 20:19:28 +08:00
|
|
|
GimpBrush *brush,
|
2006-08-16 05:46:22 +08:00
|
|
|
GimpBrushTool *brush_tool)
|
2004-06-23 20:19:28 +08:00
|
|
|
{
|
2010-03-17 03:51:59 +08:00
|
|
|
GimpPaintCore *paint_core = GIMP_PAINT_CORE (brush_core);
|
2010-10-05 05:37:14 +08:00
|
|
|
|
2006-08-16 05:46:22 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (brush_tool));
|
2010-03-17 03:51:59 +08:00
|
|
|
|
|
|
|
if (GIMP_BRUSH_CORE_GET_CLASS (brush_core)->handles_transforming_brush)
|
|
|
|
{
|
|
|
|
gimp_brush_core_eval_transform_dynamics (paint_core,
|
|
|
|
NULL,
|
|
|
|
GIMP_PAINT_TOOL_GET_OPTIONS (brush_tool),
|
|
|
|
&paint_core->cur_coords);
|
|
|
|
}
|
2004-06-23 20:19:28 +08:00
|
|
|
|
2006-08-16 05:46:22 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (brush_tool));
|
2004-06-23 20:19:28 +08:00
|
|
|
}
|
|
|
|
|
2003-08-20 01:20:05 +08:00
|
|
|
static void
|
2006-08-16 05:46:22 +08:00
|
|
|
gimp_brush_tool_notify_brush (GimpDisplayConfig *config,
|
2003-08-20 01:20:05 +08:00
|
|
|
GParamSpec *pspec,
|
2006-08-16 05:46:22 +08:00
|
|
|
GimpBrushTool *brush_tool)
|
2003-08-20 01:20:05 +08:00
|
|
|
{
|
2006-08-16 05:46:22 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (brush_tool));
|
2003-08-20 01:20:05 +08:00
|
|
|
|
2006-08-16 05:46:22 +08:00
|
|
|
brush_tool->show_cursor = config->show_paint_tool_cursor;
|
|
|
|
brush_tool->draw_brush = config->show_brush_outline;
|
2003-08-20 01:20:05 +08:00
|
|
|
|
2006-08-16 05:46:22 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (brush_tool));
|
2003-08-20 01:20:05 +08:00
|
|
|
}
|