2019-09-01 14:34:00 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2019-09-09 10:46:52 +00:00
|
|
|
# ToolRect.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-03 16:58:50 +00:00
|
|
|
from Tool import Tool
|
2019-09-26 21:34:01 +00:00
|
|
|
import wx
|
2019-09-01 14:34:00 +00:00
|
|
|
|
2019-09-03 16:58:50 +00:00
|
|
|
class ToolRect(Tool):
|
2019-09-01 14:34:00 +00:00
|
|
|
name = "Rectangle"
|
2019-09-26 21:34:01 +00:00
|
|
|
TS_NONE = 0
|
|
|
|
TS_ORIGIN = 1
|
2019-09-01 14:34:00 +00:00
|
|
|
|
2019-09-26 21:34:01 +00:00
|
|
|
def _drawRect(self, brushColours, canvas, rect):
|
|
|
|
patches = []
|
2019-09-27 12:22:58 +00: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 16:49:33 +00:00
|
|
|
patchColours = [brushColours[0]] * 2
|
|
|
|
else:
|
|
|
|
patchColours = [brushColours[1]] * 2
|
2019-10-24 19:14:00 +00:00
|
|
|
patches += [[rect[0] + brushCol, rect[1] + brushRow, *patchColours, 0, " "]]
|
2019-09-26 21:34:01 +00: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 12:22:58 +00:00
|
|
|
rect = [*mapPoint, *([a + b for a, b in zip(brushSize, mapPoint)] if brushSize[0] > 1 else mapPoint)]
|
2019-09-26 21:34:01 +00:00
|
|
|
elif self.toolState == self.TS_ORIGIN:
|
|
|
|
rect = [*self.originPoint, *mapPoint]
|
2019-09-27 12:22:58 +00:00
|
|
|
if not (mouseLeftDown or mouseRightDown):
|
2019-09-26 21:34:01 +00: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 20:38:28 +00:00
|
|
|
return True, patches if not isCursor else None, patches if isCursor else None
|
2019-09-01 14:34:00 +00:00
|
|
|
|
2019-09-26 21:34:01 +00:00
|
|
|
def __init__(self, *args):
|
|
|
|
super().__init__(*args); self.brushColours, self.originPoint, self.toolState = None, None, self.TS_NONE;
|
|
|
|
|
2019-09-01 14:34:00 +00:00
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|