2019-09-01 10:34:00 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2019-09-09 06:46:52 -04:00
|
|
|
# ToolRect.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-26 17:34:01 -04:00
|
|
|
import wx
|
2019-09-01 10:34:00 -04:00
|
|
|
|
2019-09-03 12:58:50 -04:00
|
|
|
class ToolRect(Tool):
|
2019-09-01 10:34:00 -04:00
|
|
|
name = "Rectangle"
|
2019-09-26 17:34:01 -04:00
|
|
|
TS_NONE = 0
|
|
|
|
TS_ORIGIN = 1
|
2019-09-01 10:34:00 -04:00
|
|
|
|
2019-09-26 17:34:01 -04:00
|
|
|
def _drawRect(self, brushColours, canvas, rect):
|
|
|
|
patches = []
|
2019-09-27 08:22:58 -04:00
|
|
|
for brushRow in range((rect[3] - rect[1]) + 1):
|
|
|
|
for brushCol in range((rect[2] - rect[0]) + 1):
|
|
|
|
if (brushCol in [0, (rect[2] - rect[0])]) or (brushRow in [0, (rect[3] - rect[1])]):
|
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
|
|
|
patchColours = [brushColours[0]] * 2
|
2019-09-26 17:34:01 -04:00
|
|
|
patch = [rect[0] + brushCol, rect[1] + brushRow, *patchColours, 0, " "]
|
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
|
|
|
elif brushColours[1] == -1:
|
2019-09-26 17:34:01 -04:00
|
|
|
if ((rect[0] + brushCol) < canvas.size[0]) \
|
|
|
|
and ((rect[1] + brushRow) < canvas.size[1]):
|
|
|
|
patch = [rect[0] + brushCol, rect[1] + brushRow, *canvas.map[rect[1] + brushRow][rect[0] + brushCol]]
|
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
|
|
|
else:
|
2019-09-26 17:34:01 -04:00
|
|
|
patch = [rect[0] + brushCol, rect[1] + brushRow, -1, -1, 0, " "]
|
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
|
|
|
else:
|
|
|
|
patchColours = [brushColours[1]] * 2
|
2019-09-26 17:34:01 -04:00
|
|
|
patch = [rect[0] + brushCol, rect[1] + brushRow, *patchColours, 0, " "]
|
2019-09-26 16:38:28 -04:00
|
|
|
patches += [patch]
|
2019-09-26 17:34:01 -04:00
|
|
|
return patches
|
|
|
|
|
|
|
|
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
|
|
|
|
brushColours = [brushColours[1], brushColours[0]] if mouseRightDown else brushColours
|
|
|
|
brushSize, patches = list(brushSize), []; brushSize[0] *= 2 if brushSize[0] > 1 else brushSize[0];
|
|
|
|
if self.toolState == self.TS_NONE:
|
|
|
|
if (keyModifiers == wx.MOD_CONTROL) and (mouseLeftDown or mouseRightDown):
|
|
|
|
self.brushColours, isCursor, self.originPoint, self.toolState = list(brushColours), True, list(mapPoint), self.TS_ORIGIN
|
|
|
|
else:
|
|
|
|
isCursor = not (mouseLeftDown or mouseRightDown)
|
2019-09-27 08:22:58 -04:00
|
|
|
rect = [*mapPoint, *([a + b for a, b in zip(brushSize, mapPoint)] if brushSize[0] > 1 else mapPoint)]
|
2019-09-26 17:34:01 -04:00
|
|
|
elif self.toolState == self.TS_ORIGIN:
|
|
|
|
rect = [*self.originPoint, *mapPoint]
|
2019-09-27 08:22:58 -04:00
|
|
|
if not (mouseLeftDown or mouseRightDown):
|
2019-09-26 17:34:01 -04:00
|
|
|
brushColours, isCursor, self.brushColours, self.originPoint, self.toolState = self.brushColours, False, None, None, self.TS_NONE
|
|
|
|
else:
|
|
|
|
isCursor = True
|
|
|
|
patches = self._drawRect(brushColours, canvas, rect)
|
2019-09-26 16:38:28 -04:00
|
|
|
return True, patches if not isCursor else None, patches if isCursor else None
|
2019-09-01 10:34:00 -04:00
|
|
|
|
2019-09-26 17:34:01 -04:00
|
|
|
def __init__(self, *args):
|
|
|
|
super().__init__(*args); self.brushColours, self.originPoint, self.toolState = None, None, self.TS_NONE;
|
|
|
|
|
2019-09-01 10:34:00 -04:00
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|