2011-05-24 03:11:08 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
*
|
|
|
|
* gimpwarptool.c
|
|
|
|
* Copyright (C) 2011 Michael Muré <batolettre@gmail.com>
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <gegl.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "tools-types.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpchannel.h"
|
|
|
|
#include "core/gimpdrawable-shadow.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpimagemap.h"
|
|
|
|
#include "core/gimplayer.h"
|
|
|
|
#include "core/gimpprogress.h"
|
|
|
|
#include "core/gimpprojection.h"
|
|
|
|
|
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
|
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
#include "display/gimpdisplayshell.h"
|
|
|
|
#include "display/gimpdisplayshell-transform.h"
|
|
|
|
|
|
|
|
#include "gimpwarptool.h"
|
|
|
|
#include "gimpwarpoptions.h"
|
|
|
|
#include "gimptoolcontrol.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void gimp_warp_tool_start (GimpWarpTool *wt,
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
|
|
|
static void gimp_warp_tool_options_notify (GimpTool *tool,
|
|
|
|
GimpToolOptions *options,
|
|
|
|
const GParamSpec *pspec);
|
|
|
|
static void gimp_warp_tool_button_press (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonPressType press_type,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_warp_tool_button_release (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static gboolean gimp_warp_tool_key_press (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_warp_tool_motion (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_warp_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_warp_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_warp_tool_oper_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
gboolean proximity,
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
|
|
|
static void gimp_warp_tool_draw (GimpDrawTool *draw_tool);
|
|
|
|
|
2011-06-08 20:15:21 +08:00
|
|
|
static void gimp_warp_tool_create_graph (GimpWarpTool *wt);
|
2011-05-25 07:54:38 +08:00
|
|
|
static void gimp_warp_tool_create_image_map (GimpWarpTool *wt,
|
|
|
|
GimpDrawable *drawable);
|
|
|
|
static void gimp_warp_tool_image_map_flush (GimpImageMap *image_map,
|
|
|
|
GimpTool *tool);
|
|
|
|
static void gimp_warp_tool_image_map_update (GimpWarpTool *wt);
|
2011-06-08 20:15:21 +08:00
|
|
|
static void gimp_warp_tool_add_op (GimpWarpTool *wt);
|
2011-05-25 07:54:38 +08:00
|
|
|
|
2011-05-24 03:11:08 +08:00
|
|
|
G_DEFINE_TYPE (GimpWarpTool, gimp_warp_tool, GIMP_TYPE_DRAW_TOOL)
|
|
|
|
|
|
|
|
#define parent_class gimp_warp_tool_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_warp_tool_register (GimpToolRegisterCallback callback,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
(* callback) (GIMP_TYPE_WARP_TOOL,
|
|
|
|
GIMP_TYPE_WARP_OPTIONS,
|
|
|
|
gimp_warp_options_gui,
|
|
|
|
0,
|
|
|
|
"gimp-warp-tool",
|
|
|
|
_("Warp Transform"),
|
|
|
|
_("Warp Transform: Deform with different tools"),
|
|
|
|
N_("_Warp Transform"), "W",
|
|
|
|
NULL, GIMP_HELP_TOOL_WARP,
|
|
|
|
GIMP_STOCK_TOOL_WARP,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_warp_tool_class_init (GimpWarpToolClass *klass)
|
|
|
|
{
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
|
|
|
|
|
|
|
tool_class->options_notify = gimp_warp_tool_options_notify;
|
|
|
|
tool_class->button_press = gimp_warp_tool_button_press;
|
|
|
|
tool_class->button_release = gimp_warp_tool_button_release;
|
|
|
|
tool_class->key_press = gimp_warp_tool_key_press;
|
|
|
|
tool_class->motion = gimp_warp_tool_motion;
|
|
|
|
tool_class->control = gimp_warp_tool_control;
|
|
|
|
tool_class->cursor_update = gimp_warp_tool_cursor_update;
|
|
|
|
tool_class->oper_update = gimp_warp_tool_oper_update;
|
|
|
|
|
|
|
|
draw_tool_class->draw = gimp_warp_tool_draw;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_warp_tool_init (GimpWarpTool *self)
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (self);
|
|
|
|
|
|
|
|
gimp_tool_control_set_dirty_mask (tool->control,
|
|
|
|
GIMP_DIRTY_IMAGE |
|
|
|
|
GIMP_DIRTY_IMAGE_STRUCTURE |
|
|
|
|
GIMP_DIRTY_DRAWABLE |
|
|
|
|
GIMP_DIRTY_SELECTION);
|
|
|
|
gimp_tool_control_set_wants_click (tool->control, TRUE);
|
|
|
|
gimp_tool_control_set_tool_cursor (tool->control,
|
|
|
|
GIMP_TOOL_CURSOR_PERSPECTIVE);
|
2011-05-25 07:54:38 +08:00
|
|
|
|
|
|
|
self->coords_buffer = NULL;
|
|
|
|
self->render_node = NULL;
|
|
|
|
self->image_map = NULL;
|
2011-05-24 03:11:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_warp_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpWarpTool *wt = GIMP_WARP_TOOL (tool);
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case GIMP_TOOL_ACTION_PAUSE:
|
|
|
|
case GIMP_TOOL_ACTION_RESUME:
|
2011-05-25 07:54:38 +08:00
|
|
|
break;
|
|
|
|
|
2011-05-24 03:11:08 +08:00
|
|
|
case GIMP_TOOL_ACTION_HALT:
|
2011-05-25 07:54:38 +08:00
|
|
|
if (wt->coords_buffer)
|
|
|
|
{
|
|
|
|
gegl_buffer_destroy (wt->coords_buffer);
|
|
|
|
wt->coords_buffer = NULL;
|
|
|
|
}
|
|
|
|
|
2011-06-08 20:15:21 +08:00
|
|
|
if (wt->graph)
|
2011-05-25 07:54:38 +08:00
|
|
|
{
|
2011-06-08 20:15:21 +08:00
|
|
|
g_object_unref (wt->graph);
|
|
|
|
wt->graph = NULL;
|
2011-05-25 07:54:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wt->image_map)
|
|
|
|
{
|
|
|
|
gimp_tool_control_set_preserve (tool->control, TRUE);
|
|
|
|
|
|
|
|
gimp_image_map_abort (wt->image_map);
|
|
|
|
g_object_unref (wt->image_map);
|
|
|
|
wt->image_map = NULL;
|
|
|
|
|
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
|
|
|
|
|
|
|
gimp_image_flush (gimp_display_get_image (tool->display));
|
|
|
|
}
|
|
|
|
|
|
|
|
tool->display = NULL;
|
2011-05-24 03:11:08 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_warp_tool_start (GimpWarpTool *wt,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
2011-05-25 07:54:38 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (wt);
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
|
|
|
Babl *format;
|
|
|
|
gint x1, x2, y1, y2;
|
|
|
|
GeglRectangle bbox;
|
2011-05-24 03:11:08 +08:00
|
|
|
|
|
|
|
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
|
|
|
|
|
|
|
|
tool->display = display;
|
|
|
|
|
2011-05-25 07:54:38 +08:00
|
|
|
if (wt->coords_buffer)
|
|
|
|
{
|
|
|
|
gegl_buffer_destroy (wt->coords_buffer);
|
|
|
|
wt->coords_buffer = NULL;
|
|
|
|
}
|
|
|
|
|
2011-06-08 20:15:21 +08:00
|
|
|
if (wt->graph)
|
2011-05-25 07:54:38 +08:00
|
|
|
{
|
2011-06-08 20:15:21 +08:00
|
|
|
g_object_unref (wt->graph);
|
|
|
|
wt->graph = NULL;
|
2011-05-25 07:54:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wt->image_map)
|
|
|
|
{
|
|
|
|
gimp_image_map_abort (wt->image_map);
|
|
|
|
g_object_unref (wt->image_map);
|
|
|
|
wt->image_map = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the coords buffer, with the size of the selection */
|
|
|
|
format = babl_format_n (babl_type ("float"), 2);
|
|
|
|
|
|
|
|
gimp_channel_bounds (gimp_image_get_mask (image), &x1, &y1, &x2, &y2);
|
|
|
|
|
|
|
|
bbox.x = MIN (x1, x2);
|
|
|
|
bbox.y = MIN (y1, y2);
|
|
|
|
bbox.width = ABS (x1 - x2);
|
|
|
|
bbox.height = ABS (y1 - y2);
|
|
|
|
|
2011-06-15 03:59:53 +08:00
|
|
|
printf ("Initialize coordinate buffer (%d,%d) at %d,%d\n", bbox.width, bbox.height, bbox.x, bbox.y);
|
2011-05-25 07:54:38 +08:00
|
|
|
wt->coords_buffer = gegl_buffer_new (&bbox, format);
|
|
|
|
|
|
|
|
gimp_warp_tool_create_image_map (wt, drawable);
|
2011-05-24 03:11:08 +08:00
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (wt), display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_warp_tool_options_notify (GimpTool *tool,
|
|
|
|
GimpToolOptions *options,
|
|
|
|
const GParamSpec *pspec)
|
|
|
|
{
|
2011-05-25 07:54:38 +08:00
|
|
|
GimpWarpTool *wt = GIMP_WARP_TOOL (tool);
|
2011-05-24 03:11:08 +08:00
|
|
|
|
|
|
|
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, "foo") == 0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_warp_tool_key_press (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpWarpTool *wt = GIMP_WARP_TOOL (tool);
|
|
|
|
|
|
|
|
switch (kevent->keyval)
|
|
|
|
{
|
|
|
|
case GDK_KEY_BackSpace:
|
|
|
|
case GDK_KEY_Return:
|
2011-06-04 07:38:50 +08:00
|
|
|
return TRUE;
|
|
|
|
|
2011-05-24 03:11:08 +08:00
|
|
|
case GDK_KEY_KP_Enter:
|
|
|
|
case GDK_KEY_ISO_Enter:
|
2011-06-04 07:38:50 +08:00
|
|
|
gimp_tool_control_set_preserve (tool->control, TRUE);
|
|
|
|
|
|
|
|
gimp_image_map_commit (wt->image_map);
|
|
|
|
g_object_unref (wt->image_map);
|
|
|
|
wt->image_map = NULL;
|
|
|
|
|
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
|
|
|
|
|
|
|
gimp_image_flush (gimp_display_get_image (display));
|
|
|
|
|
|
|
|
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
|
2011-05-24 03:11:08 +08:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case GDK_KEY_Escape:
|
|
|
|
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_warp_tool_motion (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpWarpTool *wt = GIMP_WARP_TOOL (tool);
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_warp_tool_oper_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
gboolean proximity,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpWarpTool *wt = GIMP_WARP_TOOL (tool);
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
2011-06-04 05:53:39 +08:00
|
|
|
if (!gimp_draw_tool_is_active (draw_tool))
|
|
|
|
{
|
|
|
|
gimp_warp_tool_start (wt, display);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (display == tool->display)
|
|
|
|
{
|
|
|
|
gimp_draw_tool_pause (draw_tool);
|
2011-05-24 03:11:08 +08:00
|
|
|
|
2011-06-04 05:53:39 +08:00
|
|
|
wt->cursor_x = coords->x;
|
|
|
|
wt->cursor_y = coords->y;
|
2011-06-04 03:17:08 +08:00
|
|
|
|
2011-06-04 05:53:39 +08:00
|
|
|
gimp_draw_tool_resume (draw_tool);
|
|
|
|
}
|
|
|
|
}
|
2011-05-24 03:11:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_warp_tool_button_press (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonPressType press_type,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpWarpTool *wt = GIMP_WARP_TOOL (tool);
|
|
|
|
|
|
|
|
if (display != tool->display)
|
|
|
|
gimp_warp_tool_start (wt, display);
|
|
|
|
|
2011-06-08 20:15:21 +08:00
|
|
|
wt->current_stroke = gegl_path_new ();
|
|
|
|
|
|
|
|
gimp_warp_tool_add_op (wt);
|
2011-05-25 07:54:38 +08:00
|
|
|
gimp_warp_tool_image_map_update (wt);
|
|
|
|
|
2011-05-24 03:11:08 +08:00
|
|
|
gimp_tool_control_activate (tool->control);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_warp_tool_button_release (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpWarpTool *wt = GIMP_WARP_TOOL (tool);
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (wt));
|
|
|
|
|
|
|
|
gimp_tool_control_halt (tool->control);
|
|
|
|
|
|
|
|
if (release_type == GIMP_BUTTON_RELEASE_CANCEL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_warp_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_PLUS;
|
|
|
|
|
|
|
|
if (tool->display)
|
|
|
|
{
|
|
|
|
modifier = GIMP_CURSOR_MODIFIER_MOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_tool_control_set_cursor_modifier (tool->control, modifier);
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_warp_tool_draw (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2011-06-07 02:07:50 +08:00
|
|
|
GimpWarpTool *wt = GIMP_WARP_TOOL (draw_tool);
|
|
|
|
GimpWarpOptions *options = GIMP_WARP_TOOL_GET_OPTIONS (wt);
|
2011-06-04 03:17:08 +08:00
|
|
|
|
2011-06-07 02:39:05 +08:00
|
|
|
gimp_draw_tool_add_arc (draw_tool,
|
|
|
|
FALSE,
|
|
|
|
wt->cursor_x - options->effect_size / 2.0,
|
|
|
|
wt->cursor_y - options->effect_size / 2.0,
|
|
|
|
options->effect_size,
|
|
|
|
options->effect_size,
|
|
|
|
0.0, 2.0 * G_PI);
|
2011-05-24 03:11:08 +08:00
|
|
|
}
|
2011-05-25 07:54:38 +08:00
|
|
|
|
|
|
|
static void
|
2011-06-08 20:15:21 +08:00
|
|
|
gimp_warp_tool_create_graph (GimpWarpTool *wt)
|
2011-05-25 07:54:38 +08:00
|
|
|
{
|
|
|
|
GeglNode *coords, *render; /* Render nodes */
|
|
|
|
GeglNode *input, *output; /* Proxy nodes*/
|
2011-06-08 20:15:21 +08:00
|
|
|
GeglNode *graph; /* wraper to be returned */
|
2011-05-25 07:54:38 +08:00
|
|
|
|
2011-06-08 20:15:21 +08:00
|
|
|
g_return_if_fail (wt->graph == NULL);
|
2011-05-25 07:54:38 +08:00
|
|
|
/* render_node is not supposed to be recreated */
|
|
|
|
|
2011-06-08 20:15:21 +08:00
|
|
|
graph = gegl_node_new ();
|
2011-05-25 07:54:38 +08:00
|
|
|
|
2011-06-08 20:15:21 +08:00
|
|
|
input = gegl_node_get_input_proxy (graph, "input");
|
|
|
|
output = gegl_node_get_output_proxy (graph, "output");
|
2011-05-25 07:54:38 +08:00
|
|
|
|
2011-06-08 20:15:21 +08:00
|
|
|
coords = gegl_node_new_child (graph,
|
2011-05-25 07:54:38 +08:00
|
|
|
"operation", "gegl:buffer-source",
|
|
|
|
"buffer", wt->coords_buffer,
|
|
|
|
NULL);
|
|
|
|
|
2011-06-08 20:15:21 +08:00
|
|
|
render = gegl_node_new_child (graph,
|
2011-05-25 07:54:38 +08:00
|
|
|
"operation", "gegl:map-relative",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gegl_node_connect_to (input, "output",
|
|
|
|
render, "input");
|
|
|
|
|
|
|
|
gegl_node_connect_to (coords, "output",
|
|
|
|
render, "aux");
|
|
|
|
|
|
|
|
gegl_node_connect_to (render, "output",
|
|
|
|
output, "input");
|
|
|
|
|
2011-06-08 20:15:21 +08:00
|
|
|
wt->graph = graph;
|
|
|
|
wt->render_node = render;
|
|
|
|
wt->read_coords_buffer_node = coords;
|
2011-05-25 07:54:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_warp_tool_create_image_map (GimpWarpTool *wt,
|
|
|
|
GimpDrawable *drawable)
|
|
|
|
{
|
2011-06-08 20:15:21 +08:00
|
|
|
if (!wt->graph)
|
|
|
|
gimp_warp_tool_create_graph (wt);
|
2011-05-25 07:54:38 +08:00
|
|
|
|
|
|
|
wt->image_map = gimp_image_map_new (drawable,
|
|
|
|
_("Warp transform"),
|
2011-06-08 20:15:21 +08:00
|
|
|
wt->graph,
|
2011-05-25 07:54:38 +08:00
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_signal_connect (wt->image_map, "flush",
|
|
|
|
G_CALLBACK (gimp_warp_tool_image_map_flush),
|
|
|
|
wt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_warp_tool_image_map_flush (GimpImageMap *image_map,
|
|
|
|
GimpTool *tool)
|
|
|
|
{
|
|
|
|
GimpImage *image = gimp_display_get_image (tool->display);
|
|
|
|
|
|
|
|
gimp_projection_flush_now (gimp_image_get_projection (image));
|
|
|
|
gimp_display_flush_now (tool->display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_warp_tool_image_map_update (GimpWarpTool *wt)
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (wt);
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
|
|
|
GimpItem *item = GIMP_ITEM (tool->drawable);
|
|
|
|
gint x, y;
|
|
|
|
gint w, h;
|
|
|
|
gint off_x, off_y;
|
|
|
|
GeglRectangle visible;
|
|
|
|
|
|
|
|
gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h);
|
|
|
|
|
|
|
|
gimp_item_get_offset (item, &off_x, &off_y);
|
|
|
|
|
|
|
|
gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
off_x,
|
|
|
|
off_y,
|
|
|
|
gimp_item_get_width (item),
|
|
|
|
gimp_item_get_height (item),
|
|
|
|
&visible.x,
|
|
|
|
&visible.y,
|
|
|
|
&visible.width,
|
|
|
|
&visible.height);
|
|
|
|
|
|
|
|
visible.x -= off_x;
|
|
|
|
visible.y -= off_y;
|
|
|
|
|
|
|
|
gimp_image_map_apply (wt->image_map, &visible);
|
|
|
|
}
|
2011-05-26 03:40:47 +08:00
|
|
|
|
2011-06-08 20:15:21 +08:00
|
|
|
static void
|
|
|
|
gimp_warp_tool_add_op (GimpWarpTool *wt)
|
|
|
|
{
|
|
|
|
GimpWarpOptions *options = GIMP_WARP_TOOL_GET_OPTIONS (wt);
|
|
|
|
GeglNode *new_op, *last_op;
|
|
|
|
|
|
|
|
g_return_if_fail (GEGL_IS_NODE (wt->render_node));
|
|
|
|
|
|
|
|
new_op = gegl_node_new_child (wt->graph,
|
|
|
|
"operation", "gimp:warp",
|
|
|
|
"strength", options->effect_strength,
|
|
|
|
"size", options->effect_size,
|
|
|
|
"stroke", wt->current_stroke,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
last_op = gegl_node_get_producer (wt->render_node, "aux", NULL);
|
|
|
|
|
|
|
|
gegl_node_disconnect (wt->render_node, "aux");
|
|
|
|
|
|
|
|
gegl_node_connect_to (last_op, "output", new_op, "input");
|
|
|
|
gegl_node_connect_to (new_op, "output", wt->render_node, "aux");
|
2011-05-26 03:40:47 +08:00
|
|
|
}
|