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"
|
|
|
|
|
|
|
|
#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"
|
2010-07-12 23:43:12 +08:00
|
|
|
#include "tools/tools-enums.h"
|
|
|
|
#include "gimptoolcontrol.h"
|
2010-06-15 05:25:08 +08:00
|
|
|
|
2010-08-15 07:29:34 +08:00
|
|
|
#include "core/core-types.h"
|
|
|
|
|
2010-07-22 06:07:27 +08:00
|
|
|
#include "core/gimp.h"
|
2010-06-15 05:25:08 +08:00
|
|
|
#include "core/gimp-transform-utils.h"
|
2010-11-04 06:10:22 +08:00
|
|
|
#include "core/gimpchannel.h"
|
2010-07-22 06:07:27 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpdrawable-operation.h"
|
2010-08-07 21:10:23 +08:00
|
|
|
#include "core/gimpdrawable-shadow.h"
|
2010-11-04 06:10:22 +08:00
|
|
|
#include "core/gimpimage.h"
|
2010-08-10 05:33:11 +08:00
|
|
|
#include "core/gimpimagemap.h"
|
2010-11-04 06:10:22 +08:00
|
|
|
#include "core/gimplayer.h"
|
2010-08-14 00:25:48 +08:00
|
|
|
#include "core/gimpprojection.h"
|
2010-11-04 06:10:22 +08:00
|
|
|
#include "core/gimpprogress.h"
|
2010-08-14 00:25:48 +08:00
|
|
|
|
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
#include "display/gimpdisplayshell.h"
|
|
|
|
#include "display/gimpdisplayshell-transform.h"
|
|
|
|
|
2010-08-07 21:10:23 +08:00
|
|
|
#include "base/tile-manager.h"
|
2010-07-22 06:07:27 +08:00
|
|
|
|
2010-06-15 05:25:08 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
|
|
|
|
#include "gimpcagetool.h"
|
2010-07-01 02:27:52 +08:00
|
|
|
#include "gimpcageoptions.h"
|
2010-06-15 05:25:08 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
2010-08-07 21:10:23 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2010-07-17 19:33:48 +08:00
|
|
|
/*static gboolean gimp_cage_tool_initialize (GimpTool *tool,
|
2010-07-12 23:43:12 +08:00
|
|
|
GimpDisplay *display,
|
2010-07-17 19:33:48 +08:00
|
|
|
GError **error);*/
|
2010-08-12 02:27:32 +08:00
|
|
|
static void gimp_cage_tool_finalize (GObject *object);
|
|
|
|
static void gimp_cage_tool_start (GimpCageTool *ct,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_cage_tool_halt (GimpCageTool *ct);
|
|
|
|
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 gboolean gimp_cage_tool_key_press (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_cage_tool_motion (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_cage_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
|
|
|
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);
|
2010-09-05 18:33:26 +08:00
|
|
|
|
|
|
|
static gint gimp_cage_tool_is_on_handle (GimpCageConfig *gcc,
|
|
|
|
GimpDrawTool *draw_tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GimpCageMode mode,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint handle_size);
|
2010-08-12 02:27:32 +08:00
|
|
|
static void gimp_cage_tool_draw (GimpDrawTool *draw_tool);
|
|
|
|
static void gimp_cage_tool_switch_to_deform (GimpCageTool *ct);
|
|
|
|
static void gimp_cage_tool_remove_last_handle (GimpCageTool *ct);
|
|
|
|
static void gimp_cage_tool_compute_coef (GimpCageTool *ct,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_cage_tool_process (GimpCageTool *ct,
|
|
|
|
GimpDisplay *display);
|
2010-11-04 03:08:10 +08:00
|
|
|
static void gimp_cage_tool_process_drawable (GimpCageTool *ct,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpProgress *progress);
|
2010-08-12 02:27:32 +08:00
|
|
|
static void gimp_cage_tool_prepare_preview (GimpCageTool *ct,
|
|
|
|
GimpDisplay *display);
|
2010-08-15 07:29:34 +08:00
|
|
|
static gboolean gimp_cage_tool_update_preview (GimpTool *tool);
|
2010-06-15 05:25:08 +08:00
|
|
|
|
2010-10-07 05:37:04 +08:00
|
|
|
static GeglNode* gimp_cage_tool_get_render_node (GimpCageTool *ct,
|
|
|
|
GeglNode *parent);
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2010-09-05 18:33:26 +08:00
|
|
|
#define HANDLE_SIZE 25
|
2010-06-15 05:25:08 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_cage_tool_register (GimpToolRegisterCallback callback,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2010-09-05 18:33:26 +08:00
|
|
|
(* callback) (GIMP_TYPE_CAGE_TOOL, /* Tool type */
|
|
|
|
GIMP_TYPE_CAGE_OPTIONS, /*Tool options type*/
|
|
|
|
gimp_cage_options_gui, /*Tool opions gui*/
|
|
|
|
0, /*context_props*/
|
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,
|
|
|
|
GIMP_STOCK_TOOL_CAGE,
|
2010-06-15 05:25:08 +08:00
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cage_tool_class_init (GimpCageToolClass *klass)
|
|
|
|
{
|
2010-07-01 02:27:52 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-01 02:27:52 +08:00
|
|
|
object_class->finalize = gimp_cage_tool_finalize;
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-17 19:33:48 +08:00
|
|
|
/*tool_class->initialize = gimp_cage_tool_initialize;*/
|
2010-07-01 02:27:52 +08:00
|
|
|
tool_class->button_press = gimp_cage_tool_button_press;
|
|
|
|
tool_class->button_release = gimp_cage_tool_button_release;
|
2010-07-12 23:43:12 +08:00
|
|
|
tool_class->key_press = gimp_cage_tool_key_press;
|
|
|
|
tool_class->motion = gimp_cage_tool_motion;
|
|
|
|
tool_class->control = gimp_cage_tool_control;
|
|
|
|
tool_class->cursor_update = gimp_cage_tool_cursor_update;
|
|
|
|
tool_class->oper_update = gimp_cage_tool_oper_update;
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-01 02:27:52 +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-07-27 01:24:05 +08:00
|
|
|
self->config = g_object_new (GIMP_TYPE_CAGE_CONFIG, NULL);
|
2010-07-12 23:43:12 +08:00
|
|
|
self->cursor_position.x = 0;
|
|
|
|
self->cursor_position.y = 0;
|
|
|
|
self->handle_moved = -1;
|
|
|
|
self->cage_complete = FALSE;
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
self->coef = NULL;
|
2010-08-14 00:25:48 +08:00
|
|
|
self->image_map = NULL;
|
|
|
|
self->node_preview = NULL;
|
2010-08-15 07:29:34 +08:00
|
|
|
|
|
|
|
self->idle_id = 0;
|
2010-06-15 05:25:08 +08:00
|
|
|
}
|
|
|
|
|
2010-07-17 19:33:48 +08:00
|
|
|
/*static gboolean
|
2010-07-12 23:43:12 +08:00
|
|
|
gimp_cage_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GimpCageTool *cage_tool = GIMP_CAGE_TOOL (tool);
|
|
|
|
|
|
|
|
return GIMP_TOOL_CLASS (parent_class)->initialize(tool, display, error);
|
2010-07-17 19:33:48 +08:00
|
|
|
}*/
|
2010-06-15 05:25:08 +08:00
|
|
|
|
2010-07-01 02:27:52 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (object);
|
|
|
|
|
2010-08-12 02:27:32 +08:00
|
|
|
gimp_cage_tool_halt (ct);
|
|
|
|
|
2010-07-01 02:27:52 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2010-07-12 23:43:12 +08:00
|
|
|
|
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case GIMP_TOOL_ACTION_PAUSE:
|
|
|
|
case GIMP_TOOL_ACTION_RESUME:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_TOOL_ACTION_HALT:
|
|
|
|
gimp_cage_tool_halt (GIMP_CAGE_TOOL (tool));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-12 23:43:12 +08:00
|
|
|
static void
|
2010-07-17 19:33:48 +08:00
|
|
|
gimp_cage_tool_start (GimpCageTool *ct,
|
2010-07-12 23:43:12 +08:00
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (ct);
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
2010-11-04 06:10:22 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
|
|
|
gint off_x;
|
|
|
|
gint off_y;
|
2010-07-12 23:43:12 +08:00
|
|
|
|
|
|
|
gimp_tool_control_activate (tool->control);
|
|
|
|
|
|
|
|
tool->display = display;
|
2010-08-12 02:27:32 +08:00
|
|
|
|
|
|
|
if (ct->config)
|
2010-09-03 03:28:06 +08:00
|
|
|
{
|
|
|
|
g_object_unref (ct->config);
|
|
|
|
}
|
2010-08-14 00:25:48 +08:00
|
|
|
|
|
|
|
if (ct->image_map)
|
2010-09-03 03:28:06 +08:00
|
|
|
{
|
|
|
|
gimp_image_map_abort (ct->image_map);
|
|
|
|
g_object_unref (ct->image_map);
|
|
|
|
}
|
2010-08-14 00:25:48 +08:00
|
|
|
|
2010-08-12 02:27:32 +08:00
|
|
|
ct->config = g_object_new (GIMP_TYPE_CAGE_CONFIG, NULL);
|
|
|
|
ct->cursor_position.x = -1000;
|
|
|
|
ct->cursor_position.y = -1000;
|
|
|
|
ct->handle_moved = -1;
|
|
|
|
ct->cage_complete = FALSE;
|
|
|
|
|
2010-11-04 06:10:22 +08:00
|
|
|
/*Setting up cage offset to convert the cage point coords to drawable coords*/
|
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable),
|
|
|
|
&off_x,
|
|
|
|
&off_y);
|
|
|
|
|
|
|
|
|
|
|
|
ct->config->offset_x = off_x;
|
|
|
|
ct->config->offset_y = off_y;
|
|
|
|
|
2010-07-12 23:43:12 +08:00
|
|
|
gimp_draw_tool_start (draw_tool, display);
|
|
|
|
}
|
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_cage_tool_key_press (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display)
|
2010-07-01 02:27:52 +08:00
|
|
|
{
|
2010-09-03 03:28:06 +08:00
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
2010-07-12 23:43:12 +08:00
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
switch (kevent->keyval)
|
|
|
|
{
|
|
|
|
case GDK_BackSpace:
|
|
|
|
gimp_cage_tool_remove_last_handle (ct);
|
|
|
|
return TRUE;
|
2010-07-12 23:43:12 +08:00
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
case GDK_Return:
|
|
|
|
case GDK_KP_Enter:
|
|
|
|
case GDK_ISO_Enter:
|
|
|
|
if (ct->cage_complete)
|
|
|
|
{
|
|
|
|
gimp_image_map_abort (ct->image_map);
|
|
|
|
g_object_unref (ct->image_map);
|
|
|
|
ct->image_map = NULL;
|
|
|
|
if (ct->idle_id)
|
|
|
|
{
|
|
|
|
g_source_remove(ct->idle_id);
|
|
|
|
ct->idle_id = 0; /*Stop preview update for now*/
|
|
|
|
}
|
|
|
|
gimp_cage_tool_process (ct, display); /*RUN IT BABY*/
|
|
|
|
}
|
|
|
|
return TRUE;
|
2010-07-01 02:27:52 +08:00
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
case GDK_Escape:
|
|
|
|
gimp_cage_tool_halt (ct);
|
|
|
|
return TRUE;
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-08-14 00:25:48 +08:00
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-09-03 01:11:34 +08:00
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_motion (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
|
|
|
GimpCageConfig *config = ct->config;
|
2010-08-14 00:25:48 +08:00
|
|
|
|
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
gimp_draw_tool_pause (draw_tool);
|
2010-08-14 00:25:48 +08:00
|
|
|
|
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
if (ct->handle_moved >= 0)
|
2010-08-14 00:25:48 +08:00
|
|
|
{
|
2010-09-03 03:28:06 +08:00
|
|
|
gimp_cage_config_move_cage_point (config,
|
|
|
|
options->cage_mode,
|
|
|
|
ct->handle_moved,
|
|
|
|
coords->x,
|
|
|
|
coords->y);
|
2010-08-14 00:25:48 +08:00
|
|
|
}
|
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
gimp_draw_tool_resume (draw_tool);
|
2010-07-01 02:27:52 +08:00
|
|
|
}
|
|
|
|
|
2010-09-03 03:28:06 +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);
|
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
|
|
|
GimpCageConfig *config = ct->config;
|
|
|
|
gint active_handle = -1;
|
|
|
|
|
|
|
|
if (config)
|
2010-09-05 18:33:26 +08:00
|
|
|
active_handle = gimp_cage_tool_is_on_handle (config,
|
|
|
|
draw_tool,
|
|
|
|
display,
|
|
|
|
options->cage_mode,
|
|
|
|
coords->x,
|
|
|
|
coords->y,
|
|
|
|
HANDLE_SIZE );
|
2010-09-03 03:28:06 +08:00
|
|
|
if (!ct->cage_complete || (active_handle > -1))
|
|
|
|
{
|
|
|
|
gimp_draw_tool_pause (draw_tool);
|
|
|
|
|
|
|
|
ct->cursor_position.x = coords->x;
|
|
|
|
ct->cursor_position.y = coords->y;
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-15 07:29:34 +08:00
|
|
|
static void
|
2010-07-12 23:43:12 +08:00
|
|
|
gimp_cage_tool_button_press (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonPressType press_type,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
2010-07-17 22:32:46 +08:00
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
2010-07-27 01:24:05 +08:00
|
|
|
GimpCageConfig *config = ct->config;
|
2010-07-17 19:33:48 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_CAGE_TOOL (ct));
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-12 23:43:12 +08:00
|
|
|
if (display != tool->display)
|
|
|
|
{
|
|
|
|
gimp_cage_tool_start (ct,
|
|
|
|
display);
|
2010-08-12 02:27:32 +08:00
|
|
|
config = ct->config;
|
2010-07-12 23:43:12 +08:00
|
|
|
}
|
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-08-12 02:27:32 +08:00
|
|
|
|
|
|
|
|
2010-07-12 23:43:12 +08:00
|
|
|
if (ct->handle_moved < 0)
|
|
|
|
{
|
2010-09-05 18:33:26 +08:00
|
|
|
ct->handle_moved = gimp_cage_tool_is_on_handle (config,
|
|
|
|
GIMP_DRAW_TOOL(ct),
|
|
|
|
display,
|
|
|
|
options->cage_mode,
|
|
|
|
coords->x,
|
|
|
|
coords->y,
|
|
|
|
HANDLE_SIZE);
|
2010-08-15 07:58:31 +08:00
|
|
|
if (ct->handle_moved > 0 && ct->idle_id > 0)
|
2010-08-15 07:29:34 +08:00
|
|
|
{
|
|
|
|
g_source_remove(ct->idle_id);
|
|
|
|
ct->idle_id = 0; /*Stop preview update for now*/
|
|
|
|
}
|
2010-07-12 23:43:12 +08:00
|
|
|
}
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-08-10 06:58:24 +08:00
|
|
|
if (ct->handle_moved < 0 && !ct->cage_complete)
|
2010-07-12 23:43:12 +08:00
|
|
|
{
|
2010-07-27 01:24:05 +08:00
|
|
|
gimp_cage_config_add_cage_point (config,
|
|
|
|
coords->x,
|
|
|
|
coords->y);
|
2010-07-12 23:43:12 +08:00
|
|
|
}
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-08-15 07:29:34 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (ct));
|
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
/* user is clicking on the first handle, we close the cage and
|
|
|
|
* switch to deform mode*/
|
2010-08-14 00:25:48 +08:00
|
|
|
if (ct->handle_moved == 0 && config->cage_vertice_number > 2 && !ct->coef)
|
2010-08-15 07:29:34 +08:00
|
|
|
{
|
2010-07-12 23:43:12 +08:00
|
|
|
ct->cage_complete = TRUE;
|
|
|
|
gimp_cage_tool_switch_to_deform (ct);
|
2010-07-27 01:24:05 +08:00
|
|
|
|
|
|
|
gimp_cage_config_reverse_cage_if_needed (config);
|
|
|
|
gimp_cage_tool_compute_coef (ct, display);
|
2010-08-14 00:25:48 +08:00
|
|
|
gimp_cage_tool_prepare_preview (ct, display);
|
2010-08-15 07:29:34 +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-08-15 07:29:34 +08:00
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-08-15 07:29:34 +08:00
|
|
|
|
|
|
|
if (ct->coef && ct->handle_moved > -1)
|
|
|
|
{
|
|
|
|
|
|
|
|
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_draw_tool_pause (GIMP_DRAW_TOOL (ct));
|
|
|
|
|
|
|
|
gimp_image_map_apply (ct->image_map, &visible);
|
|
|
|
|
|
|
|
ct->idle_id = g_idle_add ((GSourceFunc) gimp_cage_tool_update_preview, tool);
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (ct));
|
|
|
|
}
|
2010-07-12 23:43:12 +08:00
|
|
|
ct->handle_moved = -1;
|
2010-08-12 02:27:32 +08:00
|
|
|
|
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
|
|
|
|
gimp_cage_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
2010-07-17 19:33:48 +08:00
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
2010-07-12 23:43:12 +08:00
|
|
|
|
|
|
|
if (tool->display == NULL)
|
|
|
|
{
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool,
|
|
|
|
coords,
|
|
|
|
state,
|
|
|
|
display);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GimpCursorModifier modifier;
|
|
|
|
|
|
|
|
if (options->cage_mode == GIMP_CAGE_MODE_CAGE_CHANGE)
|
|
|
|
{
|
|
|
|
modifier = GIMP_CURSOR_MODIFIER_ANCHOR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
modifier = GIMP_CURSOR_MODIFIER_MOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_tool_set_cursor (tool, display,
|
|
|
|
gimp_tool_control_get_cursor (tool->control),
|
|
|
|
gimp_tool_control_get_tool_cursor (tool->control),
|
|
|
|
modifier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_cage_tool_draw:
|
2010-08-15 07:29:34 +08:00
|
|
|
* @draw_tool:
|
|
|
|
*
|
|
|
|
* Draw the tool on the canvas.
|
2010-07-12 23:43:12 +08:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gimp_cage_tool_draw (GimpDrawTool *draw_tool)
|
|
|
|
{
|
2010-07-17 22:32:46 +08:00
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (draw_tool);
|
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
2010-07-27 01:24:05 +08:00
|
|
|
GimpCageConfig *config = ct->config;
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-17 22:32:46 +08:00
|
|
|
gint i = 0;
|
|
|
|
gint on_handle = -1;
|
|
|
|
GimpVector2 *vertices;
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-17 22:32:46 +08:00
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
if (config->cage_vertice_number <= 0)
|
2010-07-12 23:43:12 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-17 22:32:46 +08:00
|
|
|
if (options->cage_mode == GIMP_CAGE_MODE_CAGE_CHANGE)
|
|
|
|
{
|
2010-07-27 01:24:05 +08:00
|
|
|
vertices = config->cage_vertices;
|
2010-07-17 22:32:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-27 01:24:05 +08:00
|
|
|
vertices = config->cage_vertices_d;
|
2010-07-17 22:32:46 +08:00
|
|
|
}
|
2010-08-12 02:27:32 +08:00
|
|
|
|
|
|
|
|
2010-11-04 06:10:22 +08:00
|
|
|
/*gimp_draw_tool_add_lines (draw_tool,
|
2010-07-17 22:32:46 +08:00
|
|
|
vertices,
|
2010-07-27 01:24:05 +08:00
|
|
|
config->cage_vertice_number,
|
2010-11-04 06:10:22 +08:00
|
|
|
FALSE);*/
|
2010-08-12 02:27:32 +08:00
|
|
|
|
|
|
|
if (!ct->cage_complete && ct->cursor_position.x != -1000)
|
2010-07-12 23:43:12 +08:00
|
|
|
{
|
2010-09-27 04:57:45 +08:00
|
|
|
gimp_draw_tool_add_line (draw_tool,
|
2010-11-04 06:10:22 +08:00
|
|
|
vertices[config->cage_vertice_number - 1].x + ct->config->offset_x,
|
|
|
|
vertices[config->cage_vertice_number - 1].y + ct->config->offset_y,
|
2010-08-12 02:27:32 +08:00
|
|
|
ct->cursor_position.x,
|
2010-09-27 04:57:45 +08:00
|
|
|
ct->cursor_position.y);
|
2010-07-12 23:43:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-27 04:57:45 +08:00
|
|
|
gimp_draw_tool_add_line (draw_tool,
|
2010-11-04 06:10:22 +08:00
|
|
|
vertices[config->cage_vertice_number - 1].x + ct->config->offset_x,
|
|
|
|
vertices[config->cage_vertice_number - 1].y + ct->config->offset_y,
|
|
|
|
vertices[0].x + ct->config->offset_x,
|
|
|
|
vertices[0].y + ct->config->offset_y);
|
2010-07-12 23:43:12 +08:00
|
|
|
}
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-09-05 18:33:26 +08:00
|
|
|
on_handle = gimp_cage_tool_is_on_handle (config,
|
|
|
|
draw_tool,
|
|
|
|
draw_tool->display,
|
|
|
|
options->cage_mode,
|
|
|
|
ct->cursor_position.x,
|
|
|
|
ct->cursor_position.y,
|
|
|
|
HANDLE_SIZE);
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
for(i = 0; i < config->cage_vertice_number; i++)
|
2010-07-12 23:43:12 +08:00
|
|
|
{
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-12 23:43:12 +08:00
|
|
|
GimpHandleType handle = GIMP_HANDLE_CIRCLE;
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-12 23:43:12 +08:00
|
|
|
if (i == on_handle)
|
|
|
|
{
|
|
|
|
handle = GIMP_HANDLE_FILLED_CIRCLE;
|
|
|
|
}
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-11-04 06:10:22 +08:00
|
|
|
if (i > 0)
|
|
|
|
gimp_draw_tool_add_line (draw_tool,
|
|
|
|
vertices[i - 1].x + ct->config->offset_x,
|
|
|
|
vertices[i - 1].y + ct->config->offset_y,
|
|
|
|
vertices[i].x + ct->config->offset_x,
|
|
|
|
vertices[i].y + ct->config->offset_y);
|
|
|
|
|
2010-09-27 04:57:45 +08:00
|
|
|
gimp_draw_tool_add_handle (draw_tool,
|
2010-11-04 06:10:22 +08:00
|
|
|
handle,
|
|
|
|
vertices[i].x + ct->config->offset_x,
|
|
|
|
vertices[i].y + ct->config->offset_y,
|
|
|
|
HANDLE_SIZE, HANDLE_SIZE,
|
|
|
|
GTK_ANCHOR_CENTER);
|
2010-07-12 23:43:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-05 18:33:26 +08:00
|
|
|
static gint
|
|
|
|
gimp_cage_tool_is_on_handle (GimpCageConfig *gcc,
|
|
|
|
GimpDrawTool *draw_tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GimpCageMode mode,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint handle_size)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gdouble vert_x;
|
|
|
|
gdouble vert_y;
|
|
|
|
gdouble dist = G_MAXDOUBLE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_CAGE_CONFIG (gcc), -1);
|
|
|
|
|
|
|
|
if (gcc->cage_vertice_number == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0; i < gcc->cage_vertice_number; i++)
|
|
|
|
{
|
|
|
|
if (mode == GIMP_CAGE_MODE_CAGE_CHANGE)
|
|
|
|
{
|
2010-11-04 06:10:22 +08:00
|
|
|
vert_x = gcc->cage_vertices[i].x + gcc->offset_x;
|
|
|
|
vert_y = gcc->cage_vertices[i].y + gcc->offset_y;
|
2010-09-05 18:33:26 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-04 06:10:22 +08:00
|
|
|
vert_x = gcc->cage_vertices_d[i].x + gcc->offset_x;
|
|
|
|
vert_y = gcc->cage_vertices_d[i].y + gcc->offset_y;
|
2010-09-05 18:33:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dist = gimp_draw_tool_calc_distance_square (GIMP_DRAW_TOOL (draw_tool),
|
|
|
|
display,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
vert_x,
|
|
|
|
vert_y);
|
|
|
|
|
|
|
|
if (dist <= (handle_size * handle_size))
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-07-12 23:43:12 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_remove_last_handle (GimpCageTool *ct)
|
|
|
|
{
|
2010-07-27 01:24:05 +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-07-27 01:24:05 +08:00
|
|
|
gimp_cage_config_remove_last_cage_point (config);
|
2010-07-12 23:43:12 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (ct));
|
2010-07-22 06:07:27 +08:00
|
|
|
}
|
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_switch_to_deform (GimpCageTool *ct)
|
|
|
|
{
|
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
|
|
|
|
|
|
|
g_object_set (options, "cage-mode", GIMP_CAGE_MODE_DEFORM, NULL);
|
|
|
|
}
|
|
|
|
|
2010-07-22 06:07:27 +08:00
|
|
|
static void
|
2010-07-27 01:24:05 +08:00
|
|
|
gimp_cage_tool_compute_coef (GimpCageTool *ct,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpCageConfig *config = ct->config;
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-11-04 06:10:22 +08:00
|
|
|
Babl *format;
|
|
|
|
GeglNode *gegl, *input, *output;
|
2010-07-27 01:24:05 +08:00
|
|
|
GeglProcessor *processor;
|
2010-11-04 06:10:22 +08:00
|
|
|
GimpProgress *progress;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
gdouble value;
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
if (ct->coef)
|
|
|
|
{
|
|
|
|
gegl_buffer_destroy (ct->coef);
|
|
|
|
ct->coef = NULL;
|
|
|
|
}
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
format = babl_format_n(babl_type("float"), config->cage_vertice_number * 2);
|
2010-08-15 20:20:47 +08:00
|
|
|
|
|
|
|
progress = gimp_progress_start (GIMP_PROGRESS (display),
|
|
|
|
_("Coefficient computation"),
|
|
|
|
FALSE);
|
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-08-12 19:47:31 +08:00
|
|
|
"operation", "gimp:cage_coef_calc",
|
2010-07-27 01:24:05 +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,
|
|
|
|
"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))
|
|
|
|
{
|
|
|
|
gimp_progress_set_value (progress, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_progress_end (progress);
|
2010-08-15 07:29:34 +08:00
|
|
|
gegl_processor_destroy (processor);
|
2010-07-27 01:24:05 +08:00
|
|
|
|
|
|
|
ct->coef = buffer;
|
|
|
|
g_object_unref (gegl);
|
|
|
|
}
|
|
|
|
|
2010-10-07 05:37:04 +08:00
|
|
|
static GeglNode*
|
|
|
|
gimp_cage_tool_get_render_node (GimpCageTool *ct,
|
|
|
|
GeglNode *parent)
|
|
|
|
{
|
|
|
|
GimpCageOptions *options = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
|
|
|
|
|
2010-11-04 03:08:10 +08:00
|
|
|
GeglNode *coef, *cage, *render; /* Render nodes */
|
|
|
|
GeglNode *input, *output; /* Proxy nodes*/
|
2010-10-07 05:37:04 +08:00
|
|
|
GeglNode *node; /* wraper to be returned */
|
|
|
|
|
|
|
|
node = gegl_node_new_child (parent,
|
2010-11-04 03:08:10 +08:00
|
|
|
NULL,
|
|
|
|
NULL);
|
2010-10-07 05:37:04 +08:00
|
|
|
|
|
|
|
input = gegl_node_get_input_proxy (node, "input");
|
2010-11-04 03:08:10 +08:00
|
|
|
|
2010-10-07 05:37:04 +08:00
|
|
|
output = gegl_node_get_output_proxy (node, "output");
|
|
|
|
|
2010-11-04 03:08:10 +08:00
|
|
|
coef = gegl_node_new_child (ct->node_preview,
|
|
|
|
"operation", "gegl:buffer-source",
|
|
|
|
"buffer", ct->coef,
|
|
|
|
NULL);
|
2010-10-07 05:37:04 +08:00
|
|
|
|
|
|
|
cage = gegl_node_new_child (parent,
|
|
|
|
"operation", "gimp:cage_transform",
|
|
|
|
"config", ct->config,
|
|
|
|
"fill_plain_color", options->fill_plain_color,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
render = gegl_node_new_child (parent,
|
2010-11-03 02:56:11 +08:00
|
|
|
"operation", "gegl:map-absolute",
|
2010-10-07 05:37:04 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
gegl_node_connect_to (input, "output",
|
|
|
|
cage, "input");
|
|
|
|
|
2010-11-04 03:08:10 +08:00
|
|
|
gegl_node_connect_to (coef, "output",
|
2010-10-07 05:37:04 +08:00
|
|
|
cage, "aux");
|
|
|
|
|
|
|
|
gegl_node_connect_to (input, "output",
|
|
|
|
render, "input");
|
|
|
|
|
|
|
|
gegl_node_connect_to (cage, "output",
|
|
|
|
render, "aux");
|
|
|
|
|
|
|
|
gegl_node_connect_to (render, "output",
|
|
|
|
output, "input");
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_prepare_preview (GimpCageTool *ct,
|
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
2010-10-07 05:37:04 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
|
2010-10-07 05:37:04 +08:00
|
|
|
GeglNode *node;
|
2010-09-03 03:28:06 +08:00
|
|
|
|
|
|
|
if (ct->node_preview)
|
|
|
|
{
|
|
|
|
g_object_unref (ct->node_preview);
|
|
|
|
ct->node_preview = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ct->node_preview = gegl_node_new ();
|
|
|
|
|
2010-10-07 05:37:04 +08:00
|
|
|
node = gimp_cage_tool_get_render_node (ct,
|
|
|
|
ct->node_preview);
|
2010-09-03 03:28:06 +08:00
|
|
|
|
|
|
|
ct->image_map = gimp_image_map_new (drawable,
|
|
|
|
_("Cage transform"),
|
2010-10-07 05:37:04 +08:00
|
|
|
node,
|
2010-09-03 03:28:06 +08:00
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_cage_tool_update_preview (GimpTool *tool)
|
|
|
|
{
|
|
|
|
GimpCageTool *ct = GIMP_CAGE_TOOL (tool);
|
|
|
|
GimpImage *image = gimp_display_get_image (tool->display);
|
|
|
|
|
|
|
|
if (!ct->image_map)
|
|
|
|
{
|
|
|
|
/*Destroyed, bailing out*/
|
|
|
|
ct->idle_id = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gimp_image_map_is_busy(ct->image_map))
|
|
|
|
{
|
|
|
|
ct->idle_id = 0;
|
2010-11-04 03:08:10 +08:00
|
|
|
gimp_projection_flush_now (gimp_image_get_projection (image));
|
|
|
|
gimp_display_flush_now (tool->display);
|
2010-09-03 03:28:06 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
static void
|
|
|
|
gimp_cage_tool_process (GimpCageTool *ct,
|
2010-07-22 06:07:27 +08:00
|
|
|
GimpDisplay *display)
|
2010-07-22 16:56:01 +08:00
|
|
|
{
|
2010-11-04 03:08:10 +08:00
|
|
|
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-08-15 07:29:34 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
2010-11-04 03:08:10 +08:00
|
|
|
GimpLayer *layer = gimp_image_get_active_layer (image);
|
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (layer);
|
|
|
|
GimpDrawable *mask = GIMP_DRAWABLE (gimp_layer_get_mask(layer));
|
|
|
|
|
2010-08-15 07:29:34 +08:00
|
|
|
|
2010-07-27 22:59:33 +08:00
|
|
|
g_return_if_fail (ct->coef);
|
2010-07-22 06:07:27 +08:00
|
|
|
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-11-04 03:08:10 +08:00
|
|
|
if (GIMP_IS_DRAWABLE (drawable))
|
|
|
|
{
|
2010-11-04 06:10:22 +08:00
|
|
|
|
2010-11-04 03:08:10 +08:00
|
|
|
GimpProgress *progress;
|
2010-11-04 06:10:22 +08:00
|
|
|
|
2010-11-04 03:08:10 +08:00
|
|
|
progress = gimp_progress_start (GIMP_PROGRESS (display),
|
|
|
|
_("Rendering cage transform"),
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
gimp_cage_tool_process_drawable (ct, drawable, progress);
|
|
|
|
|
|
|
|
gimp_progress_end (progress);
|
|
|
|
|
|
|
|
if(mask)
|
|
|
|
{
|
|
|
|
progress = gimp_progress_start (GIMP_PROGRESS (display),
|
|
|
|
_("Rendering mask cage transform"),
|
|
|
|
FALSE);
|
|
|
|
gimp_cage_tool_process_drawable (ct, mask, progress);
|
|
|
|
|
|
|
|
gimp_progress_end (progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_image_flush (image);
|
|
|
|
|
|
|
|
gimp_cage_tool_halt (ct);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cage_tool_process_drawable (GimpCageTool *ct,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpProgress *progress)
|
|
|
|
|
|
|
|
{
|
|
|
|
TileManager *new_tiles = NULL;
|
|
|
|
TileManager *old_tiles = NULL;
|
|
|
|
GeglRectangle rect;
|
|
|
|
GeglProcessor *processor;
|
|
|
|
gdouble value;
|
|
|
|
|
|
|
|
if (GIMP_IS_DRAWABLE (drawable))
|
|
|
|
{
|
2010-07-27 01:24:05 +08:00
|
|
|
GeglNode *gegl = gegl_node_new ();
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-09-05 17:48:23 +08:00
|
|
|
/* reverse transform */
|
2010-11-04 03:08:10 +08:00
|
|
|
GeglNode *node, *input, *output;
|
2010-10-07 05:37:04 +08:00
|
|
|
|
|
|
|
old_tiles = gimp_drawable_get_tiles (drawable);
|
2010-08-14 00:25:48 +08:00
|
|
|
|
2010-09-05 17:48:23 +08:00
|
|
|
input = gegl_node_new_child (gegl,
|
|
|
|
"operation", "gimp:tilemanager-source",
|
2010-10-07 05:37:04 +08:00
|
|
|
"tile-manager", old_tiles,
|
2010-09-05 17:48:23 +08:00
|
|
|
"linear", TRUE,
|
2010-08-10 05:33:11 +08:00
|
|
|
NULL);
|
2010-08-09 00:21:26 +08:00
|
|
|
|
2010-08-12 20:38:21 +08:00
|
|
|
|
2010-10-07 05:37:04 +08:00
|
|
|
node = gimp_cage_tool_get_render_node (ct,
|
|
|
|
gegl);
|
2010-08-14 00:25:48 +08:00
|
|
|
|
2010-09-05 17:48:23 +08:00
|
|
|
new_tiles = gimp_drawable_get_shadow_tiles (drawable);
|
|
|
|
output = gegl_node_new_child (gegl,
|
|
|
|
"operation", "gimp:tilemanager-sink",
|
|
|
|
"tile-manager", new_tiles,
|
|
|
|
"linear", TRUE,
|
2010-08-12 20:38:21 +08:00
|
|
|
NULL);
|
|
|
|
|
2010-09-05 17:48:23 +08:00
|
|
|
gegl_node_connect_to (input, "output",
|
2010-10-07 05:37:04 +08:00
|
|
|
node, "input");
|
2010-08-12 20:38:21 +08:00
|
|
|
|
2010-10-07 05:37:04 +08:00
|
|
|
gegl_node_connect_to (node, "output",
|
2010-09-05 17:48:23 +08:00
|
|
|
output, "input");
|
2010-10-07 05:37:04 +08:00
|
|
|
|
|
|
|
/* Debug code sample for debugging coef calculation.*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
debug = gegl_node_new_child (gegl,
|
|
|
|
"operation", "gegl:debugit",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gegl_node_connect_to (coef, "output",
|
|
|
|
debug, "input");
|
|
|
|
|
|
|
|
gegl_node_connect_to (debug, "output",
|
|
|
|
output, "input");*/
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-22 06:07:27 +08:00
|
|
|
|
2010-08-15 07:29:34 +08:00
|
|
|
processor = gegl_node_new_processor (output, NULL);
|
|
|
|
|
|
|
|
while (gegl_processor_work (processor, &value))
|
|
|
|
{
|
|
|
|
gimp_progress_set_value (progress, value);
|
|
|
|
}
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-08-07 21:10:23 +08:00
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
|
|
|
rect.width = tile_manager_width (new_tiles);
|
|
|
|
rect.height = tile_manager_height (new_tiles);
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-08-07 21:10:23 +08:00
|
|
|
gimp_drawable_merge_shadow_tiles (drawable, TRUE, _("Cage transform"));
|
|
|
|
gimp_drawable_free_shadow_tiles (drawable);
|
|
|
|
|
|
|
|
gimp_drawable_update (drawable, rect.x, rect.y, rect.width, rect.height);
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-07-27 01:24:05 +08:00
|
|
|
g_object_unref (gegl);
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-08-15 07:29:34 +08:00
|
|
|
gegl_processor_destroy (processor);
|
2010-11-04 03:08:10 +08:00
|
|
|
}
|
2010-07-22 06:07:27 +08:00
|
|
|
}
|
2010-08-09 00:21:26 +08:00
|
|
|
|
2010-08-10 05:33:11 +08:00
|
|
|
static void
|
2010-09-03 03:28:06 +08:00
|
|
|
gimp_cage_tool_halt (GimpCageTool *ct)
|
2010-08-10 05:33:11 +08:00
|
|
|
{
|
2010-09-03 03:28:06 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (ct);
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (ct);
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
if (gimp_draw_tool_is_active (draw_tool))
|
|
|
|
gimp_draw_tool_stop (draw_tool);
|
2010-08-12 02:27:32 +08:00
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
if (gimp_tool_control_is_active (tool->control))
|
|
|
|
gimp_tool_control_halt (tool->control);
|
|
|
|
|
|
|
|
if (ct->config)
|
2010-08-14 00:25:48 +08:00
|
|
|
{
|
2010-09-03 03:28:06 +08:00
|
|
|
g_object_unref (ct->config);
|
|
|
|
ct->config = NULL;
|
2010-08-14 00:25:48 +08:00
|
|
|
}
|
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
if (ct->coef)
|
|
|
|
{
|
|
|
|
gegl_buffer_destroy (ct->coef);
|
|
|
|
ct->coef = NULL;
|
|
|
|
}
|
2010-08-14 00:25:48 +08:00
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
if (ct->image_map)
|
|
|
|
{
|
2010-08-10 05:33:11 +08:00
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
if (ct->idle_id > 0)
|
|
|
|
{
|
|
|
|
g_source_remove(ct->idle_id);
|
|
|
|
ct->idle_id = 0;
|
|
|
|
}
|
|
|
|
gimp_tool_control_set_preserve (tool->control, TRUE);
|
2010-08-10 05:33:11 +08:00
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
gimp_image_map_abort (ct->image_map);
|
|
|
|
g_object_unref (ct->image_map);
|
|
|
|
ct->image_map = NULL;
|
2010-08-10 05:33:11 +08:00
|
|
|
|
2010-09-03 03:28:06 +08:00
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
|
|
|
|
|
|
|
gimp_image_flush (gimp_display_get_image (tool->display));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ct->node_preview)
|
|
|
|
{
|
|
|
|
g_object_unref (ct->node_preview);
|
|
|
|
ct->node_preview = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tool->display = NULL;
|
|
|
|
}
|