[gthumb] rotate image: batch of changes



commit cc0db4c6a9a538468b825ba45787daa18f5dc6f0
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun May 15 19:04:28 2011 +0200

    rotate image: batch of changes
    
    *) moved the grid efore the background option, because it is more useful
    *) fixed display of the crop area when the image is zoomed
    *) disable the zoom when the rotation tool is activated

 extensions/file_tools/data/ui/rotate-options.ui |   32 ++++++++++----------
 extensions/file_tools/gth-file-tool-rotate.c    |    4 ++
 extensions/file_tools/gth-image-rotator.c       |   37 +++++++++++++---------
 gthumb/cairo-utils.c                            |   14 +++++++-
 4 files changed, 54 insertions(+), 33 deletions(-)
---
diff --git a/extensions/file_tools/data/ui/rotate-options.ui b/extensions/file_tools/data/ui/rotate-options.ui
index 04679df..ebe6edd 100644
--- a/extensions/file_tools/data/ui/rotate-options.ui
+++ b/extensions/file_tools/data/ui/rotate-options.ui
@@ -338,8 +338,6 @@
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="right_attach">2</property>
-                            <property name="top_attach">1</property>
-                            <property name="bottom_attach">2</property>
                           </packing>
                         </child>
                         <child>
@@ -350,20 +348,6 @@
                             <property name="label" translatable="yes">Grid:</property>
                           </object>
                           <packing>
-                            <property name="top_attach">1</property>
-                            <property name="bottom_attach">2</property>
-                            <property name="x_options">GTK_FILL</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="label4">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes">_Background:</property>
-                            <property name="use_underline">True</property>
-                          </object>
-                          <packing>
                             <property name="x_options">GTK_FILL</property>
                           </packing>
                         </child>
@@ -408,6 +392,22 @@
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="right_attach">2</property>
+                            <property name="top_attach">1</property>
+                            <property name="bottom_attach">2</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label4">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">_Background:</property>
+                            <property name="use_underline">True</property>
+                          </object>
+                          <packing>
+                            <property name="top_attach">1</property>
+                            <property name="bottom_attach">2</property>
+                            <property name="x_options">GTK_FILL</property>
                           </packing>
                         </child>
                       </object>
diff --git a/extensions/file_tools/gth-file-tool-rotate.c b/extensions/file_tools/gth-file-tool-rotate.c
index 1483812..4e6c756 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -540,6 +540,8 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
 				      gdk_pixbuf_get_width (self->priv->src_pixbuf) / 2,
 				      gdk_pixbuf_get_height (self->priv->src_pixbuf) / 2);
 	gth_image_viewer_set_tool (GTH_IMAGE_VIEWER (viewer), self->priv->rotator);
+	gth_image_viewer_set_zoom_enabled (GTH_IMAGE_VIEWER (viewer), FALSE);
+	gth_viewer_page_update_sensitivity (GTH_VIEWER_PAGE (viewer_page));
 
 	self->priv->selector_align_direction = 0;
 	self->priv->selector_align_point = 0;
@@ -634,6 +636,8 @@ gth_file_tool_rotate_destroy_options (GthFileTool *base)
 	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);
+	gth_image_viewer_set_zoom_enabled (GTH_IMAGE_VIEWER (viewer), TRUE);
+	gth_viewer_page_update_sensitivity (GTH_VIEWER_PAGE (viewer_page));
 
 	_g_clear_object (&self->priv->src_pixbuf);
 	_g_clear_object (&self->priv->rotate_pixbuf);
