[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [nyx/master] Lighter routine redraws



commit d9a84b0ab7f9065e899282b4d0f2ff2a0b7c818b
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Jul 17 11:35:43 2016 -0700

    Lighter routine redraws
    
    Our old draw() method had a 'force' flag that, if false, would cause us to only
    be redrawn if our dimensions had changed. We did a 'soft redraw' on every
    keypress so dropping this flag was very noticeable, causing flickering and the
    interface to be laggy on things like the config panel.
    
    Inverting this flag so we force by default. This is because just about every
    time we called redraw we wanted to 'force' it. Soft redraws are the exception,
    not the rule.
---
 nyx/controller.py     |  2 +-
 nyx/curses.py         | 13 ++++++++++++-
 nyx/panel/__init__.py | 16 ++++++++++++++--
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/nyx/controller.py b/nyx/controller.py
index c5b90d6..d2f202f 100644
--- a/nyx/controller.py
+++ b/nyx/controller.py
@@ -292,7 +292,7 @@ class Controller(object):
         stdscr.clear()
 
     for panel_impl in display_panels:
-      panel_impl.redraw()
+      panel_impl.redraw(force = force)
 
     if force:
       self._last_drawn = current_time
diff --git a/nyx/curses.py b/nyx/curses.py
index 6e605a7..53a2c43 100644
--- a/nyx/curses.py
+++ b/nyx/curses.py
@@ -499,7 +499,7 @@ def is_wide_characters_supported():
   return False
 
 
-def draw(func, left = 0, top = 0, width = None, height = None, background = None):
+def draw(func, left = 0, top = 0, width = None, height = None, background = None, draw_if_resized = None):
   """
   Renders a subwindow. This calls the given draw function with a
   :class:`~nyx.curses._Subwindow`.
@@ -510,6 +510,10 @@ def draw(func, left = 0, top = 0, width = None, height = None, background = None
   :param int width: panel width, uses all available space if **None**
   :param int height: panel height, uses all available space if **None**
   :param nyx.curses.Color background: background color, unset if **None**
+  :param nyx.curses.Dimension draw_if_resized: only draw content if
+    dimentions have changed from this
+
+  :returns: :class:`~nyx.curses.Dimension` for the space we drew within
   """
 
   with CURSES_LOCK:
@@ -526,6 +530,11 @@ def draw(func, left = 0, top = 0, width = None, height = None, background = None
     if height:
       subwindow_height = min(height, subwindow_height)
 
+    subwindow_dimensions = Dimensions(subwindow_width, subwindow_height)
+
+    if subwindow_dimensions == draw_if_resized:
+      return subwindow_dimensions  # draw size hasn't changed
+
     curses_subwindow = CURSES_SCREEN.subwin(subwindow_height, subwindow_width, top, left)
     curses_subwindow.erase()
 
@@ -535,6 +544,8 @@ def draw(func, left = 0, top = 0, width = None, height = None, background = None
     func(_Subwindow(subwindow_width, subwindow_height, curses_subwindow))
     curses_subwindow.refresh()
 
+    return subwindow_dimensions
+
 
 class _Subwindow(object):
   """
diff --git a/nyx/panel/__init__.py b/nyx/panel/__init__.py
index 85d1b78..ec13aaf 100644
--- a/nyx/panel/__init__.py
+++ b/nyx/panel/__init__.py
@@ -90,6 +90,9 @@ class Panel(object):
     self._top = 0
     self._visible = False
 
+    self._last_draw_top = 0
+    self._last_draw_size = nyx.curses.Dimensions(0, 0)
+
   def get_top(self):
     """
     Provides our top position in the overall screen.
@@ -135,15 +138,24 @@ class Panel(object):
 
     return ()
 
-  def redraw(self):
+  def redraw(self, force = True):
     """
     Renders our panel's content to the screen.
+
+    :param bool force: if **False** only redraws content if the panel's
+      dimensions have changed
     """
 
     if not self._visible:
       return  # not currently visible
 
-    nyx.curses.draw(self._draw, top = self._top, height = self.get_height())
+    if not force and self._last_draw_top == self._top:
+      draw_dimension = self._last_draw_size
+    else:
+      draw_dimension = None  # force redraw
+
+    self._last_draw_top = self._top
+    self._last_draw_size = nyx.curses.draw(self._draw, top = self._top, height = self.get_height(), draw_if_resized = draw_dimension)
 
   def _draw(self, subwindow):
     pass

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits