gimp/app/tools/gimpgradienttool.c

1129 lines
42 KiB
C
Raw Normal View History

/* GIMP - The GNU Image Manipulation Program
1997-11-24 22:05:25 +00:00
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* Major improvements for interactivity
* Copyright (C) 2014 Michael Henning <drawoc@darkrefraction.com>
*
* 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
* 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
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1997-11-24 22:05:25 +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"
#include <gegl.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
Makefile.am configure.in added the new library below. 2001-01-24 Michael Natterer <mitch@gimp.org> * Makefile.am * configure.in * gimptool.in: added the new library below. * libgimpwidgets/Makefile.am * libgimpwidgets/gimpchainbutton.[ch] * libgimpwidgets/gimpcolorarea.[ch] * libgimpwidgets/gimpcolorbutton.[ch] * libgimpwidgets/gimpdialog.[ch] * libgimpwidgets/gimpfileselection.[ch] * libgimpwidgets/gimphelpui.[ch] * libgimpwidgets/gimppatheditor.[ch] * libgimpwidgets/gimppixmap.[ch] * libgimpwidgets/gimpquerybox.[ch] * libgimpwidgets/gimpsizeentry.[ch] * libgimpwidgets/gimpunitmenu.[ch] * libgimpwidgets/gimpwidgets.[ch] * libgimpwidgets/gimpwidgets.def * libgimpwidgets/gimpwidgetstypes.h: new shared library. Currently there are some ugly dependencies into libgimp. These will be removed and go to a "libgimpglue" library which will be a library for functions which share a common interface between plug-ins and the app but have different implementations. Include "libgimp/gimpunit.h" from "libgimpwidgets/gimpwidgetstypes.h" to simulate this upcoming separation. * libgimp/Makefile.am * libgimp/gimpchainbutton.[ch] * libgimp/gimpcolorarea.[ch] * libgimp/gimpcolorbutton.[ch] * libgimp/gimpdialog.[ch] * libgimp/gimpfileselection.[ch] * libgimp/gimphelpui.[ch] * libgimp/gimppatheditor.[ch] * libgimp/gimppixmap.[ch] * libgimp/gimpquerybox.[ch] * libgimp/gimpsizeentry.[ch] * libgimp/gimpunitmenu.[ch] * libgimp/gimpwidgets.[ch]: removed from here. * libgimp/gimpui.h * libgimp/gimpuitypes.h * libgimp/makefile.mingw.in * libgimp/makefile.msc: changed accordingly. * app/[all ui files] * app/pdb/palette_cmds.c * app/pdb/tools_cmds.c * tools/pdbgen/pdb/palette.pdb * tools/pdbgen/pdb/tools.pdb: #include "libgimpwidgets/gimpwidgets.h" and removed useless includes. * app/apptypes.h: #include "libgimpwidgets/gimpwidgetstypes.h" * app/Makefile.am * plug-ins/[all makefiles which link against libgimpui]: link against libgimpwidgets.la * po-libgimp/POTFILES.in: changed file locations.
2001-01-24 22:36:18 +00:00
#include "libgimpwidgets/gimpwidgets.h"
devel-docs/Makefile.am new file documenting the core's include policy. 2002-05-03 Michael Natterer <mitch@gimp.org> * devel-docs/Makefile.am * devel-docs/includes.txt: new file documenting the core's include policy. * HACKING: mention it here. * libgimptool/gimptooltypes.h: removed GimpToolOptions here. * app/core/core-types.h: and added it here. This is a temp hack needed because GimpToolInfo needs to know the GimpToolOptions type. * libgimpproxy/gimpproxytypes.h: regenerated. * libgimptool/gimptoolmodule.h: don't include gimptooltypes.h here... * libgimptool/gimptoolmodule.c: ...but here. * app/config/gimpconfig-params.c: include "libgimpbase/gimpbase.h" entirely, not single files from it. * app/core/gimp.c * app/core/gimpcontext.c * app/core/gimpcoreconfig.c * app/core/gimpdatafactory.c * app/core/gimpdocuments.c * app/core/gimpdrawable-blend.c * app/core/gimpdrawable-bucket-fill.c * app/core/gimpdrawable-offset.c * app/core/gimpdrawable-transform.c * app/core/gimpdrawable.c * app/core/gimpedit.c * app/core/gimpimage-convert.c * app/core/gimpimage-crop.c * app/core/gimpimage-duplicate.c * app/core/gimpimage-guides.c * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimpimage-new.c * app/core/gimpimage-projection.c * app/core/gimpimage-qmask.c * app/core/gimpimage-resize.c * app/core/gimpimage-scale.c * app/core/gimpimage.c * app/core/gimpitem.c * app/core/gimpmodules.c * app/core/gimppaintinfo.c * app/core/gimpparasite.c * app/core/gimppreviewcache.c * app/core/gimptoolinfo.c * app/core/gimpunit.c: include "core-types.h" and no other types file. * app/display/gimpdisplay.c * app/display/gimpdisplayshell-callbacks.c * app/display/gimpdisplayshell.c: include "tools/tools-types.h" instead of "libgimptool/gimptooltypes.h", warn about inclusion on "gui/gui-types.h" * app/file/file-open.c * app/file/file-save.c: don't include "libgimptool/gimptooltypes.h". * app/gui/about-dialog.c * app/gui/brush-select.c * app/gui/brushes-commands.c * app/gui/color-select.c * app/gui/data-commands.c * app/gui/device-status-dialog.c * app/gui/dialogs.c * app/gui/gradients-commands.c * app/gui/help-commands.c * app/gui/info-window.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/resize-dialog.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c: include "gui-types.h" and no other types file. * app/paint/gimpairbrush.c * app/paint/gimpclone.c * app/paint/gimpconvolve.c * app/paint/gimpdodgeburn.c * app/paint/gimperaser.c * app/paint/gimppaintbrush.c * app/paint/gimppaintcore-stroke.c * app/paint/gimppaintcore.c * app/paint/gimppaintoptions.c * app/paint/gimppencil.c * app/paint/gimpsmudge.c * app/paint/paint.c: include "paint-types.h" and no other types file. * app/pdb/pdb-types.h: don't include "libgimptool/gimptooltypes.h". * app/plug-in/plug-in-progress.c: warn about inclusion of "display/display-types.h" * app/tools/tools-types.h: include "libgimptool/gimptooltypes.h". * app/tools/gimpairbrushtool.c * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpbycolorselecttool.c * app/tools/gimpclonetool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpconvolvetool.c * app/tools/gimpcroptool.c * app/tools/gimpcurvestool.c * app/tools/gimpdodgeburntool.c * app/tools/gimpdrawtool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpellipseselecttool.c * app/tools/gimperasertool.c * app/tools/gimpfliptool.c * app/tools/gimpfreeselecttool.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpinktool.c * app/tools/gimplevelstool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppaintbrushtool.c * app/tools/gimppainttool.c * app/tools/gimppathtool.c * app/tools/gimppenciltool.c * app/tools/gimpperspectivetool.c * app/tools/gimpposterizetool.c * app/tools/gimprectselecttool.c * app/tools/gimprotatetool.c * app/tools/gimpscaletool.c * app/tools/gimpselectiontool.c * app/tools/gimpsheartool.c * app/tools/gimpsmudgetool.c * app/tools/gimptexttool.c * app/tools/gimpthresholdtool.c * app/tools/gimptoolcontrol.c * app/tools/gimptoolcontrol.h * app/tools/gimptransformtool.c * app/tools/gimpvectortool.c * app/tools/tools.c: include "tools-types.h" and no other types file, warn about inclusion of "gui/gui-types.h". * app/widgets/gimpcolorpanel.c * app/widgets/gimptoolbox-color-area.c: warn about inclusion of "gui/gui-types.h". * app/xcf/xcf-load.c * app/xcf/xcf.c: don't include "libgimptool/gimptooltypes.h". Split tool-safe-mode up in two files, one including libgimpproxy, one libgimp. * plug-ins/tools/Makefile.am * plug-ins/tools/tool-safe-mode-plug-in.[ch]: new files including libgimp/ stuff only. * plug-ins/tools/tool-safe-mode.[ch]: include libgimpproxy/ and libgimptool/ but don't include libgimp/ because of conflicting declarations. Unrelated: * app/tools/gimpclonetool.c: create the clone core so we don't crash. * app/gui/file-open-dialog.c: changed the way we create previews so that only out-of-date previews are created on a click in the preview area. Unconditional creation can still be forced by <Ctrl>+click. Changed the tooltip to document this.
2002-05-03 12:45:22 +00:00
#include "tools-types.h"
#include "config/gimpguiconfig.h"
#include "gegl/gimp-gegl-utils.h"
#include "operations/gimp-operation-config.h"
#include "operations/layer-modes/gimp-layer-modes.h"
#include "core/gimp.h"
#include "core/gimpdrawable.h"
#include "core/gimpdrawable-gradient.h"
#include "core/gimpdrawablefilter.h"
#include "core/gimperror.h"
#include "core/gimpgradient.h"
#include "core/gimpimage.h"
Redid the whole internal progress stuff: don't pass around 2004-08-10 Michael Natterer <mitch@gimp.org> Redid the whole internal progress stuff: don't pass around progress_callback and progress_data; instead, provide a pointer to a GimpProgressInterface which can be implemented by a variety of backends. Addresses (but not yet fixes) bugs #6010, #97266 and #135185. * app/display/Makefile.am * app/display/gimpprogress.[ch]: removed the old progress hack. * app/core/Makefile.am * app/core/core-types.h * app/core/gimpprogress.[ch]: implement GimpProgressInterface. * app/widgets/Makefile.am * app/widgets/widgets-types.h * app/widgets/gimpprogressdialog.[ch]: the standalone progress dialog as widget implementing GimpProgressInterface. * app/display/gimpdisplay.c * app/display/gimpstatusbar.[ch] * app/widgets/gimpfiledialog.[ch] * app/widgets/gimpthumbbox.[ch]: added GimpProgressInterface implementation to these classes. * app/core/gimp-gui.[ch] * app/gui/gui-vtable.c: replaced the old progress vtable entries by two new to create and destroy a GimpProgressDialog in case no other progress is available. * app/pdb/procedural_db.[ch] * app/plug-in/plug-in-run.[ch] * tools/pdbgen/app.pl: pass a GimpProgress to all PDB wrappers and all plug-ins. * app/plug-in/plug-in.[ch] * app/plug-in/plug-ins.c * app/plug-in/plug-in-message.c * app/plug-in/plug-in-progress.c: handle the case there the plug-in was crated with a progress as well as the case where it wasn't. * app/app_procs.c * app/batch.c * app/xcf/xcf.c * app/file/file-open.[ch] * app/file/file-save.[ch] * app/widgets/gimphelp.c * app/widgets/gimpbrushselect.c * app/widgets/gimpfontselect.c * app/widgets/gimpgradientselect.c * app/widgets/gimppaletteselect.c * app/widgets/gimppatternselect.c: changed accordingly. * app/core/gimpimagefile.[ch] * app/display/gimpdisplayshell-dnd.c * app/gui/file-open-dialog.c * app/gui/file-open-location-dialog.c * app/gui/file-save-dialog.c * app/widgets/gimplayertreeview.c * app/widgets/gimptoolbox-dnd.c: pass a GimpProgress to all file related functions. Embed the progress in the file dialog where possible. * app/core/gimpdrawable-blend.[ch] * app/core/gimpdrawable-transform.[ch] * app/core/gimpimage-convert.[ch] * app/core/gimpimage-flip.[ch] * app/core/gimpimage-resize.[ch] * app/core/gimpimage-rotate.[ch] * app/core/gimpimage-scale.[ch] * app/core/gimpitem-linked.[ch] * app/core/gimpitem.[ch] * app/core/gimpchannel.c * app/core/gimpdrawable.c * app/core/gimplayer.c * app/core/gimpselection.c * app/vectors/gimpvectors.c: replaced callback/data by GimpProgress. * app/tools/gimpblendtool.c * app/tools/gimptransformtool.c * app/gui/convert-dialog.c * app/actions/documents-commands.c * app/actions/file-commands.c * app/actions/image-commands.c * app/actions/layers-commands.c * app/actions/plug-in-commands.c * app/actions/vectors-commands.c * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/edit.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb: changed callers accordingly. * app/pdb/*_cmds.c: regenerated.
2004-08-10 18:47:21 +00:00
#include "core/gimpprogress.h"
#include "core/gimpprojection.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpwidgets-utils.h"
#include "display/gimpdisplay.h"
#include "display/gimptoolline.h"
#include "gimpgradientoptions.h"
#include "gimpgradienttool.h"
#include "gimpgradienttool-editor.h"
#include "gimptoolcontrol.h"
#include "gimptools-utils.h"
#include "gimp-intl.h"
/* local function prototypes */
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
2001-11-09 16:54:56 +00:00
void
gimp_gradient_tool_register (GimpToolRegisterCallback callback,
gpointer data)
{
(* callback) (GIMP_TYPE_GRADIENT_TOOL,
GIMP_TYPE_GRADIENT_OPTIONS,
gimp_gradient_options_gui,
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,
"gimp-gradient-tool",
_("Gradient"),
_("Gradient Tool: Fill selected area with a color gradient"),
N_("Gra_dient"), "G",
NULL, GIMP_HELP_TOOL_GRADIENT,
GIMP_ICON_TOOL_GRADIENT,
app/tools/gimpairbrushtool.[ch] app/tools/gimpbezierselecttool.[ch] 2002-05-03 Sven Neumann <sven@gimp.org> * app/tools/gimpairbrushtool.[ch] * app/tools/gimpbezierselecttool.[ch] * app/tools/gimpblendtool.[ch] * app/tools/gimpbrightnesscontrasttool.[ch] * app/tools/gimpbucketfilltool[.ch] * app/tools/gimpbycolorselecttool[.ch] * app/tools/gimpclonetool[.ch] * app/tools/gimpcolorbalancetool[.ch] * app/tools/gimpcolorpickertool[.ch] * app/tools/gimpconvolvetool[.ch] * app/tools/gimpcroptool[.ch] * app/tools/gimpcurvestool[.ch] * app/tools/gimpdodgeburntool[.ch] * app/tools/gimpeditselectiontool.c * app/tools/gimpellipseselecttool[.ch] * app/tools/gimperasertool[.ch] * app/tools/gimpfliptool[.ch] * app/tools/gimpfreeselecttool[.ch] * app/tools/gimpfuzzyselecttool[.ch] * app/tools/gimphistogramtool[.ch] * app/tools/gimphuesaturationtool[.ch] * app/tools/gimpinktool[.ch] * app/tools/gimpiscissorstool[.ch] * app/tools/gimplevelstool[.ch] * app/tools/gimpmagnifytool[.ch] * app/tools/gimpmeasuretool[.ch] * app/tools/gimpmovetool[.ch] * app/tools/gimppaintbrushtool[.ch] * app/tools/gimppainttool.c * app/tools/gimppathtool[.ch] * app/tools/gimppenciltool[.ch] * app/tools/gimpperspectivetool[.ch] * app/tools/gimpposterizetool[.ch] * app/tools/gimprectselecttool[.ch] * app/tools/gimprotatetool[.ch] * app/tools/gimpscaletool[.ch] * app/tools/gimpselectiontool.c * app/tools/gimpsheartool[.ch] * app/tools/gimpsmudgetool[.ch] * app/tools/gimptexttool[.ch] * app/tools/gimpthresholdtool[.ch] * app/tools/gimptool.c * app/tools/gimptoolcontrol.h * app/tools/gimptoolmodule[.ch] * app/tools/gimptransformtool.c * app/tools/gimpvectortool[.ch] * app/tools/path_tool.c * app/tools/tool_manager[.ch] * app/tools/tools.c * libgimptool/gimptool.c * libgimptool/gimptoolcontrol.h * libgimptool/gimptoolmodule.h: removed tons of warnings. Do we need to add -Werror to the CFLAGS to avoid such a mess in the future ?! Also had to enforce the GIMP coding style in lots of places :-( * libgimp/gimppixelrgn.c: got sick and tired of debugging plug-ins, so I've added checks for most parameters passed to the GimpPixelRgn functions. This will slow down plug-in execution a little bit but should help to find bugs early.
2002-05-03 11:31:08 +00:00
data);
}
static void
gimp_gradient_tool_class_init (GimpGradientToolClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
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;
}
1997-11-24 22:05:25 +00:00
static void
gimp_gradient_tool_init (GimpGradientTool *gradient_tool)
{
GimpTool *tool = GIMP_TOOL (gradient_tool);
added fields for both the tool's toggled and untoggled GdkCursorType, 2002-02-04 Michael Natterer <mitch@gimp.org> * app/tools/gimptool.[ch]: added fields for both the tool's toggled and untoggled GdkCursorType, GimpToolCursorType and GimpCursorModifier. Added a default implementation of gimp_tool_cursor_update() which uses the new fields. Added gimp_tool_set_cursor() as simple wrapper around the resp. GimpDisplayShell functions so tools don't need to know them. Tool implementations can either set the new fields in their cursor_update() function and chain up or call the new wrapper. * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpbycolorselecttool.c * app/tools/gimpclonetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpconvolvetool.c * app/tools/gimpcroptool.c * app/tools/gimpdodgeburntool.c * app/tools/gimperasertool.c * app/tools/gimpfliptool.c * app/tools/gimpinktool.c * app/tools/gimpiscissorstool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppainttool.[ch] * app/tools/gimppathtool.c * app/tools/gimpselectiontool.c * app/tools/gimpsmudgetool.c * app/tools/gimptexttool.c * app/tools/gimptransformtool.c: changed accordingly: - set default values in the tools' instance_init functions. - changed the cursor_update() stuff. - removed inclusion of subclasses in gimppainttool.c - the cursor_update() functions are better than before but still evil. - i probably broke some of them...
2002-02-04 17:43:01 +00: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);
gimp_tool_control_set_dirty_action (tool->control,
GIMP_TOOL_ACTION_COMMIT);
gimp_tool_control_set_wants_click (tool->control, TRUE);
gimp_tool_control_set_wants_double_click (tool->control, TRUE);
gimp_tool_control_set_active_modifiers (tool->control,
GIMP_TOOL_ACTIVE_MODIFIERS_SEPARATE);
gimp_tool_control_set_precision (tool->control,
GIMP_CURSOR_PRECISION_SUBPIXEL);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_GRADIENT);
gimp_tool_control_set_action_opacity (tool->control,
"context/context-opacity-set");
gimp_tool_control_set_action_object_1 (tool->control,
"context/context-gradient-select-set");
gimp_draw_tool_set_default_status (GIMP_DRAW_TOOL (tool),
_("Click-Drag to draw a gradient"));
}
1997-11-24 22:05:25 +00:00
static void
gimp_gradient_tool_dispose (GObject *object)
{
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (object);
gimp_gradient_tool_set_gradient (gradient_tool, NULL);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
added GError** parameter to GimpPaintCore::start(). 2006-09-26 Michael Natterer <mitch@gimp.org> * app/paint/gimppaintcore.[ch]: added GError** parameter to GimpPaintCore::start(). * app/tools/gimppainttool.c (button_press): display the error in the statusbar. * app/paint/gimppaintcore-stroke.c: pass a NULL error, effectively swallowing mssages. Will fix that later. * app/paint/gimpbrushcore.c * app/paint/gimpclone.c * app/paint/gimpsourcecore.c: changed accordingly. Set the error instead of calling g_message(). * app/paint/gimpheal.c * app/paint/gimpperspectiveclone.c: implement start() and bail out early on indexed drawables instead of showing a g_message() in other functions that are called later. * app/tools/gimptool.[ch]: added GError** to GimpTool::initialize(). * app/tools/gimptool.c (gimp_tool_initialize): display the error in the statusbar. Keep the external API GError-free. * app/tools/gimprectangletool.[ch]: added GError** to gimp_rectangle_tool_initialize(). * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorizetool.c * app/tools/gimpcroptool.c * app/tools/gimpcurvestool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpimagemaptool.c * app/tools/gimplevelstool.c * app/tools/gimpperspectiveclonetool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/gimptransformtool.c: changed accordingly. Set the errors in initialize() instead of using gimp_message(). * app/tools/gimpblendtool.c: implement initialize() and bail out early on indexed images instead of showing a gimp_message() in button_press().
2006-09-26 20:55:40 +00:00
static gboolean
gimp_gradient_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error)
added GError** parameter to GimpPaintCore::start(). 2006-09-26 Michael Natterer <mitch@gimp.org> * app/paint/gimppaintcore.[ch]: added GError** parameter to GimpPaintCore::start(). * app/tools/gimppainttool.c (button_press): display the error in the statusbar. * app/paint/gimppaintcore-stroke.c: pass a NULL error, effectively swallowing mssages. Will fix that later. * app/paint/gimpbrushcore.c * app/paint/gimpclone.c * app/paint/gimpsourcecore.c: changed accordingly. Set the error instead of calling g_message(). * app/paint/gimpheal.c * app/paint/gimpperspectiveclone.c: implement start() and bail out early on indexed drawables instead of showing a g_message() in other functions that are called later. * app/tools/gimptool.[ch]: added GError** to GimpTool::initialize(). * app/tools/gimptool.c (gimp_tool_initialize): display the error in the statusbar. Keep the external API GError-free. * app/tools/gimprectangletool.[ch]: added GError** to gimp_rectangle_tool_initialize(). * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorizetool.c * app/tools/gimpcroptool.c * app/tools/gimpcurvestool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpimagemaptool.c * app/tools/gimplevelstool.c * app/tools/gimpperspectiveclonetool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/gimptransformtool.c: changed accordingly. Set the errors in initialize() instead of using gimp_message(). * app/tools/gimpblendtool.c: implement initialize() and bail out early on indexed images instead of showing a gimp_message() in button_press().
2006-09-26 20:55:40 +00:00
{
GimpImage *image = gimp_display_get_image (display);
GList *drawables = gimp_image_get_selected_drawables (image);
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (tool);
GimpGuiConfig *config = GIMP_GUI_CONFIG (display->gimp->config);
GimpDrawable *drawable;
added GError** parameter to GimpPaintCore::start(). 2006-09-26 Michael Natterer <mitch@gimp.org> * app/paint/gimppaintcore.[ch]: added GError** parameter to GimpPaintCore::start(). * app/tools/gimppainttool.c (button_press): display the error in the statusbar. * app/paint/gimppaintcore-stroke.c: pass a NULL error, effectively swallowing mssages. Will fix that later. * app/paint/gimpbrushcore.c * app/paint/gimpclone.c * app/paint/gimpsourcecore.c: changed accordingly. Set the error instead of calling g_message(). * app/paint/gimpheal.c * app/paint/gimpperspectiveclone.c: implement start() and bail out early on indexed drawables instead of showing a g_message() in other functions that are called later. * app/tools/gimptool.[ch]: added GError** to GimpTool::initialize(). * app/tools/gimptool.c (gimp_tool_initialize): display the error in the statusbar. Keep the external API GError-free. * app/tools/gimprectangletool.[ch]: added GError** to gimp_rectangle_tool_initialize(). * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorizetool.c * app/tools/gimpcroptool.c * app/tools/gimpcurvestool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpimagemaptool.c * app/tools/gimplevelstool.c * app/tools/gimpperspectiveclonetool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/gimptransformtool.c: changed accordingly. Set the errors in initialize() instead of using gimp_message(). * app/tools/gimpblendtool.c: implement initialize() and bail out early on indexed images instead of showing a gimp_message() in button_press().
2006-09-26 20:55:40 +00:00
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
{
return FALSE;
}
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);
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."));
return FALSE;
}
if (gimp_item_is_content_locked (GIMP_ITEM (drawable)))
{
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
2016-11-25 00:04:04 +01:00
_("The active layer's pixels are locked."));
if (error)
gimp_tools_blink_lock_box (display->gimp, GIMP_ITEM (drawable));
return FALSE;
}
if (! gimp_item_is_visible (GIMP_ITEM (drawable)) &&
! config->edit_non_visible)
{
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
_("The active layer is not visible."));
return FALSE;
}
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;
}
added GError** parameter to GimpPaintCore::start(). 2006-09-26 Michael Natterer <mitch@gimp.org> * app/paint/gimppaintcore.[ch]: added GError** parameter to GimpPaintCore::start(). * app/tools/gimppainttool.c (button_press): display the error in the statusbar. * app/paint/gimppaintcore-stroke.c: pass a NULL error, effectively swallowing mssages. Will fix that later. * app/paint/gimpbrushcore.c * app/paint/gimpclone.c * app/paint/gimpsourcecore.c: changed accordingly. Set the error instead of calling g_message(). * app/paint/gimpheal.c * app/paint/gimpperspectiveclone.c: implement start() and bail out early on indexed drawables instead of showing a g_message() in other functions that are called later. * app/tools/gimptool.[ch]: added GError** to GimpTool::initialize(). * app/tools/gimptool.c (gimp_tool_initialize): display the error in the statusbar. Keep the external API GError-free. * app/tools/gimprectangletool.[ch]: added GError** to gimp_rectangle_tool_initialize(). * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorizetool.c * app/tools/gimpcroptool.c * app/tools/gimpcurvestool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpimagemaptool.c * app/tools/gimplevelstool.c * app/tools/gimpperspectiveclonetool.c * app/tools/gimpposterizetool.c * app/tools/gimpthresholdtool.c * app/tools/gimptransformtool.c: changed accordingly. Set the errors in initialize() instead of using gimp_message(). * app/tools/gimpblendtool.c: implement initialize() and bail out early on indexed images instead of showing a gimp_message() in button_press().
2006-09-26 20:55:40 +00:00
return TRUE;
}
static void
gimp_gradient_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display)
{
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (tool);
switch (action)
{
case GIMP_TOOL_ACTION_PAUSE:
case GIMP_TOOL_ACTION_RESUME:
break;
case GIMP_TOOL_ACTION_HALT:
gimp_gradient_tool_halt (gradient_tool);
break;
case GIMP_TOOL_ACTION_COMMIT:
gimp_gradient_tool_commit (gradient_tool);
break;
}
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
}
1997-11-24 22:05:25 +00:00
static void
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
{
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (tool);
1997-11-24 22:05:25 +00:00
if (tool->display && display != tool->display)
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, tool->display);
if (! gradient_tool->widget)
{
gimp_gradient_tool_start (gradient_tool, coords, display);
gimp_tool_widget_hover (gradient_tool->widget, coords, state, TRUE);
}
/* 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.
*/
if (press_type == GIMP_BUTTON_PRESS_NORMAL)
gimp_gradient_tool_editor_start_edit (gradient_tool);
if (gimp_tool_widget_button_press (gradient_tool->widget, coords, time, state,
press_type))
{
gradient_tool->grab_widget = gradient_tool->widget;
}
if (press_type == GIMP_BUTTON_PRESS_NORMAL)
gimp_tool_control_activate (tool->control);
1997-11-24 22:05:25 +00:00
}
static void
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
{
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (tool);
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (tool);
1997-11-24 22:05:25 +00:00
gimp_tool_pop_status (tool, display);
1998-07-26 21:49:42 +00:00
gimp_tool_control_halt (tool->control);
1997-11-24 22:05:25 +00:00
if (gradient_tool->grab_widget)
{
gimp_tool_widget_button_release (gradient_tool->grab_widget,
coords, time, state, release_type);
gradient_tool->grab_widget = NULL;
if (options->instant)
{
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);
}
}
if (! options->instant)
{
gimp_gradient_tool_editor_end_edit (gradient_tool,
release_type ==
GIMP_BUTTON_RELEASE_CANCEL);
}
1997-11-24 22:05:25 +00:00
}
static void
gimp_gradient_tool_motion (GimpTool *tool,
const GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *display)
1997-11-24 22:05:25 +00:00
{
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (tool);
1997-11-24 22:05:25 +00:00
if (gradient_tool->grab_widget)
{
gimp_tool_widget_motion (gradient_tool->grab_widget, coords, time, state);
}
}
static gboolean
gimp_gradient_tool_key_press (GimpTool *tool,
GdkEventKey *kevent,
GimpDisplay *display)
{
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (tool);
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
gboolean result;
/* 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)
gimp_gradient_tool_editor_start_edit (gradient_tool);
result = GIMP_TOOL_CLASS (parent_class)->key_press (tool, kevent, display);
if (display == draw_tool->display)
gimp_gradient_tool_editor_end_edit (gradient_tool, FALSE);
return result;
}
static void
gimp_gradient_tool_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
GdkModifierType state,
GimpDisplay *display)
{
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (tool);
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
gimp_gradient_tool_cursor_update (GimpTool *tool,
const GimpCoords *coords,
GdkModifierType state,
GimpDisplay *display)
1997-11-24 22:05:25 +00:00
{
GimpGuiConfig *config = GIMP_GUI_CONFIG (display->gimp->config);
GimpImage *image = gimp_display_get_image (display);
GList *drawables = gimp_image_get_selected_drawables (image);
if (g_list_length (drawables) != 1 ||
gimp_viewable_get_children (drawables->data) ||
gimp_item_is_content_locked (drawables->data) ||
! (gimp_item_is_visible (drawables->data) ||
config->edit_non_visible))
1997-11-24 22:05:25 +00: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;
1997-11-24 22:05:25 +00:00
}
added fields for both the tool's toggled and untoggled GdkCursorType, 2002-02-04 Michael Natterer <mitch@gimp.org> * app/tools/gimptool.[ch]: added fields for both the tool's toggled and untoggled GdkCursorType, GimpToolCursorType and GimpCursorModifier. Added a default implementation of gimp_tool_cursor_update() which uses the new fields. Added gimp_tool_set_cursor() as simple wrapper around the resp. GimpDisplayShell functions so tools don't need to know them. Tool implementations can either set the new fields in their cursor_update() function and chain up or call the new wrapper. * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpbycolorselecttool.c * app/tools/gimpclonetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpconvolvetool.c * app/tools/gimpcroptool.c * app/tools/gimpdodgeburntool.c * app/tools/gimperasertool.c * app/tools/gimpfliptool.c * app/tools/gimpinktool.c * app/tools/gimpiscissorstool.c * app/tools/gimpmagnifytool.c * app/tools/gimpmeasuretool.c * app/tools/gimpmovetool.c * app/tools/gimppainttool.[ch] * app/tools/gimppathtool.c * app/tools/gimpselectiontool.c * app/tools/gimpsmudgetool.c * app/tools/gimptexttool.c * app/tools/gimptransformtool.c: changed accordingly: - set default values in the tools' instance_init functions. - changed the cursor_update() stuff. - removed inclusion of subclasses in gimppainttool.c - the cursor_update() functions are better than before but still evil. - i probably broke some of them...
2002-02-04 17:43:01 +00:00
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
1997-11-24 22:05:25 +00:00
}
static const gchar *
gimp_gradient_tool_can_undo (GimpTool *tool,
GimpDisplay *display)
{
return gimp_gradient_tool_editor_can_undo (GIMP_GRADIENT_TOOL (tool));
}
static const gchar *
gimp_gradient_tool_can_redo (GimpTool *tool,
GimpDisplay *display)
{
return gimp_gradient_tool_editor_can_redo (GIMP_GRADIENT_TOOL (tool));
}
static gboolean
gimp_gradient_tool_undo (GimpTool *tool,
GimpDisplay *display)
{
return gimp_gradient_tool_editor_undo (GIMP_GRADIENT_TOOL (tool));
}
static gboolean
gimp_gradient_tool_redo (GimpTool *tool,
GimpDisplay *display)
{
return gimp_gradient_tool_editor_redo (GIMP_GRADIENT_TOOL (tool));
}
static void
gimp_gradient_tool_options_notify (GimpTool *tool,
GimpToolOptions *options,
const GParamSpec *pspec)
{
GimpContext *context = GIMP_CONTEXT (options);
GimpGradientTool *gradient_tool = GIMP_GRADIENT_TOOL (tool);
if (! strcmp (pspec->name, "gradient"))
{
gimp_gradient_tool_set_gradient (gradient_tool, context->gradient);
if (gradient_tool->filter)
gimp_drawable_filter_apply (gradient_tool->filter, NULL);
}
else if (gradient_tool->render_node &&
gegl_node_find_property (gradient_tool->render_node, pspec->name))
{
/* Sync any property changes on the config object that match the op */
GValue value = G_VALUE_INIT;
g_value_init (&value, pspec->value_type);
g_object_get_property (G_OBJECT (options), pspec->name, &value);
gegl_node_set_property (gradient_tool->render_node, pspec->name, &value);
g_value_unset (&value);
if (! strcmp (pspec->name, "gradient-type"))
{
GimpRepeatMode gradient_repeat;
GimpRepeatMode node_repeat;
GimpGradientType gradient_type;
gradient_repeat = GIMP_PAINT_OPTIONS (options)->gradient_options->gradient_repeat;
gradient_type = GIMP_GRADIENT_OPTIONS (options)->gradient_type;
gegl_node_get (gradient_tool->render_node,
"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
* don't keep the render node and the gradient options in
* sync.
* We could instead reset the "gradient-repeat" value on
* GimpGradientOptions, but I assume one would want to revert
* 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)
gegl_node_set (gradient_tool->render_node,
"gradient-repeat", GIMP_REPEAT_NONE,
NULL);
}
else if (node_repeat != gradient_repeat)
{
gegl_node_set (gradient_tool->render_node,
"gradient-repeat", gradient_repeat,
NULL);
}
if (gimp_gradient_tool_is_shapeburst (gradient_tool))
gimp_gradient_tool_precalc_shapeburst (gradient_tool);
gimp_gradient_tool_update_graph (gradient_tool);
}
gimp_drawable_filter_apply (gradient_tool->filter, NULL);
}
else if (gradient_tool->render_node &&
gimp_gradient_tool_is_shapeburst (gradient_tool) &&
g_strcmp0 (pspec->name, "distance-metric") == 0)
{
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);
}
else if (gradient_tool->filter &&
! strcmp (pspec->name, "opacity"))
{
gimp_drawable_filter_set_opacity (gradient_tool->filter,
gimp_context_get_opacity (context));
}
else if (gradient_tool->filter &&
! strcmp (pspec->name, "paint-mode"))
{
gimp_drawable_filter_set_mode (gradient_tool->filter,
gimp_context_get_paint_mode (context),
GIMP_LAYER_COLOR_SPACE_AUTO,
GIMP_LAYER_COLOR_SPACE_AUTO,
gimp_layer_mode_get_paint_composite_mode (
gimp_context_get_paint_mode (context)));
}
gimp_gradient_tool_editor_options_notify (gradient_tool, options, pspec);
}
static void
gimp_gradient_tool_start (GimpGradientTool *gradient_tool,
const GimpCoords *coords,
GimpDisplay *display)
{
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);
if (options->instant_toggle)
gtk_widget_set_sensitive (options->instant_toggle, FALSE);
tool->display = display;
tool->drawable = drawables->data;
g_list_free (drawables);
gradient_tool->start_x = coords->x;
gradient_tool->start_y = coords->y;
gradient_tool->end_x = coords->x;
gradient_tool->end_y = coords->y;
gradient_tool->widget = gimp_tool_line_new (shell,
gradient_tool->start_x,
gradient_tool->start_y,
gradient_tool->end_x,
gradient_tool->end_y);
g_object_set (gradient_tool->widget,
"status-title", _("Gradient: "),
NULL);
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), gradient_tool->widget);
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);
g_signal_connect_swapped (context, "background-changed",
G_CALLBACK (gimp_gradient_tool_fg_bg_changed),
gradient_tool);
g_signal_connect_swapped (context, "foreground-changed",
G_CALLBACK (gimp_gradient_tool_fg_bg_changed),
gradient_tool);
gimp_gradient_tool_create_filter (gradient_tool, tool->drawable);
/* Initially sync all of the properties */
gimp_operation_config_sync_node (G_OBJECT (options),
gradient_tool->render_node);
/* We don't allow repeat values for some shapes. */
if (options->gradient_type >= GIMP_GRADIENT_SHAPEBURST_ANGULAR)
gegl_node_set (gradient_tool->render_node,
"gradient-repeat", GIMP_REPEAT_NONE,
NULL);
/* Connect signal handlers for the gradient */
gimp_gradient_tool_set_gradient (gradient_tool, context->gradient);
if (gimp_gradient_tool_is_shapeburst (gradient_tool))
gimp_gradient_tool_precalc_shapeburst (gradient_tool);
gimp_draw_tool_start (GIMP_DRAW_TOOL (gradient_tool), display);
gimp_gradient_tool_editor_start (gradient_tool);
}
static void
gimp_gradient_tool_halt (GimpGradientTool *gradient_tool)
{
GimpTool *tool = GIMP_TOOL (gradient_tool);
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
GimpContext *context = GIMP_CONTEXT (options);
gimp_gradient_tool_editor_halt (gradient_tool);
if (gradient_tool->graph)
{
g_clear_object (&gradient_tool->graph);
gradient_tool->render_node = NULL;
#if 0
gradient_tool->subtract_node = NULL;
gradient_tool->divide_node = NULL;
#endif
gradient_tool->dist_node = NULL;
}
g_clear_object (&gradient_tool->dist_buffer);
if (gradient_tool->filter)
{
gimp_tool_control_push_preserve (tool->control, TRUE);
gimp_drawable_filter_abort (gradient_tool->filter);
g_object_unref (gradient_tool->filter);
gradient_tool->filter = NULL;
gimp_tool_control_pop_preserve (tool->control);
gimp_image_flush (gimp_display_get_image (tool->display));
}
gimp_gradient_tool_set_tentative_gradient (gradient_tool, NULL);
g_signal_handlers_disconnect_by_func (context,
G_CALLBACK (gimp_gradient_tool_fg_bg_changed),
gradient_tool);
if (tool->display)
gimp_tool_pop_status (tool, tool->display);
if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (gradient_tool)))
gimp_draw_tool_stop (GIMP_DRAW_TOOL (gradient_tool));
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), NULL);
g_clear_object (&gradient_tool->widget);
tool->display = NULL;
tool->drawable = NULL;
if (options->instant_toggle)
gtk_widget_set_sensitive (options->instant_toggle, TRUE);
}
static void
gimp_gradient_tool_commit (GimpGradientTool *gradient_tool)
{
GimpTool *tool = GIMP_TOOL (gradient_tool);
if (gradient_tool->filter)
{
/* 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);
gimp_tool_control_push_preserve (tool->control, TRUE);
gimp_drawable_filter_commit (gradient_tool->filter,
GIMP_PROGRESS (tool), FALSE);
g_clear_object (&gradient_tool->filter);
gimp_tool_control_pop_preserve (tool->control);
gimp_image_flush (gimp_display_get_image (tool->display));
}
1997-11-24 22:05:25 +00:00
}
static void
gimp_gradient_tool_line_changed (GimpToolWidget *widget,
GimpGradientTool *gradient_tool)
{
gdouble start_x;
gdouble start_y;
gdouble end_x;
gdouble end_y;
gboolean update = FALSE;
g_object_get (widget,
"x1", &start_x,
"y1", &start_y,
"x2", &end_x,
"y2", &end_y,
NULL);
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)
{
gradient_tool->start_x = start_x;
gradient_tool->start_y = start_y;
gradient_tool->end_x = end_x;
gradient_tool->end_y = end_y;
update = TRUE;
}
if (gimp_gradient_tool_editor_line_changed (gradient_tool))
update = TRUE;
if (update)
{
gimp_gradient_tool_update_graph (gradient_tool);
gimp_drawable_filter_apply (gradient_tool->filter, NULL);
}
}
static void
gimp_gradient_tool_line_response (GimpToolWidget *widget,
gint response_id,
GimpGradientTool *gradient_tool)
{
GimpTool *tool = GIMP_TOOL (gradient_tool);
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;
}
}
static void
gimp_gradient_tool_precalc_shapeburst (GimpGradientTool *gradient_tool)
{
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
GimpTool *tool = GIMP_TOOL (gradient_tool);
gint x, y, width, height;
if (gradient_tool->dist_buffer || ! tool->drawable)
return;
if (! gimp_item_mask_intersect (GIMP_ITEM (tool->drawable),
&x, &y, &width, &height))
return;
gradient_tool->dist_buffer =
gimp_drawable_gradient_shapeburst_distmap (tool->drawable,
options->distance_metric,
GEGL_RECTANGLE (x, y, width, height),
GIMP_PROGRESS (gradient_tool));
if (gradient_tool->dist_node)
gegl_node_set (gradient_tool->dist_node,
"buffer", gradient_tool->dist_buffer,
NULL);
gimp_progress_end (GIMP_PROGRESS (gradient_tool));
}
/* gegl graph stuff */
static void
gimp_gradient_tool_create_graph (GimpGradientTool *gradient_tool)
{
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
GimpContext *context = GIMP_CONTEXT (options);
GeglNode *output;
/* render_node is not supposed to be recreated */
g_return_if_fail (gradient_tool->graph == NULL);
gradient_tool->graph = gegl_node_new ();
gradient_tool->dist_node =
gegl_node_new_child (gradient_tool->graph,
"operation", "gegl:buffer-source",
"buffer", gradient_tool->dist_buffer,
NULL);
#if 0
gradient_tool->subtract_node =
gegl_node_new_child (gradient_tool->graph,
"operation", "gegl:subtract",
NULL);
gradient_tool->divide_node =
gegl_node_new_child (gradient_tool->graph,
"operation", "gegl:divide",
NULL);
#endif
gradient_tool->render_node =
gegl_node_new_child (gradient_tool->graph,
"operation", "gimp:gradient",
"context", context,
NULL);
output = gegl_node_get_output_proxy (gradient_tool->graph, "output");
gegl_node_link_many (gradient_tool->dist_node,
#if 0
gradient_tool->subtract_node,
gradient_tool->divide_node,
#endif
gradient_tool->render_node,
output,
NULL);
gimp_gegl_node_set_underlying_operation (gradient_tool->graph,
gradient_tool->render_node);
gimp_gradient_tool_update_graph (gradient_tool);
}
static void
gimp_gradient_tool_update_graph (GimpGradientTool *gradient_tool)
{
GimpTool *tool = GIMP_TOOL (gradient_tool);
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
gint off_x, off_y;
gimp_item_get_offset (GIMP_ITEM (tool->drawable), &off_x, &off_y);
#if 0
if (gimp_gradient_tool_is_shapeburst (gradient_tool))
{
gfloat start, end;
gegl_buffer_get (gradient_tool->dist_buffer,
GEGL_RECTANGLE (gradient_tool->start_x - off_x,
gradient_tool->start_y - off_y,
1, 1),
1.0, babl_format("Y float"), &start,
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
gegl_buffer_get (gradient_tool->dist_buffer,
GEGL_RECTANGLE (gradient_tool->end_x - off_x,
gradient_tool->end_y - off_y,
1, 1),
1.0, babl_format("Y float"), &end,
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
if (start != end)
{
gegl_node_set (gradient_tool->subtract_node,
"value", (gdouble) start,
NULL);
gegl_node_set (gradient_tool->divide_node,
"value", (gdouble) (end - start),
NULL);
}
}
else
#endif
{
GeglRectangle roi;
gdouble start_x, start_y;
gdouble end_x, end_y;
gimp_item_mask_intersect (GIMP_ITEM (tool->drawable),
&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;
gimp_drawable_gradient_adjust_coords (tool->drawable,
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);
}
}
static void
gimp_gradient_tool_fg_bg_changed (GimpGradientTool *gradient_tool)
{
if (! gradient_tool->filter || ! gradient_tool->gradient)
return;
if (gimp_gradient_has_fg_bg_segments (gradient_tool->gradient))
{
/* Set a property on the node. Otherwise it will cache and refuse to update */
gegl_node_set (gradient_tool->render_node,
"gradient", gradient_tool->gradient,
NULL);
/* Update the filter */
gimp_drawable_filter_apply (gradient_tool->filter, NULL);
gimp_gradient_tool_editor_fg_bg_changed (gradient_tool);
}
}
static void
gimp_gradient_tool_gradient_dirty (GimpGradientTool *gradient_tool)
{
if (! gradient_tool->filter)
return;
if (! gradient_tool->tentative_gradient)
{
/* Set a property on the node. Otherwise it will cache and refuse to update */
gegl_node_set (gradient_tool->render_node,
"gradient", gradient_tool->gradient,
NULL);
/* Update the filter */
gimp_drawable_filter_apply (gradient_tool->filter, NULL);
}
gimp_gradient_tool_editor_gradient_dirty (gradient_tool);
}
static void
gimp_gradient_tool_set_gradient (GimpGradientTool *gradient_tool,
GimpGradient *gradient)
{
if (gradient_tool->gradient)
g_signal_handlers_disconnect_by_func (gradient_tool->gradient,
G_CALLBACK (gimp_gradient_tool_gradient_dirty),
gradient_tool);
g_set_object (&gradient_tool->gradient, gradient);
if (gradient_tool->gradient)
{
g_signal_connect_swapped (gradient_tool->gradient, "dirty",
G_CALLBACK (gimp_gradient_tool_gradient_dirty),
gradient_tool);
if (gradient_tool->render_node)
gegl_node_set (gradient_tool->render_node,
"gradient", gradient_tool->gradient,
NULL);
}
gimp_gradient_tool_editor_gradient_changed (gradient_tool);
}
static gboolean
gimp_gradient_tool_is_shapeburst (GimpGradientTool *gradient_tool)
{
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
return options->gradient_type >= GIMP_GRADIENT_SHAPEBURST_ANGULAR &&
options->gradient_type <= GIMP_GRADIENT_SHAPEBURST_DIMPLED;
}
/* image map stuff */
static void
gimp_gradient_tool_create_filter (GimpGradientTool *gradient_tool,
GimpDrawable *drawable)
{
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
GimpContext *context = GIMP_CONTEXT (options);
if (! gradient_tool->graph)
gimp_gradient_tool_create_graph (gradient_tool);
gradient_tool->filter = gimp_drawable_filter_new (drawable,
C_("undo-type", "Gradient"),
gradient_tool->graph,
GIMP_ICON_TOOL_GRADIENT);
gimp_drawable_filter_set_region (gradient_tool->filter,
GIMP_FILTER_REGION_DRAWABLE);
gimp_drawable_filter_set_opacity (gradient_tool->filter,
gimp_context_get_opacity (context));
gimp_drawable_filter_set_mode (gradient_tool->filter,
gimp_context_get_paint_mode (context),
GIMP_LAYER_COLOR_SPACE_AUTO,
GIMP_LAYER_COLOR_SPACE_AUTO,
gimp_layer_mode_get_paint_composite_mode (
gimp_context_get_paint_mode (context)));
g_signal_connect (gradient_tool->filter, "flush",
G_CALLBACK (gimp_gradient_tool_filter_flush),
gradient_tool);
}
static void
gimp_gradient_tool_filter_flush (GimpDrawableFilter *filter,
GimpTool *tool)
{
GimpImage *image = gimp_display_get_image (tool->display);
gimp_projection_flush (gimp_image_get_projection (image));
}
/* protected functions */
void
gimp_gradient_tool_set_tentative_gradient (GimpGradientTool *gradient_tool,
GimpGradient *gradient)
{
g_return_if_fail (GIMP_IS_GRADIENT_TOOL (gradient_tool));
g_return_if_fail (gradient == NULL || GIMP_IS_GRADIENT (gradient));
if (g_set_object (&gradient_tool->tentative_gradient, gradient))
{
if (gradient_tool->render_node)
{
gegl_node_set (gradient_tool->render_node,
"gradient", gradient ? gradient : gradient_tool->gradient,
NULL);
gimp_drawable_filter_apply (gradient_tool->filter, NULL);
}
}
}