From 330d4c78fee4ed96774185ecd212b483f193f81e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Mon, 8 Jan 2018 02:45:03 +0100 Subject: [PATCH] MiRCARTCanvas{,Journal}.py: fix {un,re}do regarding brush sizes >(1,1). --- MiRCARTCanvas.py | 10 +++++++--- MiRCARTCanvasJournal.py | 39 ++++++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/MiRCARTCanvas.py b/MiRCARTCanvas.py index 0503889..966136b 100644 --- a/MiRCARTCanvas.py +++ b/MiRCARTCanvas.py @@ -102,7 +102,6 @@ class MiRCARTCanvas(wx.Panel): patchOld[1:] = self._getMapCell(patchOld[0]) self._setMapCell(absMapPoint, *patch[1:]) self._drawPatch(patch, eventDc, tmpDc, atPoint) - self.parentFrame.onCanvasUpdate() if isInherit: return patchOld # }}} @@ -118,6 +117,7 @@ class MiRCARTCanvas(wx.Panel): event, mapPoint, self.brushColours, self.brushSize, \ event.Dragging(), event.LeftIsDown(), event.RightIsDown()) self.canvasJournal.merge(mapPatches, eventDc, tmpDc, mapPoint) + self.parentFrame.onCanvasUpdate() self.parentFrame.onCanvasMotion(event, mapPoint) # }}} # {{{ onMouseWindowEvent(self, event): XXX @@ -168,7 +168,9 @@ class MiRCARTCanvas(wx.Panel): # }}} # {{{ redo(self): XXX def redo(self): - return self.canvasJournal.redo() + result = self.canvasJournal.redo() + self.parentFrame.onCanvasUpdate() + return result # }}} # {{{ resize(self, newCanvasSize): XXX def resize(self, newCanvasSize): @@ -191,7 +193,9 @@ class MiRCARTCanvas(wx.Panel): # }}} # {{{ undo(self): XXX def undo(self): - return self.canvasJournal.undo() + result = self.canvasJournal.undo() + self.parentFrame.onCanvasUpdate() + return result # }}} # {{{ __del__(self): destructor method diff --git a/MiRCARTCanvasJournal.py b/MiRCARTCanvasJournal.py index de9511d..5bdfbbd 100644 --- a/MiRCARTCanvasJournal.py +++ b/MiRCARTCanvasJournal.py @@ -35,18 +35,23 @@ class MiRCARTCanvasJournal(): patch[0], patch, eventDc, tmpDc, (0, 0), True) self.patchesTmp = [] # }}} - # {{{ _pushTmp(self, atPoint, patch): XXX - def _pushTmp(self, absMapPoint): - self.patchesTmp.append([absMapPoint, None, None, None]) + # {{{ _pushTmp(self, atPoint): XXX + def _pushTmp(self, atPoint): + self.patchesTmp.append([atPoint, None, None, None]) # }}} - # {{{ _pushUndo(self, atPoint, patchUndo, patchRedo): XXX - def _pushUndo(self, atPoint, patchUndo, patchRedo): + # {{{ _pushUndo(self, atPoint, patches): XXX + def _pushUndo(self, atPoint, patches): if self.patchesUndoLevel > 0: del self.patchesUndo[0:self.patchesUndoLevel] self.patchesUndoLevel = 0 - absMapPoint = self._relMapPointToAbsMapPoint(patchUndo[0], atPoint) - self.patchesUndo.insert(0, [ \ - [absMapPoint, *patchUndo[1:]], [absMapPoint, *patchRedo[1:]]]) + patchesUndo = [] + for patch in patches: + absMapPoint = self._relMapPointToAbsMapPoint(patch[0][0], atPoint) + patchesUndo.append([ \ + [absMapPoint, *patch[0][1:]], \ + [absMapPoint, *patch[1][1:]]]) + if len(patchesUndo) > 0: + self.patchesUndo.insert(0, patchesUndo) # }}} # {{{ _relMapPointToAbsMapPoint(self, relMapPoint, atPoint): XXX def _relMapPointToAbsMapPoint(self, relMapPoint, atPoint): @@ -54,6 +59,7 @@ class MiRCARTCanvasJournal(): # }}} # {{{ merge(self, mapPatches, eventDc, tmpDc, atPoint): XXX def merge(self, mapPatches, eventDc, tmpDc, atPoint): + patchesUndo = [] for mapPatch in mapPatches: mapPatchTmp = mapPatch[0] if mapPatchTmp: @@ -71,15 +77,17 @@ class MiRCARTCanvasJournal(): patchUndo = \ self.parentCanvas.onJournalUpdate(mapPatchTmp, \ absMapPoint, patch, eventDc, tmpDc, atPoint, True) - self._pushUndo(atPoint, patchUndo, patch) + patchesUndo.append([patchUndo, patch]) + if len(patchesUndo) > 0: + self._pushUndo(atPoint, patchesUndo) # }}} # {{{ redo(self): XXX def redo(self): if self.patchesUndoLevel > 0: self.patchesUndoLevel -= 1 - redoPatch = self.patchesUndo[self.patchesUndoLevel][1] - self.parentCanvas.onJournalUpdate(False, \ - redoPatch[0], redoPatch, None, None, (0, 0)) + for patch in self.patchesUndo[self.patchesUndoLevel]: + self.parentCanvas.onJournalUpdate(False, \ + patch[1][0], patch[1], None, None, (0, 0)) return True else: return False @@ -97,10 +105,11 @@ class MiRCARTCanvasJournal(): # {{{ undo(self): XXX def undo(self): if self.patchesUndo[self.patchesUndoLevel] != None: - undoPatch = self.patchesUndo[self.patchesUndoLevel][0] + patches = self.patchesUndo[self.patchesUndoLevel] self.patchesUndoLevel += 1 - self.parentCanvas.onJournalUpdate(False, \ - undoPatch[0], undoPatch, None, None, (0, 0)) + for patch in patches: + self.parentCanvas.onJournalUpdate(False, \ + patch[0][0], patch[0], None, None, (0, 0)) return True else: return False