mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-26 08:56:36 +00:00
MiRCART.py:MiRCARTCanvas.patchesUndoLevel: added to track {un,re}do queue movement in both directions.
MiRCART.py:MiRCARTCanvas._processMapPatches(): remove {un,re}do queue items 0..patchesUndoLevel when updating queue. MiRCART.py:MiRCARTCanvas._processMapPatches(): prepend to queue instead of appending. MiRCART.py:MiRCARTCanvas._processMapPatches(): insert {un,re}do queue items as single (list) item each. MiRCART.py:MiRCARTCanvas.redo(): decrement patchesUndoLevel & apply redo patch, if patchesUndoLevel > 0. MiRCART.py:MiRCARTCanvas.undo(): apply undo patch & increment patchesUndoLevel, if patchesUndo[patchesUndoLevel] != None. MiRCART.py:MiRCARTFrame.{menuFileRedo,onFileRedo(),__init__()}: adds `&Redo' File menu item w/ wx.ID_REDO. MiRCART.py:MiRCARTFrame.{accelRedoId,onAccelRedo(),__init__()}: binds ^Y accelerator to MiRCARTCanvas.redo(). MiRCART.py: update title.
This commit is contained in:
parent
bcf52d8dc5
commit
133c4dc240
77
MiRCART.py
77
MiRCART.py
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# MiRCART.py -- XXX
|
# MiRCART.py -- mIRC art editor for Windows & Linux
|
||||||
# Copyright (c) 2018 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
# Copyright (c) 2018 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@ -51,7 +51,7 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
canvasPos = canvasSize = canvasWinSize = cellPos = cellSize = None
|
canvasPos = canvasSize = canvasWinSize = cellPos = cellSize = None
|
||||||
canvasBitmap = canvasMap = canvasTools = None
|
canvasBitmap = canvasMap = canvasTools = None
|
||||||
mircBg = mircFg = mircBrushes = mircPens = None
|
mircBg = mircFg = mircBrushes = mircPens = None
|
||||||
patchesTmp = patchesUndo = None
|
patchesTmp = patchesUndo = patchesUndoLevel = None
|
||||||
|
|
||||||
# {{{ _drawPatch(): XXX
|
# {{{ _drawPatch(): XXX
|
||||||
def _drawPatch(self, patch, eventDc, tmpDc, atX, atY):
|
def _drawPatch(self, patch, eventDc, tmpDc, atX, atY):
|
||||||
@ -104,18 +104,18 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
for patch in mapPatch[3]:
|
for patch in mapPatch[3]:
|
||||||
if mapPatchTmp:
|
if mapPatchTmp:
|
||||||
mapItem = self.canvasMap[atY + patch[1]][atX + patch[0]]
|
mapItem = self.canvasMap[atY + patch[1]][atX + patch[0]]
|
||||||
self.patchesTmp.append([atX + patch[0], \
|
self.patchesTmp.append([atX + patch[0], atY + patch[1], None, None, None])
|
||||||
atY + patch[1], None, None, None])
|
|
||||||
self._drawPatch(patch, eventDc, tmpDc, atX, atY)
|
self._drawPatch(patch, eventDc, tmpDc, atX, atY)
|
||||||
else:
|
else:
|
||||||
mapItem = self.canvasMap[atY + patch[1]][atX + patch[0]]
|
mapItem = self.canvasMap[atY + patch[1]][atX + patch[0]]
|
||||||
if mapItem != [patch[2], patch[3], patch[4]]:
|
if mapItem != [patch[2], patch[3], patch[4]]:
|
||||||
self.patchesUndo.append((atX + patch[0], \
|
if self.patchesUndoLevel > 0:
|
||||||
atY + patch[1], patch[2], patch[3], " "))
|
del self.patchesUndo[0:self.patchesUndoLevel]
|
||||||
self.patchesUndo.append((atX + patch[0], \
|
self.patchesUndoLevel = 0
|
||||||
atY + patch[1], mapItem[0], mapItem[1], mapItem[2]))
|
self.patchesUndo.insert(0, ( \
|
||||||
self.canvasMap[atY + patch[1]][atX + patch[0]] =\
|
(atX + patch[0], atY + patch[1], mapItem[0], mapItem[1], mapItem[2]), \
|
||||||
[patch[2], patch[3], " "];
|
(atX + patch[0], atY + patch[1], patch[2], patch[3], " ")))
|
||||||
|
self.canvasMap[atY + patch[1]][atX + patch[0]] = [patch[2], patch[3], " "];
|
||||||
self._drawPatch(patch, eventDc, tmpDc, atX, atY)
|
self._drawPatch(patch, eventDc, tmpDc, atX, atY)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ getBackgroundColour(): XXX
|
# {{{ getBackgroundColour(): XXX
|
||||||
@ -169,16 +169,31 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
def onRightDown(self, event):
|
def onRightDown(self, event):
|
||||||
self._onMouseEvent(event)
|
self._onMouseEvent(event)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ undo(): XXX
|
# {{{ redo(): XXX
|
||||||
def undo(self):
|
def redo(self):
|
||||||
if len(self.patchesUndo) >= 2:
|
if self.patchesUndoLevel > 0:
|
||||||
deltaPatch = self.patchesUndo[-1];
|
self.patchesUndoLevel -= 1
|
||||||
del self.patchesUndo[-1]; del self.patchesUndo[-1];
|
redoPatch = self.patchesUndo[self.patchesUndoLevel][1]
|
||||||
self.canvasMap[deltaPatch[1]][deltaPatch[0]] = \
|
self.canvasMap[redoPatch[1]][redoPatch[0]] = \
|
||||||
[deltaPatch[2], deltaPatch[3], deltaPatch[4]]
|
[redoPatch[2], redoPatch[3], redoPatch[4]]
|
||||||
eventDc = wx.ClientDC(self); tmpDc = wx.MemoryDC();
|
eventDc = wx.ClientDC(self); tmpDc = wx.MemoryDC();
|
||||||
tmpDc.SelectObject(self.canvasBitmap)
|
tmpDc.SelectObject(self.canvasBitmap)
|
||||||
self._drawPatch(deltaPatch, eventDc, tmpDc, 0, 0)
|
self._drawPatch(redoPatch, eventDc, tmpDc, 0, 0)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
# }}}
|
||||||
|
# {{{ undo(): XXX
|
||||||
|
def undo(self):
|
||||||
|
if self.patchesUndo[self.patchesUndoLevel] != None:
|
||||||
|
undoPatch = self.patchesUndo[self.patchesUndoLevel][0]
|
||||||
|
self.canvasMap[undoPatch[1]][undoPatch[0]] = \
|
||||||
|
[undoPatch[2], undoPatch[3], undoPatch[4]]
|
||||||
|
eventDc = wx.ClientDC(self); tmpDc = wx.MemoryDC();
|
||||||
|
tmpDc.SelectObject(self.canvasBitmap)
|
||||||
|
self._drawPatch(undoPatch, eventDc, tmpDc, 0, 0)
|
||||||
|
self.patchesUndoLevel += 1
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
# }}}
|
# }}}
|
||||||
@ -204,7 +219,8 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
self.mircPens[mircColour] = wx.Pen( \
|
self.mircPens[mircColour] = wx.Pen( \
|
||||||
wx.Colour(mircColours[mircColour]), 1)
|
wx.Colour(mircColours[mircColour]), 1)
|
||||||
|
|
||||||
self.patchesTmp = []; self.patchesUndo = [];
|
self.patchesTmp = []
|
||||||
|
self.patchesUndo = [None]; self.patchesUndoLevel = 0;
|
||||||
|
|
||||||
self.Bind(wx.EVT_LEFT_DOWN, self.onLeftDown)
|
self.Bind(wx.EVT_LEFT_DOWN, self.onLeftDown)
|
||||||
self.Bind(wx.EVT_MOTION, self.onMotion)
|
self.Bind(wx.EVT_MOTION, self.onMotion)
|
||||||
@ -300,9 +316,9 @@ class MiRCARTPalette(wx.Panel):
|
|||||||
|
|
||||||
class MiRCARTFrame(wx.Frame):
|
class MiRCARTFrame(wx.Frame):
|
||||||
"""XXX"""
|
"""XXX"""
|
||||||
menuFile = menuFileUndo = menuFileSaveAs = menuFileExit = menuBar = None
|
menuFile = menuFileRedo = menuFileUndo = menuFileSaveAs = menuFileExit = menuBar = None
|
||||||
panelSkin = panelCanvas = panelPalette = None
|
panelSkin = panelCanvas = panelPalette = None
|
||||||
accelUndoId = accelTable = statusBar = None
|
accelRedoId = accelUndoId = accelTable = statusBar = None
|
||||||
|
|
||||||
# {{{ _updateStatusBar(): XXX
|
# {{{ _updateStatusBar(): XXX
|
||||||
def _updateStatusBar(self):
|
def _updateStatusBar(self):
|
||||||
@ -313,10 +329,18 @@ class MiRCARTFrame(wx.Frame):
|
|||||||
text += " " + str(self.panelCanvas.getBackgroundColour())
|
text += " " + str(self.panelCanvas.getBackgroundColour())
|
||||||
self.statusBar.SetStatusText(text)
|
self.statusBar.SetStatusText(text)
|
||||||
# }}}
|
# }}}
|
||||||
|
# {{{ onAccelRedo(): XXX
|
||||||
|
def onAccelRedo(self, event):
|
||||||
|
self.panelCanvas.redo()
|
||||||
|
# }}}
|
||||||
# {{{ onAccelUndo(): XXX
|
# {{{ onAccelUndo(): XXX
|
||||||
def onAccelUndo(self, event):
|
def onAccelUndo(self, event):
|
||||||
self.panelCanvas.undo()
|
self.panelCanvas.undo()
|
||||||
# }}}
|
# }}}
|
||||||
|
# {{{ onFileRedo(): XXX
|
||||||
|
def onFileRedo(self, event):
|
||||||
|
self.panelCanvas.redo()
|
||||||
|
# }}}
|
||||||
# {{{ onFileUndo(): XXX
|
# {{{ onFileUndo(): XXX
|
||||||
def onFileUndo(self, event):
|
def onFileUndo(self, event):
|
||||||
self.panelCanvas.undo()
|
self.panelCanvas.undo()
|
||||||
@ -362,6 +386,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.menuFileRedo = self.menuFile.Append(wx.ID_REDO, "&Redo", "Redo")
|
||||||
self.menuFileUndo = self.menuFile.Append(wx.ID_UNDO, "&Undo", "Undo")
|
self.menuFileUndo = self.menuFile.Append(wx.ID_UNDO, "&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")
|
||||||
@ -376,17 +401,21 @@ class MiRCARTFrame(wx.Frame):
|
|||||||
self.panelPalette = MiRCARTPalette(self.panelSkin, \
|
self.panelPalette = MiRCARTPalette(self.panelSkin, \
|
||||||
(25, (canvasSize[1] + 3) * cellSize[1]), cellSize, self.onPaletteEvent)
|
(25, (canvasSize[1] + 3) * cellSize[1]), cellSize, self.onPaletteEvent)
|
||||||
|
|
||||||
self.accelUndoId = wx.NewId()
|
self.accelRedoId = wx.NewId(); self.accelUndoId = wx.NewId();
|
||||||
self.accelTable = wx.AcceleratorTable([( \
|
accelTableEntries = [wx.AcceleratorEntry() for n in range(2)]
|
||||||
wx.ACCEL_CTRL, ord('Z'), self.accelUndoId)])
|
accelTableEntries[0].Set(wx.ACCEL_CTRL, ord('Y'), self.accelRedoId)
|
||||||
|
accelTableEntries[1].Set(wx.ACCEL_CTRL, ord('Z'), self.accelUndoId)
|
||||||
|
self.accelTable = wx.AcceleratorTable(accelTableEntries)
|
||||||
self.SetAcceleratorTable(self.accelTable)
|
self.SetAcceleratorTable(self.accelTable)
|
||||||
self.statusBar = self.CreateStatusBar()
|
self.statusBar = self.CreateStatusBar()
|
||||||
self._updateStatusBar()
|
self._updateStatusBar()
|
||||||
self.SetFocus()
|
self.SetFocus()
|
||||||
|
|
||||||
|
self.Bind(wx.EVT_MENU, self.onAccelRedo, id=self.accelRedoId)
|
||||||
self.Bind(wx.EVT_MENU, self.onAccelUndo, id=self.accelUndoId)
|
self.Bind(wx.EVT_MENU, self.onAccelUndo, id=self.accelUndoId)
|
||||||
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.onFileRedo, self.menuFileRedo)
|
||||||
self.Bind(wx.EVT_MENU, self.onFileUndo, self.menuFileUndo)
|
self.Bind(wx.EVT_MENU, self.onFileUndo, self.menuFileUndo)
|
||||||
self.Show(True)
|
self.Show(True)
|
||||||
# }}}
|
# }}}
|
||||||
|
Loading…
Reference in New Issue
Block a user