From 55b88412c921d01817ce0f5dda46b5a7eb72d764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Thu, 25 Jan 2018 15:02:09 +0100 Subject: [PATCH] MiRCARTCanvas.py:resize(): clean up & fix. MiRCARTCanvasInterface.py:_updateCanvasSize(): merged into ...Canvas.resize(). MiRCARTCanvasInterface.py:canvas{De,In}crCanvas{Height,Width}(): directly call ...Canvas.resize(). --- MiRCARTCanvas.py | 50 +++++++++++++++++++++++++------------ MiRCARTCanvasInterface.py | 52 +++++---------------------------------- 2 files changed, 40 insertions(+), 62 deletions(-) diff --git a/MiRCARTCanvas.py b/MiRCARTCanvas.py index 0d5912c..c62e853 100644 --- a/MiRCARTCanvas.py +++ b/MiRCARTCanvas.py @@ -137,30 +137,48 @@ class MiRCARTCanvas(wx.Panel): def resize(self, newCanvasSize): if newCanvasSize != self.canvasSize: if self.canvasMap == None: - self.canvasMap = [[[(1, 1), 0, " "] \ - for x in range(self.canvasSize[0])] \ - for y in range(self.canvasSize[1])] + self.canvasMap = []; oldCanvasSize = [0, 0]; else: - for numRow in range(self.canvasSize[1]): - for numNewCol in range(self.canvasSize[0], newCanvasSize[0]): - self.canvasMap[numRow].append([[1, 1], 0, " "]) - for numNewRow in range(self.canvasSize[1], newCanvasSize[1]): - self.canvasMap.append([]) - for numNewCol in range(newCanvasSize[0]): - self.canvasMap[numNewRow].append([[1, 1], 0, " "]) - self.canvasSize = newCanvasSize - newWinSize = [a*b for a,b in \ - zip(self.canvasSize, self.canvasBackend.cellSize)] + oldCanvasSize = self.canvasSize + deltaCanvasSize = [b-a for a,b in zip(oldCanvasSize, newCanvasSize)] + + newWinSize = [a*b for a,b in zip(newCanvasSize, self.canvasBackend.cellSize)] self.SetMinSize(newWinSize) self.SetSize(wx.DefaultCoord, wx.DefaultCoord, *newWinSize) curWindow = self while curWindow != None: curWindow.Layout() curWindow = curWindow.GetParent() - self.canvasBackend.reset(self.canvasSize, self.canvasBackend.cellSize) + + self.canvasBackend.resize(newCanvasSize, self.canvasBackend.cellSize) + eventDc = self.canvasBackend.getDeviceContext(self) self.canvasJournal.resetCursor(); self.canvasJournal.resetUndo(); - self.parentFrame.onCanvasUpdate( \ - size=self.canvasSize, undoLevel=-1) + + if deltaCanvasSize[0] < 0: + for numRow in range(oldCanvasSize[1]): + del self.canvasMap[numRow][-1:(deltaCanvasSize[0]-1):-1] + else: + for numRow in range(oldCanvasSize[1]): + self.canvasMap[numRow].extend( \ + [[[1, 1], 0, " "]] * deltaCanvasSize[0]) + for numNewCol in range(oldCanvasSize[0], newCanvasSize[0]): + self.canvasBackend.drawPatch( \ + eventDc, [[numNewCol, numRow], \ + *self.canvasMap[numRow][-1]]) + if deltaCanvasSize[1] < 0: + del self.canvasMap[-1:(deltaCanvasSize[1]-1):-1] + else: + for numNewRow in range(oldCanvasSize[1], newCanvasSize[1]): + self.canvasMap.extend( \ + [[[[1, 1], 0, " "]] * newCanvasSize[0]]) + for numNewCol in range(newCanvasSize[0]): + self.canvasBackend.drawPatch( \ + eventDc, [[numNewCol, numNewRow], \ + *self.canvasMap[-1][-1]]) + + self.canvasSize = newCanvasSize + wx.SafeYield() + self.parentFrame.onCanvasUpdate(size=newCanvasSize, undoLevel=-1) # }}} # diff --git a/MiRCARTCanvasInterface.py b/MiRCARTCanvasInterface.py index c95a524..11313aa 100644 --- a/MiRCARTCanvasInterface.py +++ b/MiRCARTCanvasInterface.py @@ -45,46 +45,6 @@ class MiRCARTCanvasInterface(): dialogChoice = dialog.ShowModal() return dialogChoice # }}} - # {{{ _updateCanvasSize(self, newCanvasSize): XXX - def _updateCanvasSize(self, newCanvasSize): - eventDc = self.parentCanvas.canvasBackend.getDeviceContext(self.parentCanvas) - self.parentCanvas.canvasBackend.drawCursorMaskWithJournal( \ - self.parentCanvas.canvasJournal, eventDc) - oldCanvasSize = self.parentCanvas.canvasSize - self.parentCanvas.resize(newCanvasSize) - self.parentCanvas.canvasBackend.resize( \ - newCanvasSize, \ - self.parentCanvas.canvasBackend.cellSize) - if (newCanvasSize[1] - oldCanvasSize[1]) < 0: - for numRowOff in range(1, (oldCanvasSize[1] - newCanvasSize[1]) + 1): - numRow = oldCanvasSize[1] - numRowOff - del self.parentCanvas.canvasMap[numRow] - else: - for numRowOff in range(oldCanvasSize[1] - newCanvasSize[1]): - numRow = oldCanvasSize[1] + numRowOff - self.parentCanvas.canvasMap.append(None) - self.parentCanvas.canvasMap[numRow] = \ - [[[1, 1], 0, " "]] * oldCanvasSize[0] - self.parentCanvas.canvasBackend.drawPatch( \ - eventDc, \ - [[numCol, numRow], *[[1, 1], 0, " "]]) - if (newCanvasSize[0] - oldCanvasSize[0]) < 0: - for numRow in range(newCanvasSize[1]): - for numColOff in range(1, (oldCanvasSize[0] - newCanvasSize[0]) + 1): - numCol = oldCanvasSize[0] - numColOff - del self.parentCanvas.canvasMap[numRow][numCol] - else: - for numRow in range(newCanvasSize[1]): - for numColOff in range(newCanvasSize[0] - oldCanvasSize[0]): - numCol = oldCanvasSize[0] + numColOff - self.parentCanvas.canvasMap[numRow].append(None) - self.parentCanvas.canvasMap[numRow][numCol] = \ - [[1, 1], 0, " "] - self.parentCanvas.canvasBackend.drawPatch( \ - eventDc, \ - [[numCol, numRow], *[[1, 1], 0, " "]]) - wx.SafeYield() - # }}} # {{{ canvasBrushSolid(self, event): XXX def canvasBrushSolid(self, event): @@ -126,8 +86,8 @@ class MiRCARTCanvasInterface(): # {{{ canvasDecrCanvasHeight(self, event): XXX def canvasDecrCanvasHeight(self, event): if self.parentCanvas.canvasSize[1] > 1: - self._updateCanvasSize([ \ - self.parentCanvas.canvasSize[0], \ + self.parentCanvas.resize([ \ + self.parentCanvas.canvasSize[0], \ self.parentCanvas.canvasSize[1]-1]) # }}} # {{{ canvasDecrCanvasHeightWidth(self, event): XXX @@ -138,8 +98,8 @@ class MiRCARTCanvasInterface(): # {{{ canvasDecrCanvasWidth(self, event): XXX def canvasDecrCanvasWidth(self, event): if self.parentCanvas.canvasSize[0] > 1: - self._updateCanvasSize([ \ - self.parentCanvas.canvasSize[0]-1, \ + self.parentCanvas.resize([ \ + self.parentCanvas.canvasSize[0]-1, \ self.parentCanvas.canvasSize[1]]) # }}} # {{{ canvasDelete(self, event): XXX @@ -228,7 +188,7 @@ class MiRCARTCanvasInterface(): # }}} # {{{ canvasIncrCanvasHeight(self, event): XXX def canvasIncrCanvasHeight(self, event): - self._updateCanvasSize([ \ + self.parentCanvas.resize([ \ self.parentCanvas.canvasSize[0], \ self.parentCanvas.canvasSize[1]+1]) # }}} @@ -239,7 +199,7 @@ class MiRCARTCanvasInterface(): # }}} # {{{ canvasIncrCanvasWidth(self, event): XXX def canvasIncrCanvasWidth(self, event): - self._updateCanvasSize([ \ + self.parentCanvas.resize([ \ self.parentCanvas.canvasSize[0]+1, \ self.parentCanvas.canvasSize[1]]) # }}}