2019-09-01 14:34:00 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2019-09-09 10:46:52 +00:00
|
|
|
# ToolCircle.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 ToolCircle(Tool):
|
2019-09-01 14:34:00 +00:00
|
|
|
name = "Circle"
|
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 _drawCircle(self, brushColours, canvas, mapPoint, originPoint, radius):
|
|
|
|
cells, patches = [], []
|
2019-09-01 14:34:00 +00:00
|
|
|
for brushY in range(-radius, radius + 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
|
|
|
cells += [[]]
|
2019-09-01 14:34:00 +00:00
|
|
|
for brushX in range(-radius, radius + 1):
|
2019-09-03 16:58:50 +00:00
|
|
|
if ((brushX ** 2) + (brushY ** 2) < (((radius ** 2) + radius) * 0.8)):
|
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
|
|
|
cells[-1] += [[mapPoint[i] + int(originPoint[i] + o) for i, o in zip((0, 1,), (brushX, brushY,))]]
|
|
|
|
if cells[-1] == []:
|
|
|
|
del cells[-1]
|
|
|
|
for numRow in range(len(cells)):
|
|
|
|
for numCol in range(len(cells[numRow])):
|
2019-09-27 12:22:58 +00:00
|
|
|
point = cells[numRow][numCol]
|
2019-10-01 17:03:29 +00:00
|
|
|
if (point[0] >= 0) and (point[1] >= 0):
|
2019-09-27 12:22:58 +00:00
|
|
|
if ((numRow == 0) or (numRow == (len(cells) - 1))) \
|
|
|
|
or ((numCol == 0) or (numCol == (len(cells[numRow]) - 1))):
|
|
|
|
patch = [*cells[numRow][numCol], brushColours[0], brushColours[0], 0, " "]
|
|
|
|
elif ((numRow > 0) and (cells[numRow][numCol][0] < cells[numRow - 1][0][0])) \
|
|
|
|
or ((numRow < len(cells)) and (cells[numRow][numCol][0] < cells[numRow + 1][0][0])):
|
|
|
|
patch = [*cells[numRow][numCol], brushColours[0], brushColours[0], 0, " "]
|
|
|
|
elif ((numRow > 0) and (cells[numRow][numCol][0] > cells[numRow - 1][-1][0])) \
|
|
|
|
or ((numRow < len(cells)) and (cells[numRow][numCol][0] > cells[numRow + 1][-1][0])):
|
|
|
|
patch = [*cells[numRow][numCol], brushColours[0], brushColours[0], 0, " "]
|
|
|
|
elif brushColours[1] == -1:
|
|
|
|
if (cells[numRow][numCol][0] < canvas.size[0]) \
|
|
|
|
and (cells[numRow][numCol][1] < canvas.size[1]):
|
|
|
|
patch = [cells[numRow][numCol][0], cells[numRow][numCol][1], *canvas.map[cells[numRow][numCol][1]][cells[numRow][numCol][0]]]
|
|
|
|
else:
|
|
|
|
patch = [*cells[numRow][numCol], brushColours[1], brushColours[1], 0, " "]
|
2019-09-01 14:34:00 +00:00
|
|
|
else:
|
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
|
|
|
patch = [*cells[numRow][numCol], brushColours[1], brushColours[1], 0, " "]
|
2019-09-27 12:22:58 +00:00
|
|
|
patches += [patch]
|
2019-09-26 21:34:01 +00:00
|
|
|
return patches
|
|
|
|
|
|
|
|
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
|
2019-09-27 12:22:58 +00:00
|
|
|
brushColours, brushSize = [brushColours[1], brushColours[0]] if mouseRightDown else brushColours, brushSize[0] * 2
|
2019-09-26 21:34:01 +00:00
|
|
|
if self.toolState == self.TS_NONE:
|
2019-09-27 12:22:58 +00:00
|
|
|
originPoint, radius, targetPoint = list(mapPoint), brushSize, (brushSize / 2,) * 2
|
2019-09-26 21:34:01 +00:00
|
|
|
if (keyModifiers == wx.MOD_CONTROL) and (mouseLeftDown or mouseRightDown):
|
2019-09-27 12:22:58 +00:00
|
|
|
self.brushColours, isCursor, self.originPoint, self.toolState = brushColours, True, originPoint, self.TS_ORIGIN
|
2019-09-26 21:34:01 +00:00
|
|
|
else:
|
|
|
|
isCursor = not (mouseLeftDown or mouseRightDown)
|
|
|
|
elif self.toolState == self.TS_ORIGIN:
|
|
|
|
if mapPoint[0] > self.originPoint[0]:
|
2019-09-27 12:22:58 +00:00
|
|
|
brushSize += (mapPoint[0] - self.originPoint[0]); brushSize = brushSize + (brushSize % 2);
|
|
|
|
brushColours, originPoint, radius, targetPoint = self.brushColours, self.originPoint, brushSize, (brushSize / 2,) * 2
|
|
|
|
if not (mouseLeftDown or mouseRightDown):
|
|
|
|
self.brushColours, isCursor, self.originPoint, self.toolState = None, False, None, self.TS_NONE
|
2019-09-26 21:34:01 +00:00
|
|
|
else:
|
|
|
|
isCursor = True
|
|
|
|
patches = self._drawCircle(brushColours, canvas, originPoint, targetPoint, radius)
|
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
|