diff --git a/extensions/file_tools/gth-image-rotator.c b/extensions/file_tools/gth-image-rotator.c
index bbf1ee0..950ee20 100644
--- a/extensions/file_tools/gth-image-rotator.c
+++ b/extensions/file_tools/gth-image-rotator.c
@@ -51,9 +51,6 @@ struct _GthImageRotatorPrivate {
 	gboolean            enable_crop;
 	GdkRectangle        crop_region;
 	GthGridType         grid_type;
-
-	/* FIXME: delete these options */
-
 	GthTransformResize  resize;
 
 	/* utility variables */
@@ -143,15 +140,13 @@ gth_transform_resize (cairo_matrix_t     *matrix,
 static void
 _gth_image_rotator_update_tranformation_matrix (GthImageRotator *self)
 {
-	int    tx, ty;
-	double zoom;
+	int tx, ty;
 
 	self->priv->preview_center.x = self->priv->center.x * self->priv->preview_zoom;
 	self->priv->preview_center.y = self->priv->center.y * self->priv->preview_zoom;
 
 	tx = self->priv->preview_image_area.x + self->priv->preview_center.x;
 	ty = self->priv->preview_image_area.y + self->priv->preview_center.y;
-	zoom = gth_image_viewer_get_zoom (self->priv->viewer);
 
 	cairo_matrix_init_identity (&self->priv->matrix);
 	cairo_matrix_translate (&self->priv->matrix, tx, ty);
@@ -189,7 +184,7 @@ update_image_surface (GthImageRotator *self)
 	width = self->priv->original_width;
 	height = self->priv->original_height;
 	gtk_widget_get_allocation (GTK_WIDGET (self->priv->viewer), &allocation);
-	max_size = MIN (allocation.width, allocation.height) / 1.2;
+	max_size = MAX (allocation.width, allocation.height) / G_SQRT2 + 2;
 	if (scale_keeping_ratio (&width, &height, max_size, max_size, FALSE))
 		preview_image = _cairo_image_surface_scale_to (image, width, height, CAIRO_FILTER_BILINEAR);
 	else
@@ -256,23 +251,33 @@ paint_darker_background (GthImageRotator *self,
 			 GdkEventExpose  *event,
 			 cairo_t         *cr)
 {
+	GdkRectangle crop_region;
+
 	cairo_save (cr);
 	cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
 
+	/* the crop_region is not zoomed the clip_area is already zoomed */
+
+	crop_region = self->priv->crop_region;
+	crop_region.x = crop_region.x * self->priv->preview_zoom;
+	crop_region.y = crop_region.y * self->priv->preview_zoom;
+	crop_region.width = crop_region.width * self->priv->preview_zoom;
+	crop_region.height = crop_region.height * self->priv->preview_zoom;
+
 	/* left side */
 
 	cairo_rectangle (cr,
 			 self->priv->clip_area.x,
 			 self->priv->clip_area.y,
-			 self->priv->crop_region.x,
+			 crop_region.x,
 			 self->priv->clip_area.height);
 
 	/* right side */
 
 	cairo_rectangle (cr,
-			 self->priv->clip_area.x + self->priv->crop_region.x + self->priv->crop_region.width,
+			 self->priv->clip_area.x + crop_region.x + crop_region.width,
 			 self->priv->clip_area.y,
-			 self->priv->clip_area.width - self->priv->crop_region.x - self->priv->crop_region.width,
+			 self->priv->clip_area.width - crop_region.x - crop_region.width,
 			 self->priv->clip_area.height);
 
 	/* top */
@@ -281,15 +286,15 @@ paint_darker_background (GthImageRotator *self,
 			 self->priv->clip_area.x,
 			 self->priv->clip_area.y,
 			 self->priv->clip_area.width,
-			 self->priv->crop_region.y);
+			 crop_region.y);
 
 	/* bottom */
 
 	cairo_rectangle (cr,
 			 self->priv->clip_area.x,
-			 self->priv->clip_area.y + self->priv->crop_region.y + self->priv->crop_region.height,
+			 self->priv->clip_area.y + crop_region.y + crop_region.height,
 			 self->priv->clip_area.width,
-			 self->priv->clip_area.height - self->priv->crop_region.y - self->priv->crop_region.height);
+			 self->priv->clip_area.height - crop_region.y - crop_region.height);
 
 	cairo_fill (cr);
 	cairo_restore (cr);
@@ -305,12 +310,14 @@ paint_grid (GthImageRotator *self,
 
 	cairo_save (cr);
 
+	cairo_scale (cr, self->priv->preview_zoom, self->priv->preview_zoom);
+
 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 9, 2)
 	/* cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE); */
 #endif
 	grid = self->priv->crop_region;
-	grid.x += self->priv->clip_area.x;
-	grid.y += self->priv->clip_area.y;
+	grid.x += self->priv->clip_area.x / self->priv->preview_zoom;
+	grid.y += self->priv->clip_area.y / self->priv->preview_zoom;
 	_cairo_paint_grid (cr, &grid, self->priv->grid_type);
 
 	cairo_restore (cr);
diff --git a/gthumb/cairo-utils.c b/gthumb/cairo-utils.c
index c72c4c9..5d3f43d 100644
--- a/gthumb/cairo-utils.c
+++ b/gthumb/cairo-utils.c
@@ -772,10 +772,18 @@ _cairo_paint_grid (cairo_t      *cr,
 		   GdkRectangle *rectangle,
 		   GthGridType   grid_type)
 {
-	cairo_rectangle (cr, rectangle->x, rectangle->y, rectangle->width, rectangle->height);
+	double ux, uy;
+
+	cairo_save (cr);
+
+	ux = uy = 1.0;
+	cairo_device_to_user_distance (cr, &ux, &uy);
+	cairo_set_line_width (cr, MAX (ux, uy));
+
+	cairo_rectangle (cr, rectangle->x - ux, rectangle->y - uy, rectangle->width + (ux * 2), rectangle->height + (uy * 2));
 	cairo_clip (cr);
 
-	cairo_rectangle (cr, rectangle->x + 0.5, rectangle->y + 0.5, rectangle->width - 1, rectangle->height - 1);
+	cairo_rectangle (cr, rectangle->x, rectangle->y, rectangle->width, rectangle->height);
 	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
 	cairo_stroke (cr);
 
@@ -917,4 +925,6 @@ _cairo_paint_grid (cairo_t      *cr,
 		}
 		cairo_stroke (cr);
 	}
+
+	cairo_restore (cr);
 }



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