2019-09-01 14:34:00 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2019-09-09 10:46:52 +00:00
|
|
|
# ToolLine.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-01 14:34:00 +00:00
|
|
|
|
2019-09-03 16:58:50 +00:00
|
|
|
class ToolLine(Tool):
|
2019-09-01 14:34:00 +00:00
|
|
|
name = "Line"
|
|
|
|
TS_NONE = 0
|
|
|
|
TS_ORIGIN = 1
|
|
|
|
|
2019-09-16 14:54:07 +00:00
|
|
|
# {{{ _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint)
|
|
|
|
def _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint):
|
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}().
libgui/GuiCanvasPanel.py:applyTool(): updated.
libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch().
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty.
libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
2019-09-09 16:43:33 +00:00
|
|
|
dirty = False
|
2019-09-03 16:58:50 +00:00
|
|
|
originPoint, targetPoint = originPoint.copy(), targetPoint.copy()
|
2019-09-01 14:34:00 +00:00
|
|
|
pointDelta = self._pointDelta(originPoint, targetPoint)
|
2019-09-03 16:58:50 +00:00
|
|
|
lineXSign = 1 if pointDelta[0] > 0 else -1; lineYSign = 1 if pointDelta[1] > 0 else -1;
|
2019-09-01 14:34:00 +00: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 16:58:50 +00:00
|
|
|
pointDelta = [pointDelta[1], pointDelta[0]]
|
2019-09-01 14:34:00 +00:00
|
|
|
lineD = 2 * pointDelta[1] - pointDelta[0]; lineY = 0;
|
|
|
|
for lineX in range(pointDelta[0] + 1):
|
|
|
|
for brushStep in range(brushSize[0]):
|
2019-09-03 16:58:50 +00:00
|
|
|
patch = [ \
|
|
|
|
originPoint[0] + lineX * lineXX + lineY * lineYX + brushStep, \
|
|
|
|
originPoint[1] + lineX * lineXY + lineY * lineYY, \
|
2019-09-01 14:34:00 +00:00
|
|
|
*brushColours, 0, " "]
|
|
|
|
if isCursor:
|
2019-09-16 14:54:07 +00:00
|
|
|
dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
|
2019-09-01 14:34:00 +00:00
|
|
|
else:
|
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}().
libgui/GuiCanvasPanel.py:applyTool(): updated.
libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch().
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty.
libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
2019-09-09 16:43:33 +00:00
|
|
|
if not dirty:
|
|
|
|
dirty = True
|
2019-09-16 14:54:07 +00:00
|
|
|
dispatchFn(eventDc, True, patch)
|
2019-09-01 14:34:00 +00:00
|
|
|
if lineD > 0:
|
|
|
|
lineD -= pointDelta[0]; lineY += 1;
|
|
|
|
lineD += pointDelta[1]
|
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}().
libgui/GuiCanvasPanel.py:applyTool(): updated.
libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch().
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty.
libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
2019-09-09 16:43:33 +00:00
|
|
|
return dirty
|
2019-09-01 14:34:00 +00:00
|
|
|
# }}}
|
2019-09-08 16:08:04 +00:00
|
|
|
# {{{ _pointDelta(self, a, b)
|
2019-09-03 16:58:50 +00:00
|
|
|
def _pointDelta(self, a, b):
|
|
|
|
return [a2 - a1 for a1, a2 in zip(a, b)]
|
|
|
|
# }}}
|
2019-09-08 16:08:04 +00:00
|
|
|
# {{{ _pointSwap(self, a, b)
|
2019-09-03 16:58:50 +00:00
|
|
|
def _pointSwap(self, a, b):
|
|
|
|
return [b, a]
|
|
|
|
# }}}
|
2019-09-01 14:34:00 +00:00
|
|
|
|
|
|
|
#
|
2019-09-16 14:54:07 +00:00
|
|
|
# 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):
|
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}().
libgui/GuiCanvasPanel.py:applyTool(): updated.
libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch().
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty.
libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
2019-09-09 16:43:33 +00:00
|
|
|
brushColours, dirty = brushColours.copy(), 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 16:18:54 +00:00
|
|
|
if mouseLeftDown:
|
2019-09-01 14:34:00 +00: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 16:18:54 +00:00
|
|
|
elif mouseRightDown:
|
2019-09-01 14:34:00 +00: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 16:18:54 +00:00
|
|
|
if mouseLeftDown or mouseRightDown:
|
|
|
|
self.toolColours, self.toolOriginPoint, self.toolState = brushColours, list(mapPoint), self.TS_ORIGIN
|
2019-09-16 14:54:07 +00:00
|
|
|
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "])
|
2019-09-01 14:34:00 +00: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 16:18:54 +00:00
|
|
|
originPoint, targetPoint = self.toolOriginPoint, list(mapPoint)
|
2019-09-16 14:54:07 +00:00
|
|
|
dirty = self._getLine(self.toolColours, brushSize, dispatchFn, eventDc, mouseLeftDown or mouseRightDown, originPoint, targetPoint)
|
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 16:18:54 +00:00
|
|
|
if mouseLeftDown or mouseRightDown:
|
2019-09-03 16:58:50 +00:00
|
|
|
self.toolColours, self.toolOriginPoint, self.toolState = None, None, 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 16:18:54 +00:00
|
|
|
else:
|
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}().
libgui/GuiCanvasPanel.py:applyTool(): updated.
libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch().
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty.
libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
2019-09-09 16:43:33 +00:00
|
|
|
return False, dirty
|
|
|
|
return True, dirty
|
2019-09-01 14:34:00 +00:00
|
|
|
|
|
|
|
# __init__(self, *args): initialisation method
|
|
|
|
def __init__(self, *args):
|
|
|
|
super().__init__(*args)
|
2019-09-03 16:58:50 +00:00
|
|
|
self.toolColours, self.toolOriginPoint, 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
|