MiRCARTCanvas{,Journal}.py: fix {un,re}do regarding brush sizes >(1,1).

This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-08 02:45:03 +01:00
parent e7b7e05234
commit 1099341b5d
2 changed files with 31 additions and 18 deletions

View File

@ -102,7 +102,6 @@ class MiRCARTCanvas(wx.Panel):
patchOld[1:] = self._getMapCell(patchOld[0]) patchOld[1:] = self._getMapCell(patchOld[0])
self._setMapCell(absMapPoint, *patch[1:]) self._setMapCell(absMapPoint, *patch[1:])
self._drawPatch(patch, eventDc, tmpDc, atPoint) self._drawPatch(patch, eventDc, tmpDc, atPoint)
self.parentFrame.onCanvasUpdate()
if isInherit: if isInherit:
return patchOld return patchOld
# }}} # }}}
@ -118,6 +117,7 @@ class MiRCARTCanvas(wx.Panel):
event, mapPoint, self.brushColours, self.brushSize, \ event, mapPoint, self.brushColours, self.brushSize, \
event.Dragging(), event.LeftIsDown(), event.RightIsDown()) event.Dragging(), event.LeftIsDown(), event.RightIsDown())
self.canvasJournal.merge(mapPatches, eventDc, tmpDc, mapPoint) self.canvasJournal.merge(mapPatches, eventDc, tmpDc, mapPoint)
self.parentFrame.onCanvasUpdate()
self.parentFrame.onCanvasMotion(event, mapPoint) self.parentFrame.onCanvasMotion(event, mapPoint)
# }}} # }}}
# {{{ onMouseWindowEvent(self, event): XXX # {{{ onMouseWindowEvent(self, event): XXX
@ -168,7 +168,9 @@ class MiRCARTCanvas(wx.Panel):
# }}} # }}}
# {{{ redo(self): XXX # {{{ redo(self): XXX
def redo(self): def redo(self):
return self.canvasJournal.redo() result = self.canvasJournal.redo()
self.parentFrame.onCanvasUpdate()
return result
# }}} # }}}
# {{{ resize(self, newCanvasSize): XXX # {{{ resize(self, newCanvasSize): XXX
def resize(self, newCanvasSize): def resize(self, newCanvasSize):
@ -191,7 +193,9 @@ class MiRCARTCanvas(wx.Panel):
# }}} # }}}
# {{{ undo(self): XXX # {{{ undo(self): XXX
def undo(self): def undo(self):
return self.canvasJournal.undo() result = self.canvasJournal.undo()
self.parentFrame.onCanvasUpdate()
return result
# }}} # }}}
# {{{ __del__(self): destructor method # {{{ __del__(self): destructor method

View File

@ -35,18 +35,23 @@ class MiRCARTCanvasJournal():
patch[0], patch, eventDc, tmpDc, (0, 0), True) patch[0], patch, eventDc, tmpDc, (0, 0), True)
self.patchesTmp = [] self.patchesTmp = []
# }}} # }}}
# {{{ _pushTmp(self, atPoint, patch): XXX # {{{ _pushTmp(self, atPoint): XXX
def _pushTmp(self, absMapPoint): def _pushTmp(self, atPoint):
self.patchesTmp.append([absMapPoint, None, None, None]) self.patchesTmp.append([atPoint, None, None, None])
# }}} # }}}
# {{{ _pushUndo(self, atPoint, patchUndo, patchRedo): XXX # {{{ _pushUndo(self, atPoint, patches): XXX
def _pushUndo(self, atPoint, patchUndo, patchRedo): def _pushUndo(self, atPoint, patches):
if self.patchesUndoLevel > 0: if self.patchesUndoLevel > 0:
del self.patchesUndo[0:self.patchesUndoLevel] del self.patchesUndo[0:self.patchesUndoLevel]
self.patchesUndoLevel = 0 self.patchesUndoLevel = 0
absMapPoint = self._relMapPointToAbsMapPoint(patchUndo[0], atPoint) patchesUndo = []
self.patchesUndo.insert(0, [ \ for patch in patches:
[absMapPoint, *patchUndo[1:]], [absMapPoint, *patchRedo[1:]]]) 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 # {{{ _relMapPointToAbsMapPoint(self, relMapPoint, atPoint): XXX
def _relMapPointToAbsMapPoint(self, relMapPoint, atPoint): def _relMapPointToAbsMapPoint(self, relMapPoint, atPoint):
@ -54,6 +59,7 @@ class MiRCARTCanvasJournal():
# }}} # }}}
# {{{ merge(self, mapPatches, eventDc, tmpDc, atPoint): XXX # {{{ merge(self, mapPatches, eventDc, tmpDc, atPoint): XXX
def merge(self, mapPatches, eventDc, tmpDc, atPoint): def merge(self, mapPatches, eventDc, tmpDc, atPoint):
patchesUndo = []
for mapPatch in mapPatches: for mapPatch in mapPatches:
mapPatchTmp = mapPatch[0] mapPatchTmp = mapPatch[0]
if mapPatchTmp: if mapPatchTmp:
@ -71,15 +77,17 @@ class MiRCARTCanvasJournal():
patchUndo = \ patchUndo = \
self.parentCanvas.onJournalUpdate(mapPatchTmp, \ self.parentCanvas.onJournalUpdate(mapPatchTmp, \
absMapPoint, patch, eventDc, tmpDc, atPoint, True) 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 # {{{ redo(self): XXX
def redo(self): def redo(self):
if self.patchesUndoLevel > 0: if self.patchesUndoLevel > 0:
self.patchesUndoLevel -= 1 self.patchesUndoLevel -= 1
redoPatch = self.patchesUndo[self.patchesUndoLevel][1] for patch in self.patchesUndo[self.patchesUndoLevel]:
self.parentCanvas.onJournalUpdate(False, \ self.parentCanvas.onJournalUpdate(False, \
redoPatch[0], redoPatch, None, None, (0, 0)) patch[1][0], patch[1], None, None, (0, 0))
return True return True
else: else:
return False return False
@ -97,10 +105,11 @@ class MiRCARTCanvasJournal():
# {{{ undo(self): XXX # {{{ undo(self): XXX
def undo(self): def undo(self):
if self.patchesUndo[self.patchesUndoLevel] != None: if self.patchesUndo[self.patchesUndoLevel] != None:
undoPatch = self.patchesUndo[self.patchesUndoLevel][0] patches = self.patchesUndo[self.patchesUndoLevel]
self.patchesUndoLevel += 1 self.patchesUndoLevel += 1
self.parentCanvas.onJournalUpdate(False, \ for patch in patches:
undoPatch[0], undoPatch, None, None, (0, 0)) self.parentCanvas.onJournalUpdate(False, \
patch[0][0], patch[0], None, None, (0, 0))
return True return True
else: else:
return False return False