2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-24 22:05:25 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2014-06-07 23:18:29 -04:00
|
|
|
* Major improvements for interactivity
|
|
|
|
* Copyright (C) 2014 Michael Henning <drawoc@darkrefraction.com>
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-24 22:05:25 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-24 22:05:25 +00: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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-24 22:05:25 +00:00
|
|
|
*/
|
2000-12-16 21:37:03 +00: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-01 20:30:56 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2000-12-16 21:37:03 +00:00
|
|
|
#include <gtk/gtk.h>
|
2014-06-07 23:18:29 -04:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2000-12-16 21:37:03 +00:00
|
|
|
|
2001-01-24 22:36:18 +00:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-23 23:56:18 +00:00
|
|
|
|
2002-05-03 12:45:22 +00:00
|
|
|
#include "tools-types.h"
|
2000-12-16 21:37:03 +00:00
|
|
|
|
2019-02-06 15:22:27 -05:00
|
|
|
#include "config/gimpguiconfig.h"
|
|
|
|
|
2019-07-28 11:53:03 +03:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
|
|
|
|
2017-02-05 20:17:31 +01:00
|
|
|
#include "operations/gimp-operation-config.h"
|
2016-02-03 14:29:23 +01:00
|
|
|
|
2018-04-25 11:12:47 -04:00
|
|
|
#include "operations/layer-modes/gimp-layer-modes.h"
|
|
|
|
|
2019-02-06 15:22:27 -05:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimpdrawable.h"
|
2018-04-14 00:52:20 +02:00
|
|
|
#include "core/gimpdrawable-gradient.h"
|
2016-05-12 01:49:53 +02:00
|
|
|
#include "core/gimpdrawablefilter.h"
|
2008-11-12 10:56:06 +00:00
|
|
|
#include "core/gimperror.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimpgradient.h"
|
|
|
|
#include "core/gimpimage.h"
|
2004-08-10 18:47:21 +00:00
|
|
|
#include "core/gimpprogress.h"
|
2014-06-20 11:28:01 -04:00
|
|
|
#include "core/gimpprojection.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
|
2003-08-22 01:42:57 +00:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2007-01-21 01:24:51 +00:00
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2003-08-22 01:42:57 +00:00
|
|
|
|
2001-09-25 23:23:09 +00:00
|
|
|
#include "display/gimpdisplay.h"
|
2017-06-10 23:54:11 +02:00
|
|
|
#include "display/gimptoolline.h"
|
2001-09-25 23:23:09 +00:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
#include "gimpgradientoptions.h"
|
|
|
|
#include "gimpgradienttool.h"
|
|
|
|
#include "gimpgradienttool-editor.h"
|
2003-04-15 16:05:52 +00:00
|
|
|
#include "gimptoolcontrol.h"
|
2018-12-10 08:22:50 -05:00
|
|
|
#include "gimptools-utils.h"
|
2001-03-11 20:01:14 +00:00
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
2000-04-27 17:27:28 +00:00
|
|
|
|
2016-02-02 00:38:26 +01:00
|
|
|
|
2001-03-11 20:01:14 +00:00
|
|
|
/* local function prototypes */
|
1999-04-08 22:25:54 +00:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
static void gimp_gradient_tool_dispose (GObject *object);
|
|
|
|
|
|
|
|
static gboolean gimp_gradient_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error);
|
|
|
|
static void gimp_gradient_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_gradient_tool_button_press (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonPressType press_type,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_gradient_tool_button_release (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_gradient_tool_motion (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static gboolean gimp_gradient_tool_key_press (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_gradient_tool_modifier_key (GimpTool *tool,
|
|
|
|
GdkModifierType key,
|
|
|
|
gboolean press,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_gradient_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static const gchar * gimp_gradient_tool_can_undo (GimpTool *tool,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static const gchar * gimp_gradient_tool_can_redo (GimpTool *tool,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static gboolean gimp_gradient_tool_undo (GimpTool *tool,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static gboolean gimp_gradient_tool_redo (GimpTool *tool,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_gradient_tool_options_notify (GimpTool *tool,
|
|
|
|
GimpToolOptions *options,
|
|
|
|
const GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gimp_gradient_tool_start (GimpGradientTool *gradient_tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_gradient_tool_halt (GimpGradientTool *gradient_tool);
|
|
|
|
static void gimp_gradient_tool_commit (GimpGradientTool *gradient_tool);
|
|
|
|
|
|
|
|
static void gimp_gradient_tool_line_changed (GimpToolWidget *widget,
|
|
|
|
GimpGradientTool *gradient_tool);
|
|
|
|
static void gimp_gradient_tool_line_response (GimpToolWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
GimpGradientTool *gradient_tool);
|
|
|
|
|
|
|
|
static void gimp_gradient_tool_precalc_shapeburst (GimpGradientTool *gradient_tool);
|
|
|
|
|
|
|
|
static void gimp_gradient_tool_create_graph (GimpGradientTool *gradient_tool);
|
|
|
|
static void gimp_gradient_tool_update_graph (GimpGradientTool *gradient_tool);
|
|
|
|
|
|
|
|
static void gimp_gradient_tool_fg_bg_changed (GimpGradientTool *gradient_tool);
|
|
|
|
|
|
|
|
static void gimp_gradient_tool_gradient_dirty (GimpGradientTool *gradient_tool);
|
|
|
|
static void gimp_gradient_tool_set_gradient (GimpGradientTool *gradient_tool,
|
|
|
|
GimpGradient *gradient);
|
|
|
|
|
|
|
|
static gboolean gimp_gradient_tool_is_shapeburst (GimpGradientTool *gradient_tool);
|
|
|
|
|
|
|
|
static void gimp_gradient_tool_create_filter (GimpGradientTool *gradient_tool,
|
|
|
|
GimpDrawable *drawable);
|
|
|
|
static void gimp_gradient_tool_filter_flush (GimpDrawableFilter *filter,
|
|
|
|
GimpTool *tool);
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpGradientTool, gimp_gradient_tool, GIMP_TYPE_DRAW_TOOL)
|
|
|
|
|
|
|
|
#define parent_class gimp_gradient_tool_parent_class
|
1999-04-08 22:25:54 +00:00
|
|
|
|
2001-11-09 16:54:56 +00:00
|
|
|
|
2001-03-11 20:01:14 +00:00
|
|
|
void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_register (GimpToolRegisterCallback callback,
|
|
|
|
gpointer data)
|
2001-03-11 20:01:14 +00:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
(* callback) (GIMP_TYPE_GRADIENT_TOOL,
|
|
|
|
GIMP_TYPE_GRADIENT_OPTIONS,
|
|
|
|
gimp_gradient_options_gui,
|
2015-09-08 21:18:49 +02:00
|
|
|
GIMP_CONTEXT_PROP_MASK_FOREGROUND |
|
|
|
|
GIMP_CONTEXT_PROP_MASK_BACKGROUND |
|
|
|
|
GIMP_CONTEXT_PROP_MASK_OPACITY |
|
|
|
|
GIMP_CONTEXT_PROP_MASK_PAINT_MODE |
|
|
|
|
GIMP_CONTEXT_PROP_MASK_GRADIENT,
|
2018-04-14 00:52:20 +02:00
|
|
|
"gimp-gradient-tool",
|
|
|
|
_("Gradient"),
|
|
|
|
_("Gradient Tool: Fill selected area with a color gradient"),
|
|
|
|
N_("Gra_dient"), "G",
|
|
|
|
NULL, GIMP_HELP_TOOL_GRADIENT,
|
2018-04-13 23:07:08 +02:00
|
|
|
GIMP_ICON_TOOL_GRADIENT,
|
2002-05-03 11:31:08 +00:00
|
|
|
data);
|
1999-04-08 22:25:54 +00:00
|
|
|
}
|
|
|
|
|
2001-03-11 20:01:14 +00:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_class_init (GimpGradientToolClass *klass)
|
2001-03-11 20:01:14 +00:00
|
|
|
{
|
2017-06-26 19:50:31 +02:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
2000-02-13 22:26:41 +00:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
object_class->dispose = gimp_gradient_tool_dispose;
|
|
|
|
|
|
|
|
tool_class->initialize = gimp_gradient_tool_initialize;
|
|
|
|
tool_class->control = gimp_gradient_tool_control;
|
|
|
|
tool_class->button_press = gimp_gradient_tool_button_press;
|
|
|
|
tool_class->button_release = gimp_gradient_tool_button_release;
|
|
|
|
tool_class->motion = gimp_gradient_tool_motion;
|
|
|
|
tool_class->key_press = gimp_gradient_tool_key_press;
|
|
|
|
tool_class->modifier_key = gimp_gradient_tool_modifier_key;
|
|
|
|
tool_class->cursor_update = gimp_gradient_tool_cursor_update;
|
|
|
|
tool_class->can_undo = gimp_gradient_tool_can_undo;
|
|
|
|
tool_class->can_redo = gimp_gradient_tool_can_redo;
|
|
|
|
tool_class->undo = gimp_gradient_tool_undo;
|
|
|
|
tool_class->redo = gimp_gradient_tool_redo;
|
|
|
|
tool_class->options_notify = gimp_gradient_tool_options_notify;
|
2001-03-11 20:01:14 +00:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-03-11 20:01:14 +00:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_init (GimpGradientTool *gradient_tool)
|
2001-03-11 20:01:14 +00:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpTool *tool = GIMP_TOOL (gradient_tool);
|
2002-02-04 17:43:01 +00:00
|
|
|
|
2017-08-01 18:45:13 -04:00
|
|
|
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
|
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
|
|
|
gimp_tool_control_set_dirty_mask (tool->control,
|
|
|
|
GIMP_DIRTY_IMAGE |
|
|
|
|
GIMP_DIRTY_IMAGE_STRUCTURE |
|
|
|
|
GIMP_DIRTY_DRAWABLE |
|
|
|
|
GIMP_DIRTY_ACTIVE_DRAWABLE);
|
2018-09-29 12:25:51 -04:00
|
|
|
gimp_tool_control_set_dirty_action (tool->control,
|
|
|
|
GIMP_TOOL_ACTION_COMMIT);
|
2017-08-01 18:45:13 -04:00
|
|
|
gimp_tool_control_set_wants_click (tool->control, TRUE);
|
|
|
|
gimp_tool_control_set_wants_double_click (tool->control, TRUE);
|
2017-10-29 16:38:24 +01:00
|
|
|
gimp_tool_control_set_active_modifiers (tool->control,
|
|
|
|
GIMP_TOOL_ACTIVE_MODIFIERS_SEPARATE);
|
2017-08-01 18:45:13 -04:00
|
|
|
gimp_tool_control_set_precision (tool->control,
|
|
|
|
GIMP_CURSOR_PRECISION_SUBPIXEL);
|
|
|
|
gimp_tool_control_set_tool_cursor (tool->control,
|
2018-04-13 23:27:03 +02:00
|
|
|
GIMP_TOOL_CURSOR_GRADIENT);
|
2017-08-01 18:45:13 -04:00
|
|
|
gimp_tool_control_set_action_opacity (tool->control,
|
2023-02-26 19:53:24 +01:00
|
|
|
"context-opacity-set");
|
2017-08-01 18:45:13 -04:00
|
|
|
gimp_tool_control_set_action_object_1 (tool->control,
|
2023-02-26 19:53:24 +01:00
|
|
|
"context-gradient-select-set");
|
2017-06-26 21:48:43 +02:00
|
|
|
|
|
|
|
gimp_draw_tool_set_default_status (GIMP_DRAW_TOOL (tool),
|
|
|
|
_("Click-Drag to draw a gradient"));
|
2001-03-11 20:01:14 +00:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2016-02-02 00:38:26 +01:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_dispose (GObject *object)
|
2016-02-02 00:38:26 +01:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (object);
|
2016-02-02 00:38:26 +01:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_set_gradient (gradient_tool, NULL);
|
2016-02-02 00:38:26 +01:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2006-09-26 20:55:40 +00:00
|
|
|
static gboolean
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error)
|
2006-09-26 20:55:40 +00:00
|
|
|
{
|
2022-02-15 15:42:44 +01:00
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (tool);
|
|
|
|
GimpGuiConfig *config = GIMP_GUI_CONFIG (display->gimp->config);
|
|
|
|
GimpItem *locked_item = NULL;
|
2020-05-25 11:30:31 +02:00
|
|
|
GList *drawables;
|
2020-05-18 11:37:25 +02:00
|
|
|
GimpDrawable *drawable;
|
2006-09-26 20:55:40 +00:00
|
|
|
|
|
|
|
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-05-25 11:30:31 +02:00
|
|
|
drawables = gimp_image_get_selected_drawables (image);
|
2020-05-18 11:37:25 +02:00
|
|
|
if (g_list_length (drawables) != 1)
|
|
|
|
{
|
|
|
|
if (g_list_length (drawables) > 1)
|
|
|
|
gimp_tool_message_literal (tool, display,
|
|
|
|
_("Cannot paint on multiple drawables. Select only one."));
|
|
|
|
else
|
|
|
|
gimp_tool_message_literal (tool, display, _("No active drawables."));
|
|
|
|
|
|
|
|
g_list_free (drawables);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only a single drawable at this point. */
|
|
|
|
drawable = drawables->data;
|
|
|
|
g_list_free (drawables);
|
|
|
|
|
2009-08-28 20:07:14 +02:00
|
|
|
if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
2016-11-25 00:04:04 +01:00
|
|
|
_("Cannot modify the pixels of layer groups."));
|
2009-08-28 20:07:14 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-02-15 15:42:44 +01:00
|
|
|
if (gimp_item_is_content_locked (GIMP_ITEM (drawable), &locked_item))
|
2009-08-20 17:05:23 +02:00
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
2022-02-15 15:42:44 +01:00
|
|
|
_("The selected layer's pixels are locked."));
|
2018-12-10 08:22:50 -05:00
|
|
|
if (error)
|
2022-02-15 15:42:44 +01:00
|
|
|
gimp_tools_blink_lock_box (display->gimp, locked_item);
|
2009-08-20 17:05:23 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-06-24 15:57:21 +02:00
|
|
|
if (! gimp_item_is_visible (GIMP_ITEM (drawable)) &&
|
|
|
|
! config->edit_non_visible)
|
2013-04-24 16:27:12 +02:00
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
2022-02-15 15:42:44 +01:00
|
|
|
_("The selected item is not visible."));
|
2013-04-24 16:27:12 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-04-03 00:32:59 +02:00
|
|
|
if (! gimp_context_get_gradient (GIMP_CONTEXT (options)))
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
|
|
|
_("No gradient available for use with this tool."));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-09-26 20:55:40 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-06-07 23:18:29 -04:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *display)
|
2014-06-07 23:18:29 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (tool);
|
2014-06-07 23:18:29 -04:00
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case GIMP_TOOL_ACTION_PAUSE:
|
|
|
|
case GIMP_TOOL_ACTION_RESUME:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_TOOL_ACTION_HALT:
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_halt (gradient_tool);
|
2014-06-07 23:18:29 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_TOOL_ACTION_COMMIT:
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_commit (gradient_tool);
|
2014-06-07 23:18:29 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
|
|
|
|
}
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_button_press (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonPressType press_type,
|
|
|
|
GimpDisplay *display)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (tool);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2014-06-07 23:18:29 -04:00
|
|
|
if (tool->display && display != tool->display)
|
2017-06-26 21:48:43 +02:00
|
|
|
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, tool->display);
|
2014-06-07 23:18:29 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (! gradient_tool->widget)
|
2014-06-24 20:27:58 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_start (gradient_tool, coords, display);
|
2017-06-26 21:48:43 +02:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_tool_widget_hover (gradient_tool->widget, coords, state, TRUE);
|
2016-02-02 00:38:26 +01:00
|
|
|
}
|
2014-06-07 23:18:29 -04:00
|
|
|
|
app: implement tool undo for gradient editing in the blend tool
Move the tool undo functionality of the blend tool to the editor,
and add support for undoing gradient edit operations. Each undo
step that affects the gradient holds, in addition to the line
endpoint poisitions, a copy of the gradient at the beginning of the
operation, as well as necessary information to allow the selection
to "follow" undo. When undoing the operation, the saved gradient
is copied back to the active gradient.
To avoid all kinds of complex scenarios, when the active gradient
changes, or when the gradient is modified externally (e.g., by the
(old) gradient editor), all undo steps that affect the gradient are
deleted from the history, while those that affect only the endpoint
positions are kept.
2017-08-03 19:59:21 -04:00
|
|
|
/* call start_edit() before widget_button_press(), because we need to record
|
|
|
|
* the undo state before widget_button_press() potentially changes it. note
|
|
|
|
* that if widget_button_press() return FALSE, nothing changes and no undo
|
|
|
|
* step is created.
|
2017-06-10 23:54:11 +02:00
|
|
|
*/
|
app: implement tool undo for gradient editing in the blend tool
Move the tool undo functionality of the blend tool to the editor,
and add support for undoing gradient edit operations. Each undo
step that affects the gradient holds, in addition to the line
endpoint poisitions, a copy of the gradient at the beginning of the
operation, as well as necessary information to allow the selection
to "follow" undo. When undoing the operation, the saved gradient
is copied back to the active gradient.
To avoid all kinds of complex scenarios, when the active gradient
changes, or when the gradient is modified externally (e.g., by the
(old) gradient editor), all undo steps that affect the gradient are
deleted from the history, while those that affect only the endpoint
positions are kept.
2017-08-03 19:59:21 -04:00
|
|
|
if (press_type == GIMP_BUTTON_PRESS_NORMAL)
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_editor_start_edit (gradient_tool);
|
2017-06-10 23:54:11 +02:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gimp_tool_widget_button_press (gradient_tool->widget, coords, time, state,
|
2017-06-10 23:54:11 +02:00
|
|
|
press_type))
|
2017-04-28 00:27:34 +02:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->grab_widget = gradient_tool->widget;
|
2017-04-28 00:27:34 +02:00
|
|
|
}
|
|
|
|
|
2017-08-01 18:45:13 -04:00
|
|
|
if (press_type == GIMP_BUTTON_PRESS_NORMAL)
|
|
|
|
gimp_tool_control_activate (tool->control);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_button_release (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
GimpDisplay *display)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (tool);
|
|
|
|
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (tool);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2006-03-28 17:55:52 +00:00
|
|
|
gimp_tool_pop_status (tool, display);
|
1998-07-26 21:49:42 +00:00
|
|
|
|
2003-01-03 13:59:23 +00:00
|
|
|
gimp_tool_control_halt (tool->control);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gradient_tool->grab_widget)
|
2014-08-04 17:17:01 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_tool_widget_button_release (gradient_tool->grab_widget,
|
2017-06-10 23:54:11 +02:00
|
|
|
coords, time, state, release_type);
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->grab_widget = NULL;
|
2014-08-04 17:17:01 -04:00
|
|
|
|
2017-08-01 08:14:10 -04:00
|
|
|
if (options->instant)
|
2017-04-28 00:27:34 +02:00
|
|
|
{
|
2017-08-01 08:14:10 -04:00
|
|
|
if (release_type == GIMP_BUTTON_RELEASE_CANCEL)
|
|
|
|
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
|
|
|
|
else
|
|
|
|
gimp_tool_control (tool, GIMP_TOOL_ACTION_COMMIT, display);
|
2017-04-28 00:27:34 +02:00
|
|
|
}
|
app: implement tool undo for gradient editing in the blend tool
Move the tool undo functionality of the blend tool to the editor,
and add support for undoing gradient edit operations. Each undo
step that affects the gradient holds, in addition to the line
endpoint poisitions, a copy of the gradient at the beginning of the
operation, as well as necessary information to allow the selection
to "follow" undo. When undoing the operation, the saved gradient
is copied back to the active gradient.
To avoid all kinds of complex scenarios, when the active gradient
changes, or when the gradient is modified externally (e.g., by the
(old) gradient editor), all undo steps that affect the gradient are
deleted from the history, while those that affect only the endpoint
positions are kept.
2017-08-03 19:59:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! options->instant)
|
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_editor_end_edit (gradient_tool,
|
|
|
|
release_type ==
|
|
|
|
GIMP_BUTTON_RELEASE_CANCEL);
|
2017-06-10 23:54:11 +02:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_motion (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (tool);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gradient_tool->grab_widget)
|
2017-06-11 18:16:47 +02:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_tool_widget_motion (gradient_tool->grab_widget, coords, time, state);
|
2017-06-11 18:16:47 +02:00
|
|
|
}
|
2006-09-12 19:36:05 +00:00
|
|
|
}
|
|
|
|
|
app: implement tool undo for gradient editing in the blend tool
Move the tool undo functionality of the blend tool to the editor,
and add support for undoing gradient edit operations. Each undo
step that affects the gradient holds, in addition to the line
endpoint poisitions, a copy of the gradient at the beginning of the
operation, as well as necessary information to allow the selection
to "follow" undo. When undoing the operation, the saved gradient
is copied back to the active gradient.
To avoid all kinds of complex scenarios, when the active gradient
changes, or when the gradient is modified externally (e.g., by the
(old) gradient editor), all undo steps that affect the gradient are
deleted from the history, while those that affect only the endpoint
positions are kept.
2017-08-03 19:59:21 -04:00
|
|
|
static gboolean
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_key_press (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display)
|
app: implement tool undo for gradient editing in the blend tool
Move the tool undo functionality of the blend tool to the editor,
and add support for undoing gradient edit operations. Each undo
step that affects the gradient holds, in addition to the line
endpoint poisitions, a copy of the gradient at the beginning of the
operation, as well as necessary information to allow the selection
to "follow" undo. When undoing the operation, the saved gradient
is copied back to the active gradient.
To avoid all kinds of complex scenarios, when the active gradient
changes, or when the gradient is modified externally (e.g., by the
(old) gradient editor), all undo steps that affect the gradient are
deleted from the history, while those that affect only the endpoint
positions are kept.
2017-08-03 19:59:21 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (tool);
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
gboolean result;
|
app: implement tool undo for gradient editing in the blend tool
Move the tool undo functionality of the blend tool to the editor,
and add support for undoing gradient edit operations. Each undo
step that affects the gradient holds, in addition to the line
endpoint poisitions, a copy of the gradient at the beginning of the
operation, as well as necessary information to allow the selection
to "follow" undo. When undoing the operation, the saved gradient
is copied back to the active gradient.
To avoid all kinds of complex scenarios, when the active gradient
changes, or when the gradient is modified externally (e.g., by the
(old) gradient editor), all undo steps that affect the gradient are
deleted from the history, while those that affect only the endpoint
positions are kept.
2017-08-03 19:59:21 -04:00
|
|
|
|
|
|
|
/* call start_edit() before widget_key_press(), because we need to record the
|
|
|
|
* undo state before widget_key_press() potentially changes it. note that if
|
|
|
|
* widget_key_press() return FALSE, nothing changes and no undo step is
|
|
|
|
* created.
|
|
|
|
*/
|
|
|
|
if (display == draw_tool->display)
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_editor_start_edit (gradient_tool);
|
app: implement tool undo for gradient editing in the blend tool
Move the tool undo functionality of the blend tool to the editor,
and add support for undoing gradient edit operations. Each undo
step that affects the gradient holds, in addition to the line
endpoint poisitions, a copy of the gradient at the beginning of the
operation, as well as necessary information to allow the selection
to "follow" undo. When undoing the operation, the saved gradient
is copied back to the active gradient.
To avoid all kinds of complex scenarios, when the active gradient
changes, or when the gradient is modified externally (e.g., by the
(old) gradient editor), all undo steps that affect the gradient are
deleted from the history, while those that affect only the endpoint
positions are kept.
2017-08-03 19:59:21 -04:00
|
|
|
|
|
|
|
result = GIMP_TOOL_CLASS (parent_class)->key_press (tool, kevent, display);
|
|
|
|
|
|
|
|
if (display == draw_tool->display)
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_editor_end_edit (gradient_tool, FALSE);
|
app: implement tool undo for gradient editing in the blend tool
Move the tool undo functionality of the blend tool to the editor,
and add support for undoing gradient edit operations. Each undo
step that affects the gradient holds, in addition to the line
endpoint poisitions, a copy of the gradient at the beginning of the
operation, as well as necessary information to allow the selection
to "follow" undo. When undoing the operation, the saved gradient
is copied back to the active gradient.
To avoid all kinds of complex scenarios, when the active gradient
changes, or when the gradient is modified externally (e.g., by the
(old) gradient editor), all undo steps that affect the gradient are
deleted from the history, while those that affect only the endpoint
positions are kept.
2017-08-03 19:59:21 -04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-08-01 08:14:10 -04:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_modifier_key (GimpTool *tool,
|
|
|
|
GdkModifierType key,
|
|
|
|
gboolean press,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
2017-08-01 08:14:10 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (tool);
|
2017-08-01 08:14:10 -04:00
|
|
|
|
|
|
|
if (key == gimp_get_extend_selection_mask ())
|
|
|
|
{
|
|
|
|
if (options->instant_toggle &&
|
|
|
|
gtk_widget_get_sensitive (options->instant_toggle))
|
|
|
|
{
|
|
|
|
g_object_set (options,
|
|
|
|
"instant", ! options->instant,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2020-05-18 11:37:25 +02:00
|
|
|
GimpGuiConfig *config = GIMP_GUI_CONFIG (display->gimp->config);
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GList *drawables = gimp_image_get_selected_drawables (image);
|
|
|
|
|
2022-02-15 15:42:44 +01:00
|
|
|
if (g_list_length (drawables) != 1 ||
|
|
|
|
gimp_viewable_get_children (drawables->data) ||
|
|
|
|
gimp_item_is_content_locked (drawables->data, NULL) ||
|
2020-05-18 11:37:25 +02:00
|
|
|
! (gimp_item_is_visible (drawables->data) ||
|
2019-06-24 15:57:21 +02:00
|
|
|
config->edit_non_visible))
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2017-06-27 22:41:25 +02: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);
|
2020-05-25 11:30:31 +02:00
|
|
|
g_list_free (drawables);
|
2017-06-27 22:41:25 +02:00
|
|
|
return;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2020-05-25 11:30:31 +02:00
|
|
|
g_list_free (drawables);
|
2002-02-04 17:43:01 +00:00
|
|
|
|
2006-03-28 17:55:52 +00:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 00:27:34 +02:00
|
|
|
static const gchar *
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_can_undo (GimpTool *tool,
|
|
|
|
GimpDisplay *display)
|
2017-04-28 00:27:34 +02:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
return gimp_gradient_tool_editor_can_undo (GIMP_GRADIENT_TOOL (tool));
|
2017-04-28 00:27:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_can_redo (GimpTool *tool,
|
|
|
|
GimpDisplay *display)
|
2017-04-28 00:27:34 +02:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
return gimp_gradient_tool_editor_can_redo (GIMP_GRADIENT_TOOL (tool));
|
2017-04-28 00:27:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_undo (GimpTool *tool,
|
|
|
|
GimpDisplay *display)
|
2017-04-28 00:27:34 +02:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
return gimp_gradient_tool_editor_undo (GIMP_GRADIENT_TOOL (tool));
|
2017-04-28 00:27:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_redo (GimpTool *tool,
|
|
|
|
GimpDisplay *display)
|
2017-04-28 00:27:34 +02:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
return gimp_gradient_tool_editor_redo (GIMP_GRADIENT_TOOL (tool));
|
2017-04-28 00:27:34 +02:00
|
|
|
}
|
|
|
|
|
2016-02-02 00:38:26 +01:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_options_notify (GimpTool *tool,
|
|
|
|
GimpToolOptions *options,
|
|
|
|
const GParamSpec *pspec)
|
2016-02-02 00:38:26 +01:00
|
|
|
{
|
|
|
|
GimpContext *context = GIMP_CONTEXT (options);
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (tool);
|
2016-02-02 00:38:26 +01:00
|
|
|
|
|
|
|
if (! strcmp (pspec->name, "gradient"))
|
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_set_gradient (gradient_tool, context->gradient);
|
2016-02-02 00:38:26 +01:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gradient_tool->filter)
|
|
|
|
gimp_drawable_filter_apply (gradient_tool->filter, NULL);
|
2016-02-02 00:38:26 +01:00
|
|
|
}
|
2018-04-14 00:52:20 +02:00
|
|
|
else if (gradient_tool->render_node &&
|
|
|
|
gegl_node_find_property (gradient_tool->render_node, pspec->name))
|
2016-02-02 00:38:26 +01:00
|
|
|
{
|
|
|
|
/* Sync any property changes on the config object that match the op */
|
|
|
|
GValue value = G_VALUE_INIT;
|
2016-05-18 09:47:58 +02:00
|
|
|
|
2016-02-02 00:38:26 +01:00
|
|
|
g_value_init (&value, pspec->value_type);
|
|
|
|
|
|
|
|
g_object_get_property (G_OBJECT (options), pspec->name, &value);
|
2018-04-14 00:52:20 +02:00
|
|
|
gegl_node_set_property (gradient_tool->render_node, pspec->name, &value);
|
2016-02-02 00:38:26 +01:00
|
|
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
|
|
|
if (! strcmp (pspec->name, "gradient-type"))
|
|
|
|
{
|
2018-03-15 14:53:49 +01:00
|
|
|
GimpRepeatMode gradient_repeat;
|
|
|
|
GimpRepeatMode node_repeat;
|
|
|
|
GimpGradientType gradient_type;
|
|
|
|
|
|
|
|
gradient_repeat = GIMP_PAINT_OPTIONS (options)->gradient_options->gradient_repeat;
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_type = GIMP_GRADIENT_OPTIONS (options)->gradient_type;
|
|
|
|
gegl_node_get (gradient_tool->render_node,
|
2018-03-15 14:53:49 +01:00
|
|
|
"gradient-repeat", &node_repeat,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (gradient_type >= GIMP_GRADIENT_SHAPEBURST_ANGULAR)
|
|
|
|
{
|
|
|
|
/* These gradient types are only meant to work with repeat
|
|
|
|
* value of "none" so these are the only ones where we
|
2018-04-14 00:52:20 +02:00
|
|
|
* don't keep the render node and the gradient options in
|
2018-03-15 14:53:49 +01:00
|
|
|
* sync.
|
|
|
|
* We could instead reset the "gradient-repeat" value on
|
2018-04-14 00:52:20 +02:00
|
|
|
* GimpGradientOptions, but I assume one would want to revert
|
2018-03-15 14:53:49 +01:00
|
|
|
* back to the last set value if changing back the
|
|
|
|
* gradient type. So instead we just make the option
|
|
|
|
* insensitive (both in GUI and in render).
|
|
|
|
*/
|
|
|
|
if (node_repeat != GIMP_REPEAT_NONE)
|
2018-04-14 00:52:20 +02:00
|
|
|
gegl_node_set (gradient_tool->render_node,
|
2018-03-15 14:53:49 +01:00
|
|
|
"gradient-repeat", GIMP_REPEAT_NONE,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else if (node_repeat != gradient_repeat)
|
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
gegl_node_set (gradient_tool->render_node,
|
2018-03-15 14:53:49 +01:00
|
|
|
"gradient-repeat", gradient_repeat,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gimp_gradient_tool_is_shapeburst (gradient_tool))
|
|
|
|
gimp_gradient_tool_precalc_shapeburst (gradient_tool);
|
2016-02-02 00:38:26 +01:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_update_graph (gradient_tool);
|
2016-02-02 00:38:26 +01:00
|
|
|
}
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_drawable_filter_apply (gradient_tool->filter, NULL);
|
2016-02-02 00:38:26 +01:00
|
|
|
}
|
2018-04-14 00:52:20 +02:00
|
|
|
else if (gradient_tool->render_node &&
|
|
|
|
gimp_gradient_tool_is_shapeburst (gradient_tool) &&
|
2018-03-14 19:54:10 +01:00
|
|
|
g_strcmp0 (pspec->name, "distance-metric") == 0)
|
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
g_clear_object (&gradient_tool->dist_buffer);
|
|
|
|
gimp_gradient_tool_precalc_shapeburst (gradient_tool);
|
|
|
|
gimp_gradient_tool_update_graph (gradient_tool);
|
|
|
|
gimp_drawable_filter_apply (gradient_tool->filter, NULL);
|
2018-03-14 19:54:10 +01:00
|
|
|
}
|
2018-04-14 00:52:20 +02:00
|
|
|
else if (gradient_tool->filter &&
|
2016-05-18 09:47:58 +02:00
|
|
|
! strcmp (pspec->name, "opacity"))
|
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_drawable_filter_set_opacity (gradient_tool->filter,
|
2016-05-18 09:47:58 +02:00
|
|
|
gimp_context_get_opacity (context));
|
|
|
|
}
|
2018-04-14 00:52:20 +02:00
|
|
|
else if (gradient_tool->filter &&
|
2016-05-18 09:47:58 +02:00
|
|
|
! strcmp (pspec->name, "paint-mode"))
|
2016-02-02 00:38:26 +01:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_drawable_filter_set_mode (gradient_tool->filter,
|
2017-02-02 00:38:25 +01:00
|
|
|
gimp_context_get_paint_mode (context),
|
2017-02-12 23:49:26 +01:00
|
|
|
GIMP_LAYER_COLOR_SPACE_AUTO,
|
|
|
|
GIMP_LAYER_COLOR_SPACE_AUTO,
|
2018-04-25 11:12:47 -04:00
|
|
|
gimp_layer_mode_get_paint_composite_mode (
|
|
|
|
gimp_context_get_paint_mode (context)));
|
2016-02-02 00:38:26 +01:00
|
|
|
}
|
2017-08-01 11:33:36 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_editor_options_notify (gradient_tool, options, pspec);
|
2016-02-02 00:38:26 +01:00
|
|
|
}
|
|
|
|
|
2014-06-07 23:18:29 -04:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_start (GimpGradientTool *gradient_tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GimpDisplay *display)
|
2014-06-07 23:18:29 -04:00
|
|
|
{
|
2020-05-18 11:37:25 +02:00
|
|
|
GimpTool *tool = GIMP_TOOL (gradient_tool);
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GList *drawables = gimp_image_get_selected_drawables (image);
|
|
|
|
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
|
|
|
|
GimpContext *context = GIMP_CONTEXT (options);
|
|
|
|
|
|
|
|
g_return_if_fail (g_list_length (drawables) == 1);
|
2014-06-07 23:18:29 -04:00
|
|
|
|
2017-08-01 08:14:10 -04:00
|
|
|
if (options->instant_toggle)
|
|
|
|
gtk_widget_set_sensitive (options->instant_toggle, FALSE);
|
|
|
|
|
2020-05-25 11:30:31 +02:00
|
|
|
tool->display = display;
|
|
|
|
g_list_free (tool->drawables);
|
|
|
|
tool->drawables = drawables;
|
2014-06-07 23:18:29 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->start_x = coords->x;
|
|
|
|
gradient_tool->start_y = coords->y;
|
|
|
|
gradient_tool->end_x = coords->x;
|
|
|
|
gradient_tool->end_y = coords->y;
|
2017-06-26 21:54:45 +02:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->widget = gimp_tool_line_new (shell,
|
|
|
|
gradient_tool->start_x,
|
|
|
|
gradient_tool->start_y,
|
|
|
|
gradient_tool->end_x,
|
|
|
|
gradient_tool->end_y);
|
2017-06-26 21:54:45 +02:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
g_object_set (gradient_tool->widget,
|
|
|
|
"status-title", _("Gradient: "),
|
2017-07-03 01:02:23 +02:00
|
|
|
NULL);
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), gradient_tool->widget);
|
2017-06-26 21:54:45 +02:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
g_signal_connect (gradient_tool->widget, "changed",
|
|
|
|
G_CALLBACK (gimp_gradient_tool_line_changed),
|
|
|
|
gradient_tool);
|
|
|
|
g_signal_connect (gradient_tool->widget, "response",
|
|
|
|
G_CALLBACK (gimp_gradient_tool_line_response),
|
|
|
|
gradient_tool);
|
2017-06-26 21:54:45 +02:00
|
|
|
|
2017-08-04 08:44:32 -04:00
|
|
|
g_signal_connect_swapped (context, "background-changed",
|
2018-04-14 00:52:20 +02:00
|
|
|
G_CALLBACK (gimp_gradient_tool_fg_bg_changed),
|
|
|
|
gradient_tool);
|
2017-08-04 08:44:32 -04:00
|
|
|
g_signal_connect_swapped (context, "foreground-changed",
|
2018-04-14 00:52:20 +02:00
|
|
|
G_CALLBACK (gimp_gradient_tool_fg_bg_changed),
|
|
|
|
gradient_tool);
|
2017-08-04 08:44:32 -04:00
|
|
|
|
2020-05-25 11:30:31 +02:00
|
|
|
gimp_gradient_tool_create_filter (gradient_tool, tool->drawables->data);
|
2014-06-20 11:28:01 -04:00
|
|
|
|
2015-04-26 21:38:11 -04:00
|
|
|
/* Initially sync all of the properties */
|
2017-07-09 19:20:55 +02:00
|
|
|
gimp_operation_config_sync_node (G_OBJECT (options),
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->render_node);
|
2014-06-24 14:23:55 -04:00
|
|
|
|
2018-03-15 14:53:49 +01:00
|
|
|
/* We don't allow repeat values for some shapes. */
|
|
|
|
if (options->gradient_type >= GIMP_GRADIENT_SHAPEBURST_ANGULAR)
|
2018-04-14 00:52:20 +02:00
|
|
|
gegl_node_set (gradient_tool->render_node,
|
2018-03-15 14:53:49 +01:00
|
|
|
"gradient-repeat", GIMP_REPEAT_NONE,
|
|
|
|
NULL);
|
|
|
|
|
2015-04-26 21:38:11 -04:00
|
|
|
/* Connect signal handlers for the gradient */
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_set_gradient (gradient_tool, context->gradient);
|
2014-06-28 22:53:38 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gimp_gradient_tool_is_shapeburst (gradient_tool))
|
|
|
|
gimp_gradient_tool_precalc_shapeburst (gradient_tool);
|
2016-02-02 00:38:26 +01:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (gradient_tool), display);
|
2017-08-01 16:58:13 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_editor_start (gradient_tool);
|
2014-06-07 23:18:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_halt (GimpGradientTool *gradient_tool)
|
2014-06-07 23:18:29 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpTool *tool = GIMP_TOOL (gradient_tool);
|
|
|
|
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
|
|
|
|
GimpContext *context = GIMP_CONTEXT (options);
|
2014-06-07 23:18:29 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_editor_halt (gradient_tool);
|
2017-08-02 16:31:10 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gradient_tool->graph)
|
2014-06-20 11:28:01 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
g_clear_object (&gradient_tool->graph);
|
|
|
|
gradient_tool->render_node = NULL;
|
2016-02-02 00:38:26 +01:00
|
|
|
#if 0
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->subtract_node = NULL;
|
|
|
|
gradient_tool->divide_node = NULL;
|
2016-02-02 00:38:26 +01:00
|
|
|
#endif
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->dist_node = NULL;
|
2015-04-26 21:38:11 -04:00
|
|
|
}
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
g_clear_object (&gradient_tool->dist_buffer);
|
2014-06-20 11:28:01 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gradient_tool->filter)
|
2014-06-20 11:28:01 -04:00
|
|
|
{
|
2016-12-24 18:40:25 +01:00
|
|
|
gimp_tool_control_push_preserve (tool->control, TRUE);
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_drawable_filter_abort (gradient_tool->filter);
|
|
|
|
g_object_unref (gradient_tool->filter);
|
|
|
|
gradient_tool->filter = NULL;
|
2014-06-20 11:28:01 -04:00
|
|
|
|
2016-12-24 18:40:25 +01:00
|
|
|
gimp_tool_control_pop_preserve (tool->control);
|
|
|
|
|
2014-06-20 11:28:01 -04:00
|
|
|
gimp_image_flush (gimp_display_get_image (tool->display));
|
|
|
|
}
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_set_tentative_gradient (gradient_tool, NULL);
|
2017-10-11 05:55:36 -04:00
|
|
|
|
2017-08-04 08:44:32 -04:00
|
|
|
g_signal_handlers_disconnect_by_func (context,
|
2018-04-14 00:52:20 +02:00
|
|
|
G_CALLBACK (gimp_gradient_tool_fg_bg_changed),
|
|
|
|
gradient_tool);
|
2017-08-04 08:44:32 -04:00
|
|
|
|
2017-06-26 21:48:43 +02:00
|
|
|
if (tool->display)
|
|
|
|
gimp_tool_pop_status (tool, tool->display);
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (gradient_tool)))
|
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (gradient_tool));
|
2017-06-10 23:54:11 +02:00
|
|
|
|
2017-06-27 22:30:17 +02:00
|
|
|
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), NULL);
|
2018-04-14 00:52:20 +02:00
|
|
|
g_clear_object (&gradient_tool->widget);
|
2017-06-27 22:30:17 +02:00
|
|
|
|
2020-05-25 11:30:31 +02:00
|
|
|
tool->display = NULL;
|
|
|
|
g_list_free (tool->drawables);
|
|
|
|
tool->drawables = NULL;
|
2017-08-01 08:14:10 -04:00
|
|
|
|
|
|
|
if (options->instant_toggle)
|
|
|
|
gtk_widget_set_sensitive (options->instant_toggle, TRUE);
|
2014-06-07 23:18:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_commit (GimpGradientTool *gradient_tool)
|
2014-06-07 23:18:29 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpTool *tool = GIMP_TOOL (gradient_tool);
|
2016-02-03 00:22:15 +01:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gradient_tool->filter)
|
2016-02-03 00:22:15 +01:00
|
|
|
{
|
2019-01-12 04:48:17 -05:00
|
|
|
/* halt the editor before committing the filter so that the image-flush
|
|
|
|
* idle source is removed, to avoid flushing the image, and hence
|
|
|
|
* restarting the projection rendering, while applying the filter.
|
|
|
|
*/
|
|
|
|
gimp_gradient_tool_editor_halt (gradient_tool);
|
|
|
|
|
2016-12-24 18:40:25 +01:00
|
|
|
gimp_tool_control_push_preserve (tool->control, TRUE);
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_drawable_filter_commit (gradient_tool->filter,
|
2016-05-12 01:49:53 +02:00
|
|
|
GIMP_PROGRESS (tool), FALSE);
|
2018-04-14 00:52:20 +02:00
|
|
|
g_clear_object (&gradient_tool->filter);
|
2016-02-03 00:22:15 +01:00
|
|
|
|
2016-12-24 18:40:25 +01:00
|
|
|
gimp_tool_control_pop_preserve (tool->control);
|
|
|
|
|
2016-02-03 00:22:15 +01:00
|
|
|
gimp_image_flush (gimp_display_get_image (tool->display));
|
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2006-09-13 10:06:49 +00:00
|
|
|
|
2017-06-10 23:54:11 +02:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_line_changed (GimpToolWidget *widget,
|
|
|
|
GimpGradientTool *gradient_tool)
|
2017-06-10 23:54:11 +02:00
|
|
|
{
|
2017-08-12 11:25:22 -04:00
|
|
|
gdouble start_x;
|
|
|
|
gdouble start_y;
|
|
|
|
gdouble end_x;
|
|
|
|
gdouble end_y;
|
|
|
|
gboolean update = FALSE;
|
|
|
|
|
2017-06-10 23:54:11 +02:00
|
|
|
g_object_get (widget,
|
2017-08-12 11:25:22 -04:00
|
|
|
"x1", &start_x,
|
|
|
|
"y1", &start_y,
|
|
|
|
"x2", &end_x,
|
|
|
|
"y2", &end_y,
|
2017-06-10 23:54:11 +02:00
|
|
|
NULL);
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (start_x != gradient_tool->start_x ||
|
|
|
|
start_y != gradient_tool->start_y ||
|
|
|
|
end_x != gradient_tool->end_x ||
|
|
|
|
end_y != gradient_tool->end_y)
|
2017-08-12 11:25:22 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->start_x = start_x;
|
|
|
|
gradient_tool->start_y = start_y;
|
|
|
|
gradient_tool->end_x = end_x;
|
|
|
|
gradient_tool->end_y = end_y;
|
2017-08-12 11:25:22 -04:00
|
|
|
|
|
|
|
update = TRUE;
|
|
|
|
}
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gimp_gradient_tool_editor_line_changed (gradient_tool))
|
2017-08-12 11:25:22 -04:00
|
|
|
update = TRUE;
|
2017-08-01 14:04:28 -04:00
|
|
|
|
2017-08-12 11:25:22 -04:00
|
|
|
if (update)
|
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_update_graph (gradient_tool);
|
|
|
|
gimp_drawable_filter_apply (gradient_tool->filter, NULL);
|
2017-08-12 11:25:22 -04:00
|
|
|
}
|
2017-06-10 23:54:11 +02:00
|
|
|
}
|
|
|
|
|
2017-06-25 23:23:27 +02:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_line_response (GimpToolWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
GimpGradientTool *gradient_tool)
|
2017-06-25 23:23:27 +02:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpTool *tool = GIMP_TOOL (gradient_tool);
|
2017-06-25 23:23:27 +02:00
|
|
|
|
|
|
|
switch (response_id)
|
|
|
|
{
|
|
|
|
case GIMP_TOOL_WIDGET_RESPONSE_CONFIRM:
|
|
|
|
gimp_tool_control (tool, GIMP_TOOL_ACTION_COMMIT, tool->display);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_TOOL_WIDGET_RESPONSE_CANCEL:
|
|
|
|
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, tool->display);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-26 21:38:11 -04:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_precalc_shapeburst (GimpGradientTool *gradient_tool)
|
2015-04-26 21:38:11 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
|
|
|
|
GimpTool *tool = GIMP_TOOL (gradient_tool);
|
|
|
|
gint x, y, width, height;
|
2015-04-26 21:38:11 -04:00
|
|
|
|
2020-05-25 11:30:31 +02:00
|
|
|
if (gradient_tool->dist_buffer || ! tool->drawables)
|
2015-04-26 21:38:11 -04:00
|
|
|
return;
|
|
|
|
|
2020-05-25 11:30:31 +02:00
|
|
|
g_return_if_fail (g_list_length (tool->drawables) == 1);
|
|
|
|
|
|
|
|
if (! gimp_item_mask_intersect (GIMP_ITEM (tool->drawables->data),
|
2016-02-02 00:38:26 +01:00
|
|
|
&x, &y, &width, &height))
|
2015-04-26 21:38:11 -04:00
|
|
|
return;
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->dist_buffer =
|
2020-05-25 11:30:31 +02:00
|
|
|
gimp_drawable_gradient_shapeburst_distmap (tool->drawables->data,
|
2018-04-14 00:52:20 +02:00
|
|
|
options->distance_metric,
|
|
|
|
GEGL_RECTANGLE (x, y, width, height),
|
|
|
|
GIMP_PROGRESS (gradient_tool));
|
2015-04-26 21:38:11 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gradient_tool->dist_node)
|
|
|
|
gegl_node_set (gradient_tool->dist_node,
|
|
|
|
"buffer", gradient_tool->dist_buffer,
|
2015-04-26 21:38:11 -04:00
|
|
|
NULL);
|
2016-02-02 00:38:26 +01:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_progress_end (GIMP_PROGRESS (gradient_tool));
|
2015-04-26 21:38:11 -04:00
|
|
|
}
|
|
|
|
|
2016-02-02 00:38:26 +01:00
|
|
|
|
2014-06-20 11:28:01 -04:00
|
|
|
/* gegl graph stuff */
|
|
|
|
|
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_create_graph (GimpGradientTool *gradient_tool)
|
2014-06-20 11:28:01 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
|
|
|
|
GimpContext *context = GIMP_CONTEXT (options);
|
|
|
|
GeglNode *output;
|
2014-06-20 11:28:01 -04:00
|
|
|
|
|
|
|
/* render_node is not supposed to be recreated */
|
2018-04-14 00:52:20 +02:00
|
|
|
g_return_if_fail (gradient_tool->graph == NULL);
|
2014-06-20 11:28:01 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->graph = gegl_node_new ();
|
2016-02-02 00:38:26 +01:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->dist_node =
|
|
|
|
gegl_node_new_child (gradient_tool->graph,
|
2016-02-02 00:38:26 +01:00
|
|
|
"operation", "gegl:buffer-source",
|
2018-04-14 00:52:20 +02:00
|
|
|
"buffer", gradient_tool->dist_buffer,
|
2016-02-02 00:38:26 +01:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
#if 0
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->subtract_node =
|
|
|
|
gegl_node_new_child (gradient_tool->graph,
|
2016-02-02 00:38:26 +01:00
|
|
|
"operation", "gegl:subtract",
|
|
|
|
NULL);
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->divide_node =
|
|
|
|
gegl_node_new_child (gradient_tool->graph,
|
2016-02-02 00:38:26 +01:00
|
|
|
"operation", "gegl:divide",
|
|
|
|
NULL);
|
|
|
|
#endif
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->render_node =
|
|
|
|
gegl_node_new_child (gradient_tool->graph,
|
2018-04-13 23:36:16 +02:00
|
|
|
"operation", "gimp:gradient",
|
2016-02-02 00:38:26 +01:00
|
|
|
"context", context,
|
|
|
|
NULL);
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
output = gegl_node_get_output_proxy (gradient_tool->graph, "output");
|
2016-02-02 00:38:26 +01:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gegl_node_link_many (gradient_tool->dist_node,
|
2016-02-02 00:38:26 +01:00
|
|
|
#if 0
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->subtract_node,
|
|
|
|
gradient_tool->divide_node,
|
2016-02-02 00:38:26 +01:00
|
|
|
#endif
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->render_node,
|
2016-02-02 00:38:26 +01:00
|
|
|
output,
|
|
|
|
NULL);
|
2015-04-26 21:38:11 -04:00
|
|
|
|
2019-07-28 11:53:03 +03:00
|
|
|
gimp_gegl_node_set_underlying_operation (gradient_tool->graph,
|
|
|
|
gradient_tool->render_node);
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_update_graph (gradient_tool);
|
2014-06-20 11:28:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_update_graph (GimpGradientTool *gradient_tool)
|
2014-06-20 11:28:01 -04:00
|
|
|
{
|
2018-04-25 13:58:09 -04:00
|
|
|
GimpTool *tool = GIMP_TOOL (gradient_tool);
|
|
|
|
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
|
|
|
|
gint off_x, off_y;
|
2014-07-22 17:39:58 -04:00
|
|
|
|
2020-05-25 11:30:31 +02:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (tool->drawables->data), &off_x, &off_y);
|
2015-05-11 21:41:16 -04:00
|
|
|
|
2016-02-02 00:38:26 +01:00
|
|
|
#if 0
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gimp_gradient_tool_is_shapeburst (gradient_tool))
|
2015-04-26 21:38:11 -04:00
|
|
|
{
|
|
|
|
gfloat start, end;
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gegl_buffer_get (gradient_tool->dist_buffer,
|
|
|
|
GEGL_RECTANGLE (gradient_tool->start_x - off_x,
|
|
|
|
gradient_tool->start_y - off_y,
|
2015-04-26 21:38:11 -04:00
|
|
|
1, 1),
|
|
|
|
1.0, babl_format("Y float"), &start,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gegl_buffer_get (gradient_tool->dist_buffer,
|
|
|
|
GEGL_RECTANGLE (gradient_tool->end_x - off_x,
|
|
|
|
gradient_tool->end_y - off_y,
|
2015-04-26 21:38:11 -04:00
|
|
|
1, 1),
|
|
|
|
1.0, babl_format("Y float"), &end,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
|
|
|
|
2016-02-02 00:38:26 +01:00
|
|
|
if (start != end)
|
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
gegl_node_set (gradient_tool->subtract_node,
|
2016-02-02 00:38:26 +01:00
|
|
|
"value", (gdouble) start,
|
|
|
|
NULL);
|
2018-04-14 00:52:20 +02:00
|
|
|
gegl_node_set (gradient_tool->divide_node,
|
2016-02-02 00:38:26 +01:00
|
|
|
"value", (gdouble) (end - start),
|
|
|
|
NULL);
|
|
|
|
}
|
2015-04-26 21:38:11 -04:00
|
|
|
}
|
|
|
|
else
|
2016-02-02 00:38:26 +01:00
|
|
|
#endif
|
2015-04-26 21:38:11 -04:00
|
|
|
{
|
2018-04-25 13:58:09 -04:00
|
|
|
GeglRectangle roi;
|
|
|
|
gdouble start_x, start_y;
|
|
|
|
gdouble end_x, end_y;
|
|
|
|
|
2020-05-25 11:30:31 +02:00
|
|
|
gimp_item_mask_intersect (GIMP_ITEM (tool->drawables->data),
|
2018-04-25 13:58:09 -04:00
|
|
|
&roi.x, &roi.y, &roi.width, &roi.height);
|
|
|
|
|
|
|
|
start_x = gradient_tool->start_x - off_x;
|
|
|
|
start_y = gradient_tool->start_y - off_y;
|
|
|
|
end_x = gradient_tool->end_x - off_x;
|
|
|
|
end_y = gradient_tool->end_y - off_y;
|
|
|
|
|
2020-05-25 11:30:31 +02:00
|
|
|
gimp_drawable_gradient_adjust_coords (tool->drawables->data,
|
2018-04-25 13:58:09 -04:00
|
|
|
options->gradient_type,
|
|
|
|
&roi,
|
|
|
|
&start_x, &start_y, &end_x, &end_y);
|
|
|
|
|
|
|
|
gegl_node_set (gradient_tool->render_node,
|
|
|
|
"start-x", start_x,
|
|
|
|
"start-y", start_y,
|
|
|
|
"end-x", end_x,
|
|
|
|
"end-y", end_y,
|
|
|
|
NULL);
|
2015-04-26 21:38:11 -04:00
|
|
|
}
|
2014-06-20 11:28:01 -04:00
|
|
|
}
|
|
|
|
|
2017-08-04 08:44:32 -04:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_fg_bg_changed (GimpGradientTool *gradient_tool)
|
2017-08-04 08:44:32 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
if (! gradient_tool->filter || ! gradient_tool->gradient)
|
2017-08-04 08:44:32 -04:00
|
|
|
return;
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gimp_gradient_has_fg_bg_segments (gradient_tool->gradient))
|
2017-08-04 08:44:32 -04:00
|
|
|
{
|
|
|
|
/* Set a property on the node. Otherwise it will cache and refuse to update */
|
2018-04-14 00:52:20 +02:00
|
|
|
gegl_node_set (gradient_tool->render_node,
|
|
|
|
"gradient", gradient_tool->gradient,
|
2017-08-04 08:44:32 -04:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Update the filter */
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_drawable_filter_apply (gradient_tool->filter, NULL);
|
2017-08-04 08:44:32 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_editor_fg_bg_changed (gradient_tool);
|
2017-08-04 08:44:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-28 22:53:38 -04:00
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_gradient_dirty (GimpGradientTool *gradient_tool)
|
2014-06-28 22:53:38 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
if (! gradient_tool->filter)
|
2014-06-28 22:53:38 -04:00
|
|
|
return;
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (! gradient_tool->tentative_gradient)
|
2017-10-06 12:11:45 -04:00
|
|
|
{
|
|
|
|
/* Set a property on the node. Otherwise it will cache and refuse to update */
|
2018-04-14 00:52:20 +02:00
|
|
|
gegl_node_set (gradient_tool->render_node,
|
|
|
|
"gradient", gradient_tool->gradient,
|
2017-10-06 12:11:45 -04:00
|
|
|
NULL);
|
2014-06-28 22:53:38 -04:00
|
|
|
|
2017-10-06 12:11:45 -04:00
|
|
|
/* Update the filter */
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_drawable_filter_apply (gradient_tool->filter, NULL);
|
2017-10-06 12:11:45 -04:00
|
|
|
}
|
2017-08-01 11:33:36 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_editor_gradient_dirty (gradient_tool);
|
2014-06-28 22:53:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_set_gradient (GimpGradientTool *gradient_tool,
|
|
|
|
GimpGradient *gradient)
|
2014-06-28 22:53:38 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gradient_tool->gradient)
|
2018-06-01 12:59:52 +02:00
|
|
|
g_signal_handlers_disconnect_by_func (gradient_tool->gradient,
|
|
|
|
G_CALLBACK (gimp_gradient_tool_gradient_dirty),
|
|
|
|
gradient_tool);
|
2016-02-02 00:38:26 +01:00
|
|
|
|
2014-06-28 22:53:38 -04:00
|
|
|
|
2018-06-01 12:59:52 +02:00
|
|
|
g_set_object (&gradient_tool->gradient, gradient);
|
2016-02-02 00:38:26 +01:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gradient_tool->gradient)
|
2014-06-28 22:53:38 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
g_signal_connect_swapped (gradient_tool->gradient, "dirty",
|
|
|
|
G_CALLBACK (gimp_gradient_tool_gradient_dirty),
|
|
|
|
gradient_tool);
|
2014-06-29 20:40:47 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gradient_tool->render_node)
|
|
|
|
gegl_node_set (gradient_tool->render_node,
|
|
|
|
"gradient", gradient_tool->gradient,
|
2014-06-28 22:53:38 -04:00
|
|
|
NULL);
|
|
|
|
}
|
2017-08-01 09:18:50 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_editor_gradient_changed (gradient_tool);
|
2014-06-28 22:53:38 -04:00
|
|
|
}
|
|
|
|
|
2014-08-04 12:28:21 -04:00
|
|
|
static gboolean
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_is_shapeburst (GimpGradientTool *gradient_tool)
|
2014-08-04 12:28:21 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
|
2014-08-04 12:28:21 -04:00
|
|
|
|
|
|
|
return options->gradient_type >= GIMP_GRADIENT_SHAPEBURST_ANGULAR &&
|
|
|
|
options->gradient_type <= GIMP_GRADIENT_SHAPEBURST_DIMPLED;
|
|
|
|
}
|
|
|
|
|
2016-02-02 00:38:26 +01:00
|
|
|
|
|
|
|
/* image map stuff */
|
2014-06-20 11:28:01 -04:00
|
|
|
|
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_create_filter (GimpGradientTool *gradient_tool,
|
|
|
|
GimpDrawable *drawable)
|
2014-06-20 11:28:01 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
|
|
|
|
GimpContext *context = GIMP_CONTEXT (options);
|
2014-06-24 15:17:45 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
if (! gradient_tool->graph)
|
|
|
|
gimp_gradient_tool_create_graph (gradient_tool);
|
2014-06-20 11:28:01 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gradient_tool->filter = gimp_drawable_filter_new (drawable,
|
|
|
|
C_("undo-type", "Gradient"),
|
|
|
|
gradient_tool->graph,
|
2018-04-13 23:07:08 +02:00
|
|
|
GIMP_ICON_TOOL_GRADIENT);
|
2014-06-20 11:28:01 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_drawable_filter_set_region (gradient_tool->filter,
|
2016-05-12 01:49:53 +02:00
|
|
|
GIMP_FILTER_REGION_DRAWABLE);
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_drawable_filter_set_opacity (gradient_tool->filter,
|
2016-05-18 09:47:58 +02:00
|
|
|
gimp_context_get_opacity (context));
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_drawable_filter_set_mode (gradient_tool->filter,
|
2017-02-02 00:38:25 +01:00
|
|
|
gimp_context_get_paint_mode (context),
|
2017-02-12 23:49:26 +01:00
|
|
|
GIMP_LAYER_COLOR_SPACE_AUTO,
|
|
|
|
GIMP_LAYER_COLOR_SPACE_AUTO,
|
2018-04-25 11:12:47 -04:00
|
|
|
gimp_layer_mode_get_paint_composite_mode (
|
|
|
|
gimp_context_get_paint_mode (context)));
|
2014-06-20 11:28:01 -04:00
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
g_signal_connect (gradient_tool->filter, "flush",
|
|
|
|
G_CALLBACK (gimp_gradient_tool_filter_flush),
|
|
|
|
gradient_tool);
|
2014-06-20 11:28:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_filter_flush (GimpDrawableFilter *filter,
|
|
|
|
GimpTool *tool)
|
2014-06-20 11:28:01 -04:00
|
|
|
{
|
|
|
|
GimpImage *image = gimp_display_get_image (tool->display);
|
|
|
|
|
|
|
|
gimp_projection_flush (gimp_image_get_projection (image));
|
|
|
|
}
|
2017-04-28 00:27:34 +02:00
|
|
|
|
2017-10-06 12:11:45 -04:00
|
|
|
|
|
|
|
/* protected functions */
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_gradient_tool_set_tentative_gradient (GimpGradientTool *gradient_tool,
|
|
|
|
GimpGradient *gradient)
|
2017-10-06 12:11:45 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
g_return_if_fail (GIMP_IS_GRADIENT_TOOL (gradient_tool));
|
2017-10-06 12:11:45 -04:00
|
|
|
g_return_if_fail (gradient == NULL || GIMP_IS_GRADIENT (gradient));
|
|
|
|
|
2018-06-01 12:59:52 +02:00
|
|
|
if (g_set_object (&gradient_tool->tentative_gradient, gradient))
|
2017-10-06 12:11:45 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
if (gradient_tool->render_node)
|
2017-10-06 12:11:45 -04:00
|
|
|
{
|
2018-04-14 00:52:20 +02:00
|
|
|
gegl_node_set (gradient_tool->render_node,
|
|
|
|
"gradient", gradient ? gradient : gradient_tool->gradient,
|
2017-10-06 12:11:45 -04:00
|
|
|
NULL);
|
|
|
|
|
2018-04-14 00:52:20 +02:00
|
|
|
gimp_drawable_filter_apply (gradient_tool->filter, NULL);
|
2017-10-06 12:11:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|