[gthumb: 113/129] rotate tool: fixed display of cropping region



commit 2175b9e2559d09e4d676e2bdcb9bddb10f7b384e
Author: Stefano Pettini <spettini users sourceforge net>
Date:   Sun Apr 24 22:39:58 2011 +0100

    rotate tool: fixed display of cropping region

 extensions/file_tools/data/ui/rotate-options.ui |    8 ++++----
 extensions/file_tools/gdk-pixbuf-rotate.c       |   12 +++++++++++-
 extensions/file_tools/gth-file-tool-rotate.c    |   16 ++++++++--------
 3 files changed, 23 insertions(+), 13 deletions(-)
---
diff --git a/extensions/file_tools/data/ui/rotate-options.ui b/extensions/file_tools/data/ui/rotate-options.ui
index 6b539f7..a039772 100644
--- a/extensions/file_tools/data/ui/rotate-options.ui
+++ b/extensions/file_tools/data/ui/rotate-options.ui
@@ -221,8 +221,8 @@
                         <property name="visible">True</property>
                         <property name="spacing">6</property>
                         <child>
-                          <object class="GtkCheckButton" id="auto_crop">
-                            <property name="label" translatable="yes">A_uto-crop</property>
+                          <object class="GtkCheckButton" id="enable_guided_crop">
+                            <property name="label" translatable="yes">Enable _guided crop</property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">False</property>
@@ -275,9 +275,9 @@
                   </object>
                 </child>
                 <child type="label">
-                  <object class="GtkLabel" id="assisted_crop_label">
+                  <object class="GtkLabel" id="guided_crop_label">
                     <property name="visible">True</property>
-                    <property name="label" translatable="yes">Assisted crop</property>
+                    <property name="label" translatable="yes">Guided crop</property>
                     <attributes>
                       <attribute name="weight" value="bold"/>
                     </attributes>
diff --git a/extensions/file_tools/gdk-pixbuf-rotate.c b/extensions/file_tools/gdk-pixbuf-rotate.c
index 43c18bf..4c1d5de 100644
--- a/extensions/file_tools/gdk-pixbuf-rotate.c
+++ b/extensions/file_tools/gdk-pixbuf-rotate.c
@@ -70,7 +70,7 @@ _gdk_pixbuf_rotate_get_cropping_parameters (GdkPixbuf *src_pixbuf,
 	pz = - sin_angle * src_width + cos_angle * src_height;
 
 	*alpha_plus_beta  = 1.0 + (px * src_height) / (py * src_width);
-	*gamma_plus_delta = 1.0 + (pz * src_width)  / (px * src_height);
+	*gamma_plus_delta = *alpha_plus_beta; // 1.0 + (pz * src_width)  / (px * src_height);
 }
 
 
@@ -89,6 +89,7 @@ _gdk_pixbuf_rotate_get_cropping_region (GdkPixbuf *src_pixbuf,
 	double angle_rad;
 	double cos_angle, sin_angle;
 	double src_width, src_height;
+	double new_width;
 
 	double xx1, yy1, xx2, yy2;
 	
@@ -107,6 +108,7 @@ _gdk_pixbuf_rotate_get_cropping_region (GdkPixbuf *src_pixbuf,
 	src_height = gdk_pixbuf_get_height (src_pixbuf) - 1;
 
 	if (src_width > src_height) {
+	
 		xx1 = alpha * src_width * cos_angle + src_height * sin_angle;
 		yy1 = alpha * src_width * sin_angle;
 	
@@ -121,6 +123,14 @@ _gdk_pixbuf_rotate_get_cropping_region (GdkPixbuf *src_pixbuf,
 		yy2 = delta       * src_height * cos_angle + src_width * sin_angle;
 	}
 	
+	if (angle < 0) {
+
+		new_width  = cos_angle * src_width + sin_angle * src_height;
+
+		xx1 = new_width - xx1;
+		xx2 = new_width - xx2;
+	}
+
 	*x1 = ROUND (MIN (xx1, xx2));
 	*y1 = ROUND (MIN (yy1, yy2));
 	
diff --git a/extensions/file_tools/gth-file-tool-rotate.c b/extensions/file_tools/gth-file-tool-rotate.c
index fe390e5..9c79b30 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -44,7 +44,7 @@ struct _GthFileToolRotatePrivate {
 	int               screen_height;
 	GtkAdjustment    *rotation_angle_adj;
 	GtkWidget        *high_quality;
-	GtkWidget        *auto_crop;
+	GtkWidget        *enable_guided_crop;
 	GtkWidget        *keep_aspect_ratio;
 	GtkAdjustment    *crop_p1_adj;
 	GtkAdjustment    *crop_p2_adj;
@@ -167,7 +167,7 @@ update_crop_region (gpointer user_data)
 	GtkWidget         *viewer_page;
 	GtkWidget         *viewer;
 	double             rotation_angle;
-	gboolean           auto_crop;
+	gboolean           enable_guided_crop;
 	gboolean           keep_aspect_ratio;
 	double             crop_alpha, crop_beta, crop_alpha_plus_beta;
 	double             crop_gamma, crop_delta, crop_gamma_plus_delta;
@@ -178,9 +178,9 @@ update_crop_region (gpointer user_data)
 	viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
 	viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
 
-	auto_crop = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->auto_crop));
+	enable_guided_crop = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->enable_guided_crop));
 	
-	if (auto_crop) {
+	if (enable_guided_crop) {
 
 		gtk_widget_set_sensitive (GTK_WIDGET (self->priv->keep_aspect_ratio), TRUE);
 		
@@ -361,15 +361,15 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
 							       0.0, -90.0, 90.0, 0.1, 1.0, 1);
 	
 	self->priv->high_quality = _gtk_builder_get_widget (self->priv->builder, "high_quality");
-	self->priv->auto_crop = _gtk_builder_get_widget (self->priv->builder, "auto_crop");
+	self->priv->enable_guided_crop = _gtk_builder_get_widget (self->priv->builder, "enable_guided_crop");
 	self->priv->keep_aspect_ratio = _gtk_builder_get_widget (self->priv->builder, "keep_aspect_ratio");
 
 	self->priv->crop_p1_adj = gimp_scale_entry_new (GET_WIDGET ("crop_p1_hbox"),
-							GTK_LABEL (GET_WIDGET ("assisted_crop_label")),
+							GTK_LABEL (GET_WIDGET ("guided_crop_label")),
 							1.0, 0.0, 1.0, 0.01, 0.1, 2);
 
 	self->priv->crop_p2_adj = gimp_scale_entry_new (GET_WIDGET ("crop_p2_hbox"),
-							GTK_LABEL (GET_WIDGET ("assisted_crop_label")),
+							GTK_LABEL (GET_WIDGET ("guided_crop_label")),
 							1.0, 0.0, 1.0, 0.01, 0.1, 2);
 
 	self->priv->selector_crop = (GthImageSelector *) gth_image_selector_new (GTH_IMAGE_VIEWER (viewer), GTH_SELECTOR_TYPE_REGION);
@@ -419,7 +419,7 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
 			  "toggled",
 			  G_CALLBACK (value_changed_cb),
 			  self);
-	g_signal_connect (G_OBJECT (self->priv->auto_crop),
+	g_signal_connect (G_OBJECT (self->priv->enable_guided_crop),
 			  "toggled",
 			  G_CALLBACK (value_changed_cb),
 			  self);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]