Commit 2989bad3 authored by Johannes Matschke's avatar Johannes Matschke Committed by Michael Natterer

Bug 721009 - new transform tool with freely placeable handles

Add new tool GimpHandleTransformTool which allows to freely place up
to 4 handles on the image, then move any one of them, which transforms
the image so that the remaining handles keep their position.

Did quite some cleanup on the code before pushing --Mitch
parent 67673e0b
......@@ -244,6 +244,7 @@ static const GimpDialogFactoryEntry entries[] =
FOREIGN ("gimp-threshold-tool-dialog", TRUE, FALSE),
FOREIGN ("gimp-perspective-tool-dialog", TRUE, FALSE),
FOREIGN ("gimp-unified-transform-tool-dialog", TRUE, FALSE),
FOREIGN ("gimp-handle-transform-tool-dialog", TRUE, FALSE),
FOREIGN ("gimp-toolbox-color-dialog", TRUE, FALSE),
FOREIGN ("gimp-gradient-editor-color-dialog", TRUE, FALSE),
......
......@@ -96,6 +96,10 @@ libapptools_a_sources = \
gimpfuzzyselecttool.h \
gimpgegltool.c \
gimpgegltool.h \
gimphandletransformoptions.c \
gimphandletransformoptions.h \
gimphandletransformtool.c \
gimphandletransformtool.h \
gimphealtool.c \
gimphealtool.h \
gimphistogramoptions.c \
......
......@@ -61,6 +61,7 @@
#include "gimpforegroundselecttool.h"
#include "gimpfuzzyselecttool.h"
#include "gimpgegltool.h"
#include "gimphandletransformtool.h"
#include "gimphealtool.h"
#include "gimphuesaturationtool.h"
#include "gimpinktool.h"
......@@ -160,6 +161,7 @@ gimp_tools_init (Gimp *gimp)
gimp_cage_tool_register,
gimp_flip_tool_register,
gimp_perspective_tool_register,
gimp_handle_transform_tool_register,
gimp_shear_tool_register,
gimp_scale_tool_register,
gimp_rotate_tool_register,
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <gegl.h>
#include <gtk/gtk.h>
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "core/gimp.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimppropwidgets.h"
#include "widgets/gimpspinscale.h"
#include "widgets/gimpwidgets-utils.h"
#include "gimphandletransformoptions.h"
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_HANDLE_MODE
};
static void gimp_handle_transform_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_handle_transform_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE (GimpHandleTransformOptions, gimp_handle_transform_options,
GIMP_TYPE_TRANSFORM_OPTIONS)
#define parent_class gimp_handle_transform_options_parent_class
static void
gimp_handle_transform_options_class_init (GimpHandleTransformOptionsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = gimp_handle_transform_options_set_property;
object_class->get_property = gimp_handle_transform_options_get_property;
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_HANDLE_MODE,
"handle-mode",
N_("Handle mode"),
GIMP_TYPE_TRANSFORM_HANDLE_MODE,
GIMP_HANDLE_MODE_TRANSFORM,
GIMP_PARAM_STATIC_STRINGS);
}
static void
gimp_handle_transform_options_init (GimpHandleTransformOptions *options)
{
}
static void
gimp_handle_transform_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpHandleTransformOptions *options = GIMP_HANDLE_TRANSFORM_OPTIONS (object);
switch (property_id)
{
case PROP_HANDLE_MODE:
options->handle_mode = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_handle_transform_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpHandleTransformOptions *options = GIMP_HANDLE_TRANSFORM_OPTIONS (object);
switch (property_id)
{
case PROP_HANDLE_MODE:
g_value_set_enum (value, options->handle_mode);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
/**
* gimp_handle_transform_options_gui:
* @tool_options: a #GimpToolOptions
*
* Build the Transform Tool Options.
*
* Return value: a container holding the transform tool options
**/
GtkWidget *
gimp_handle_transform_options_gui (GimpToolOptions *tool_options)
{
GObject *config = G_OBJECT (tool_options);
GtkWidget *vbox = gimp_transform_options_gui (tool_options);
GtkWidget *frame;
GtkWidget *button;
gint i;
frame = gimp_prop_enum_radio_frame_new (config, "handle-mode",
_("Handle mode"), 0, 0);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
/* add modifier to name, add tooltip */
button = g_object_get_data (G_OBJECT (frame), "radio-button");
if (GTK_IS_RADIO_BUTTON (button))
{
GSList *list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
for (i = g_slist_length (list) - 1 ; list; list = list->next, i--)
{
GdkModifierType shift = gimp_get_extend_selection_mask ();
GdkModifierType ctrl = gimp_get_constrain_behavior_mask ();
GdkModifierType modifier = 0;
gchar *tooltip = "";
gchar *tip;
gchar *label;
switch (i)
{
case GIMP_HANDLE_MODE_ADD_MOVE:
modifier = shift;
tooltip = "Add or move transform handles";
break;
case GIMP_HANDLE_MODE_REMOVE:
modifier = ctrl;
tooltip = "Remove transform handles";
break;
case GIMP_HANDLE_MODE_TRANSFORM:
modifier = 0;
tooltip = "Transform image by moving handles";
break;
}
if (modifier)
{
label = g_strdup_printf ("%s (%s)",
gtk_button_get_label (GTK_BUTTON (list->data)),
gimp_get_mod_string (modifier));
gtk_button_set_label (GTK_BUTTON (list->data), label);
g_free (label);
tip = g_strdup_printf ("%s (%s)",
tooltip, gimp_get_mod_string (modifier));
gimp_help_set_help_data (list->data, tip, NULL);
g_free (tip);
}
else
{
gimp_help_set_help_data (list->data, tooltip, NULL);
}
}
}
return vbox;
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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/>.
*/
#ifndef __GIMP_HANDLE_TRANSFORM_OPTIONS_H__
#define __GIMP_HANDLE_TRANSFORM_OPTIONS_H__
#include "gimptransformoptions.h"
#define GIMP_TYPE_HANDLE_TRANSFORM_OPTIONS (gimp_handle_transform_options_get_type ())
#define GIMP_HANDLE_TRANSFORM_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_HANDLE_TRANSFORM_OPTIONS, GimpHandleTransformOptions))
#define GIMP_HANDLE_TRANSFORM_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_HANDLE_TRANSFORM_OPTIONS, GimpHandleTransformOptionsClass))
#define GIMP_IS_HANDLE_TRANSFORM_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_HANDLE_TRANSFORM_OPTIONS))
#define GIMP_IS_HANDLE_TRANSFORM_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_HANDLE_TRANSFORM_OPTIONS))
#define GIMP_HANDLE_TRANSFORM_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_HANDLE_TRANSFORM_OPTIONS, GimpHandleTransformOptionsClass))
typedef struct _GimpHandleTransformOptions GimpHandleTransformOptions;
typedef struct _GimpHandleTransformOptionsClass GimpHandleTransformOptionsClass;
struct _GimpHandleTransformOptions
{
GimpTransformOptions parent_instance;
GimpTransformHandleMode handle_mode;
};
struct _GimpHandleTransformOptionsClass
{
GimpTransformOptionsClass parent_class;
};
GType gimp_handle_transform_options_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_handle_transform_options_gui (GimpToolOptions *tool_options);
#endif /* __GIMP_HANDLE_TRANSFORM_OPTIONS_H__ */
This diff is collapsed.
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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/>.
*/
#ifndef __GIMP_HANDLE_TRANSFORM_TOOL_H__
#define __GIMP_HANDLE_TRANSFORM_TOOL_H__
#include "gimptransformtool.h"
#define GIMP_TYPE_HANDLE_TRANSFORM_TOOL (gimp_handle_transform_tool_get_type ())
#define GIMP_HANDLE_TRANSFORM_TOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_HANDLE_TRANSFORM_TOOL, GimpHandleTransformTool))
#define GIMP_HANDLE_TRANSFORM_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_HANDLE_TRANSFORM_TOOL, GimpHandleTransformToolClass))
#define GIMP_IS_HANDLE_TRANSFORM_TOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_HANDLE_TRANSFORM_TOOL))
#define GIMP_IS_HANDLE_TRANSFORM_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_HANDLE_TRANSFORM_TOOL))
#define GIMP_HANDLE_TRANSFORM_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_HANDLE_TRANSFORM_TOOL, GimpHandleTransformToolClass))
#define GIMP_HANDLE_TRANSFORM_TOOL_GET_OPTIONS(t) (GIMP_HANDLE_TRANSFORM_OPTIONS (gimp_tool_get_options (GIMP_TOOL (t))))
typedef struct _GimpHandleTransformTool GimpHandleTransformTool;
typedef struct _GimpHandleTransformToolClass GimpHandleTransformToolClass;
struct _GimpHandleTransformTool
{
GimpTransformTool parent_instance;
GtkWidget *label[3][3];
gboolean matrix_recalculation;
GimpTransformHandleMode saved_handle_mode;
};
struct _GimpHandleTransformToolClass
{
GimpTransformToolClass parent_class;
};
void gimp_handle_transform_tool_register (GimpToolRegisterCallback callback,
gpointer data);
GType gimp_handle_transform_tool_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_HANDLE_TRANSFORM_TOOL_H__ */
......@@ -59,6 +59,7 @@
#include "display/gimptoolgui.h"
#include "gimptoolcontrol.h"
#include "gimphandletransformtool.h"
#include "gimpperspectivetool.h"
#include "gimpunifiedtransformtool.h"
#include "gimptransformoptions.h"
......@@ -1088,10 +1089,15 @@ gimp_transform_tool_draw (GimpDrawTool *draw_tool)
if (gimp_transform_options_show_preview (options))
{
GimpMatrix3 matrix = tr_tool->transform;
gboolean perspective;
if (options->direction == GIMP_TRANSFORM_BACKWARD)
gimp_matrix3_invert (&matrix);
perspective = (GIMP_IS_PERSPECTIVE_TOOL (tr_tool) ||
GIMP_IS_HANDLE_TRANSFORM_TOOL (tr_tool) ||
GIMP_IS_UNIFIED_TRANSFORM_TOOL (tr_tool));
gimp_draw_tool_add_transform_preview (draw_tool,
tool->drawable,
&matrix,
......@@ -1099,8 +1105,7 @@ gimp_transform_tool_draw (GimpDrawTool *draw_tool)
tr_tool->y1,
tr_tool->x2,
tr_tool->y2,
GIMP_IS_PERSPECTIVE_TOOL (tr_tool) ||
GIMP_IS_UNIFIED_TRANSFORM_TOOL (tr_tool),
perspective,
options->preview_opacity);
}
......
......@@ -54,7 +54,7 @@ typedef enum
* of the enums at the top of each transformation tool, stored in
* trans_info and related
*/
#define TRANS_INFO_SIZE 10
#define TRANS_INFO_SIZE 17
typedef gdouble TransInfo[TRANS_INFO_SIZE];
......
......@@ -73,6 +73,37 @@ gimp_button_release_type_get_type (void)
return type;
}
GType
gimp_transform_handle_mode_get_type (void)
{
static const GEnumValue values[] =
{
{ GIMP_HANDLE_MODE_ADD_MOVE, "GIMP_HANDLE_MODE_ADD_MOVE", "add-move" },
{ GIMP_HANDLE_MODE_REMOVE, "GIMP_HANDLE_MODE_REMOVE", "remove" },
{ GIMP_HANDLE_MODE_TRANSFORM, "GIMP_HANDLE_MODE_TRANSFORM", "transform" },
{ 0, NULL, NULL }
};
static const GimpEnumDesc descs[] =
{
{ GIMP_HANDLE_MODE_ADD_MOVE, NC_("transform-handle-mode", "Add/Move"), NULL },
{ GIMP_HANDLE_MODE_REMOVE, NC_("transform-handle-mode", "Remove"), NULL },
{ GIMP_HANDLE_MODE_TRANSFORM, NC_("transform-handle-mode", "Transform"), NULL },
{ 0, NULL, NULL }
};
static GType type = 0;
if (G_UNLIKELY (! type))
{
type = g_enum_register_static ("GimpTransformHandleMode", values);
gimp_type_set_translation_context (type, "transform-handle-mode");
gimp_enum_set_value_descriptions (type, descs);
}
return type;
}
GType
gimp_rectangle_constraint_get_type (void)
{
......
......@@ -47,6 +47,18 @@ typedef enum
} GimpButtonReleaseType;
#define GIMP_TYPE_TRANSFORM_HANDLE_MODE (gimp_transform_handle_mode_get_type ())
GType gimp_transform_handle_mode_get_type (void) G_GNUC_CONST;
typedef enum
{
GIMP_HANDLE_MODE_ADD_MOVE, /*< desc="Add/Move" >*/
GIMP_HANDLE_MODE_REMOVE, /*< desc="Remove" >*/
GIMP_HANDLE_MODE_TRANSFORM, /*< desc="Transform" >*/
} GimpTransformHandleMode;
#define GIMP_TYPE_RECTANGLE_CONSTRAINT (gimp_rectangle_constraint_get_type ())
GType gimp_rectangle_constraint_get_type (void) G_GNUC_CONST;
......
......@@ -281,6 +281,7 @@
#define GIMP_HELP_TOOL_FOREGROUND_SELECT "gimp-tool-foreground-select"
#define GIMP_HELP_TOOL_FUZZY_SELECT "gimp-tool-fuzzy-select"
#define GIMP_HELP_TOOL_GEGL "gimp-tool-gegl"
#define GIMP_HELP_TOOL_HANDLE_TRANSFORM "gimp-tool-handle-transform"
#define GIMP_HELP_TOOL_HEAL "gimp-tool-heal"
#define GIMP_HELP_TOOL_HUE_SATURATION "gimp-tool-hue-saturation"
#define GIMP_HELP_TOOL_INK "gimp-tool-ink"
......
......@@ -180,6 +180,7 @@ icons16_DATA = \
16/gimp-tool-foreground-select.png \
16/gimp-tool-free-select.png \
16/gimp-tool-fuzzy-select.png \
16/gimp-tool-handle-transform.png \
16/gimp-tool-heal.png \
16/gimp-tool-hue-saturation.png \
16/gimp-tool-ink.png \
......@@ -290,6 +291,7 @@ icons22_DATA = \
22/gimp-tool-foreground-select.png \
22/gimp-tool-free-select.png \
22/gimp-tool-fuzzy-select.png \
22/gimp-tool-handle-transform.png \
22/gimp-tool-heal.png \
22/gimp-tool-hue-saturation.png \
22/gimp-tool-ink.png \
......
......@@ -256,6 +256,7 @@ static const GtkStockItem gimp_stock_items[] =
{ GIMP_STOCK_TOOL_FOREGROUND_SELECT, N_("_Select"), 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_TOOL_FUZZY_SELECT, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_TOOL_HUE_SATURATION, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_TOOL_HANDLE_TRANSFORM,N_("_Transform"),0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_TOOL_HEAL, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_TOOL_INK, NULL, 0, 0, LIBGIMP_DOMAIN },
{ GIMP_STOCK_TOOL_ISCISSORS, NULL, 0, 0, LIBGIMP_DOMAIN },
......
......@@ -125,6 +125,7 @@ G_BEGIN_DECLS
#define GIMP_STOCK_TOOL_FREE_SELECT "gimp-tool-free-select"
#define GIMP_STOCK_TOOL_FOREGROUND_SELECT "gimp-tool-foreground-select"
#define GIMP_STOCK_TOOL_FUZZY_SELECT "gimp-tool-fuzzy-select"
#define GIMP_STOCK_TOOL_HANDLE_TRANSFORM "gimp-tool-handle-transform"
#define GIMP_STOCK_TOOL_HEAL "gimp-tool-heal"
#define GIMP_STOCK_TOOL_HUE_SATURATION "gimp-tool-hue-saturation"
#define GIMP_STOCK_TOOL_INK "gimp-tool-ink"
......
......@@ -602,6 +602,7 @@
<menuitem action="tools-shear" />
<menuitem action="tools-perspective" />
<menuitem action="tools-unified-transform" />
<menuitem action="tools-handle-transform" />
<menuitem action="tools-flip" />
<menuitem action="tools-cage" />
<menuitem action="tools-warp" />
......
......@@ -368,6 +368,8 @@ app/tools/gimpforegroundselecttool.c
app/tools/gimpfreeselecttool.c
app/tools/gimpfuzzyselecttool.c
app/tools/gimpgegltool.c
app/tools/gimphandletransformoptions.c
app/tools/gimphandletransformtool.c
app/tools/gimphealtool.c
app/tools/gimphistogramoptions.c
app/tools/gimphuesaturationtool.c
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment