2010-06-15 05:25:08 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2010-07-01 02:27:52 +08:00
|
|
|
*
|
|
|
|
* gimpcagetool.c
|
|
|
|
* Copyright (C) 2010 Michael Muré <batolettre@gmail.com>
|
2010-06-15 05:25:08 +08:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-07-22 06:07:27 +08:00
|
|
|
#include <gegl.h>
|
2010-06-15 05:25:08 +08:00
|
|
|
#include <gtk/gtk.h>
|
2010-07-12 23:43:12 +08:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2010-06-15 05:25:08 +08:00
|
|
|
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "tools-types.h"
|
|
|
|
|
2012-05-11 03:22:44 +08:00
|
|
|
#include "gegl/gimp-gegl-utils.h"
|
|
|
|
|
|
|
|
#include "operations/gimpcageconfig.h"
|
|
|
|
|
2016-05-12 07:49:53 +08:00
|
|
|
#include "core/gimpdrawablefilter.h"
|
2017-02-09 02:28:14 +08:00
|
|
|
#include "core/gimperror.h"
|
2010-11-04 06:10:22 +08:00
|
|
|
#include "core/gimpimage.h"
|
2017-02-08 05:18:01 +08:00
|
|
|
#include "core/gimpitem.h"
|
2011-03-25 17:55:07 +08:00
|
|
|
#include "core/gimpprogress.h"
|
2010-11-05 05:14:58 +08:00
|
|
|
#include "core/gimpprojection.h"
|
|
|
|
|
|
|
|
#include "widgets/gimphelp-ids.h"
|
2015-10-17 21:31:08 +08:00
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2010-08-14 00:25:48 +08:00
|
|
|
|
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
2010-06-15 05:25:08 +08:00
|
|
|
#include "gimpcagetool.h"
|
2010-07-01 02:27:52 +08:00
|
|
|
#include "gimpcageoptions.h"
|
2010-11-05 05:14:58 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
2010-06-15 05:25:08 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
2010-11-05 05:14:58 +08:00
|
|
|
|
2013-09-21 17:51:38 +08:00
|
|
|
/* XXX: if this state list is updated, in particular if for some reason,
|
|
|
|
a new CAGE_STATE_* was to be inserted after CAGE_STATE_CLOSING, check
|
|
|
|
if the function gimp_cage_tool_is_complete() has to be updated.
|
|
|
|
Current algorithm is that all DEFORM_* states are complete states,
|
|
|
|
and all CAGE_* states are incomplete states. */
|
2011-03-24 05:29:00 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CAGE_STATE_INIT,
|
|
|
|
CAGE_STATE_WAIT,
|
|
|
|
CAGE_STATE_MOVE_HANDLE,
|
|
|
|
CAGE_STATE_SELECTING,
|
|
|
|
CAGE_STATE_CLOSING,
|
|
|
|
DEFORM_STATE_WAIT,
|
|
|
|
DEFORM_STATE_MOVE_HANDLE,
|
|
|
|
DEFORM_STATE_SELECTING
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
static gboolean gimp_cage_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error);
|
2017-02-08 05:18:01 +08:00
|
|
|
static void gimp_cage_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
2010-11-05 05:14:58 +08:00
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_cage_tool_button_press (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonPressType press_type,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_cage_tool_button_release (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_cage_tool_motion (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
2017-02-08 05:18:01 +08:00
|
|
|
static gboolean gimp_cage_tool_key_press (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
2010-11-05 05:14:58 +08:00
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_cage_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_cage_tool_oper_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
gboolean proximity,
|
|
|
|
GimpDisplay *display);
|
2017-02-08 05:18:01 +08:00
|
|
|
static void gimp_cage_tool_options_notify (GimpTool *tool,
|
|
|
|
GimpToolOptions *options,
|
|
|
|
const GParamSpec *pspec);
|
2010-11-05 05:14:58 +08:00
|
|
|
|
|
|
|
static void gimp_cage_tool_draw (GimpDrawTool *draw_tool);
|
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
static void gimp_cage_tool_start (GimpCageTool *ct,
|
|
|
|
GimpDisplay *display);
|
2014-04-05 04:34:26 +08:00
|
|
|
static void gimp_cage_tool_halt (GimpCageTool *ct);
|
|
|
|
static void gimp_cage_tool_commit (GimpCageTool *ct);
|
|
|
|
|
2011-01-02 23:15:55 +08:00
|
|
|
static gint gimp_cage_tool_is_on_handle (GimpCageTool *ct,
|
2010-11-05 05:38:41 +08:00
|
|
|
GimpDrawTool *draw_tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint handle_size);
|
2011-05-03 06:45:39 +08:00
|
|
|
static gint gimp_cage_tool_is_on_edge (GimpCageTool *ct,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint handle_size);
|
2010-11-05 05:14:58 +08:00
|
|
|
|
2013-09-21 17:51:38 +08:00
|
|
|
static gboolean gimp_cage_tool_is_complete (GimpCageTool *ct);
|
2010-11-05 05:14:58 +08:00
|
|
|
static void gimp_cage_tool_remove_last_handle (GimpCageTool *ct);
|
2011-06-29 05:24:06 +08:00
|
|
|
static void gimp_cage_tool_compute_coef (GimpCageTool *ct);
|
2017-02-08 05:18:01 +08:00
|
|
|
static void gimp_cage_tool_create_filter (GimpCageTool *ct);
|
2016-05-12 07:49:53 +08:00
|
|
|
static void gimp_cage_tool_filter_flush (GimpDrawableFilter *filter,
|
2010-11-06 02:10:03 +08:00
|
|
|
GimpTool *tool);
|
2016-05-12 07:49:53 +08:00
|
|
|
static void gimp_cage_tool_filter_update (GimpCageTool *ct);
|
2010-11-05 05:14:58 +08:00
|
|
|
|
2011-01-22 07:44:35 +08:00
|
|
|
static void gimp_cage_tool_create_render_node (GimpCageTool *ct);
|
|
|
|
static void gimp_cage_tool_render_node_update (GimpCageTool *ct);
|
2010-10-07 05:37:04 +08:00
|
|
|
|
2011-03-24 05:29:00 +08:00
|
|
|
|
2010-07-17 19:33:48 +08:00
|
|
|
G_DEFINE_TYPE (GimpCageTool, gimp_cage_tool, GIMP_TYPE_DRAW_TOOL)
|
2010-06-15 05:25:08 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_cage_tool_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_cage_tool_register (GimpToolRegisterCallback callback,
|
2010-11-05 05:38:41 +08:00
|
|
|
gpointer data)
|
2010-06-15 05:25:08 +08:00
|
|
|
{
|
2010-11-05 05:14:58 +08:00
|
|
|
(* callback) (GIMP_TYPE_CAGE_TOOL,
|
|
|
|
GIMP_TYPE_CAGE_OPTIONS,
|
|
|
|
gimp_cage_options_gui,
|
|
|
|
0,
|
2010-06-15 05:25:08 +08:00
|
|
|
"gimp-cage-tool",
|
2010-07-01 02:27:52 +08:00
|
|
|
_("Cage Transform"),
|
|
|
|
_("Cage Transform: Deform a selection with a cage"),
|
2010-11-05 04:44:31 +08:00
|
|
|
N_("_Cage Transform"), "<shift>G",
|
2010-07-01 02:27:52 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_CAGE,
|
2017-03-05 23:01:59 +08:00
|
|
|
GIMP_ICON_TOOL_CAGE,
|
2010-06-15 05:25:08 +08:00
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cage_tool_class_init (GimpCageToolClass *klass)
|
|
|
|
{
|
2010-11-05 05:14:58 +08:00
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
tool_class->initialize = gimp_cage_tool_initialize;
|
2017-02-08 05:18:01 +08:00
|
|
|
tool_class->control = gimp_cage_tool_control;
|
2010-11-05 05:14:58 +08:00
|
|
|
tool_class->button_press = gimp_cage_tool_button_press;
|
|
|
|
tool_class->button_release = gimp_cage_tool_button_release;
|
|
|
|
tool_class->key_press = gimp_cage_tool_key_press;
|
|
|
|
tool_class->motion = gimp_cage_tool_motion;
|
|
|
|
tool_class->cursor_update = gimp_cage_tool_cursor_update;
|
|
|
|
tool_class->oper_update = gimp_cage_tool_oper_update;
|
2017-02-08 05:18:01 +08:00
|
|
|
tool_class->options_notify = gimp_cage_tool_options_notify;
|
2010-11-05 05:14:58 +08:00
|
|
|
|
|
|
|
draw_tool_class->draw = gimp_cage_tool_draw;
|
2010-06-15 05:25:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cage_tool_init (GimpCageTool *self)
|
|
|
|
{
|
2010-11-06 06:49:48 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (self);
|
|
|
|
|
2013-06-19 01:05:54 +08:00
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
2010-11-21 21:13:58 +08:00
|
|
|
gimp_tool_control_set_dirty_mask (tool->control,
|
|
|
|
GIMP_DIRTY_IMAGE |
|
|
|
|
GIMP_DIRTY_IMAGE_STRUCTURE |
|
|
|
|
GIMP_DIRTY_DRAWABLE |
|
2012-09-07 05:55:35 +08:00
|
|
|
GIMP_DIRTY_SELECTION |
|
|
|
|
GIMP_DIRTY_ACTIVE_DRAWABLE);
|
2010-11-21 21:13:58 +08:00
|
|
|
gimp_tool_control_set_wants_click (tool->control, TRUE);
|
|
|
|
gimp_tool_control_set_tool_cursor (tool->control,
|
|
|
|
GIMP_TOOL_CURSOR_PERSPECTIVE);
|
|
|
|
|
2010-11-06 06:49:48 +08:00
|
|
|
self->config = g_object_new (GIMP_TYPE_CAGE_CONFIG, NULL);
|
|
|
|
self->hovering_handle = -1;
|
2010-12-17 21:49:37 +08:00
|
|
|
self->tool_state = CAGE_STATE_INIT;
|
2010-06-15 05:25:08 +08:00
|
|
|
}
|
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_cage_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
|
|
|
|
|
|
|
if (! drawable)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
|
|
|
_("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,
|
|
|
|
_("The active layer's pixels are locked."));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! gimp_item_is_visible (GIMP_ITEM (drawable)))
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
|
|
|
_("The active layer is not visible."));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_cage_tool_start (GIMP_CAGE_TOOL (tool), display);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_control (GimpTool *tool,
|
2010-11-05 05:14:58 +08:00
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *display)
|
2010-09-03 03:28:06 +08:00
|
|
|
{
|
2011-04-01 21:06:34 +08:00
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case GIMP_TOOL_ACTION_PAUSE:
|
|
|
|
case GIMP_TOOL_ACTION_RESUME:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_TOOL_ACTION_HALT:
|
2014-04-05 04:34:26 +08:00
|
|
|
gimp_cage_tool_halt (ct);
|
|
|
|
break;
|
2011-04-01 21:06:34 +08:00
|
|
|
|
2014-04-05 04:34:26 +08:00
|
|
|
case GIMP_TOOL_ACTION_COMMIT:
|
|
|
|
gimp_cage_tool_commit (ct);
|
2010-09-03 03:28:06 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
|
|
|
|
}
|
|
|
|
|
2010-08-15 07:29:34 +08:00
|
|
|
static void
|
2010-11-05 05:14:58 +08:00
|
|
|
gimp_cage_tool_button_press (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonPressType press_type,
|
|
|
|
GimpDisplay *display)
|
2010-07-12 23:43:12 +08:00
|
|
|
{
|
2017-02-09 02:28:14 +08:00
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
gint handle = -1;
|
|
|
|
gint edge = -1;
|
2010-08-15 07:29:34 +08:00
|
|
|
|
2011-03-30 17:48:05 +08:00
|
|
|
gimp_tool_control_activate (tool->control);
|
|
|
|
|
2010-12-17 21:49:37 +08:00
|
|
|
if (ct->config)
|
2011-05-03 06:45:39 +08:00
|
|
|
{
|
|
|
|
handle = gimp_cage_tool_is_on_handle (ct,
|
|
|
|
draw_tool,
|
|
|
|
display,
|
|
|
|
coords->x,
|
|
|
|
coords->y,
|
|
|
|
GIMP_TOOL_HANDLE_SIZE_CIRCLE);
|
|
|
|
edge = gimp_cage_tool_is_on_edge (ct,
|
|
|
|
coords->x,
|
|
|
|
coords->y,
|
|
|
|
GIMP_TOOL_HANDLE_SIZE_CIRCLE);
|
|
|
|
}
|
|
|
|
|
2011-01-02 23:15:55 +08:00
|
|
|
ct->movement_start_x = coords->x;
|
|
|
|
ct->movement_start_y = coords->y;
|
2010-12-17 21:49:37 +08:00
|
|
|
|
|
|
|
switch (ct->tool_state)
|
|
|
|
{
|
2017-02-09 02:28:14 +08:00
|
|
|
case CAGE_STATE_INIT:
|
|
|
|
/* No handle yet, we add the first one and swith the tool to
|
|
|
|
* moving handle state.
|
|
|
|
*/
|
|
|
|
gimp_cage_config_add_cage_point (ct->config,
|
|
|
|
coords->x - ct->offset_x,
|
|
|
|
coords->y - ct->offset_y);
|
|
|
|
gimp_cage_config_select_point (ct->config, 0);
|
|
|
|
ct->tool_state = CAGE_STATE_MOVE_HANDLE;
|
|
|
|
break;
|
2011-03-24 05:29:00 +08:00
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
case CAGE_STATE_WAIT:
|
|
|
|
if (handle == -1 && edge <= 0)
|
|
|
|
{
|
|
|
|
/* User clicked on the background, we add a new handle
|
|
|
|
* and move it
|
|
|
|
*/
|
|
|
|
gimp_cage_config_add_cage_point (ct->config,
|
|
|
|
coords->x - ct->offset_x,
|
|
|
|
coords->y - ct->offset_y);
|
|
|
|
gimp_cage_config_select_point (ct->config,
|
|
|
|
gimp_cage_config_get_n_points (ct->config) - 1);
|
|
|
|
ct->tool_state = CAGE_STATE_MOVE_HANDLE;
|
|
|
|
}
|
|
|
|
else if (handle == 0 && gimp_cage_config_get_n_points (ct->config) > 2)
|
|
|
|
{
|
|
|
|
/* User clicked on the first handle, we wait for
|
|
|
|
* release for closing the cage and switching to
|
|
|
|
* deform if possible
|
|
|
|
*/
|
|
|
|
gimp_cage_config_select_point (ct->config, 0);
|
|
|
|
ct->tool_state = CAGE_STATE_CLOSING;
|
|
|
|
}
|
|
|
|
else if (handle >= 0)
|
|
|
|
{
|
|
|
|
/* User clicked on a handle, so we move it */
|
2013-09-21 17:51:38 +08:00
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
if (state & gimp_get_extend_selection_mask ())
|
|
|
|
{
|
|
|
|
/* Multiple selection */
|
2011-03-24 05:29:00 +08:00
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
gimp_cage_config_toggle_point_selection (ct->config, handle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* New selection */
|
2011-05-03 06:45:39 +08:00
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
if (! gimp_cage_config_point_is_selected (ct->config, handle))
|
|
|
|
{
|
|
|
|
gimp_cage_config_select_point (ct->config, handle);
|
|
|
|
}
|
|
|
|
}
|
2013-09-21 17:51:38 +08:00
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
ct->tool_state = CAGE_STATE_MOVE_HANDLE;
|
|
|
|
}
|
|
|
|
else if (edge > 0)
|
|
|
|
{
|
|
|
|
/* User clicked on an edge, we add a new handle here and select it */
|
2010-12-17 21:49:37 +08:00
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
gimp_cage_config_insert_cage_point (ct->config, edge,
|
|
|
|
coords->x, coords->y);
|
|
|
|
gimp_cage_config_select_point (ct->config, edge);
|
|
|
|
ct->tool_state = CAGE_STATE_MOVE_HANDLE;
|
|
|
|
}
|
|
|
|
break;
|
2011-03-24 05:29:00 +08:00
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
case DEFORM_STATE_WAIT:
|
|
|
|
if (handle == -1)
|
|
|
|
{
|
|
|
|
/* User clicked on the background, we start a rubber band
|
|
|
|
* selection
|
|
|
|
*/
|
|
|
|
ct->selection_start_x = coords->x;
|
|
|
|
ct->selection_start_y = coords->y;
|
|
|
|
ct->tool_state = DEFORM_STATE_SELECTING;
|
|
|
|
}
|
2011-03-24 05:29:00 +08:00
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
if (handle >= 0)
|
|
|
|
{
|
|
|
|
/* User clicked on a handle, so we move it */
|
2011-03-24 05:29:00 +08:00
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
if (state & gimp_get_extend_selection_mask ())
|
|
|
|
{
|
|
|
|
/* Multiple selection */
|
2011-03-24 05:29:00 +08:00
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
gimp_cage_config_toggle_point_selection (ct->config, handle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* New selection */
|
2011-03-24 05:29:00 +08:00
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
if (! gimp_cage_config_point_is_selected (ct->config, handle))
|
|
|
|
{
|
|
|
|
gimp_cage_config_select_point (ct->config, handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ct->tool_state = DEFORM_STATE_MOVE_HANDLE;
|
|
|
|
}
|
|
|
|
break;
|
2010-12-17 21:49:37 +08:00
|
|
|
}
|
2010-07-12 23:43:12 +08:00
|
|
|
}
|
|
|
|
|
2010-08-15 07:29:34 +08:00
|
|
|
void
|
2010-07-12 23:43:12 +08:00
|
|
|
gimp_cage_tool_button_release (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
GimpDisplay *display)
|
2010-08-12 02:27:32 +08:00
|
|
|
{
|
2010-11-06 06:49:48 +08:00
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
2011-01-22 07:44:35 +08:00
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
2010-11-06 06:49:48 +08:00
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (ct));
|
|
|
|
|
2011-03-30 17:48:05 +08:00
|
|
|
gimp_tool_control_halt (tool->control);
|
|
|
|
|
2011-03-30 17:51:51 +08:00
|
|
|
if (release_type == GIMP_BUTTON_RELEASE_CANCEL)
|
2010-11-05 05:14:58 +08:00
|
|
|
{
|
2011-03-24 05:29:00 +08:00
|
|
|
/* Cancelling */
|
|
|
|
|
|
|
|
switch (ct->tool_state)
|
2010-11-06 06:49:48 +08:00
|
|
|
{
|
2011-03-24 05:29:00 +08:00
|
|
|
case CAGE_STATE_CLOSING:
|
|
|
|
ct->tool_state = CAGE_STATE_WAIT;
|
|
|
|
break;
|
2010-12-17 21:49:37 +08:00
|
|
|
|
2011-03-24 05:29:00 +08:00
|
|
|
case CAGE_STATE_MOVE_HANDLE:
|
|
|
|
gimp_cage_config_remove_last_cage_point (ct->config);
|
|
|
|
ct->tool_state = CAGE_STATE_WAIT;
|
|
|
|
break;
|
2010-12-17 21:49:37 +08:00
|
|
|
|
2011-03-24 05:29:00 +08:00
|
|
|
case CAGE_STATE_SELECTING:
|
|
|
|
ct->tool_state = CAGE_STATE_WAIT;
|
|
|
|
break;
|
2011-01-22 22:38:35 +08:00
|
|
|
|
2011-03-24 05:29:00 +08:00
|
|
|
case DEFORM_STATE_MOVE_HANDLE:
|
2016-05-12 07:49:53 +08:00
|
|
|
gimp_cage_tool_filter_update (ct);
|
2011-03-24 05:29:00 +08:00
|
|
|
ct->tool_state = DEFORM_STATE_WAIT;
|
|
|
|
break;
|
2011-01-10 21:55:38 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
case DEFORM_STATE_SELECTING:
|
|
|
|
ct->tool_state = DEFORM_STATE_WAIT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_cage_config_reset_displacement (ct->config);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Normal release */
|
|
|
|
|
|
|
|
switch (ct->tool_state)
|
|
|
|
{
|
|
|
|
case CAGE_STATE_CLOSING:
|
|
|
|
ct->dirty_coef = TRUE;
|
|
|
|
gimp_cage_config_commit_displacement (ct->config);
|
|
|
|
|
|
|
|
if (release_type == GIMP_BUTTON_RELEASE_CLICK)
|
|
|
|
g_object_set (options, "cage-mode", GIMP_CAGE_MODE_DEFORM, NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CAGE_STATE_MOVE_HANDLE:
|
|
|
|
ct->dirty_coef = TRUE;
|
|
|
|
ct->tool_state = CAGE_STATE_WAIT;
|
|
|
|
gimp_cage_config_commit_displacement (ct->config);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CAGE_STATE_SELECTING:
|
|
|
|
{
|
|
|
|
GeglRectangle area =
|
|
|
|
{ MIN (ct->selection_start_x, coords->x) - ct->offset_x,
|
|
|
|
MIN (ct->selection_start_y, coords->y) - ct->offset_y,
|
|
|
|
ABS (ct->selection_start_x - coords->x),
|
|
|
|
ABS (ct->selection_start_y - coords->y) };
|
|
|
|
|
|
|
|
if (state & gimp_get_extend_selection_mask ())
|
|
|
|
{
|
|
|
|
gimp_cage_config_select_add_area (ct->config,
|
|
|
|
GIMP_CAGE_MODE_CAGE_CHANGE,
|
|
|
|
area);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_cage_config_select_area (ct->config,
|
|
|
|
GIMP_CAGE_MODE_CAGE_CHANGE,
|
|
|
|
area);
|
|
|
|
}
|
|
|
|
|
|
|
|
ct->tool_state = CAGE_STATE_WAIT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DEFORM_STATE_MOVE_HANDLE:
|
|
|
|
ct->tool_state = DEFORM_STATE_WAIT;
|
|
|
|
gimp_cage_config_commit_displacement (ct->config);
|
|
|
|
gegl_node_set (ct->cage_node,
|
|
|
|
"config", ct->config,
|
|
|
|
NULL);
|
|
|
|
gimp_cage_tool_filter_update (ct);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DEFORM_STATE_SELECTING:
|
|
|
|
{
|
|
|
|
GeglRectangle area =
|
|
|
|
{ MIN (ct->selection_start_x, coords->x) - ct->offset_x,
|
|
|
|
MIN (ct->selection_start_y, coords->y) - ct->offset_y,
|
|
|
|
ABS (ct->selection_start_x - coords->x),
|
|
|
|
ABS (ct->selection_start_y - coords->y) };
|
|
|
|
|
|
|
|
if (state & gimp_get_extend_selection_mask ())
|
|
|
|
{
|
|
|
|
gimp_cage_config_select_add_area (ct->config,
|
|
|
|
GIMP_CAGE_MODE_DEFORM, area);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_cage_config_select_area (ct->config,
|
|
|
|
GIMP_CAGE_MODE_DEFORM, area);
|
|
|
|
}
|
|
|
|
|
|
|
|
ct->tool_state = DEFORM_STATE_WAIT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cage_tool_motion (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
|
|
|
ct->cursor_x = coords->x;
|
|
|
|
ct->cursor_y = coords->y;
|
|
|
|
|
|
|
|
switch (ct->tool_state)
|
|
|
|
{
|
|
|
|
case CAGE_STATE_MOVE_HANDLE:
|
|
|
|
case CAGE_STATE_CLOSING:
|
|
|
|
case DEFORM_STATE_MOVE_HANDLE:
|
|
|
|
gimp_cage_config_add_displacement (ct->config,
|
|
|
|
options->cage_mode,
|
|
|
|
ct->cursor_x - ct->movement_start_x,
|
|
|
|
ct->cursor_y - ct->movement_start_y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_cage_tool_key_press (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
|
|
|
|
|
|
|
if (! ct->config)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (kevent->keyval)
|
|
|
|
{
|
|
|
|
case GDK_KEY_BackSpace:
|
|
|
|
if (ct->tool_state == CAGE_STATE_WAIT)
|
|
|
|
{
|
|
|
|
if (gimp_cage_config_get_n_points (ct->config) != 0)
|
|
|
|
gimp_cage_tool_remove_last_handle (ct);
|
|
|
|
}
|
|
|
|
else if (ct->tool_state == DEFORM_STATE_WAIT)
|
|
|
|
{
|
|
|
|
gimp_cage_config_remove_selected_points (ct->config);
|
|
|
|
|
|
|
|
/* if the cage have less than 3 handles, we reopen it */
|
|
|
|
if (gimp_cage_config_get_n_points (ct->config) <= 2)
|
|
|
|
{
|
|
|
|
ct->tool_state = CAGE_STATE_WAIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_cage_tool_compute_coef (ct);
|
|
|
|
gimp_cage_tool_render_node_update (ct);
|
2010-11-06 06:49:48 +08:00
|
|
|
}
|
2017-02-08 05:18:01 +08:00
|
|
|
return TRUE;
|
2011-03-24 05:29:00 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
case GDK_KEY_Return:
|
|
|
|
case GDK_KEY_KP_Enter:
|
|
|
|
case GDK_KEY_ISO_Enter:
|
|
|
|
if (! gimp_cage_tool_is_complete (ct) &&
|
|
|
|
gimp_cage_config_get_n_points (ct->config) > 2)
|
2010-11-06 06:49:48 +08:00
|
|
|
{
|
2017-02-08 05:18:01 +08:00
|
|
|
g_object_set (gimp_tool_get_options (tool),
|
|
|
|
"cage-mode", GIMP_CAGE_MODE_DEFORM,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else if (ct->tool_state == DEFORM_STATE_WAIT)
|
|
|
|
{
|
|
|
|
gimp_tool_control (tool, GIMP_TOOL_ACTION_COMMIT, display);
|
|
|
|
}
|
|
|
|
return TRUE;
|
2011-03-24 05:29:00 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
case GDK_KEY_Escape:
|
|
|
|
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
|
|
|
|
return TRUE;
|
2010-12-17 21:49:37 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-01-22 22:38:35 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-01-22 22:38:35 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_oper_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
gboolean proximity,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
2011-01-10 21:55:38 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
if (ct->config)
|
|
|
|
{
|
|
|
|
ct->hovering_handle = gimp_cage_tool_is_on_handle (ct,
|
|
|
|
draw_tool,
|
|
|
|
display,
|
|
|
|
coords->x,
|
|
|
|
coords->y,
|
|
|
|
GIMP_TOOL_HANDLE_SIZE_CIRCLE);
|
2011-01-10 21:55:38 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
ct->hovering_edge = gimp_cage_tool_is_on_edge (ct,
|
|
|
|
coords->x,
|
|
|
|
coords->y,
|
|
|
|
GIMP_TOOL_HANDLE_SIZE_CIRCLE);
|
|
|
|
}
|
2011-03-24 05:29:00 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
gimp_draw_tool_pause (draw_tool);
|
2011-03-24 05:29:00 +08:00
|
|
|
|
2017-02-09 02:28:14 +08:00
|
|
|
ct->cursor_x = coords->x;
|
|
|
|
ct->cursor_y = coords->y;
|
2010-11-06 06:49:48 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
gimp_draw_tool_resume (draw_tool);
|
2010-07-12 23:43:12 +08:00
|
|
|
}
|
2010-07-01 02:27:52 +08:00
|
|
|
|
2010-07-12 23:43:12 +08:00
|
|
|
static void
|
2010-11-05 05:14:58 +08:00
|
|
|
gimp_cage_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
2010-07-12 23:43:12 +08:00
|
|
|
{
|
2010-11-06 07:03:38 +08:00
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
2011-05-03 06:45:39 +08:00
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
2010-11-06 07:03:38 +08:00
|
|
|
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_PLUS;
|
2010-07-12 23:43:12 +08:00
|
|
|
|
2010-11-06 07:03:38 +08:00
|
|
|
if (tool->display)
|
2010-07-12 23:43:12 +08:00
|
|
|
{
|
2010-11-06 07:03:38 +08:00
|
|
|
if (ct->hovering_handle != -1)
|
2010-11-05 05:14:58 +08:00
|
|
|
{
|
2010-11-06 07:03:38 +08:00
|
|
|
modifier = GIMP_CURSOR_MODIFIER_MOVE;
|
2010-11-05 05:14:58 +08:00
|
|
|
}
|
2015-03-02 08:02:06 +08:00
|
|
|
else if (ct->hovering_edge != -1 &&
|
|
|
|
options->cage_mode == GIMP_CAGE_MODE_CAGE_CHANGE)
|
2011-05-03 06:45:39 +08:00
|
|
|
{
|
|
|
|
modifier = GIMP_CURSOR_MODIFIER_PLUS;
|
|
|
|
}
|
2010-11-05 05:14:58 +08:00
|
|
|
else
|
|
|
|
{
|
2013-09-21 17:51:38 +08:00
|
|
|
if (gimp_cage_tool_is_complete (ct))
|
2010-11-06 07:03:38 +08:00
|
|
|
modifier = GIMP_CURSOR_MODIFIER_BAD;
|
2010-11-05 05:14:58 +08:00
|
|
|
}
|
2010-07-12 23:43:12 +08:00
|
|
|
}
|
2017-02-09 02:28:14 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
|
|
|
|
|
|
|
if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) ||
|
|
|
|
gimp_item_is_content_locked (GIMP_ITEM (drawable)) ||
|
|
|
|
! gimp_item_is_visible (GIMP_ITEM (drawable)))
|
|
|
|
{
|
|
|
|
modifier = GIMP_CURSOR_MODIFIER_BAD;
|
|
|
|
}
|
|
|
|
}
|
2010-11-06 07:03:38 +08:00
|
|
|
|
|
|
|
gimp_tool_control_set_cursor_modifier (tool->control, modifier);
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
|
2010-07-12 23:43:12 +08:00
|
|
|
}
|
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_options_notify (GimpTool *tool,
|
|
|
|
GimpToolOptions *options,
|
|
|
|
const GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec);
|
|
|
|
|
|
|
|
if (! tool->display)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
|
|
|
if (strcmp (pspec->name, "cage-mode") == 0)
|
|
|
|
{
|
|
|
|
GimpCageMode mode;
|
|
|
|
|
|
|
|
g_object_get (options,
|
|
|
|
"cage-mode", &mode,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (mode == GIMP_CAGE_MODE_DEFORM)
|
|
|
|
{
|
|
|
|
/* switch to deform mode */
|
|
|
|
|
|
|
|
if (gimp_cage_config_get_n_points (ct->config) > 2)
|
|
|
|
{
|
|
|
|
gimp_cage_config_reset_displacement (ct->config);
|
|
|
|
gimp_cage_config_reverse_cage_if_needed (ct->config);
|
|
|
|
gimp_tool_push_status (tool, tool->display,
|
|
|
|
_("Press ENTER to commit the transform"));
|
|
|
|
ct->tool_state = DEFORM_STATE_WAIT;
|
|
|
|
|
|
|
|
if (! ct->render_node)
|
|
|
|
{
|
|
|
|
gimp_cage_tool_create_render_node (ct);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ct->dirty_coef)
|
|
|
|
{
|
|
|
|
gimp_cage_tool_compute_coef (ct);
|
|
|
|
gimp_cage_tool_render_node_update (ct);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! ct->filter)
|
|
|
|
gimp_cage_tool_create_filter (ct);
|
|
|
|
|
|
|
|
gimp_cage_tool_filter_update (ct);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_set (options,
|
|
|
|
"cage-mode", GIMP_CAGE_MODE_CAGE_CHANGE,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* switch to edit mode */
|
|
|
|
if (ct->filter)
|
|
|
|
{
|
|
|
|
gimp_drawable_filter_abort (ct->filter);
|
|
|
|
|
|
|
|
gimp_tool_pop_status (tool, tool->display);
|
|
|
|
ct->tool_state = CAGE_STATE_WAIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp (pspec->name, "fill-plain-color") == 0)
|
|
|
|
{
|
|
|
|
if (ct->tool_state == DEFORM_STATE_WAIT)
|
|
|
|
{
|
|
|
|
gimp_cage_tool_render_node_update (ct);
|
|
|
|
gimp_cage_tool_filter_update (ct);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
}
|
|
|
|
|
2010-07-12 23:43:12 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_draw (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2010-11-05 05:14:58 +08:00
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (draw_tool);
|
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
|
|
|
GimpCageConfig *config = ct->config;
|
2010-11-06 02:59:48 +08:00
|
|
|
GimpCanvasGroup *stroke_group;
|
2010-11-05 17:04:45 +08:00
|
|
|
gint n_vertices;
|
2010-11-06 06:49:48 +08:00
|
|
|
gint i;
|
2010-12-17 21:49:37 +08:00
|
|
|
GimpHandleType handle;
|
2010-11-06 06:49:48 +08:00
|
|
|
|
2011-04-21 00:40:13 +08:00
|
|
|
n_vertices = gimp_cage_config_get_n_points (config);
|
|
|
|
|
|
|
|
if (n_vertices == 0)
|
|
|
|
return;
|
2010-07-17 22:32:46 +08:00
|
|
|
|
2010-12-17 21:49:37 +08:00
|
|
|
if (ct->tool_state == CAGE_STATE_INIT)
|
2010-07-12 23:43:12 +08:00
|
|
|
return;
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-11-06 02:59:48 +08:00
|
|
|
stroke_group = gimp_draw_tool_add_stroke_group (draw_tool);
|
|
|
|
|
|
|
|
gimp_draw_tool_push_group (draw_tool, stroke_group);
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2011-04-01 21:13:06 +08:00
|
|
|
/* If needed, draw line to the cursor. */
|
2013-09-21 17:51:38 +08:00
|
|
|
if (! gimp_cage_tool_is_complete (ct))
|
2010-11-05 05:14:58 +08:00
|
|
|
{
|
2011-03-24 05:29:00 +08:00
|
|
|
GimpVector2 last_point;
|
|
|
|
|
|
|
|
last_point = gimp_cage_config_get_point_coordinate (ct->config,
|
2011-03-25 17:18:56 +08:00
|
|
|
options->cage_mode,
|
2011-03-24 05:29:00 +08:00
|
|
|
n_vertices - 1);
|
|
|
|
|
2011-01-02 23:15:55 +08:00
|
|
|
gimp_draw_tool_add_line (draw_tool,
|
|
|
|
last_point.x + ct->offset_x,
|
|
|
|
last_point.y + ct->offset_y,
|
|
|
|
ct->cursor_x,
|
|
|
|
ct->cursor_y);
|
2010-11-05 05:14:58 +08:00
|
|
|
}
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-11-06 02:59:48 +08:00
|
|
|
gimp_draw_tool_pop_group (draw_tool);
|
|
|
|
|
2010-12-17 21:49:37 +08:00
|
|
|
/* Draw the cage with handles. */
|
2010-11-05 17:04:45 +08:00
|
|
|
for (i = 0; i < n_vertices; i++)
|
2010-07-12 23:43:12 +08:00
|
|
|
{
|
2011-01-02 23:15:55 +08:00
|
|
|
GimpVector2 point1, point2;
|
2010-11-06 02:59:48 +08:00
|
|
|
|
2011-01-02 23:15:55 +08:00
|
|
|
point1 = gimp_cage_config_get_point_coordinate (ct->config,
|
|
|
|
options->cage_mode,
|
|
|
|
i);
|
|
|
|
point1.x += ct->offset_x;
|
|
|
|
point1.y += ct->offset_y;
|
2010-11-06 06:49:48 +08:00
|
|
|
|
2013-09-21 17:51:38 +08:00
|
|
|
if (i > 0 || gimp_cage_tool_is_complete (ct))
|
2010-11-06 06:49:48 +08:00
|
|
|
{
|
2011-03-24 05:29:00 +08:00
|
|
|
gint index_point2;
|
2010-11-06 06:49:48 +08:00
|
|
|
|
|
|
|
if (i == 0)
|
2011-01-02 23:15:55 +08:00
|
|
|
index_point2 = n_vertices - 1;
|
2010-11-06 06:49:48 +08:00
|
|
|
else
|
2011-01-02 23:15:55 +08:00
|
|
|
index_point2 = i - 1;
|
2010-11-06 06:49:48 +08:00
|
|
|
|
2011-01-02 23:15:55 +08:00
|
|
|
point2 = gimp_cage_config_get_point_coordinate (ct->config,
|
|
|
|
options->cage_mode,
|
|
|
|
index_point2);
|
|
|
|
point2.x += ct->offset_x;
|
|
|
|
point2.y += ct->offset_y;
|
2010-11-06 06:49:48 +08:00
|
|
|
|
2010-11-06 02:59:48 +08:00
|
|
|
gimp_draw_tool_push_group (draw_tool, stroke_group);
|
|
|
|
|
|
|
|
gimp_draw_tool_add_line (draw_tool,
|
2011-01-02 23:15:55 +08:00
|
|
|
point1.x,
|
|
|
|
point1.y,
|
|
|
|
point2.x,
|
|
|
|
point2.y);
|
2010-11-06 02:59:48 +08:00
|
|
|
|
|
|
|
gimp_draw_tool_pop_group (draw_tool);
|
|
|
|
}
|
2010-11-05 05:14:58 +08:00
|
|
|
|
2010-11-06 06:49:48 +08:00
|
|
|
if (i == ct->hovering_handle)
|
2010-11-05 05:14:58 +08:00
|
|
|
handle = GIMP_HANDLE_FILLED_CIRCLE;
|
2010-11-06 02:59:48 +08:00
|
|
|
else
|
|
|
|
handle = GIMP_HANDLE_CIRCLE;
|
2010-11-05 05:14:58 +08:00
|
|
|
|
|
|
|
gimp_draw_tool_add_handle (draw_tool,
|
|
|
|
handle,
|
2011-01-02 23:15:55 +08:00
|
|
|
point1.x,
|
|
|
|
point1.y,
|
2010-11-09 05:37:00 +08:00
|
|
|
GIMP_TOOL_HANDLE_SIZE_CIRCLE,
|
|
|
|
GIMP_TOOL_HANDLE_SIZE_CIRCLE,
|
2010-11-05 05:47:03 +08:00
|
|
|
GIMP_HANDLE_ANCHOR_CENTER);
|
2011-01-02 23:15:55 +08:00
|
|
|
|
2011-04-21 00:40:13 +08:00
|
|
|
if (gimp_cage_config_point_is_selected (ct->config, i))
|
2011-01-02 23:15:55 +08:00
|
|
|
{
|
|
|
|
gimp_draw_tool_add_handle (draw_tool,
|
2011-03-25 17:18:56 +08:00
|
|
|
GIMP_HANDLE_SQUARE,
|
|
|
|
point1.x,
|
|
|
|
point1.y,
|
|
|
|
GIMP_TOOL_HANDLE_SIZE_CIRCLE,
|
|
|
|
GIMP_TOOL_HANDLE_SIZE_CIRCLE,
|
|
|
|
GIMP_HANDLE_ANCHOR_CENTER);
|
2011-01-02 23:15:55 +08:00
|
|
|
}
|
2010-07-12 23:43:12 +08:00
|
|
|
}
|
2011-01-10 21:55:38 +08:00
|
|
|
|
2011-03-24 05:29:00 +08:00
|
|
|
if (ct->tool_state == DEFORM_STATE_SELECTING ||
|
|
|
|
ct->tool_state == CAGE_STATE_SELECTING)
|
2011-01-10 21:55:38 +08:00
|
|
|
{
|
|
|
|
gimp_draw_tool_add_rectangle (draw_tool,
|
|
|
|
FALSE,
|
2011-03-24 05:29:00 +08:00
|
|
|
MIN (ct->selection_start_x, ct->cursor_x),
|
|
|
|
MIN (ct->selection_start_y, ct->cursor_y),
|
2016-02-13 05:48:59 +08:00
|
|
|
ABS (ct->selection_start_x - ct->cursor_x),
|
|
|
|
ABS (ct->selection_start_y - ct->cursor_y));
|
2011-01-10 21:55:38 +08:00
|
|
|
}
|
2010-07-12 23:43:12 +08:00
|
|
|
}
|
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_start (GimpCageTool *ct,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (ct);
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
|
|
|
|
|
|
|
tool->display = display;
|
|
|
|
tool->drawable = drawable;
|
|
|
|
|
|
|
|
if (ct->config)
|
|
|
|
{
|
|
|
|
g_object_unref (ct->config);
|
|
|
|
ct->config = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ct->coef)
|
|
|
|
{
|
|
|
|
g_object_unref (ct->coef);
|
|
|
|
ct->dirty_coef = TRUE;
|
|
|
|
ct->coef = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ct->filter)
|
|
|
|
{
|
|
|
|
gimp_drawable_filter_abort (ct->filter);
|
|
|
|
g_object_unref (ct->filter);
|
|
|
|
ct->filter = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ct->render_node)
|
|
|
|
{
|
|
|
|
g_object_unref (ct->render_node);
|
|
|
|
ct->render_node = NULL;
|
|
|
|
ct->coef_node = NULL;
|
|
|
|
ct->cage_node = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ct->config = g_object_new (GIMP_TYPE_CAGE_CONFIG, NULL);
|
|
|
|
ct->hovering_handle = -1;
|
|
|
|
ct->hovering_edge = -1;
|
|
|
|
ct->tool_state = CAGE_STATE_INIT;
|
|
|
|
|
|
|
|
/* Setting up cage offset to convert the cage point coords to
|
|
|
|
* drawable coords
|
|
|
|
*/
|
|
|
|
gimp_item_get_offset (GIMP_ITEM (tool->drawable),
|
|
|
|
&ct->offset_x, &ct->offset_y);
|
|
|
|
|
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (ct), display);
|
|
|
|
}
|
|
|
|
|
2014-04-05 04:34:26 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_halt (GimpCageTool *ct)
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (ct);
|
|
|
|
|
|
|
|
if (ct->config)
|
|
|
|
{
|
|
|
|
g_object_unref (ct->config);
|
|
|
|
ct->config = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ct->coef)
|
|
|
|
{
|
|
|
|
g_object_unref (ct->coef);
|
|
|
|
ct->coef = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ct->render_node)
|
|
|
|
{
|
|
|
|
g_object_unref (ct->render_node);
|
|
|
|
ct->render_node = NULL;
|
|
|
|
ct->coef_node = NULL;
|
|
|
|
ct->cage_node = NULL;
|
|
|
|
}
|
|
|
|
|
2016-05-12 07:49:53 +08:00
|
|
|
if (ct->filter)
|
2014-04-05 04:34:26 +08:00
|
|
|
{
|
|
|
|
gimp_tool_control_push_preserve (tool->control, TRUE);
|
|
|
|
|
2016-05-12 07:49:53 +08:00
|
|
|
gimp_drawable_filter_abort (ct->filter);
|
|
|
|
g_object_unref (ct->filter);
|
|
|
|
ct->filter = NULL;
|
2014-04-05 04:34:26 +08:00
|
|
|
|
|
|
|
gimp_tool_control_pop_preserve (tool->control);
|
|
|
|
|
|
|
|
gimp_image_flush (gimp_display_get_image (tool->display));
|
|
|
|
}
|
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
tool->display = NULL;
|
|
|
|
tool->drawable = NULL;
|
2014-12-12 01:37:49 +08:00
|
|
|
ct->tool_state = CAGE_STATE_INIT;
|
2014-04-05 04:34:26 +08:00
|
|
|
|
|
|
|
g_object_set (gimp_tool_get_options (tool),
|
|
|
|
"cage-mode", GIMP_CAGE_MODE_CAGE_CHANGE,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cage_tool_commit (GimpCageTool *ct)
|
|
|
|
{
|
2016-05-12 07:49:53 +08:00
|
|
|
if (ct->filter)
|
2016-03-24 06:00:48 +08:00
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (ct);
|
2014-04-05 04:34:26 +08:00
|
|
|
|
2016-03-24 06:00:48 +08:00
|
|
|
gimp_tool_control_push_preserve (tool->control, TRUE);
|
2014-04-05 04:34:26 +08:00
|
|
|
|
2016-05-12 07:49:53 +08:00
|
|
|
gimp_drawable_filter_commit (ct->filter, GIMP_PROGRESS (tool), FALSE);
|
|
|
|
g_object_unref (ct->filter);
|
|
|
|
ct->filter = NULL;
|
2014-04-05 04:34:26 +08:00
|
|
|
|
2016-03-24 06:00:48 +08:00
|
|
|
gimp_tool_control_pop_preserve (tool->control);
|
2014-04-05 04:34:26 +08:00
|
|
|
|
2016-03-24 06:00:48 +08:00
|
|
|
gimp_image_flush (gimp_display_get_image (tool->display));
|
|
|
|
}
|
2014-04-05 04:34:26 +08:00
|
|
|
}
|
|
|
|
|
2010-09-05 18:33:26 +08:00
|
|
|
static gint
|
2011-03-24 05:29:00 +08:00
|
|
|
gimp_cage_tool_is_on_handle (GimpCageTool *ct,
|
|
|
|
GimpDrawTool *draw_tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint handle_size)
|
2010-09-05 18:33:26 +08:00
|
|
|
{
|
2011-03-24 05:29:00 +08:00
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
|
|
|
GimpCageConfig *config = ct->config;
|
|
|
|
gdouble dist = G_MAXDOUBLE;
|
2011-01-02 23:15:55 +08:00
|
|
|
gint i;
|
|
|
|
GimpVector2 cage_point;
|
2011-04-21 00:40:13 +08:00
|
|
|
guint n_cage_vertices;
|
2010-09-05 18:33:26 +08:00
|
|
|
|
2011-01-02 23:15:55 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CAGE_TOOL (ct), -1);
|
2010-09-05 18:33:26 +08:00
|
|
|
|
2011-04-21 00:40:13 +08:00
|
|
|
n_cage_vertices = gimp_cage_config_get_n_points (config);
|
|
|
|
|
|
|
|
if (n_cage_vertices == 0)
|
2010-09-05 18:33:26 +08:00
|
|
|
return -1;
|
|
|
|
|
2011-04-21 00:40:13 +08:00
|
|
|
for (i = 0; i < n_cage_vertices; i++)
|
2010-09-05 18:33:26 +08:00
|
|
|
{
|
2011-01-02 23:15:55 +08:00
|
|
|
cage_point = gimp_cage_config_get_point_coordinate (config,
|
|
|
|
options->cage_mode,
|
|
|
|
i);
|
|
|
|
cage_point.x += ct->offset_x;
|
|
|
|
cage_point.y += ct->offset_y;
|
2010-11-05 05:14:58 +08:00
|
|
|
|
|
|
|
dist = gimp_draw_tool_calc_distance_square (GIMP_DRAW_TOOL (draw_tool),
|
|
|
|
display,
|
|
|
|
x, y,
|
2011-01-02 23:15:55 +08:00
|
|
|
cage_point.x,
|
|
|
|
cage_point.y);
|
2010-11-05 05:14:58 +08:00
|
|
|
|
2010-11-06 07:05:35 +08:00
|
|
|
if (dist <= SQR (handle_size / 2))
|
2010-11-05 05:14:58 +08:00
|
|
|
return i;
|
2010-09-05 18:33:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-03 06:45:39 +08:00
|
|
|
static gint
|
|
|
|
gimp_cage_tool_is_on_edge (GimpCageTool *ct,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint handle_size)
|
|
|
|
{
|
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
|
|
|
GimpCageConfig *config = ct->config;
|
|
|
|
gint i;
|
|
|
|
guint n_cage_vertices;
|
|
|
|
GimpVector2 A, B, C, AB, BC, AC;
|
|
|
|
gdouble lAB, lBC, lAC, lEB, lEC;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_CAGE_TOOL (ct), -1);
|
|
|
|
|
|
|
|
n_cage_vertices = gimp_cage_config_get_n_points (config);
|
|
|
|
|
|
|
|
if (n_cage_vertices < 2)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
A = gimp_cage_config_get_point_coordinate (config,
|
|
|
|
options->cage_mode,
|
|
|
|
n_cage_vertices-1);
|
|
|
|
B = gimp_cage_config_get_point_coordinate (config,
|
|
|
|
options->cage_mode,
|
|
|
|
0);
|
|
|
|
C.x = x;
|
|
|
|
C.y = y;
|
|
|
|
|
|
|
|
for (i = 0; i < n_cage_vertices; i++)
|
|
|
|
{
|
|
|
|
gimp_vector2_sub (&AB, &A, &B);
|
|
|
|
gimp_vector2_sub (&BC, &B, &C);
|
|
|
|
gimp_vector2_sub (&AC, &A, &C);
|
|
|
|
|
|
|
|
lAB = gimp_vector2_length (&AB);
|
|
|
|
lBC = gimp_vector2_length (&BC);
|
|
|
|
lAC = gimp_vector2_length (&AC);
|
|
|
|
lEB = lAB / 2 + (SQR (lBC) - SQR (lAC)) / (2 * lAB);
|
|
|
|
lEC = sqrt (SQR (lBC) - SQR (lEB));
|
|
|
|
|
2016-02-13 05:48:59 +08:00
|
|
|
if ((lEC < handle_size / 2) && (ABS (SQR (lBC) - SQR (lAC)) <= SQR (lAB)))
|
2011-05-03 06:45:39 +08:00
|
|
|
return i;
|
|
|
|
|
|
|
|
A = B;
|
|
|
|
B = gimp_cage_config_get_point_coordinate (config,
|
|
|
|
options->cage_mode,
|
|
|
|
(i+1) % n_cage_vertices);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-09-21 17:51:38 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_cage_tool_is_complete (GimpCageTool *ct)
|
|
|
|
{
|
|
|
|
return (ct->tool_state > CAGE_STATE_CLOSING);
|
|
|
|
}
|
|
|
|
|
2010-07-12 23:43:12 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_remove_last_handle (GimpCageTool *ct)
|
|
|
|
{
|
2010-11-05 05:14:58 +08:00
|
|
|
GimpCageConfig *config = ct->config;
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-12 23:43:12 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (ct));
|
2010-11-05 05:14:58 +08:00
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
gimp_cage_config_remove_last_cage_point (config);
|
2010-11-05 05:14:58 +08:00
|
|
|
|
2010-07-12 23:43:12 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (ct));
|
2010-07-22 06:07:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-29 05:24:06 +08:00
|
|
|
gimp_cage_tool_compute_coef (GimpCageTool *ct)
|
2010-07-27 01:24:05 +08:00
|
|
|
{
|
2011-03-25 16:48:26 +08:00
|
|
|
GimpCageConfig *config = ct->config;
|
2011-03-25 17:55:07 +08:00
|
|
|
GimpProgress *progress;
|
2012-03-25 01:52:31 +08:00
|
|
|
const Babl *format;
|
2011-03-25 16:48:26 +08:00
|
|
|
GeglNode *gegl;
|
|
|
|
GeglNode *input;
|
|
|
|
GeglNode *output;
|
|
|
|
GeglProcessor *processor;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
gdouble value;
|
|
|
|
|
2014-07-13 05:45:20 +08:00
|
|
|
progress = gimp_progress_start (GIMP_PROGRESS (ct), FALSE,
|
|
|
|
_("Computing Cage Coefficients"));
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
if (ct->coef)
|
2010-11-05 05:14:58 +08:00
|
|
|
{
|
2012-03-30 05:21:05 +08:00
|
|
|
g_object_unref (ct->coef);
|
2010-11-05 05:14:58 +08:00
|
|
|
ct->coef = NULL;
|
|
|
|
}
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-11-05 05:14:58 +08:00
|
|
|
format = babl_format_n (babl_type ("float"),
|
2011-04-21 00:40:13 +08:00
|
|
|
gimp_cage_config_get_n_points (config) * 2);
|
2010-08-15 20:20:47 +08:00
|
|
|
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
gegl = gegl_node_new ();
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
input = gegl_node_new_child (gegl,
|
2010-11-05 19:45:07 +08:00
|
|
|
"operation", "gimp:cage-coef-calc",
|
2010-11-05 05:14:58 +08:00
|
|
|
"config", ct->config,
|
|
|
|
NULL);
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
output = gegl_node_new_child (gegl,
|
2010-11-05 05:14:58 +08:00
|
|
|
"operation", "gegl:buffer-sink",
|
|
|
|
"buffer", &buffer,
|
|
|
|
"format", format,
|
|
|
|
NULL);
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
gegl_node_connect_to (input, "output",
|
2010-10-07 05:37:04 +08:00
|
|
|
output, "input");
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-08-15 07:29:34 +08:00
|
|
|
processor = gegl_node_new_processor (output, NULL);
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
while (gegl_processor_work (processor, &value))
|
2010-11-05 05:14:58 +08:00
|
|
|
{
|
2011-03-25 17:55:07 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_set_value (progress, value);
|
2010-11-05 05:14:58 +08:00
|
|
|
}
|
2010-07-27 01:24:05 +08:00
|
|
|
|
2011-03-25 17:55:07 +08:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_end (progress);
|
2010-11-05 05:14:58 +08:00
|
|
|
|
2012-03-30 05:21:05 +08:00
|
|
|
g_object_unref (processor);
|
2010-07-27 01:24:05 +08:00
|
|
|
|
|
|
|
ct->coef = buffer;
|
|
|
|
g_object_unref (gegl);
|
2010-11-10 02:35:54 +08:00
|
|
|
|
2011-01-22 07:44:35 +08:00
|
|
|
ct->dirty_coef = FALSE;
|
2010-07-27 01:24:05 +08:00
|
|
|
}
|
|
|
|
|
2011-01-22 07:44:35 +08:00
|
|
|
static void
|
2010-11-06 02:47:57 +08:00
|
|
|
gimp_cage_tool_create_render_node (GimpCageTool *ct)
|
2010-10-07 05:37:04 +08:00
|
|
|
{
|
2017-02-08 05:18:01 +08:00
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
|
|
|
GeglNode *render;
|
|
|
|
GeglNode *input;
|
|
|
|
GeglNode *output;
|
2010-10-07 05:37:04 +08:00
|
|
|
|
2011-01-22 07:44:35 +08:00
|
|
|
g_return_if_fail (ct->render_node == NULL);
|
|
|
|
/* render_node is not supposed to be recreated */
|
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
ct->render_node = gegl_node_new ();
|
2010-10-07 05:37:04 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
input = gegl_node_get_input_proxy (ct->render_node, "input");
|
|
|
|
output = gegl_node_get_output_proxy (ct->render_node, "output");
|
2010-10-07 05:37:04 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
ct->coef_node = gegl_node_new_child (ct->render_node,
|
|
|
|
"operation", "gegl:buffer-source",
|
|
|
|
"buffer", ct->coef,
|
|
|
|
NULL);
|
2010-10-07 05:37:04 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
ct->cage_node = gegl_node_new_child (ct->render_node,
|
|
|
|
"operation", "gimp:cage-transform",
|
|
|
|
"config", ct->config,
|
|
|
|
"fill-plain-color", options->fill_plain_color,
|
|
|
|
NULL);
|
2010-10-07 05:37:04 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
render = gegl_node_new_child (ct->render_node,
|
2010-11-03 02:56:11 +08:00
|
|
|
"operation", "gegl:map-absolute",
|
2010-10-07 05:37:04 +08:00
|
|
|
NULL);
|
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
gegl_node_connect_to (input, "output",
|
|
|
|
ct->cage_node, "input");
|
2010-10-07 05:37:04 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
gegl_node_connect_to (ct->coef_node, "output",
|
|
|
|
ct->cage_node, "aux");
|
2010-10-07 05:37:04 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
gegl_node_connect_to (input, "output",
|
2010-10-07 05:37:04 +08:00
|
|
|
render, "input");
|
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
gegl_node_connect_to (ct->cage_node, "output",
|
|
|
|
render, "aux");
|
2010-10-07 05:37:04 +08:00
|
|
|
|
|
|
|
gegl_node_connect_to (render, "output",
|
|
|
|
output, "input");
|
2010-11-06 02:10:03 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
gimp_gegl_progress_connect (ct->cage_node, GIMP_PROGRESS (ct),
|
|
|
|
_("Cage Transform"));
|
2011-01-22 07:44:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cage_tool_render_node_update (GimpCageTool *ct)
|
|
|
|
{
|
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
2017-02-08 05:18:01 +08:00
|
|
|
gboolean fill;
|
2011-01-22 07:44:35 +08:00
|
|
|
GeglBuffer *buffer;
|
|
|
|
|
|
|
|
gegl_node_get (ct->cage_node,
|
2017-02-08 05:18:01 +08:00
|
|
|
"fill-plain-color", &fill,
|
2011-01-22 07:44:35 +08:00
|
|
|
NULL);
|
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
if (fill != options->fill_plain_color)
|
2011-01-22 07:44:35 +08:00
|
|
|
{
|
|
|
|
gegl_node_set (ct->cage_node,
|
2017-02-08 05:18:01 +08:00
|
|
|
"fill-plain-color", options->fill_plain_color,
|
2011-01-22 07:44:35 +08:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
gegl_node_get (ct->coef_node,
|
|
|
|
"buffer", &buffer,
|
|
|
|
NULL);
|
|
|
|
|
2011-04-05 03:35:18 +08:00
|
|
|
if (buffer != ct->coef)
|
2011-01-22 07:44:35 +08:00
|
|
|
{
|
|
|
|
gegl_node_set (ct->coef_node,
|
2017-02-08 05:18:01 +08:00
|
|
|
"buffer", ct->coef,
|
2011-01-22 07:44:35 +08:00
|
|
|
NULL);
|
|
|
|
}
|
2011-04-05 16:18:07 +08:00
|
|
|
|
|
|
|
if (buffer)
|
2017-02-08 05:18:01 +08:00
|
|
|
g_object_unref (buffer);
|
2010-10-07 05:37:04 +08:00
|
|
|
}
|
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
static void
|
2017-02-08 05:18:01 +08:00
|
|
|
gimp_cage_tool_create_filter (GimpCageTool *ct)
|
2010-09-03 03:28:06 +08:00
|
|
|
{
|
2016-05-12 07:49:53 +08:00
|
|
|
if (! ct->render_node)
|
2011-01-22 07:44:35 +08:00
|
|
|
gimp_cage_tool_create_render_node (ct);
|
2010-09-03 03:28:06 +08:00
|
|
|
|
2017-02-08 05:18:01 +08:00
|
|
|
ct->filter = gimp_drawable_filter_new (GIMP_TOOL (ct)->drawable,
|
2016-05-12 07:49:53 +08:00
|
|
|
_("Cage transform"),
|
|
|
|
ct->render_node,
|
2017-03-05 23:01:59 +08:00
|
|
|
GIMP_ICON_TOOL_CAGE);
|
2010-11-06 02:10:03 +08:00
|
|
|
|
2016-05-12 07:49:53 +08:00
|
|
|
g_signal_connect (ct->filter, "flush",
|
|
|
|
G_CALLBACK (gimp_cage_tool_filter_flush),
|
2010-11-06 02:10:03 +08:00
|
|
|
ct);
|
2010-09-03 03:28:06 +08:00
|
|
|
}
|
|
|
|
|
2010-11-06 02:10:03 +08:00
|
|
|
static void
|
2016-05-12 07:49:53 +08:00
|
|
|
gimp_cage_tool_filter_flush (GimpDrawableFilter *filter,
|
|
|
|
GimpTool *tool)
|
2010-09-03 03:28:06 +08:00
|
|
|
{
|
2010-11-06 02:10:03 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (tool->display);
|
2010-09-03 03:28:06 +08:00
|
|
|
|
2013-04-12 20:35:27 +08:00
|
|
|
gimp_projection_flush (gimp_image_get_projection (image));
|
2010-09-03 03:28:06 +08:00
|
|
|
}
|
|
|
|
|
2010-12-17 21:49:37 +08:00
|
|
|
static void
|
2016-05-12 07:49:53 +08:00
|
|
|
gimp_cage_tool_filter_update (GimpCageTool *ct)
|
2010-12-17 21:49:37 +08:00
|
|
|
{
|
2016-05-12 07:49:53 +08:00
|
|
|
gimp_drawable_filter_apply (ct->filter, NULL);
|
2010-12-17 21:49:37 +08:00
|
|
|
}
|