mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-04 14:56:38 +00:00
f504fa2b76
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}.
79 lines
3.5 KiB
Python
79 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
#
|
|
# ToolLine.py
|
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
|
#
|
|
|
|
from Tool import Tool
|
|
|
|
class ToolLine(Tool):
|
|
name = "Line"
|
|
TS_NONE = 0
|
|
TS_ORIGIN = 1
|
|
|
|
def _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint):
|
|
dirty = False
|
|
originPoint, targetPoint = originPoint.copy(), targetPoint.copy()
|
|
pointDelta = self._pointDelta(originPoint, targetPoint)
|
|
lineXSign = 1 if pointDelta[0] > 0 else -1; lineYSign = 1 if pointDelta[1] > 0 else -1;
|
|
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
|
|
pointDelta = [pointDelta[1], pointDelta[0]]
|
|
lineD = 2 * pointDelta[1] - pointDelta[0]; lineY = 0;
|
|
for lineX in range(pointDelta[0] + 1):
|
|
for brushStep in range(brushSize[0]):
|
|
patch = [ \
|
|
originPoint[0] + lineX * lineXX + lineY * lineYX + brushStep, \
|
|
originPoint[1] + lineX * lineXY + lineY * lineYY, \
|
|
*brushColours, 0, " "]
|
|
if isCursor:
|
|
dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
|
|
else:
|
|
if not dirty:
|
|
dirty = True
|
|
dispatchFn(eventDc, True, patch)
|
|
if lineD > 0:
|
|
lineD -= pointDelta[0]; lineY += 1;
|
|
lineD += pointDelta[1]
|
|
return dirty
|
|
|
|
def _pointDelta(self, a, b):
|
|
return [a2 - a1 for a1, a2 in zip(a, b)]
|
|
|
|
def _pointSwap(self, a, b):
|
|
return [b, a]
|
|
|
|
|
|
#
|
|
# onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown)
|
|
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
|
|
brushColours, dirty = brushColours.copy(), False
|
|
if mouseLeftDown:
|
|
brushColours[1] = brushColours[0]
|
|
elif mouseRightDown:
|
|
brushColours[0] = brushColours[1]
|
|
else:
|
|
brushColours[1] = brushColours[0]
|
|
if self.toolState == self.TS_NONE:
|
|
if mouseLeftDown or mouseRightDown:
|
|
self.toolColours, self.toolOriginPoint, self.toolState = brushColours, list(mapPoint), self.TS_ORIGIN
|
|
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "])
|
|
elif self.toolState == self.TS_ORIGIN:
|
|
originPoint, targetPoint = self.toolOriginPoint, list(mapPoint)
|
|
dirty = self._getLine(self.toolColours, brushSize, dispatchFn, eventDc, mouseLeftDown or mouseRightDown, originPoint, targetPoint)
|
|
if mouseLeftDown or mouseRightDown:
|
|
self.toolColours, self.toolOriginPoint, self.toolState = None, None, self.TS_NONE
|
|
else:
|
|
return False, dirty
|
|
return True, dirty
|
|
|
|
# __init__(self, *args): initialisation method
|
|
def __init__(self, *args):
|
|
super().__init__(*args)
|
|
self.toolColours, self.toolOriginPoint, self.toolState = None, None, self.TS_NONE
|
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|