2019-09-01 10:34:00 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2019-09-09 06:46:52 -04:00
|
|
|
# ToolLine.py
|
2019-09-04 10:23:59 -04:00
|
|
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
2019-09-01 10:34:00 -04:00
|
|
|
#
|
|
|
|
|
2019-09-03 12:58:50 -04:00
|
|
|
from Tool import Tool
|
2019-09-01 10:34:00 -04:00
|
|
|
|
2019-09-03 12:58:50 -04:00
|
|
|
class ToolLine(Tool):
|
2019-09-01 10:34:00 -04:00
|
|
|
name = "Line"
|
|
|
|
TS_NONE = 0
|
|
|
|
TS_ORIGIN = 1
|
|
|
|
|
2019-09-26 16:38:28 -04:00
|
|
|
def _getLine(self, brushColours, brushSize, isCursor, originPoint, targetPoint):
|
|
|
|
originPoint, patches, targetPoint = originPoint.copy(), [], targetPoint.copy()
|
2019-09-01 10:34:00 -04:00
|
|
|
pointDelta = self._pointDelta(originPoint, targetPoint)
|
2019-09-03 12:58:50 -04:00
|
|
|
lineXSign = 1 if pointDelta[0] > 0 else -1; lineYSign = 1 if pointDelta[1] > 0 else -1;
|
2019-09-01 10:34:00 -04:00
|
|
|
pointDelta = [abs(a) for a in pointDelta]
|
|
|
|
if pointDelta[0] > pointDelta[1]:
|
|
|
|
lineXX, lineXY, lineYX, lineYY = lineXSign, 0, 0, lineYSign
|
|
|
|
else:
|
|
|
|
lineXX, lineXY, lineYX, lineYY = 0, lineYSign, lineXSign, 0
|
2019-09-03 12:58:50 -04:00
|
|
|
pointDelta = [pointDelta[1], pointDelta[0]]
|
2019-09-01 10:34:00 -04:00
|
|
|
lineD = 2 * pointDelta[1] - pointDelta[0]; lineY = 0;
|
2019-09-24 08:03:16 -04:00
|
|
|
pointsDone = []
|
2019-09-01 10:34:00 -04:00
|
|
|
for lineX in range(pointDelta[0] + 1):
|
|
|
|
for brushStep in range(brushSize[0]):
|
2019-09-24 08:03:16 -04:00
|
|
|
if not ([originPoint[0] + lineX * lineXX + lineY * lineYX + brushStep, originPoint[1] + lineX * lineXY + lineY * lineYY] in pointsDone):
|
2019-09-26 16:38:28 -04:00
|
|
|
patches += [[ \
|
2019-09-24 08:03:16 -04:00
|
|
|
originPoint[0] + lineX * lineXX + lineY * lineYX + brushStep, \
|
|
|
|
originPoint[1] + lineX * lineXY + lineY * lineYY, \
|
2019-09-26 16:38:28 -04:00
|
|
|
*brushColours, 0, " "]]
|
2019-09-24 08:03:16 -04:00
|
|
|
pointsDone += [[originPoint[0] + lineX * lineXX + lineY * lineYX + brushStep, originPoint[1] + lineX * lineXY + lineY * lineYY]]
|
2019-09-01 10:34:00 -04:00
|
|
|
if lineD > 0:
|
|
|
|
lineD -= pointDelta[0]; lineY += 1;
|
|
|
|
lineD += pointDelta[1]
|
2019-09-26 16:38:28 -04:00
|
|
|
return patches
|
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 12:49:33 -04:00
|
|
|
|
2019-09-03 12:58:50 -04:00
|
|
|
def _pointDelta(self, a, b):
|
|
|
|
return [a2 - a1 for a1, a2 in zip(a, b)]
|
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 12:49:33 -04:00
|
|
|
|
2019-09-03 12:58:50 -04:00
|
|
|
def _pointSwap(self, a, b):
|
|
|
|
return [b, a]
|
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 12:49:33 -04:00
|
|
|
|
2019-09-26 16:38:28 -04:00
|
|
|
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
|
|
|
|
brushColours, isCursor, patches, rc = brushColours.copy(), not (mouseLeftDown or mouseRightDown), [], False
|
libgui/GuiCanvasInterface.py:canvasTool(): call applyTool() w/ new tool post-selection.
libgui/GuiCanvasPanel.py:{applyTool,onPanelInput}(): split from onPanelInput().
libtools/Tool{,Circle,Fill,Line,Rect,Select,Text}.py:on{Keyboard,Mouse}Event(): updated.
libtools/ToolFill.py:onMouseEvent(): display cursor.
libtools/ToolSelect{,Clone,Move}.py:onSelectEvent(): updated.
2019-09-09 12:18:54 -04:00
|
|
|
if mouseLeftDown:
|
2019-09-01 10:34:00 -04:00
|
|
|
brushColours[1] = brushColours[0]
|
libgui/GuiCanvasInterface.py:canvasTool(): call applyTool() w/ new tool post-selection.
libgui/GuiCanvasPanel.py:{applyTool,onPanelInput}(): split from onPanelInput().
libtools/Tool{,Circle,Fill,Line,Rect,Select,Text}.py:on{Keyboard,Mouse}Event(): updated.
libtools/ToolFill.py:onMouseEvent(): display cursor.
libtools/ToolSelect{,Clone,Move}.py:onSelectEvent(): updated.
2019-09-09 12:18:54 -04:00
|
|
|
elif mouseRightDown:
|
2019-09-01 10:34:00 -04:00
|
|
|
brushColours[0] = brushColours[1]
|
|
|
|
else:
|
|
|
|
brushColours[1] = brushColours[0]
|
|
|
|
if self.toolState == self.TS_NONE:
|
libgui/GuiCanvasInterface.py:canvasTool(): call applyTool() w/ new tool post-selection.
libgui/GuiCanvasPanel.py:{applyTool,onPanelInput}(): split from onPanelInput().
libtools/Tool{,Circle,Fill,Line,Rect,Select,Text}.py:on{Keyboard,Mouse}Event(): updated.
libtools/ToolFill.py:onMouseEvent(): display cursor.
libtools/ToolSelect{,Clone,Move}.py:onSelectEvent(): updated.
2019-09-09 12:18:54 -04:00
|
|
|
if mouseLeftDown or mouseRightDown:
|
2019-09-24 08:03:16 -04:00
|
|
|
self.toolOriginPoint, self.toolState = list(mapPoint), self.TS_ORIGIN
|
2019-09-27 08:22:58 -04:00
|
|
|
isCursor, patches, rc = True, [], True
|
2019-09-26 16:38:28 -04:00
|
|
|
for brushCol in range(brushSize[0]):
|
|
|
|
if ((mapPoint[0] + brushCol) < canvas.size[0]) \
|
|
|
|
and (mapPoint[1] < canvas.size[1]):
|
|
|
|
patches += [[mapPoint[0] + brushCol, mapPoint[1], *brushColours, 0, " "]]
|
2019-09-01 10:34:00 -04:00
|
|
|
elif self.toolState == self.TS_ORIGIN:
|
libgui/GuiCanvasInterface.py:canvasTool(): call applyTool() w/ new tool post-selection.
libgui/GuiCanvasPanel.py:{applyTool,onPanelInput}(): split from onPanelInput().
libtools/Tool{,Circle,Fill,Line,Rect,Select,Text}.py:on{Keyboard,Mouse}Event(): updated.
libtools/ToolFill.py:onMouseEvent(): display cursor.
libtools/ToolSelect{,Clone,Move}.py:onSelectEvent(): updated.
2019-09-09 12:18:54 -04:00
|
|
|
originPoint, targetPoint = self.toolOriginPoint, list(mapPoint)
|
|
|
|
if mouseLeftDown or mouseRightDown:
|
2019-09-26 16:38:28 -04:00
|
|
|
patches = self._getLine(brushColours, brushSize, False, originPoint, targetPoint)
|
2019-09-24 08:03:16 -04:00
|
|
|
self.toolOriginPoint, self.toolState = None, self.TS_NONE
|
|
|
|
else:
|
2019-09-26 16:38:28 -04:00
|
|
|
patches = self._getLine(brushColours, brushSize, True, originPoint, targetPoint)
|
|
|
|
rc = True
|
|
|
|
return rc, patches if not isCursor else None, patches if isCursor else None
|
2019-09-01 10:34:00 -04:00
|
|
|
|
|
|
|
def __init__(self, *args):
|
|
|
|
super().__init__(*args)
|
2019-09-24 08:03:16 -04:00
|
|
|
self.toolOriginPoint, self.toolState = None, self.TS_NONE
|
2019-09-01 10:34:00 -04:00
|
|
|
|
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|