[gimp/gimp-2-10] Bug 526719: add easy way to set rotation angle to straighten an image
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] Bug 526719: add easy way to set rotation angle to straighten an image
- Date: Tue, 5 Jun 2018 14:54:57 +0000 (UTC)
commit c179dfa7146895fc403930d731f4a9ae0a2c557c
Author: Massimo Valentini <mvalentini src gnome org>
Date: Wed Dec 27 12:08:03 2017 +0100
Bug 526719: add easy way to set rotation angle to straighten an image
(cherry picked from commit 9baf2b62cd5a5622caa3a478a08538ed778a7397)
app/tools/gimpmeasureoptions.c | 7 +++++
app/tools/gimpmeasureoptions.h | 1 +
app/tools/gimpmeasuretool.c | 62 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 70 insertions(+)
---
diff --git a/app/tools/gimpmeasureoptions.c b/app/tools/gimpmeasureoptions.c
index 61338766be..f8b96a7293 100644
--- a/app/tools/gimpmeasureoptions.c
+++ b/app/tools/gimpmeasureoptions.c
@@ -127,5 +127,12 @@ gimp_measure_options_gui (GimpToolOptions *tool_options)
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
+ button = gtk_button_new_with_label (_("Auto straighten"));
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+ gtk_widget_set_sensitive (button, FALSE);
+// gimp_help_set_help_data (button, NULL, GIMP_HELP_PATH_STROKE);
+ gtk_widget_show (button);
+
+ GIMP_MEASURE_OPTIONS (tool_options)->auto_straighten = button;
return vbox;
}
diff --git a/app/tools/gimpmeasureoptions.h b/app/tools/gimpmeasureoptions.h
index de83c187d0..b87bdd141d 100644
--- a/app/tools/gimpmeasureoptions.h
+++ b/app/tools/gimpmeasureoptions.h
@@ -38,6 +38,7 @@ struct _GimpMeasureOptions
GimpToolOptions parent_instance;
gboolean use_info_window;
+ GtkWidget *auto_straighten;
};
diff --git a/app/tools/gimpmeasuretool.c b/app/tools/gimpmeasuretool.c
index 76d2240f7f..86a738af8e 100644
--- a/app/tools/gimpmeasuretool.c
+++ b/app/tools/gimpmeasuretool.c
@@ -30,10 +30,17 @@
#include "tools-types.h"
+#include "config/gimpcoreconfig.h"
+
+#include "core/gimp.h"
+#include "core/gimpdrawable.h"
+#include "core/gimpdrawable-transform.h"
#include "core/gimpimage.h"
#include "core/gimpimage-guides.h"
+#include "core/gimpimage-resize.h"
#include "core/gimpimage-undo.h"
#include "core/gimpimage-undo-push.h"
+#include "core/gimp-transform-utils.h"
#include "widgets/gimphelp-ids.h"
@@ -103,6 +110,8 @@ static GimpToolGui * gimp_measure_tool_dialog_new (GimpMeasureTool *measur
static void gimp_measure_tool_dialog_update (GimpMeasureTool *measure,
GimpDisplay *display);
+static void rotate_active_layer (GtkWidget *button,
+ GimpMeasureTool *measure);
G_DEFINE_TYPE (GimpMeasureTool, gimp_measure_tool, GIMP_TYPE_DRAW_TOOL)
@@ -271,6 +280,7 @@ static void
gimp_measure_tool_compass_changed (GimpToolWidget *widget,
GimpMeasureTool *measure)
{
+ GimpMeasureOptions *options = GIMP_MEASURE_TOOL_GET_OPTIONS (measure);
g_object_get (widget,
"n-points", &measure->n_points,
"x1", &measure->x[0],
@@ -281,6 +291,7 @@ gimp_measure_tool_compass_changed (GimpToolWidget *widget,
"y3", &measure->y[2],
NULL);
+ gtk_widget_set_sensitive (options->auto_straighten, measure->n_points >= 2);
gimp_measure_tool_dialog_update (measure, GIMP_TOOL (measure)->display);
}
@@ -353,6 +364,7 @@ gimp_measure_tool_start (GimpMeasureTool *measure,
{
GimpTool *tool = GIMP_TOOL (measure);
GimpDisplayShell *shell = gimp_display_get_shell (display);
+ GimpMeasureOptions *options = GIMP_MEASURE_TOOL_GET_OPTIONS (tool);
measure->n_points = 1;
measure->x[0] = coords->x;
@@ -385,6 +397,9 @@ gimp_measure_tool_start (GimpMeasureTool *measure,
g_signal_connect (measure->widget, "create-guides",
G_CALLBACK (gimp_measure_tool_compass_create_guides),
measure);
+ g_signal_connect (options->auto_straighten, "clicked",
+ G_CALLBACK (rotate_active_layer),
+ measure);
tool->display = display;
@@ -394,14 +409,21 @@ gimp_measure_tool_start (GimpMeasureTool *measure,
static void
gimp_measure_tool_halt (GimpMeasureTool *measure)
{
+ GimpMeasureOptions *options = GIMP_MEASURE_TOOL_GET_OPTIONS (measure);
GimpTool *tool = GIMP_TOOL (measure);
+ gtk_widget_set_sensitive (options->auto_straighten, FALSE);
+
if (tool->display)
gimp_tool_pop_status (tool, tool->display);
if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (measure)))
gimp_draw_tool_stop (GIMP_DRAW_TOOL (measure));
+ g_signal_handlers_disconnect_by_func (options->auto_straighten,
+ G_CALLBACK (rotate_active_layer),
+ measure);
+
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), NULL);
g_clear_object (&measure->widget);
@@ -780,3 +802,43 @@ gimp_measure_tool_dialog_new (GimpMeasureTool *measure)
return gui;
}
+
+static void
+rotate_active_layer (GtkWidget *button,
+ GimpMeasureTool *measure)
+{
+ GimpMeasureOptions *options = GIMP_MEASURE_TOOL_GET_OPTIONS (measure);
+ GimpDisplay *display = GIMP_TOOL (measure)->display;
+ GimpImage *image = gimp_display_get_image (display);
+ GimpContext *context = GIMP_CONTEXT (options);
+ gdouble ax = measure->x[1] - measure->x[0];
+ gdouble ay = measure->y[1] - measure->y[0];
+ GimpLayer *item = gimp_image_get_active_layer (image);
+ gdouble angle = atan2 (ay, ax);
+ GimpMatrix3 matrix;
+
+
+ gimp_matrix3_identity (&matrix);
+ gimp_transform_matrix_rotate_center (&matrix, measure->x[0], measure->y[0], angle);
+
+ /* Start a transform undo group */
+ gimp_image_undo_group_start (image,
+ GIMP_UNDO_GROUP_TRANSFORM,
+ C_("undo-type", "Transform"));
+
+ gimp_drawable_transform_affine (GIMP_DRAWABLE (item),
+ context,
+ &matrix,
+ GIMP_TRANSFORM_BACKWARD,
+ display->gimp->config->interpolation_type,
+ GIMP_TRANSFORM_RESIZE_ADJUST,
+ NULL);
+
+ gimp_image_resize_to_layers (image, context, NULL);
+
+ /* push the undo group end */
+ gimp_image_undo_group_end (image);
+
+ gimp_image_flush (image);
+ gimp_tool_control (GIMP_TOOL (measure), GIMP_TOOL_ACTION_HALT, display);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]