From f6559de704028403ce638ddfa360a63315fabc6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Sun, 8 Sep 2019 19:04:27 +0200 Subject: [PATCH] {libcanvas/Canvas,libgui/GuiCanvasPanel}.py: neither commit nor draw patches referencing cells outside of the current map. --- libcanvas/Canvas.py | 21 +++++++++++++-------- libgui/GuiCanvasPanel.py | 4 ++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/libcanvas/Canvas.py b/libcanvas/Canvas.py index 45f17c0..0d44f18 100644 --- a/libcanvas/Canvas.py +++ b/libcanvas/Canvas.py @@ -16,15 +16,20 @@ class Canvas(): # {{{ dispatchPatch(self, isCursor, patch, commitUndo=True) def dispatchPatch(self, isCursor, patch, commitUndo=True): - patchDeltaCell = self.map[patch[1]][patch[0]]; patchDelta = [*patch[0:2], *patchDeltaCell]; - if isCursor: - self.journal.pushCursor(patchDelta) + if (patch[0] >= self.size[0]) \ + or (patch[1] >= self.size[1]): + return False else: - if commitUndo: - if not self.dirtyJournal: - self.journal.pushDeltas([], []); self.dirtyJournal = True; - self.journal.updateCurrentDeltas(patch, patchDelta) - self._commitPatch(patch) + patchDeltaCell = self.map[patch[1]][patch[0]]; patchDelta = [*patch[0:2], *patchDeltaCell]; + if isCursor: + self.journal.pushCursor(patchDelta) + else: + if commitUndo: + if not self.dirtyJournal: + self.journal.pushDeltas([], []); self.dirtyJournal = True; + self.journal.updateCurrentDeltas(patch, patchDelta) + self._commitPatch(patch) + return True # }}} # {{{ resize(self, newSize, commitUndo=True) def resize(self, newSize, commitUndo=True): diff --git a/libgui/GuiCanvasPanel.py b/libgui/GuiCanvasPanel.py index 0746d8d..0bc74e2 100644 --- a/libgui/GuiCanvasPanel.py +++ b/libgui/GuiCanvasPanel.py @@ -31,8 +31,8 @@ class GuiCanvasPanel(wx.Panel): # }}} # {{{ dispatchPatch(self, eventDc, isCursor, patch) def dispatchPatch(self, eventDc, isCursor, patch): - self.canvas.dispatchPatch(isCursor, patch, False if isCursor else True) - self._drawPatch(eventDc, isCursor, patch) + if self.canvas.dispatchPatch(isCursor, patch, False if isCursor else True): + self._drawPatch(eventDc, isCursor, patch) # }}} # {{{ resize(self, newSize, commitUndo=True) def resize(self, newSize, commitUndo=True):