[gthumb: 119/129] rotate tool: automatic alignment completed
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 119/129] rotate tool: automatic alignment completed
- Date: Wed, 27 Apr 2011 21:00:23 +0000 (UTC)
commit 136824fdda04eb9016840215e21cbf7195378dcd
Author: Stefano Pettini <spettini users sourceforge net>
Date: Mon Apr 25 20:33:09 2011 +0100
rotate tool: automatic alignment completed
extensions/file_tools/data/ui/rotate-options.ui | 145 ++-------------------
extensions/file_tools/gdk-pixbuf-rotate.c | 35 +++++
extensions/file_tools/gdk-pixbuf-rotate.h | 4 +
extensions/file_tools/gth-file-tool-rotate.c | 160 +++++++++++------------
4 files changed, 126 insertions(+), 218 deletions(-)
---
diff --git a/extensions/file_tools/data/ui/rotate-options.ui b/extensions/file_tools/data/ui/rotate-options.ui
index 4eebc22..36a35ed 100644
--- a/extensions/file_tools/data/ui/rotate-options.ui
+++ b/extensions/file_tools/data/ui/rotate-options.ui
@@ -13,7 +13,7 @@
<property name="visible">True</property>
<property name="spacing">12</property>
<child>
- <object class="GtkFrame" id="frame4">
+ <object class="GtkFrame" id="rotation_frame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
@@ -92,7 +92,7 @@
</packing>
</child>
<child>
- <object class="GtkFrame" id="frame2">
+ <object class="GtkFrame" id="align_frame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
@@ -106,121 +106,7 @@
<property name="visible">True</property>
<property name="spacing">6</property>
<child>
- <object class="GtkHBox" id="hbox2">
- <property name="visible">True</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkButton" id="get_1_button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <child>
- <object class="GtkLabel" id="label1">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Get</property>
- <attributes>
- <attribute name="size" value="8000"/>
- </attributes>
- </object>
- </child>
- </object>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkSpinButton" id="p1_x_spinbutton">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="invisible_char">â?¢</property>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label3">
- <property name="visible">True</property>
- <property name="label" translatable="yes">x</property>
- </object>
- <packing>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkSpinButton" id="p1_y_spinbutton">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="invisible_char">â?¢</property>
- </object>
- <packing>
- <property name="position">3</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkHBox" id="hbox1">
- <property name="visible">True</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkButton" id="get_2_button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <child>
- <object class="GtkLabel" id="label5">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Get</property>
- <attributes>
- <attribute name="size" value="8000"/>
- </attributes>
- </object>
- </child>
- </object>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkSpinButton" id="p2_x_spinbutton">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="invisible_char">â?¢</property>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label2">
- <property name="visible">True</property>
- <property name="label" translatable="yes">x</property>
- </object>
- <packing>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkSpinButton" id="p2_y_spinbutton">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="invisible_char">â?¢</property>
- </object>
- <packing>
- <property name="position">3</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkVButtonBox" id="vbuttonbox1">
+ <object class="GtkHButtonBox" id="hbuttonbox3">
<property name="visible">True</property>
<property name="spacing">6</property>
<property name="layout_style">spread</property>
@@ -233,7 +119,7 @@
<child>
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
- <property name="label" translatable="yes">Align the points horizontally</property>
+ <property name="label" translatable="yes">Align horizontally</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
@@ -255,7 +141,7 @@
<child>
<object class="GtkLabel" id="label7">
<property name="visible">True</property>
- <property name="label" translatable="yes">Align the points vertically</property>
+ <property name="label" translatable="yes">Align vertically</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
@@ -270,7 +156,7 @@
</child>
</object>
<packing>
- <property name="position">2</property>
+ <property name="position">0</property>
</packing>
</child>
</object>
@@ -278,9 +164,9 @@
</object>
</child>
<child type="label">
- <object class="GtkLabel" id="automatic_rotation_label">
+ <object class="GtkLabel" id="label12">
<property name="visible">True</property>
- <property name="label" translatable="yes">Automatic rotation</property>
+ <property name="label" translatable="yes">Automatic alignment</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
@@ -294,7 +180,7 @@
</packing>
</child>
<child>
- <object class="GtkFrame" id="frame3">
+ <object class="GtkFrame" id="crop_frame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
@@ -550,17 +436,4 @@
</object>
</child>
</object>
- <object class="GtkAdjustment" id="rotation_angle_adjustment">
- <property name="lower">-90</property>
- <property name="upper">91</property>
- <property name="step_increment">0.10000000000000001</property>
- <property name="page_increment">1</property>
- <property name="page_size">1</property>
- </object>
- <object class="GtkAdjustment" id="p1_x_adjustment">
- <property name="upper">100</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
- <property name="page_size">10</property>
- </object>
</interface>
diff --git a/extensions/file_tools/gdk-pixbuf-rotate.c b/extensions/file_tools/gdk-pixbuf-rotate.c
index 58a76a0..8e11908 100644
--- a/extensions/file_tools/gdk-pixbuf-rotate.c
+++ b/extensions/file_tools/gdk-pixbuf-rotate.c
@@ -249,6 +249,41 @@ rotate (GdkPixbuf *src_pixbuf,
}
+double
+_gdk_pixbuf_rotate_get_align_angle (gboolean vertical,
+ GdkPoint p1,
+ GdkPoint p2)
+{
+ double angle;
+
+ if (! vertical) {
+
+ if (p1.y == p2.y)
+ return 0.0;
+
+ if (p2.x > p1.x)
+ angle = -atan2 (p2.y - p1.y, p2.x - p1.x);
+ else
+ angle = -atan2 (p1.y - p2.y, p1.x - p2.x);
+ }
+ else {
+
+ if (p1.x == p2.x)
+ return 0.0;
+
+ if (p2.y > p1.y)
+ angle = atan2 (p2.x - p1.x, p2.y - p1.y);
+ else
+ angle = atan2 (p1.x - p2.x, p1.y - p2.y);
+ }
+
+ angle = angle * 180.0 / PI;
+ angle = ROUND (angle * 10.0) / 10.0;
+
+ return angle;
+}
+
+
GdkPixbuf*
_gdk_pixbuf_rotate (GdkPixbuf *src_pixbuf,
double angle,
diff --git a/extensions/file_tools/gdk-pixbuf-rotate.h b/extensions/file_tools/gdk-pixbuf-rotate.h
index 3e8dd57..6bc289c 100644
--- a/extensions/file_tools/gdk-pixbuf-rotate.h
+++ b/extensions/file_tools/gdk-pixbuf-rotate.h
@@ -41,6 +41,10 @@ void _gdk_pixbuf_rotate_get_cropping_region (GdkPixbuf *src_pixbuf,
double delta,
GdkRectangle *region);
+double _gdk_pixbuf_rotate_get_align_angle (gboolean vertical,
+ GdkPoint p1,
+ GdkPoint p2);
+
GdkPixbuf* _gdk_pixbuf_rotate (GdkPixbuf *src_pixbuf,
double angle,
gboolean high_quality);
diff --git a/extensions/file_tools/gth-file-tool-rotate.c b/extensions/file_tools/gth-file-tool-rotate.c
index 1d391d7..ec81508 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -19,6 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <math.h>
#include <config.h>
#include <gthumb.h>
#include <extensions/image_viewer/gth-image-viewer-page.h>
@@ -39,6 +40,7 @@ struct _GthFileToolRotatePrivate {
GdkPixbuf *dest_pixbuf;
GdkPixbuf *crop_pixbuf;
GtkBuilder *builder;
+ GtkWidget *options;
GtkAdjustment *rotation_angle_adj;
GtkWidget *high_quality;
GtkWidget *show_grid;
@@ -47,11 +49,13 @@ struct _GthFileToolRotatePrivate {
GtkAdjustment *crop_p1_adj;
GtkAdjustment *crop_p2_adj;
GtkWidget *crop_grid;
+ GdkRectangle crop_region;
GthImageSelector *selector_crop;
GthImageSelector *selector_align;
+ guint selector_align_direction;
guint selector_align_point;
+ GdkPoint align_points[2];
guint apply_event;
- GdkRectangle crop_region;
};
@@ -146,6 +150,62 @@ update_crop_grid (gpointer user_data)
}
+static void
+align_begin (GthFileToolRotate *self)
+{
+ GtkWidget *window;
+ GtkWidget *viewer_page;
+ GtkWidget *viewer;
+
+ window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
+ viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
+ viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
+
+ self->priv->selector_align_point = 0;
+
+ gtk_widget_set_sensitive (self->priv->options, FALSE);
+
+ gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), self->priv->src_pixbuf, FALSE);
+ gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), (GthImageViewerTool *) self->priv->selector_align);
+}
+
+
+static void
+align_end (GthFileToolRotate *self)
+{
+ GtkWidget *window;
+ GtkWidget *viewer_page;
+ GtkWidget *viewer;
+ double angle;
+
+ window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
+ viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
+ viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
+
+ angle = _gdk_pixbuf_rotate_get_align_angle (self->priv->selector_align_direction == 1,
+ self->priv->align_points[0],
+ self->priv->align_points[1]),
+
+ self->priv->selector_align_direction = 0;
+ self->priv->selector_align_point = 0;
+
+ gtk_widget_set_sensitive (self->priv->options, TRUE);
+
+ if (angle == gtk_adjustment_get_value (self->priv->rotation_angle_adj)) {
+
+ // We already have the pixmap ready
+
+ gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), self->priv->dest_pixbuf, FALSE);
+
+ update_crop_region (self);
+ }
+ else
+ {
+ gtk_adjustment_set_value (self->priv->rotation_angle_adj, angle);
+ }
+}
+
+
static gboolean
apply_cb (gpointer user_data)
{
@@ -193,46 +253,12 @@ gth_file_tool_rotate_update_sensitivity (GthFileTool *base)
static void
-get_1_button_clicked_cb (GtkButton *button,
- GthFileToolRotate *self)
-{
- GtkWidget *window;
- GtkWidget *viewer_page;
- GtkWidget *viewer;
-
- self->priv->selector_align_point = 1;
-
- window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
- viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
- viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
-
- gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), (GthImageViewerTool *) self->priv->selector_align);
-}
-
-
-static void
-get_2_button_clicked_cb (GtkButton *button,
- GthFileToolRotate *self)
-{
- GtkWidget *window;
- GtkWidget *viewer_page;
- GtkWidget *viewer;
-
- self->priv->selector_align_point = 2;
-
- window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
- viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
- viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
-
- gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), (GthImageViewerTool *) self->priv->selector_align);
-}
-
-
-static void
align_h_button_clicked_cb (GtkButton *button,
GthFileToolRotate *self)
{
-
+ self->priv->selector_align_direction = 0;
+
+ align_begin (self);
}
@@ -240,7 +266,9 @@ static void
align_v_button_clicked_cb (GtkButton *button,
GthFileToolRotate *self)
{
-
+ self->priv->selector_align_direction = 1;
+
+ align_begin (self);
}
@@ -380,34 +408,13 @@ selector_selected_cb (GthImageSelector *selector,
int y,
GthFileToolRotate *self)
{
- GtkWidget *window;
- GtkWidget *viewer_page;
- GtkWidget *viewer;
-
- self->priv->selector_align_point = 0;
+ guint i = self->priv->selector_align_point++;
- window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
- viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
- viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
-
- gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), NULL);
-}
-
-
-static void
-selector_motion_notify_cb (GthImageSelector *selector,
- int x,
- int y,
- GthFileToolRotate *self)
-{
- if (self->priv->selector_align_point == 1) {
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("p1_x_spinbutton")), (double) x);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("p1_y_spinbutton")), (double) y);
- }
- else if (self->priv->selector_align_point == 2) {
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("p2_x_spinbutton")), (double) x);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("p2_y_spinbutton")), (double) y);
- }
+ self->priv->align_points[i].x = x;
+ self->priv->align_points[i].y = y;
+
+ if (self->priv->selector_align_point == 2)
+ align_end (self);
}
@@ -418,7 +425,6 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
GtkWidget *window;
GtkWidget *viewer_page;
GtkWidget *viewer;
- GtkWidget *options;
self = (GthFileToolRotate *) base;
@@ -440,8 +446,8 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
self->priv->builder = _gtk_builder_new_from_file ("rotate-options.ui", "file_tools");
- options = _gtk_builder_get_widget (self->priv->builder, "options");
- gtk_widget_show (options);
+ self->priv->options = _gtk_builder_get_widget (self->priv->builder, "options");
+ gtk_widget_show (self->priv->options);
self->priv->rotation_angle_adj = gimp_scale_entry_new (GET_WIDGET ("rotation_angle_hbox"),
GTK_LABEL (GET_WIDGET ("rotation_angle_label")),
@@ -478,6 +484,7 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
gth_image_selector_set_mask_visible (self->priv->selector_crop, TRUE);
gth_image_selector_set_mask_visible (self->priv->selector_align, TRUE);
+ self->priv->selector_align_direction = 0;
self->priv->selector_align_point = 0;
self->priv->crop_region.x = 0;
@@ -493,14 +500,6 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
"clicked",
G_CALLBACK (cancel_button_clicked_cb),
self);
- g_signal_connect (GET_WIDGET ("get_1_button"),
- "clicked",
- G_CALLBACK (get_1_button_clicked_cb),
- self);
- g_signal_connect (GET_WIDGET ("get_2_button"),
- "clicked",
- G_CALLBACK (get_2_button_clicked_cb),
- self);
g_signal_connect (GET_WIDGET ("align_h_button"),
"clicked",
G_CALLBACK (align_h_button_clicked_cb),
@@ -549,15 +548,11 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
"selected",
G_CALLBACK (selector_selected_cb),
self);
- g_signal_connect (self->priv->selector_align,
- "motion_notify",
- G_CALLBACK (selector_motion_notify_cb),
- self);
update_crop_region (self);
update_crop_grid (self);
- return options;
+ return self->priv->options;
}
@@ -593,6 +588,7 @@ gth_file_tool_rotate_destroy_options (GthFileTool *base)
self->priv->builder = NULL;
self->priv->selector_crop = NULL;
self->priv->selector_align = NULL;
+ self->priv->selector_align_direction = 0;
self->priv->selector_align_point = 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]