2019-09-01 14:34:00 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2019-09-09 10:46:52 +00:00
|
|
|
# Canvas.py
|
2019-09-04 14:23:59 +00:00
|
|
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
2019-09-01 14:34:00 +00:00
|
|
|
#
|
|
|
|
|
2019-09-07 08:39:26 +00:00
|
|
|
from CanvasExportStore import CanvasExportStore
|
2019-09-03 16:58:50 +00:00
|
|
|
from CanvasImportStore import CanvasImportStore
|
2019-09-01 14:34:00 +00:00
|
|
|
|
2019-09-07 08:39:26 +00:00
|
|
|
class Canvas():
|
2019-09-01 14:34:00 +00:00
|
|
|
def _commitPatch(self, patch):
|
2019-09-07 08:39:26 +00:00
|
|
|
self.map[patch[1]][patch[0]] = patch[2:]
|
2019-09-01 14:34:00 +00:00
|
|
|
|
2019-09-28 10:08:52 +00:00
|
|
|
def applyPatch(self, patch, commitUndo=True):
|
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}().
libgui/GuiCanvasPanel.py:applyTool(): updated.
libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch().
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty.
libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
2019-09-09 16:43:33 +00:00
|
|
|
if (patch[0] >= self.size[0]) or (patch[1] >= self.size[1]):
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
patchDeltaCell = self.map[patch[1]][patch[0]]; patchDelta = [*patch[0:2], *patchDeltaCell];
|
2019-09-28 10:08:52 +00:00
|
|
|
if commitUndo:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.updateCurrentDeltas(patch, patchDelta)
|
2019-09-28 10:08:52 +00:00
|
|
|
self._commitPatch(patch)
|
2019-09-08 17:04:27 +00:00
|
|
|
return True
|
Various bugfixes & usability improvements.
1) Add background colour toolbar beneath (foreground) colour toolbar.
2) Add colour flipping command w/ {accelerator,{menu,toolbar} item}.
3) Add {de,in}crease {brush,canvas} size accelerator.
4) Add {hide,show} assets window toolbar item.
5) Circle tool: draw outline with foreground colour.
6) Circle tool: honour transparency.
7) Fill tool: change comprehensive fill modifier key from <Shift> to <Ctrl>.
8) Fill tool: fill with {back,fore}ground colour given <[RL]MB>
9) Fix arrow keys cursor motion when scrolled down.
10 Instantly reflect {brush size,colour,tool} changes in canvas.
11) Object tool: honour transparency w/ non-external objects.
12) Object tool: update selection rectangle during <LMB> whilst dragging, set w/ release of <LMB>.
13) Rectangle tool: draw outline with foreground colour.
14) Rectangle tool: honour transparency.
15) Replace wx.ToolBar() w/ wx.lib.agw.aui.AuiToolBar() & custom wx.lib.agw.aui.AuiDefaultToolBarArt().
16) Restore scrolling position after resizing canvas.
.TODO: deleted.
assets/audio/roar{arab8,spoke11}.wav: added.
assets/text/hotkeys.txt: added to document hotkeys.
assets/text/requirements.txt, requirements.txt: moved.
assets/text/TODO: updated.
{assets/tools,lib{canvas,gui,roar,rtl,tools}}/*.py: remove Vim fold markers.
libroar/RoarCanvasCommandsFile.py:_importFile(): update wx.FileDialog() message.
libroar/RoarCanvasCommandsOperators.py:canvasOperator(): update invert colours {caption,label}.
2019-09-23 16:49:33 +00:00
|
|
|
|
2019-10-24 19:14:00 +00:00
|
|
|
def begin(self):
|
|
|
|
deltaItem = [[], []]; self.patchesUndo.insert(self.patchesUndoLevel, deltaItem);
|
|
|
|
|
|
|
|
def end(self):
|
|
|
|
if self.patchesUndo[self.patchesUndoLevel] == [[], []]:
|
|
|
|
del self.patchesUndo[self.patchesUndoLevel]
|
|
|
|
else:
|
|
|
|
if self.patchesUndoLevel > 0:
|
|
|
|
del self.patchesUndo[:self.patchesUndoLevel]; self.patchesUndoLevel = 0;
|
|
|
|
|
|
|
|
def popCursor(self, reset=True):
|
|
|
|
patchesCursor = []
|
|
|
|
if len(self.patchesCursor):
|
|
|
|
patchesCursor = self.patchesCursor
|
|
|
|
if reset:
|
|
|
|
self.resetCursor()
|
|
|
|
return patchesCursor
|
|
|
|
|
|
|
|
def popUndo(self, redo=False):
|
|
|
|
patches = []
|
|
|
|
if not redo:
|
|
|
|
if self.patchesUndo[self.patchesUndoLevel] != None:
|
|
|
|
patches = self.patchesUndo[self.patchesUndoLevel][0]; self.patchesUndoLevel += 1;
|
|
|
|
else:
|
|
|
|
if self.patchesUndoLevel > 0:
|
|
|
|
self.patchesUndoLevel -= 1; patches = self.patchesUndo[self.patchesUndoLevel][1];
|
|
|
|
return patches
|
|
|
|
|
|
|
|
def pushCursor(self, patches):
|
|
|
|
self.patchesCursor = patches
|
|
|
|
|
|
|
|
def resetCursor(self):
|
|
|
|
self.patchesCursor = []
|
|
|
|
|
|
|
|
def resetUndo(self):
|
|
|
|
if self.patchesUndo != None:
|
|
|
|
self.patchesUndo.clear()
|
|
|
|
self.patchesUndo = [None]; self.patchesUndoLevel = 0;
|
|
|
|
|
|
|
|
def resize(self, brushColours, newSize, commitUndo=True):
|
|
|
|
newCells = []
|
2019-09-07 08:39:26 +00:00
|
|
|
if newSize != self.size:
|
|
|
|
if self.map == None:
|
|
|
|
self.map, oldSize = [], [0, 0]
|
2019-09-01 14:34:00 +00:00
|
|
|
else:
|
2019-09-07 08:39:26 +00:00
|
|
|
oldSize = self.size
|
|
|
|
deltaSize = [b - a for a, b in zip(oldSize, newSize)]
|
2019-09-04 13:52:54 +00:00
|
|
|
if commitUndo:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.begin()
|
2019-09-07 08:39:26 +00:00
|
|
|
undoPatches, redoPatches = ["resize", *oldSize], ["resize", *newSize]
|
2019-10-24 19:14:00 +00:00
|
|
|
self.updateCurrentDeltas(redoPatches, undoPatches)
|
2019-09-07 08:39:26 +00:00
|
|
|
if deltaSize[0] < 0:
|
|
|
|
for numRow in range(oldSize[1]):
|
2019-09-04 13:52:54 +00:00
|
|
|
if commitUndo:
|
2019-09-07 08:39:26 +00:00
|
|
|
for numCol in range((oldSize[0] + deltaSize[0]), oldSize[0]):
|
2019-10-24 19:14:00 +00:00
|
|
|
self.updateCurrentDeltas(None, [numCol, numRow, *self.map[numRow][numCol]])
|
2019-09-07 08:39:26 +00:00
|
|
|
del self.map[numRow][-1:(deltaSize[0]-1):-1]
|
2019-09-01 14:34:00 +00:00
|
|
|
else:
|
2019-09-07 08:39:26 +00:00
|
|
|
for numRow in range(oldSize[1]):
|
2019-10-24 19:14:00 +00:00
|
|
|
self.map[numRow].extend([[*brushColours, 0, " "]] * deltaSize[0])
|
2019-09-07 08:39:26 +00:00
|
|
|
for numNewCol in range(oldSize[0], newSize[0]):
|
2019-09-08 16:00:11 +00:00
|
|
|
if commitUndo:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.updateCurrentDeltas([numNewCol, numRow, *brushColours, 0, " "], None)
|
|
|
|
newCells += [[numNewCol, numRow, *brushColours, 0, " "]]
|
|
|
|
self.applyPatch([numNewCol, numRow, *brushColours, 0, " "], False)
|
2019-09-07 08:39:26 +00:00
|
|
|
if deltaSize[1] < 0:
|
2019-09-04 13:52:54 +00:00
|
|
|
if commitUndo:
|
2019-09-07 08:39:26 +00:00
|
|
|
for numRow in range((oldSize[1] + deltaSize[1]), oldSize[1]):
|
|
|
|
for numCol in range(oldSize[0] + deltaSize[0]):
|
2019-10-24 19:14:00 +00:00
|
|
|
self.updateCurrentDeltas(None, [numCol, numRow, *self.map[numRow][numCol]])
|
2019-09-07 08:39:26 +00:00
|
|
|
del self.map[-1:(deltaSize[1]-1):-1]
|
2019-09-01 14:34:00 +00:00
|
|
|
else:
|
2019-09-07 08:39:26 +00:00
|
|
|
for numNewRow in range(oldSize[1], newSize[1]):
|
2019-10-24 19:14:00 +00:00
|
|
|
self.map.extend([[[*brushColours, 0, " "]] * newSize[0]])
|
2019-09-07 08:39:26 +00:00
|
|
|
for numNewCol in range(newSize[0]):
|
2019-09-08 16:00:11 +00:00
|
|
|
if commitUndo:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.updateCurrentDeltas([numNewCol, numNewRow, *brushColours, 0, " "], None)
|
|
|
|
newCells += [[numNewCol, numNewRow, *brushColours, 0, " "]]
|
|
|
|
self.applyPatch([numNewCol, numNewRow, *brushColours, 0, " "], False)
|
2019-09-07 08:39:26 +00:00
|
|
|
self.size = newSize
|
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}().
libgui/GuiCanvasPanel.py:applyTool(): updated.
libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch().
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty.
libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
2019-09-09 16:43:33 +00:00
|
|
|
if commitUndo:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.end()
|
|
|
|
return True, newCells
|
2019-09-07 08:39:26 +00:00
|
|
|
else:
|
2019-10-24 19:14:00 +00:00
|
|
|
return False, newCells
|
Various bugfixes & usability improvements.
1) Add background colour toolbar beneath (foreground) colour toolbar.
2) Add colour flipping command w/ {accelerator,{menu,toolbar} item}.
3) Add {de,in}crease {brush,canvas} size accelerator.
4) Add {hide,show} assets window toolbar item.
5) Circle tool: draw outline with foreground colour.
6) Circle tool: honour transparency.
7) Fill tool: change comprehensive fill modifier key from <Shift> to <Ctrl>.
8) Fill tool: fill with {back,fore}ground colour given <[RL]MB>
9) Fix arrow keys cursor motion when scrolled down.
10 Instantly reflect {brush size,colour,tool} changes in canvas.
11) Object tool: honour transparency w/ non-external objects.
12) Object tool: update selection rectangle during <LMB> whilst dragging, set w/ release of <LMB>.
13) Rectangle tool: draw outline with foreground colour.
14) Rectangle tool: honour transparency.
15) Replace wx.ToolBar() w/ wx.lib.agw.aui.AuiToolBar() & custom wx.lib.agw.aui.AuiDefaultToolBarArt().
16) Restore scrolling position after resizing canvas.
.TODO: deleted.
assets/audio/roar{arab8,spoke11}.wav: added.
assets/text/hotkeys.txt: added to document hotkeys.
assets/text/requirements.txt, requirements.txt: moved.
assets/text/TODO: updated.
{assets/tools,lib{canvas,gui,roar,rtl,tools}}/*.py: remove Vim fold markers.
libroar/RoarCanvasCommandsFile.py:_importFile(): update wx.FileDialog() message.
libroar/RoarCanvasCommandsOperators.py:canvasOperator(): update invert colours {caption,label}.
2019-09-23 16:49:33 +00:00
|
|
|
|
2019-09-07 08:39:26 +00:00
|
|
|
def update(self, newSize, newCanvas=None):
|
|
|
|
for numRow in range(self.size[1]):
|
|
|
|
for numCol in range(self.size[0]):
|
2019-09-28 10:08:52 +00:00
|
|
|
if (newCanvas != None) \
|
|
|
|
and (numRow < len(newCanvas)) and (numCol < len(newCanvas[numRow])):
|
2019-09-07 08:39:26 +00:00
|
|
|
self._commitPatch([numCol, numRow, *newCanvas[numRow][numCol]])
|
Various bugfixes & usability improvements.
1) Add background colour toolbar beneath (foreground) colour toolbar.
2) Add colour flipping command w/ {accelerator,{menu,toolbar} item}.
3) Add {de,in}crease {brush,canvas} size accelerator.
4) Add {hide,show} assets window toolbar item.
5) Circle tool: draw outline with foreground colour.
6) Circle tool: honour transparency.
7) Fill tool: change comprehensive fill modifier key from <Shift> to <Ctrl>.
8) Fill tool: fill with {back,fore}ground colour given <[RL]MB>
9) Fix arrow keys cursor motion when scrolled down.
10 Instantly reflect {brush size,colour,tool} changes in canvas.
11) Object tool: honour transparency w/ non-external objects.
12) Object tool: update selection rectangle during <LMB> whilst dragging, set w/ release of <LMB>.
13) Rectangle tool: draw outline with foreground colour.
14) Rectangle tool: honour transparency.
15) Replace wx.ToolBar() w/ wx.lib.agw.aui.AuiToolBar() & custom wx.lib.agw.aui.AuiDefaultToolBarArt().
16) Restore scrolling position after resizing canvas.
.TODO: deleted.
assets/audio/roar{arab8,spoke11}.wav: added.
assets/text/hotkeys.txt: added to document hotkeys.
assets/text/requirements.txt, requirements.txt: moved.
assets/text/TODO: updated.
{assets/tools,lib{canvas,gui,roar,rtl,tools}}/*.py: remove Vim fold markers.
libroar/RoarCanvasCommandsFile.py:_importFile(): update wx.FileDialog() message.
libroar/RoarCanvasCommandsOperators.py:canvasOperator(): update invert colours {caption,label}.
2019-09-23 16:49:33 +00:00
|
|
|
|
2019-10-24 19:14:00 +00:00
|
|
|
def updateCurrentDeltas(self, redoPatches, undoPatches):
|
|
|
|
self.patchesUndo[self.patchesUndoLevel][0].append(undoPatches)
|
|
|
|
self.patchesUndo[self.patchesUndoLevel][1].append(redoPatches)
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
self.resetCursor(); self.resetUndo();
|
|
|
|
|
2019-09-07 08:39:26 +00:00
|
|
|
def __init__(self, size):
|
2019-10-24 19:14:00 +00:00
|
|
|
self.exportStore, self.importStore, self.map, self.size = CanvasExportStore(), CanvasImportStore(), None, size
|
|
|
|
self.patchesCursor, self.patchesUndo, self.patchesUndoLevel = [], [None], 0
|
2019-09-01 14:34:00 +00:00
|
|
|
|
2019-09-08 14:57:45 +00:00
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|