From 2c51db72113b0308303271b04914157751d4b31f Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Wed, 14 Nov 2012 15:46:22 +0000 Subject: Use fast scaling in cairo to resize selections - SL #4208 Signed-off-by: Gonzalo Odiard --- diff --git a/Area.py b/Area.py index eaff84b..e4e0428 100644 --- a/Area.py +++ b/Area.py @@ -217,6 +217,7 @@ class Area(Gtk.DrawingArea): self._on_touch = False self._update_timer = None + self._resize_hq_timer = None def _set_screen_dpi(self): dpi = _get_screen_dpi() @@ -408,7 +409,7 @@ class Area(Gtk.DrawingArea): y = int(event.get_coords()[2]) seq = str(event.touch.sequence) - logging.error('event x %d y %d type %s', x, y, event.type) + #logging.error('event x %d y %d type %s', x, y, event.type) if event.type in (Gdk.EventType.TOUCH_BEGIN, Gdk.EventType.BUTTON_PRESS): #Gdk.EventType.MOTION_NOTIFY): @@ -1478,7 +1479,8 @@ class Area(Gtk.DrawingArea): ctx.fill() ctx.restore() - def resize_selection_surface(self, horizontal_scale, vertical_scale): + def resize_selection_surface(self, horizontal_scale, vertical_scale, + fast=True): x, y = self._selection_bounds[0], self._selection_bounds[1] new_width = int(self .selection_surface.get_width() * horizontal_scale) new_height = int(self.selection_surface.get_height() * vertical_scale) @@ -1496,12 +1498,28 @@ class Area(Gtk.DrawingArea): self.temp_ctx.translate(x, y) self.temp_ctx.set_source_surface(self.selection_resized_surface) self.temp_ctx.rectangle(0, 0, new_width, new_height) + if fast: + self.temp_ctx.get_source().set_filter(cairo.FILTER_NEAREST) + # Add a timer for resize with high quality: + if self._resize_hq_timer is not None: + GObject.source_remove(self._resize_hq_timer) + self._resize_hq_timer = GObject.timeout_add(200, + self.resize_selection_surface, horizontal_scale, + vertical_scale, False) + else: + self._resize_hq_timer = None + self.temp_ctx.paint() self.temp_ctx.restore() self._selection_horizontal_scale = horizontal_scale self._selection_vertical_scale = vertical_scale + self.desenha = True + self.queue_draw() + + return False + def get_selection(self): if self.selection_resized_surface is not None: return self.selection_resized_surface diff --git a/Desenho.py b/Desenho.py index e05a907..01d5002 100644 --- a/Desenho.py +++ b/Desenho.py @@ -685,8 +685,6 @@ class Desenho: @param pixbuf_copy -- For import image """ - widget.desenha = True - dx = int(coords[0] - widget.oldx) dy = int(coords[1] - widget.oldy) @@ -704,18 +702,7 @@ class Desenho: if width_scale < 0 or height_scale < 0: return - # Add a timer for resize or update it if there is one already: - if self._resize_timer is not None: - GObject.source_remove(self._resize_timer) - self._resize_timer = GObject.timeout_add(RESIZE_DELAY, - self._do_resize, widget, width_scale, height_scale) - - def _do_resize(self, widget, width_scale, height_scale): -# """Do the resize calculation. -# """ - widget.desenha = True widget.resize_selection_surface(width_scale, height_scale) - widget.queue_draw() def freeform(self, widget, coords, temp, fill, param=None): """Draw polygon. -- cgit v0.9.1