Ticket #4034: 0001-Scale-the-image-through-its-center.patch

File 0001-Scale-the-image-through-its-center.patch, 2.9 KB (added by humitos, 12 years ago)

This patch just zooms the image always from its centre

  • ImageView.py

    From 701fc2cc84aa8fe5682e2d77473147bbf571027d Mon Sep 17 00:00:00 2001
    From: Manuel Kaufmann <humitos@gmail.com>
    Date: Tue, 16 Oct 2012 14:45:15 +0000
    Subject: [PATCH ImageViewer] Scale the image through its center
    
    
    Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
    ---
     ImageView.py           | 33 ++++++++++++++++++++++-----------
     ImageViewerActivity.py |  1 +
     2 files changed, 23 insertions(+), 11 deletions(-)
    
    diff --git a/ImageView.py b/ImageView.py
    index 7ec9a41..30b19ac 100644
    a b class ImageViewer(Gtk.DrawingArea): 
    7070        self._angle_ori = 0.0
    7171        self._fast = True
    7272        self._redraw_id = None
     73        self._is_touching = False
    7374
    7475    def do_get_property(self, pspec):
    7576        if pspec.name == 'zoom':
    class ImageViewer(Gtk.DrawingArea): 
    131132            ctx.rotate(self.angle)
    132133            ctx.translate(-0.5 * w, -0.5 * h)
    133134
     135        scrolled_window = self.get_parent()
     136        rect = scrolled_window.get_allocation()
     137        x = y = 0
     138        if rect.width >= w:
     139            x = int((rect.width - w) / 2)
     140        elif self._is_touching:
     141            hadj = int((w - rect.width) / 2)
     142            hadjustment = scrolled_window.get_hadjustment()
     143            hadjustment.set_value(hadj)
     144
     145        if rect.height >= h:
     146            y = int((rect.height - h) / 2)
     147        elif self._is_touching:
     148            vadj = int((h - rect.height) / 2)
     149            vadjustment = scrolled_window.get_vadjustment()
     150            vadjustment.set_value(vadj)
     151
    134152        if self.zoom != 1:
    135153            logging.error('Scaling: %s', self.zoom)
     154            ctx.translate(x, y)
    136155            ctx.scale(self.zoom, self.zoom)
    137156
    138         rect = self.get_allocation()
    139         x = rect.x
    140         y = rect.y
    141 
    142         rect = self.get_allocation()
    143         if rect.width > w:
    144             x = int((rect.width - w) / 2)
    145         if rect.height > h:
    146             y = int((rect.height - h) / 2)
    147 
    148         ctx.set_source_surface(self.surface, x, y)
     157        ctx.set_source_surface(self.surface, 0, 0)
    149158        if self._fast:
    150159            ctx.get_source().set_filter(cairo.FILTER_NEAREST)
    151160        ctx.paint()
    class ImageViewer(Gtk.DrawingArea): 
    157166            self._redraw_id = GObject.timeout_add(200,
    158167                    self._redraw_high_quality)
    159168
     169        self._is_touching = False
     170
    160171    def _redraw_high_quality(self):
    161172        self._fast = False
    162173        self._redraw_id = None
  • ImageViewerActivity.py

    diff --git a/ImageViewerActivity.py b/ImageViewerActivity.py
    index 2cfe88b..f17d4cf 100644
    a b class ImageViewerActivity(activity.Activity): 
    213213            self._last_scale = scale
    214214            logging.error('Scale changed %f', scale)
    215215
     216            self.view._is_touching = True
    216217            self.view.set_zoom_relative(scale)
    217218
    218219    def handle_view_source(self):