Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2012-10-16 14:45:15 (GMT)
committer Agustin Zubiaga <aguz@sugarlabs.org>2012-10-16 21:39:32 (GMT)
commit10bccb434a41a50299d595a97253af05502c703f (patch)
tree3c0730f161245b748df55e1bb1503ba5226aa812
parent8053af848858cb0727401e7abbc12db0991a2b36 (diff)
Scale the image through its center
Signed-off-by: Manuel Kaufmann <humitos@gmail.com> Signed-off-by: Agustin Zubiaga <aguz@sugarlabs.org>
-rw-r--r--ImageView.py33
-rw-r--r--ImageViewerActivity.py1
2 files changed, 23 insertions, 11 deletions
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):