From 10bccb434a41a50299d595a97253af05502c703f Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Tue, 16 Oct 2012 14:45:15 +0000 Subject: Scale the image through its center Signed-off-by: Manuel Kaufmann Signed-off-by: Agustin Zubiaga --- diff --git a/ImageView.py b/ImageView.py index 7ec9a41..30b19ac 100644 --- a/ImageView.py +++ b/ImageView.py @@ -70,6 +70,7 @@ class ImageViewer(Gtk.DrawingArea): self._angle_ori = 0.0 self._fast = True self._redraw_id = None + self._is_touching = False def do_get_property(self, pspec): if pspec.name == 'zoom': @@ -131,21 +132,29 @@ class ImageViewer(Gtk.DrawingArea): ctx.rotate(self.angle) ctx.translate(-0.5 * w, -0.5 * h) + scrolled_window = self.get_parent() + rect = scrolled_window.get_allocation() + x = y = 0 + if rect.width >= w: + x = int((rect.width - w) / 2) + elif self._is_touching: + hadj = int((w - rect.width) / 2) + hadjustment = scrolled_window.get_hadjustment() + hadjustment.set_value(hadj) + + if rect.height >= h: + y = int((rect.height - h) / 2) + elif self._is_touching: + vadj = int((h - rect.height) / 2) + vadjustment = scrolled_window.get_vadjustment() + vadjustment.set_value(vadj) + if self.zoom != 1: logging.error('Scaling: %s', self.zoom) + ctx.translate(x, y) ctx.scale(self.zoom, self.zoom) - rect = self.get_allocation() - x = rect.x - y = rect.y - - rect = self.get_allocation() - if rect.width > w: - x = int((rect.width - w) / 2) - if rect.height > h: - y = int((rect.height - h) / 2) - - ctx.set_source_surface(self.surface, x, y) + ctx.set_source_surface(self.surface, 0, 0) if self._fast: ctx.get_source().set_filter(cairo.FILTER_NEAREST) ctx.paint() @@ -157,6 +166,8 @@ class ImageViewer(Gtk.DrawingArea): self._redraw_id = GObject.timeout_add(200, self._redraw_high_quality) + self._is_touching = False + def _redraw_high_quality(self): self._fast = False self._redraw_id = None diff --git a/ImageViewerActivity.py b/ImageViewerActivity.py index 2cfe88b..f17d4cf 100644 --- a/ImageViewerActivity.py +++ b/ImageViewerActivity.py @@ -213,6 +213,7 @@ class ImageViewerActivity(activity.Activity): self._last_scale = scale logging.error('Scale changed %f', scale) + self.view._is_touching = True self.view.set_zoom_relative(scale) def handle_view_source(self): -- cgit v0.9.1