From 715385e4eeba320f04ce5dc01a81482957036cec Mon Sep 17 00:00:00 2001 From: Manuel QuiƱones Date: Wed, 15 May 2013 21:45:18 +0000 Subject: Center image when it is reduced in other ways --- diff --git a/ImageView.py b/ImageView.py index 6f34c83..e17862e 100644 --- a/ImageView.py +++ b/ImageView.py @@ -86,6 +86,18 @@ class ImageViewer(Gtk.DrawingArea): self._anchor_point = (self._surface.get_width() / 2, self._surface.get_height() / 2) + def _center_if_small(self): + # If at the current size the image surface is smaller than the + # available space, center it on the canvas. + + alloc = self.get_allocation() + + scaled_width = self._surface.get_width() * self._zoom + scaled_height = self._surface.get_height() * self._zoom + + if alloc.width >= scaled_width and alloc.height >= scaled_height: + self._center_target_point() + self._center_anchor_point() def set_zoom(self, zoom): if zoom < ZOOM_MIN or zoom > ZOOM_MAX: @@ -112,6 +124,8 @@ class ImageViewer(Gtk.DrawingArea): if not self.can_zoom_out(): return self._zoom -= ZOOM_MIN + + self._center_if_small() self.queue_draw() def zoom_to_fit(self): @@ -137,6 +151,7 @@ class ImageViewer(Gtk.DrawingArea): def zoom_original(self): self._zoom = 1 + self._center_if_small() self.queue_draw() def start_zoomtouch(self, center): @@ -186,18 +201,7 @@ class ImageViewer(Gtk.DrawingArea): elif self._zoom > ZOOM_MAX: self._zoom = ZOOM_MAX - # If at the current size the image surface is smaller than the - # available space, center it on the canvas. - - alloc = self.get_allocation() - - scaled_width = self._surface.get_width() * self._zoom - scaled_height = self._surface.get_height() * self._zoom - - if alloc.width >= scaled_width and alloc.height >= scaled_height: - self._center_target_point() - self._center_anchor_point() - + self._center_if_small() self.queue_draw() def rotate_anticlockwise(self): -- cgit v0.9.1