2019-09-07 08:39:26 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2019-09-10 08:14:12 +00:00
|
|
|
# RoarCanvasWindow.py
|
2019-09-07 08:39:26 +00:00
|
|
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
|
|
|
#
|
|
|
|
|
2019-09-10 08:14:12 +00:00
|
|
|
from GuiWindow import GuiWindow
|
2019-09-28 17:45:45 +00:00
|
|
|
from Rtl import natural_sort
|
|
|
|
from RtlPlatform import getLocalConfPathName
|
2019-09-12 10:49:53 +00:00
|
|
|
from ToolObject import ToolObject
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
from ToolText import ToolText
|
2019-10-24 19:14:00 +00:00
|
|
|
import copy, hashlib, json, os, pdb, re, time, wx, sys
|
2019-09-12 10:49:53 +00:00
|
|
|
|
|
|
|
class RoarCanvasWindowDropTarget(wx.TextDropTarget):
|
2019-09-15 11:57:41 +00:00
|
|
|
def done(self):
|
|
|
|
self.inProgress = False
|
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-12 10:49:53 +00:00
|
|
|
def OnDropText(self, x, y, data):
|
|
|
|
rc = False
|
2019-09-15 13:57:38 +00:00
|
|
|
if ((self.parent.commands.currentTool.__class__ != ToolObject) \
|
|
|
|
or (self.parent.commands.currentTool.toolState == self.parent.commands.currentTool.TS_NONE)) \
|
|
|
|
and (not self.inProgress):
|
2019-09-15 11:57:41 +00:00
|
|
|
try:
|
|
|
|
dropMap, dropSize = json.loads(data)
|
|
|
|
rectX, rectY = x - (x % self.parent.backend.cellSize[0]), y - (y % self.parent.backend.cellSize[1])
|
|
|
|
mapX, mapY = int(rectX / self.parent.backend.cellSize[0] if rectX else 0), int(rectY / self.parent.backend.cellSize[1] if rectY else 0)
|
2019-09-16 14:54:07 +00:00
|
|
|
viewRect = self.parent.GetViewStart(); mapPoint = [m + n for m, n in zip((mapX, mapY), viewRect)];
|
2019-09-15 11:57:41 +00:00
|
|
|
self.parent.commands.lastTool, self.parent.commands.currentTool = self.parent.commands.currentTool, ToolObject()
|
|
|
|
self.parent.commands.currentTool.setRegion(self.parent.canvas, mapPoint, dropMap, dropSize, external=True)
|
2019-10-24 19:14:00 +00:00
|
|
|
self.parent.parent.menuItemsById[self.parent.commands.canvasOperator.attrList[4]["id"]].Enable(True)
|
|
|
|
self.parent.commands.update(currentTool=self.parent.commands.currentTool, currentToolIdx=5)
|
2019-09-15 11:57:41 +00:00
|
|
|
eventDc = self.parent.backend.getDeviceContext(self.parent.GetClientSize(), self.parent, viewRect)
|
2019-09-16 14:54:07 +00:00
|
|
|
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
self.parent.applyTool(eventDc, True, None, None, None, self.parent.brushPos, False, False, False, self.parent.commands.currentTool, viewRect)
|
2019-09-16 14:54:07 +00:00
|
|
|
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
2019-09-15 11:57:41 +00:00
|
|
|
rc = True; self.inProgress = True;
|
|
|
|
except:
|
|
|
|
with wx.MessageDialog(self.parent, "Error: {}".format(sys.exc_info()[1]), "", wx.OK | wx.OK_DEFAULT) as dialog:
|
|
|
|
dialogChoice = dialog.ShowModal()
|
2019-09-12 10:49:53 +00:00
|
|
|
return rc
|
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-12 10:49:53 +00:00
|
|
|
def __init__(self, parent):
|
2019-09-15 11:57:41 +00:00
|
|
|
super().__init__(); self.inProgress, self.parent = False, parent;
|
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-10 08:14:12 +00:00
|
|
|
class RoarCanvasWindow(GuiWindow):
|
2019-10-24 19:14:00 +00:00
|
|
|
def _applyPatches(self, eventDc, patches, patchesCursor, rc, commitUndo=True, dirty=True, eventDcResetOrigin=True, hideCursor=True):
|
2019-09-26 20:38:28 +00:00
|
|
|
if rc:
|
2019-10-24 19:14:00 +00:00
|
|
|
if eventDc == None:
|
|
|
|
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, self.GetViewStart())
|
|
|
|
if eventDcResetOrigin:
|
|
|
|
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
|
|
|
if hideCursor and (((patches != None) and (len(patches) > 0)) or ((patchesCursor != None) and (len(patchesCursor) > 0))):
|
|
|
|
self.cursorHide(eventDc, False, True)
|
2019-09-26 20:38:28 +00:00
|
|
|
if (patches != None) and (len(patches) > 0):
|
|
|
|
self.backend.drawPatches(self.canvas, eventDc, patches, isCursor=False)
|
2019-10-24 19:14:00 +00:00
|
|
|
if dirty and not self.dirty:
|
|
|
|
self.dirty = True
|
|
|
|
if commitUndo:
|
|
|
|
self.canvas.begin()
|
2019-09-26 20:38:28 +00:00
|
|
|
for patch in patches if patches != None else []:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.canvas.applyPatch(patch, commitUndo=commitUndo)
|
|
|
|
if commitUndo:
|
|
|
|
self.canvas.end()
|
|
|
|
if hideCursor and (patchesCursor != None):
|
|
|
|
self.cursorShow(eventDc, False, patchesCursor=patchesCursor)
|
|
|
|
if eventDcResetOrigin:
|
|
|
|
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
|
|
|
self.commands.update(cellPos=self.brushPos, dirty=self.dirty, undoLevel=self.canvas.patchesUndoLevel)
|
|
|
|
return eventDc
|
2019-10-01 17:03:29 +00:00
|
|
|
|
2019-09-28 17:45:45 +00:00
|
|
|
def _snapshotsReset(self):
|
|
|
|
self._snapshotFiles, self._snapshotsUpdateLast = [], time.time()
|
2019-10-24 19:14:00 +00:00
|
|
|
self.commands._snapshotsReset()
|
2019-09-28 17:45:45 +00:00
|
|
|
if self.commands.canvasPathName != None:
|
|
|
|
canvasPathName = os.path.abspath(self.commands.canvasPathName)
|
|
|
|
canvasFileName = os.path.basename(canvasPathName)
|
|
|
|
canvasPathNameHash = hashlib.sha1(canvasPathName.encode()).hexdigest()
|
|
|
|
self._snapshotsDirName = os.path.join(getLocalConfPathName(), "{}_{}".format(canvasFileName, canvasPathNameHash))
|
|
|
|
if os.path.exists(self._snapshotsDirName):
|
|
|
|
for snapshotFile in natural_sort([f for f in os.listdir(self._snapshotsDirName) \
|
|
|
|
if (re.match(r'snapshot\d+\.txt$', f)) and os.path.isfile(os.path.join(self._snapshotsDirName, f))]):
|
2019-10-24 19:14:00 +00:00
|
|
|
self.commands._snapshotsPush(os.path.join(self._snapshotsDirName, snapshotFile))
|
2019-09-28 17:45:45 +00:00
|
|
|
else:
|
|
|
|
self._snapshotsDirName = None
|
|
|
|
|
|
|
|
def _snapshotsUpdate(self):
|
|
|
|
if self._snapshotsDirName != None:
|
|
|
|
t = time.time()
|
|
|
|
if (t > self._snapshotsUpdateLast) and ((t - self._snapshotsUpdateLast) >= (5 * 60)):
|
|
|
|
try:
|
|
|
|
if not os.path.exists(self._snapshotsDirName):
|
|
|
|
os.makedirs(self._snapshotsDirName)
|
|
|
|
self._snapshotFiles = natural_sort([f for f in os.listdir(self._snapshotsDirName)
|
|
|
|
if (re.match(r'snapshot\d+\.txt$', f)) and os.path.isfile(os.path.join(self._snapshotsDirName, f))])
|
|
|
|
if self._snapshotFiles != []:
|
|
|
|
snapshotsCount, snapshotIndex = len(self._snapshotFiles), abs(int(re.match(r'snapshot(\d+)\.txt$', self._snapshotFiles[-1])[1])) + 1
|
|
|
|
else:
|
|
|
|
snapshotsCount, snapshotIndex = 0, 1
|
|
|
|
snapshotPathName = os.path.join(self._snapshotsDirName, "snapshot{}.txt".format(snapshotIndex));
|
|
|
|
self.commands.update(snapshotStatus=True)
|
|
|
|
with open(snapshotPathName, "w", encoding="utf-8") as outFile:
|
|
|
|
self.SetCursor(wx.Cursor(wx.CURSOR_WAIT))
|
|
|
|
self.canvas.exportStore.exportTextFile(self.canvas.map, self.canvas.size, outFile)
|
|
|
|
self.SetCursor(wx.Cursor(wx.NullCursor))
|
|
|
|
self.commands.update(snapshotStatus=False); self._snapshotsUpdateLast = time.time();
|
|
|
|
self._snapshotFiles += [os.path.basename(snapshotPathName)];
|
2019-10-24 19:14:00 +00:00
|
|
|
self.commands._snapshotsPush(snapshotPathName)
|
2019-09-28 17:45:45 +00:00
|
|
|
if len(self._snapshotFiles) > 72:
|
|
|
|
for snapshotFile in self._snapshotFiles[:len(self._snapshotFiles) - 8]:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.commands._snapshotsPop(os.path.join(self._snapshotsDirName, snapshotFile))
|
2019-09-28 17:45:45 +00:00
|
|
|
os.remove(os.path.join(self._snapshotsDirName, snapshotFile)); snapshotsCount -= 1;
|
|
|
|
except:
|
|
|
|
print("Exception during _snapshotsUpdate(): {}".format(sys.exc_info()[1]))
|
|
|
|
|
2019-10-24 19:14:00 +00:00
|
|
|
def _windowEraseBackground(self, eventDc):
|
|
|
|
viewRect = self.GetViewStart()
|
|
|
|
canvasSize, panelSize = [a * b for a, b in zip(self.backend.canvasSize, self.backend.cellSize)], self.GetSize()
|
|
|
|
if viewRect != (0, 0):
|
|
|
|
viewRect = [a * b for a, b in zip(self.backend.cellSize, viewRect)]
|
|
|
|
canvasSize = [a - b for a, b in zip(canvasSize, viewRect)]
|
|
|
|
rectangles, pens, brushes = [], [], []
|
|
|
|
if panelSize[0] > canvasSize[0]:
|
|
|
|
brushes += [self.bgBrush]; pens += [self.bgPen];
|
|
|
|
rectangles += [[canvasSize[0], 0, panelSize[0] - canvasSize[0], panelSize[1]]]
|
|
|
|
if panelSize[1] > canvasSize[1]:
|
|
|
|
brushes += [self.bgBrush]; pens += [self.bgPen];
|
|
|
|
rectangles += [[0, canvasSize[1], panelSize[0], panelSize[1] - canvasSize[1]]]
|
|
|
|
if len(rectangles) > 0:
|
|
|
|
eventDc.DrawRectangleList(rectangles, pens, brushes)
|
|
|
|
|
2019-09-21 09:27:52 +00:00
|
|
|
def applyOperator(self, currentTool, mapPoint, mouseLeftDown, mousePoint, operator, viewRect):
|
2019-09-26 20:38:28 +00:00
|
|
|
eventDc, patches, patchesCursor, rc = self.backend.getDeviceContext(self.GetClientSize(), self), None, None, True
|
|
|
|
if (currentTool.__class__ == ToolObject) and (currentTool.toolState >= currentTool.TS_SELECT):
|
2019-09-21 09:27:52 +00:00
|
|
|
region = currentTool.getRegion(self.canvas)
|
|
|
|
else:
|
|
|
|
region = self.canvas.map
|
|
|
|
if hasattr(operator, "apply2"):
|
2019-10-01 19:34:42 +00:00
|
|
|
self.commands.update(operator=self.commands.currentOperator.name)
|
2019-09-21 09:27:52 +00:00
|
|
|
if mouseLeftDown:
|
2019-09-26 20:38:28 +00:00
|
|
|
self.commands.operatorState = True if self.commands.operatorState == None else self.commands.operatorState
|
2019-09-21 09:27:52 +00:00
|
|
|
region = operator.apply2(mapPoint, mousePoint, region, copy.deepcopy(region))
|
|
|
|
elif self.commands.operatorState != None:
|
2019-09-26 20:38:28 +00:00
|
|
|
self.commands.currentOperator = None; self.commands.update(operator=None); rc = False;
|
2019-09-21 09:27:52 +00:00
|
|
|
else:
|
2019-09-26 20:38:28 +00:00
|
|
|
region = operator.apply(copy.deepcopy(region)); self.commands.currentOperator = None;
|
|
|
|
if rc:
|
|
|
|
if (currentTool.__class__ == ToolObject) and (currentTool.toolState >= currentTool.TS_SELECT):
|
|
|
|
currentTool.setRegion(self.canvas, None, region, [len(region[0]), len(region)], currentTool.external)
|
|
|
|
rc, patches, patchesCursor = currentTool.onSelectEvent(self.canvas, (0, 0), True, wx.MOD_NONE, None, currentTool.targetRect)
|
|
|
|
patchesCursor = [] if patchesCursor == None else patchesCursor
|
|
|
|
patchesCursor += currentTool._drawSelectRect(currentTool.targetRect)
|
2019-09-28 17:45:45 +00:00
|
|
|
self._applyPatches(eventDc, patches, patchesCursor, rc)
|
2019-09-26 20:38:28 +00:00
|
|
|
else:
|
|
|
|
patches = []
|
|
|
|
for numRow in range(len(region)):
|
|
|
|
for numCol in range(len(region[numRow])):
|
|
|
|
patches += [[numCol, numRow, *region[numRow][numCol]]]
|
2019-09-28 17:45:45 +00:00
|
|
|
self._applyPatches(eventDc, patches, patchesCursor, rc)
|
|
|
|
if (patches != None) and (len(patches) > 0):
|
|
|
|
self._snapshotsUpdate()
|
2019-09-26 20:38:28 +00:00
|
|
|
return rc
|
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
|
|
|
|
|
|
|
def applyTool(self, eventDc, eventMouse, keyChar, keyCode, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, tool, viewRect, force=False):
|
2019-09-28 17:45:45 +00:00
|
|
|
patches, patchesCursor, rc = None, None, False
|
2019-10-24 19:14:00 +00:00
|
|
|
if viewRect == None:
|
|
|
|
viewRect = self.GetViewStart()
|
|
|
|
if eventDc == None:
|
|
|
|
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, viewRect)
|
2019-09-10 08:14:12 +00:00
|
|
|
if eventMouse:
|
2019-09-26 20:38:28 +00:00
|
|
|
self.lastCellState = None if force else self.lastCellState
|
|
|
|
if ((mapPoint[0] < self.canvas.size[0]) and (mapPoint[1] < self.canvas.size[1])) \
|
|
|
|
and ((self.lastCellState == None) or (self.lastCellState != [list(mapPoint), mouseDragging, mouseLeftDown, mouseRightDown, list(viewRect)])):
|
|
|
|
self.brushPos = list(mapPoint) if tool.__class__ != ToolText else self.brushPos
|
2019-09-15 19:33:19 +00:00
|
|
|
if tool != None:
|
2019-09-26 20:38:28 +00:00
|
|
|
rc, patches, patchesCursor = tool.onMouseEvent(mapPoint, self.brushColours, self.brushPos, self.brushSize, self.canvas, keyModifiers, self.brushPos, mouseDragging, mouseLeftDown, mouseRightDown)
|
2019-09-15 19:33:19 +00:00
|
|
|
else:
|
2019-09-26 20:38:28 +00:00
|
|
|
rc, patches, patchesCursor = True, None, [[*mapPoint, self.brushColours[0], self.brushColours[0], 0, " "]]
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
self.lastCellState = [list(mapPoint), mouseDragging, mouseLeftDown, mouseRightDown, list(viewRect)]
|
2019-09-10 08:14:12 +00:00
|
|
|
else:
|
2019-09-15 19:33:19 +00:00
|
|
|
if tool != None:
|
2019-09-26 20:38:28 +00:00
|
|
|
rc, patches, patchesCursor = tool.onKeyboardEvent(mapPoint, self.brushColours, self.brushPos, self.brushSize, self.canvas, keyChar, keyCode, keyModifiers, self.brushPos)
|
2019-09-16 06:05:50 +00:00
|
|
|
elif mapPoint != None:
|
2019-09-26 20:38:28 +00:00
|
|
|
rc, patches, patchesCursor = True, None, [[*mapPoint, self.brushColours[0], self.brushColours[0], 0, " "]]
|
|
|
|
if rc:
|
2019-10-24 19:14:00 +00:00
|
|
|
for patch in patches if patches != None else []:
|
|
|
|
if ((patch[2] == -1) and (patch[3] == -1)) \
|
|
|
|
and (patch[0] < self.canvas.size[0]) \
|
|
|
|
and (patch[1] < self.canvas.size[1]):
|
|
|
|
patch[2:] = self.canvas.map[patch[1]][patch[0]]
|
2019-09-26 20:38:28 +00:00
|
|
|
self._applyPatches(eventDc, patches, patchesCursor, rc)
|
2019-10-24 19:14:00 +00:00
|
|
|
if (tool.__class__ == ToolObject) and (tool.external, tool.toolState) == (True, tool.TS_NONE):
|
|
|
|
self.dropTarget.done(); self.commands.currentTool, self.commands.lastTool = self.commands.lastTool, self.commands.currentTool;
|
|
|
|
self.commands.update(currentTool=self.commands.currentTool)
|
2019-09-28 17:45:45 +00:00
|
|
|
if (patches != None) and (len(patches) > 0):
|
|
|
|
self._snapshotsUpdate()
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
return rc
|
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 cursorHide(self, eventDc=None, eventDcResetOrigin=True, reset=False):
|
|
|
|
if eventDc == None:
|
|
|
|
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self)
|
|
|
|
if eventDcResetOrigin:
|
|
|
|
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
|
|
|
patchesCursor = self.canvas.popCursor(reset=reset); patchesCursor_ = [];
|
|
|
|
for cursorCell in [p[:2] for p in patchesCursor]:
|
|
|
|
if (cursorCell[0] < self.canvas.size[0]) and (cursorCell[1] < self.canvas.size[1]):
|
|
|
|
patchesCursor_ += [[*cursorCell, *self.canvas.map[cursorCell[1]][cursorCell[0]]]]
|
|
|
|
if len(patchesCursor_) > 0:
|
|
|
|
self.backend.drawPatches(self.canvas, eventDc, patchesCursor_, False)
|
|
|
|
if eventDcResetOrigin:
|
|
|
|
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
|
|
|
return eventDc
|
|
|
|
|
|
|
|
def cursorShow(self, eventDc=None, eventDcResetOrigin=True, patchesCursor=None):
|
|
|
|
if eventDc == None:
|
|
|
|
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self)
|
|
|
|
if eventDcResetOrigin:
|
|
|
|
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
|
|
|
if patchesCursor == None:
|
|
|
|
patchesCursor = self.canvas.popCursor(reset=False)
|
|
|
|
elif len(patchesCursor) > 0:
|
|
|
|
self.canvas.pushCursor(patchesCursor)
|
|
|
|
if (patchesCursor != None) and (len(patchesCursor) > 0):
|
|
|
|
self.backend.drawPatches(self.canvas, eventDc, patchesCursor, isCursor=True)
|
|
|
|
if eventDcResetOrigin:
|
|
|
|
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
|
|
|
|
|
|
|
def onEnterWindow(self, event):
|
|
|
|
self.lastCellState = None
|
|
|
|
|
2019-09-10 08:14:12 +00:00
|
|
|
def onKeyboardInput(self, event):
|
2019-09-15 19:33:19 +00:00
|
|
|
keyCode, keyModifiers = event.GetKeyCode(), event.GetModifiers()
|
|
|
|
viewRect = self.GetViewStart(); eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, viewRect);
|
2019-10-24 19:14:00 +00:00
|
|
|
if (keyCode, keyModifiers,) == (wx.WXK_PAUSE, wx.MOD_SHIFT,):
|
|
|
|
pdb.set_trace()
|
2019-09-15 19:33:19 +00:00
|
|
|
elif keyCode in (wx.WXK_DOWN, wx.WXK_LEFT, wx.WXK_RIGHT, wx.WXK_UP):
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
if keyCode == wx.WXK_DOWN:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.brushPos[1] = (self.brushPos[1] + 1) % self.canvas.size[1]
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
elif keyCode == wx.WXK_LEFT:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.brushPos[0] = (self.brushPos[0] - 1) if (self.brushPos[0] > 0) else (self.canvas.size[0] - 1)
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
elif keyCode == wx.WXK_RIGHT:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.brushPos[0] = (self.brushPos[0] + 1) % self.canvas.size[0]
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
elif keyCode == wx.WXK_UP:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.brushPos[1] = (self.brushPos[1] - 1) if (self.brushPos[1] > 0) else (self.canvas.size[1] - 1)
|
2019-09-15 19:33:19 +00:00
|
|
|
self.commands.update(cellPos=self.brushPos)
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
self.applyTool(eventDc, True, None, None, None, self.brushPos, False, False, False, self.commands.currentTool, viewRect)
|
2019-10-24 19:14:00 +00:00
|
|
|
elif (chr(event.GetUnicodeKey()) == " ") and (self.commands.currentTool.__class__ != ToolText):
|
2019-09-16 15:31:17 +00:00
|
|
|
if not self.applyTool(eventDc, True, None, None, event.GetModifiers(), self.brushPos, False, True, False, self.commands.currentTool, viewRect):
|
|
|
|
event.Skip()
|
|
|
|
else:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.brushPos[0] = (self.brushPos[0] + 1) if (self.brushPos[0] < (self.canvas.size[0] - 1)) else 0
|
|
|
|
self.commands.update(cellPos=self.brushPos)
|
|
|
|
self.applyTool(eventDc, True, None, None, None, self.brushPos, False, False, False, self.commands.currentTool, viewRect)
|
|
|
|
elif not self.applyTool(eventDc, False, chr(event.GetUnicodeKey()), keyCode, keyModifiers, None, None, None, None, self.commands.currentTool, viewRect):
|
|
|
|
event.Skip()
|
2019-10-01 17:03:29 +00:00
|
|
|
|
2019-09-10 08:14:12 +00:00
|
|
|
def onLeaveWindow(self, event):
|
Implements merged object tool & flip operators.
assets/images/toolObject.png: added.
liboperators/Operator{,Flip{Horizontal,Vertical}}.py: initial implementation.
libroar/RoarCanvasCommands.py: adds RoarCanvasCommandsOperators.
libroar/RoarCanvasCommandsOperators.py: initial implementation.
libroar/Roar{CanvasCommands{,Tools},Client}.py: replaces ToolSelect{Clone,Move} w/ ToolObject.
libroar/RoarCanvasWindow.py:RoarCanvasWindowDropTarget.OnDropText(): update ToolObject() invocation.
libroar/RoarCanvasWindow.py:{applyTool,onMouseInput}(): pass keyModifiers to Tool.onMouseEvent().
libroar/RoarCanvasWindow.py:applyTool(): only switch back to lastTool if current object tool contains an external object.
libroar/RoarCanvasWindow.py:onLeaveWindow(): disable hiding cursor for now.
libtools/Tool{,Circle,Fill,Line,Rect,Text}.py:onMouseEvent(): update type signature.
libtools/Tool{Object,Select{,Clone,Move}}.py: merged into libtools/ToolObject.py.
roar.py: add liboperators to sys.path[].
assets/text/TODO: updated.
2019-09-15 09:06:25 +00:00
|
|
|
if False:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.cursorHide()
|
2019-09-13 18:20:26 +00:00
|
|
|
self.lastCellState = None
|
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-10 08:14:12 +00:00
|
|
|
def onMouseInput(self, event):
|
2019-09-11 06:28:56 +00:00
|
|
|
viewRect = self.GetViewStart(); eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, viewRect);
|
2019-09-10 08:14:12 +00:00
|
|
|
mouseDragging, mouseLeftDown, mouseRightDown = event.Dragging(), event.LeftIsDown(), event.RightIsDown()
|
2019-09-28 18:12:53 +00:00
|
|
|
self.lastMouseState = [mouseDragging, mouseLeftDown, mouseRightDown]
|
2019-09-10 08:14:12 +00:00
|
|
|
mapPoint = self.backend.xlateEventPoint(event, eventDc, viewRect)
|
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
|
|
|
if viewRect != (0, 0):
|
|
|
|
mapPoint = [a + b for a, b in zip(mapPoint, viewRect)]
|
2019-09-21 09:27:52 +00:00
|
|
|
if self.commands.currentOperator != None:
|
|
|
|
self.applyOperator(self.commands.currentTool, mapPoint, mouseLeftDown, event.GetLogicalPosition(eventDc), self.commands.currentOperator, viewRect)
|
|
|
|
elif mouseRightDown \
|
2019-09-15 11:52:44 +00:00
|
|
|
and (self.commands.currentTool.__class__ == ToolObject) \
|
|
|
|
and (self.commands.currentTool.toolState >= self.commands.currentTool.TS_SELECT):
|
|
|
|
self.popupEventDc = eventDc; self.PopupMenu(self.operatorsMenu); self.popupEventDc = None;
|
Fully implement {{arrow keys,backspace,enter},arrow keys} in {text,} tool{,s}.
libroar/RoarCanvasWindow.py:applyTool(): delegate updating of brushPos to ToolText if current tool.
libroar/RoarCanvasWindow.py:applyTool(): fix function result.
libroar/RoarCanvasWindow.py:applyTool(): pass updated set of arguments to on{Keyboard,Mouse}Event().
libroar/RoarCanvasWindow.py:onKeyboardInput(): allow wrapping around canvas when receiving cursor key input.
libroar/RoarCanvasWindow.py:onKeyboardInput(): supply keyCode or None to applyTool().
libroar/RoarCanvas{CommandsTools,Window}.py: supply keyCode or None to applyTool().
libtools/Tool{,Circle,Fill,Line,Object,Rect}.py:on{Keyboard,Mouse}Event(): update type signature.
libtools/ToolText.py:onKeyboardEvent(): fully implement {arrow keys,backspace,enter}.
libtools/ToolText.py:onKeyboardEvent(): update cursor when necessary.
libtools/ToolText.py:onMouseEvent(): correctly set brushPos if mouseLeftDown or mouseRightDown.
libtools/ToolText.py:__init__(): removed.
assets/text/TODO: updated.
2019-09-16 07:55:30 +00:00
|
|
|
elif not self.applyTool(eventDc, True, None, None, event.GetModifiers(), mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, self.commands.currentTool, viewRect):
|
2019-09-10 08:14:12 +00:00
|
|
|
event.Skip()
|
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-14 13:44:17 +00:00
|
|
|
def onMouseWheel(self, event):
|
2019-09-28 10:08:52 +00:00
|
|
|
delta, modifiers = +1 if event.GetWheelRotation() >= event.GetWheelDelta() else -1, event.GetModifiers()
|
|
|
|
if modifiers == (wx.MOD_CONTROL | wx.MOD_ALT):
|
|
|
|
newFontSize = self.backend.fontSize + delta
|
2019-09-27 18:17:39 +00:00
|
|
|
if newFontSize > 0:
|
2019-10-01 17:03:29 +00:00
|
|
|
self.Freeze()
|
2019-10-24 19:14:00 +00:00
|
|
|
self.backend.fontSize = newFontSize; self.backend.resize(self.canvas.size); self.scrollStep = self.backend.cellSize;
|
2019-09-14 13:44:17 +00:00
|
|
|
super().resize([a * b for a, b in zip(self.canvas.size, self.backend.cellSize)])
|
2019-09-26 20:38:28 +00:00
|
|
|
patches = []
|
2019-09-14 13:44:17 +00:00
|
|
|
for numRow in range(self.canvas.size[1]):
|
|
|
|
for numCol in range(len(self.canvas.map[numRow])):
|
2019-09-26 20:38:28 +00:00
|
|
|
patches += [[numCol, numRow, *self.canvas.map[numRow][numCol]]]
|
2019-10-24 19:14:00 +00:00
|
|
|
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, self.GetViewStart())
|
|
|
|
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
|
|
|
self.cursorHide(eventDc, False, False)
|
2019-09-26 20:38:28 +00:00
|
|
|
self.backend.drawPatches(self.canvas, eventDc, patches, isCursor=False)
|
2019-10-24 19:14:00 +00:00
|
|
|
self.cursorShow(eventDc, False)
|
2019-09-16 14:54:07 +00:00
|
|
|
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
2019-10-24 19:14:00 +00:00
|
|
|
self.Thaw(); self._windowEraseBackground(wx.ClientDC(self));
|
2019-09-28 10:08:52 +00:00
|
|
|
elif modifiers == (wx.MOD_CONTROL | wx.MOD_SHIFT):
|
|
|
|
self.commands.canvasCanvasSize(self.commands.canvasCanvasSize, 2, 1 if delta > 0 else 0)(None)
|
|
|
|
elif modifiers == wx.MOD_CONTROL:
|
|
|
|
self.commands.canvasBrushSize(self.commands.canvasBrushSize, 2, 1 if delta > 0 else 0)(None)
|
2019-09-14 13:44:17 +00:00
|
|
|
else:
|
|
|
|
event.Skip()
|
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-10 08:14:12 +00:00
|
|
|
def onPaint(self, event):
|
2019-10-01 17:03:29 +00:00
|
|
|
viewRect = self.GetViewStart()
|
2019-09-16 14:54:07 +00:00
|
|
|
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self)
|
2019-10-01 17:03:29 +00:00
|
|
|
self.backend.onPaint(self.GetClientSize(), self, viewRect)
|
2019-10-24 19:14:00 +00:00
|
|
|
del eventDc; self._windowEraseBackground(wx.PaintDC(self));
|
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-01 17:03:29 +00:00
|
|
|
def resize(self, newSize, commitUndo=True, dirty=True, freeze=True):
|
|
|
|
if freeze:
|
|
|
|
self.Freeze()
|
2019-09-26 20:38:28 +00:00
|
|
|
viewRect = self.GetViewStart()
|
|
|
|
oldSize = [0, 0] if self.canvas.map == None else self.canvas.size
|
|
|
|
deltaSize = [b - a for a, b in zip(oldSize, newSize)]
|
2019-10-24 19:14:00 +00:00
|
|
|
rc, newCells = self.canvas.resize(self.brushColours, newSize, commitUndo)
|
|
|
|
if rc:
|
2019-09-27 18:17:39 +00:00
|
|
|
self.backend.resize(newSize); self.scrollStep = self.backend.cellSize;
|
2019-09-26 20:38:28 +00:00
|
|
|
super().resize([a * b for a, b in zip(newSize, self.backend.cellSize)])
|
2019-10-24 19:14:00 +00:00
|
|
|
self._applyPatches(None, newCells, None, True, commitUndo=False, dirty=True, hideCursor=False)
|
2019-09-26 20:38:28 +00:00
|
|
|
self.Scroll(*viewRect); self.dirty = dirty;
|
2019-10-24 19:14:00 +00:00
|
|
|
self.commands.update(dirty=self.dirty, size=newSize, undoLevel=self.canvas.patchesUndoLevel)
|
2019-09-28 17:45:45 +00:00
|
|
|
if commitUndo:
|
|
|
|
self._snapshotsUpdate()
|
2019-10-01 17:03:29 +00:00
|
|
|
if freeze:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.cursorShow(); self.Thaw(); self._windowEraseBackground(wx.ClientDC(self));
|
2019-09-26 20:38:28 +00:00
|
|
|
|
2019-09-28 10:08:52 +00:00
|
|
|
def undo(self, redo=False):
|
2019-10-24 19:14:00 +00:00
|
|
|
freezeFlag, patches, patchesDelta = False, [], self.canvas.popUndo(redo)
|
|
|
|
for patch in [p for p in patchesDelta if p != None]:
|
|
|
|
if patch[0] == "resize":
|
2019-10-01 17:03:29 +00:00
|
|
|
if not freezeFlag:
|
|
|
|
self.Freeze(); freezeFlag = True;
|
2019-10-24 19:14:00 +00:00
|
|
|
self.resize(patch[1:], False, freeze=False)
|
2019-09-28 10:08:52 +00:00
|
|
|
else:
|
2019-10-24 19:14:00 +00:00
|
|
|
patches += [patch]
|
|
|
|
eventDc = self._applyPatches(None, patches, None, True, commitUndo=False, hideCursor=False)
|
|
|
|
self.cursorShow(eventDc, True, None)
|
2019-10-01 17:03:29 +00:00
|
|
|
if freezeFlag:
|
2019-10-24 19:14:00 +00:00
|
|
|
self.Thaw(); self._windowEraseBackground(wx.ClientDC(self));
|
2019-09-28 10:08:52 +00:00
|
|
|
|
2019-09-26 20:38:28 +00:00
|
|
|
def update(self, newSize, commitUndo=True, newCanvas=None, dirty=True):
|
2019-10-24 19:14:00 +00:00
|
|
|
self.resize(newSize, commitUndo, dirty); self.canvas.update(newSize, newCanvas);
|
|
|
|
patches = []
|
2019-09-26 20:38:28 +00:00
|
|
|
for numRow in range(newSize[1]):
|
|
|
|
for numCol in range(newSize[0]):
|
|
|
|
patches += [[numCol, numRow, *self.canvas.map[numRow][numCol]]]
|
2019-10-24 19:14:00 +00:00
|
|
|
self._applyPatches(None, patches, None, True, dirty=False)
|
2019-09-26 20:38:28 +00:00
|
|
|
|
2019-09-27 18:17:39 +00:00
|
|
|
def __init__(self, backend, canvas, commands, parent, pos, size):
|
2019-10-24 19:14:00 +00:00
|
|
|
super().__init__(parent, pos); self.parent, self.size = parent, size;
|
|
|
|
self.backend, self.canvas, self.commands = backend(self.size), canvas, commands(self, parent)
|
2019-10-01 17:03:29 +00:00
|
|
|
self.bgBrush, self.bgPen = wx.Brush(self.GetBackgroundColour(), wx.BRUSHSTYLE_SOLID), wx.Pen(self.GetBackgroundColour(), 1)
|
2019-10-24 19:14:00 +00:00
|
|
|
self.brushColours, self.brushPos, self.brushSize, = [3, -1], [0, 0], [1, 1]
|
|
|
|
self.dirty, self.lastCellState, self.lastMouseState = False, None, [False, False, False]
|
|
|
|
self.dropTarget, self.popupEventDc = RoarCanvasWindowDropTarget(self), None
|
|
|
|
for event, handler in ((wx.EVT_ERASE_BACKGROUND, lambda event: None,), (wx.EVT_MOUSEWHEEL, self.onMouseWheel,),):
|
|
|
|
self.Bind(event, handler)
|
|
|
|
self.SetDropTarget(self.dropTarget)
|
2019-09-28 17:45:45 +00:00
|
|
|
self._snapshotsReset()
|
2019-09-07 08:39:26 +00:00
|
|
|
|
2019-09-08 14:57:45 +00:00
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|