mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-22 15:26:37 +00:00
MiRCART.py:MiRCARTCanvas._processMapPatches(): don't process patches that don't introduce changes..
MiRCART.py:MiRCARTCanvas._processMapPatches(): append redo and undo patches to self.patchesUndo. MiRCART.py:MiRCARTCanvas.undo(): initial implementation. MiRCART.py:MiRCARTFrame.{menuFileUndo,onFileUndo,__init__}(): add GUI for MiRCARTCanvas.undo().
This commit is contained in:
parent
7a891d9863
commit
423f923b4e
29
MiRCART.py
29
MiRCART.py
@ -105,9 +105,15 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
atY + patch[1], mapItem[0], mapItem[1], mapItem[2]))
|
atY + patch[1], mapItem[0], mapItem[1], mapItem[2]))
|
||||||
self._drawPatch(patch, eventDc, tmpDc, atX, atY)
|
self._drawPatch(patch, eventDc, tmpDc, atX, atY)
|
||||||
else:
|
else:
|
||||||
self._drawPatch(patch, eventDc, tmpDc, atX, atY)
|
mapItem = self.canvasMap[atY + patch[1]][atX + patch[0]]
|
||||||
|
if mapItem != [patch[2], patch[3], patch[4]]:
|
||||||
|
self.patchesUndo.append((atX + patch[0], \
|
||||||
|
atY + patch[1], patch[2], patch[3], " "))
|
||||||
|
self.patchesUndo.append((atX + patch[0], \
|
||||||
|
atY + patch[1], mapItem[0], mapItem[1], mapItem[2]))
|
||||||
self.canvasMap[atY + patch[1]][atX + patch[0]] =\
|
self.canvasMap[atY + patch[1]][atX + patch[0]] =\
|
||||||
[patch[2], patch[3], " "];
|
[patch[2], patch[3], " "];
|
||||||
|
self._drawPatch(patch, eventDc, tmpDc, atX, atY)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ getBackgroundColour(): XXX
|
# {{{ getBackgroundColour(): XXX
|
||||||
def getBackgroundColour(self):
|
def getBackgroundColour(self):
|
||||||
@ -160,6 +166,19 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
def onRightDown(self, event):
|
def onRightDown(self, event):
|
||||||
self._onMouseEvent(event)
|
self._onMouseEvent(event)
|
||||||
# }}}
|
# }}}
|
||||||
|
# {{{ undo(): XXX
|
||||||
|
def undo(self):
|
||||||
|
if len(self.patchesUndo) >= 2:
|
||||||
|
deltaPatch = self.patchesUndo[-1];
|
||||||
|
del self.patchesUndo[-1]; del self.patchesUndo[-1];
|
||||||
|
self.canvasMap[deltaPatch[1]][deltaPatch[0]] = \
|
||||||
|
[deltaPatch[2], deltaPatch[3], deltaPatch[4]]
|
||||||
|
eventDc = wx.ClientDC(self); tmpDc = wx.MemoryDC();
|
||||||
|
tmpDc.SelectObject(self.canvasBitmap)
|
||||||
|
self._drawPatch(deltaPatch, eventDc, tmpDc, 0, 0)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
# }}}
|
||||||
# {{{ Initialisation method
|
# {{{ Initialisation method
|
||||||
def __init__(self, parent, canvasPos, cellSize, canvasSize, canvasTools):
|
def __init__(self, parent, canvasPos, cellSize, canvasSize, canvasTools):
|
||||||
canvasWinSize = (cellSize[0] * canvasSize[0], cellSize[1] * canvasSize[1])
|
canvasWinSize = (cellSize[0] * canvasSize[0], cellSize[1] * canvasSize[1])
|
||||||
@ -278,7 +297,7 @@ class MiRCARTPalette(wx.Panel):
|
|||||||
|
|
||||||
class MiRCARTFrame(wx.Frame):
|
class MiRCARTFrame(wx.Frame):
|
||||||
"""XXX"""
|
"""XXX"""
|
||||||
menuFile = menuFileSaveAs = menuFileExit = menuBar = None
|
menuFile = menuFileUndo = menuFileSaveAs = menuFileExit = menuBar = None
|
||||||
panelSkin = panelCanvas = panelPalette = None
|
panelSkin = panelCanvas = panelPalette = None
|
||||||
statusBar = None
|
statusBar = None
|
||||||
|
|
||||||
@ -291,6 +310,10 @@ class MiRCARTFrame(wx.Frame):
|
|||||||
text += " " + str(self.panelCanvas.getBackgroundColour())
|
text += " " + str(self.panelCanvas.getBackgroundColour())
|
||||||
self.statusBar.SetStatusText(text)
|
self.statusBar.SetStatusText(text)
|
||||||
# }}}
|
# }}}
|
||||||
|
# {{{ onFileUndo(): XXX
|
||||||
|
def onFileUndo(self, event):
|
||||||
|
self.panelCanvas.undo()
|
||||||
|
# }}}
|
||||||
# {{{ onFileSaveAs(): XXX
|
# {{{ onFileSaveAs(): XXX
|
||||||
def onFileSaveAs(self, event):
|
def onFileSaveAs(self, event):
|
||||||
with wx.FileDialog(self, "Save As...", os.getcwd(), "", \
|
with wx.FileDialog(self, "Save As...", os.getcwd(), "", \
|
||||||
@ -332,6 +355,7 @@ class MiRCARTFrame(wx.Frame):
|
|||||||
super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize)
|
super().__init__(parent, wx.ID_ANY, "MiRCART", size=appSize)
|
||||||
|
|
||||||
self.menuFile = wx.Menu()
|
self.menuFile = wx.Menu()
|
||||||
|
self.menuFileUndo = self.menuFile.Append(wx.ID_SAVE, "&Undo", "Undo")
|
||||||
self.menuFileSaveAs = self.menuFile.Append(wx.ID_SAVE, "Save &As...", "Save As...")
|
self.menuFileSaveAs = self.menuFile.Append(wx.ID_SAVE, "Save &As...", "Save As...")
|
||||||
self.menuFileExit = self.menuFile.Append(wx.ID_EXIT, "E&xit", "Exit")
|
self.menuFileExit = self.menuFile.Append(wx.ID_EXIT, "E&xit", "Exit")
|
||||||
self.menuBar = wx.MenuBar()
|
self.menuBar = wx.MenuBar()
|
||||||
@ -349,6 +373,7 @@ class MiRCARTFrame(wx.Frame):
|
|||||||
|
|
||||||
self.Bind(wx.EVT_MENU, self.onFileExit, self.menuFileExit)
|
self.Bind(wx.EVT_MENU, self.onFileExit, self.menuFileExit)
|
||||||
self.Bind(wx.EVT_MENU, self.onFileSaveAs, self.menuFileSaveAs)
|
self.Bind(wx.EVT_MENU, self.onFileSaveAs, self.menuFileSaveAs)
|
||||||
|
self.Bind(wx.EVT_MENU, self.onFileUndo, self.menuFileUndo)
|
||||||
self.SetMenuBar(self.menuBar)
|
self.SetMenuBar(self.menuBar)
|
||||||
self.Show(True)
|
self.Show(True)
|
||||||
# }}}
|
# }}}
|
||||||
|
Loading…
Reference in New Issue
Block a user