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])
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

View File

@ -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]
for patch in self.patchesUndo[self.patchesUndoLevel]:
self.parentCanvas.onJournalUpdate(False, \
redoPatch[0], redoPatch, None, None, (0, 0))
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
for patch in patches:
self.parentCanvas.onJournalUpdate(False, \
undoPatch[0], undoPatch, None, None, (0, 0))
patch[0][0], patch[0], None, None, (0, 0))
return True
else:
return False