libgui/GuiCanvasPanel.py:_updateScrollBars(): split from resize().

libgui/GuiCanvasPanel.py:_updateScrollBars(): reduce flickering induced by calling SetVirtualSize() when scrollbars are not required.
libgui/GuiCanvasPanel.py:{resize,update}(): updated.
libgui/GuiCanvasWxBackend.py:{reset,__init__}(): removes obsolete reset().
This commit is contained in:
Lucio Andrés Illanes Albornoz 2019-09-09 17:27:37 +02:00
parent 04430e7c0c
commit c2657eeefd
2 changed files with 17 additions and 15 deletions

View File

@ -16,6 +16,17 @@ class GuiCanvasPanel(wx.ScrolledWindow):
patchDeltaCell = self.canvas.map[patch[1]][patch[0]]; patchDelta = [*patch[0:2], *patchDeltaCell]; patchDeltaCell = self.canvas.map[patch[1]][patch[0]]; patchDelta = [*patch[0:2], *patchDeltaCell];
self.canvas.journal.pushCursor(patchDelta) self.canvas.journal.pushCursor(patchDelta)
# }}} # }}}
# {{{ _updateScrollBars(self)
def _updateScrollBars(self):
clientSize = self.GetClientSize()
if (self.winSize[0] > clientSize[0]) \
or (self.winSize[1] > clientSize[1]):
self.scrollFlag = True; super().SetVirtualSize(self.winSize);
elif self.scrollFlag \
and ((self.winSize[0] <= clientSize[0]) \
or (self.winSize[1] <= clientSize[1])):
self.scrollFlag = False; super().SetVirtualSize((0, 0));
# }}}
# {{{ dispatchDeltaPatches(self, deltaPatches) # {{{ dispatchDeltaPatches(self, deltaPatches)
def dispatchDeltaPatches(self, deltaPatches): def dispatchDeltaPatches(self, deltaPatches):
@ -38,16 +49,13 @@ class GuiCanvasPanel(wx.ScrolledWindow):
oldSize = [0, 0] if self.canvas.map == None else self.canvas.size oldSize = [0, 0] if self.canvas.map == None else self.canvas.size
deltaSize = [b - a for a, b in zip(oldSize, newSize)] deltaSize = [b - a for a, b in zip(oldSize, newSize)]
if self.canvas.resize(newSize, commitUndo): if self.canvas.resize(newSize, commitUndo):
self.winSize = [a * b for a, b in zip(newSize, self.backend.cellSize)] self.winSize = [a * b for a, b in zip(newSize, self.backend.cellSize)]; self._updateScrollBars();
self.SetMinSize(self.winSize) self.SetMinSize(self.winSize); self.SetSize(wx.DefaultCoord, wx.DefaultCoord, *self.winSize);
self.SetSize(wx.DefaultCoord, wx.DefaultCoord, *self.winSize)
self.SetVirtualSize(self.winSize)
curWindow = self curWindow = self
while curWindow != None: while curWindow != None:
curWindow.Layout(); curWindow = curWindow.GetParent(); curWindow.Layout(); curWindow = curWindow.GetParent();
self.backend.resize(newSize, self.backend.cellSize) self.backend.resize(newSize, self.backend.cellSize)
eventDc = self.backend.getDeviceContext(self, self.GetViewStart()) viewRect = self.GetViewStart(); eventDc = self.backend.getDeviceContext(self, viewRect);
viewRect = self.GetViewStart()
if deltaSize[0] > 0: if deltaSize[0] > 0:
for numRow in range(oldSize[1]): for numRow in range(oldSize[1]):
for numNewCol in range(oldSize[0], newSize[0]): for numNewCol in range(oldSize[0], newSize[0]):
@ -56,7 +64,6 @@ class GuiCanvasPanel(wx.ScrolledWindow):
for numNewRow in range(oldSize[1], newSize[1]): for numNewRow in range(oldSize[1], newSize[1]):
for numNewCol in range(newSize[0]): for numNewCol in range(newSize[0]):
self._drawPatch(eventDc, False, [numNewCol, numNewRow, 1, 1, 0, " "], viewRect) self._drawPatch(eventDc, False, [numNewCol, numNewRow, 1, 1, 0, " "], viewRect)
del eventDc; wx.SafeYield();
self.interface.update(size=newSize, undoLevel=self.canvas.journal.patchesUndoLevel) self.interface.update(size=newSize, undoLevel=self.canvas.journal.patchesUndoLevel)
# }}} # }}}
# {{{ update(self, newSize, commitUndo=True, newCanvas=None) # {{{ update(self, newSize, commitUndo=True, newCanvas=None)
@ -67,7 +74,6 @@ class GuiCanvasPanel(wx.ScrolledWindow):
for numRow in range(newSize[1]): for numRow in range(newSize[1]):
for numCol in range(newSize[0]): for numCol in range(newSize[0]):
self.backend.drawPatch(eventDc, [numCol, numRow, *self.canvas.map[numRow][numCol]], self.GetViewStart()) self.backend.drawPatch(eventDc, [numCol, numRow, *self.canvas.map[numRow][numCol]], self.GetViewStart())
wx.SafeYield()
# }}} # }}}
# {{{ onPanelClose(self, event) # {{{ onPanelClose(self, event)
@ -113,7 +119,8 @@ class GuiCanvasPanel(wx.ScrolledWindow):
self.backend, self.interface = backend(defaultCanvasSize, defaultCellSize), interface(self, parentFrame) self.backend, self.interface = backend(defaultCanvasSize, defaultCellSize), interface(self, parentFrame)
self.brushColours, self.brushPos, self.brushSize = [4, 1], [0, 0], [1, 1] self.brushColours, self.brushPos, self.brushSize = [4, 1], [0, 0], [1, 1]
self.canvas, self.canvasPos, self.defaultCanvasPos, self.defaultCanvasSize, self.defaultCellSize = canvas, defaultCanvasPos, defaultCanvasPos, defaultCanvasSize, defaultCellSize self.canvas, self.canvasPos, self.defaultCanvasPos, self.defaultCanvasSize, self.defaultCellSize = canvas, defaultCanvasPos, defaultCanvasPos, defaultCanvasSize, defaultCellSize
self.dirty, self.parentFrame = False, parentFrame self.dirty, self.parentFrame, self.scrollFlag = False, parentFrame, False
self.SetScrollRate(*defaultCellSize); self._updateScrollBars();
self.Bind(wx.EVT_CLOSE, self.onPanelClose) self.Bind(wx.EVT_CLOSE, self.onPanelClose)
self.Bind(wx.EVT_LEAVE_WINDOW, self.onPanelLeaveWindow) self.Bind(wx.EVT_LEAVE_WINDOW, self.onPanelLeaveWindow)
@ -121,6 +128,5 @@ class GuiCanvasPanel(wx.ScrolledWindow):
for eventType in (wx.EVT_LEFT_DOWN, wx.EVT_MOTION, wx.EVT_RIGHT_DOWN): for eventType in (wx.EVT_LEFT_DOWN, wx.EVT_MOTION, wx.EVT_RIGHT_DOWN):
self.Bind(eventType, self.onPanelInput) self.Bind(eventType, self.onPanelInput)
self.Bind(wx.EVT_PAINT, self.onPanelPaint) self.Bind(wx.EVT_PAINT, self.onPanelPaint)
self.SetScrollRate(*defaultCellSize); self.SetVirtualSize(self.winSize);
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -120,10 +120,6 @@ class GuiCanvasWxBackend():
canvasDc.SelectObject(wx.NullBitmap); viewDc.SelectObject(wx.NullBitmap); canvasDc.SelectObject(wx.NullBitmap); viewDc.SelectObject(wx.NullBitmap);
eventDc = wx.BufferedPaintDC(panelWindow, viewBitmap) eventDc = wx.BufferedPaintDC(panelWindow, viewBitmap)
# }}} # }}}
# {{{ reset(self, canvasSize, cellSize):
def reset(self, canvasSize, cellSize):
self.resize(canvasSize, cellSize)
# }}}
# {{{ resize(self, canvasSize, cellSize): # {{{ resize(self, canvasSize, cellSize):
def resize(self, canvasSize, cellSize): def resize(self, canvasSize, cellSize):
winSize = [a * b for a, b in zip(canvasSize, cellSize)] winSize = [a * b for a, b in zip(canvasSize, cellSize)]
@ -158,6 +154,6 @@ class GuiCanvasWxBackend():
def __init__(self, canvasSize, cellSize): def __init__(self, canvasSize, cellSize):
self._brushes, self._font, self._lastBrush, self._lastPen, self._pens = None, None, None, None, None self._brushes, self._font, self._lastBrush, self._lastPen, self._pens = None, None, None, None, None
self.canvasBitmap, self.cellSize = None, None self.canvasBitmap, self.cellSize = None, None
self._initBrushesAndPens(); self.reset(canvasSize, cellSize); self._initBrushesAndPens(); self.resize(canvasSize, cellSize);
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120