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
|
|
|
|
|
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
|
|
|
# {{{ _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint, viewRect)
|
|
|
|
def _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint, viewRect):
|
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:
|
Initial canvas panel scrollbar implementation.
assets/text/TODO: updated.
libgui/GuiCanvasPanel.py:__init__(): provide self.winSize & call SetScrollRate().
libgui/GuiCanvasPanel.py:{_drawPatch,dispatch{DeltaPatches,Patch},onPanel{Input,LeaveWindow},resize,update}(): receive and/or pass viewRect.
libgui/GuiCanvasPanel.py:onPanelPaint(): updated.
libgui/GuiCanvasPanel.py:resize(): call SetVirtualSize().
libgui/GuiCanvasWxBackend.py:_{draw{Brush,Char}Patch,_get{Brush,Char}PatchColours,xlatePoint}(): updated.
libgui/GuiCanvasWxBackend.py:{draw{CursorMaskWithJournal,Patch},getDeviceContext,xlateEventPoint}(): receive and/or pass viewRect.
libgui/GuiCanvasWxBackend.py:getDeviceContext(): return ClientDC() if viewRect > (0, 0)
libgui/GuiCanvasWxBackend.py:onPanelPaintEvent(): blit subset of canvasBitmap into BufferedPaintDC() if viewRect > (0, 0).
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py: receive & pass viewRect to dispatchFn().
2019-09-09 10:30:25 +00:00
|
|
|
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect);
|
2019-09-01 14:34:00 +00:00
|
|
|
else:
|
Initial canvas panel scrollbar implementation.
assets/text/TODO: updated.
libgui/GuiCanvasPanel.py:__init__(): provide self.winSize & call SetScrollRate().
libgui/GuiCanvasPanel.py:{_drawPatch,dispatch{DeltaPatches,Patch},onPanel{Input,LeaveWindow},resize,update}(): receive and/or pass viewRect.
libgui/GuiCanvasPanel.py:onPanelPaint(): updated.
libgui/GuiCanvasPanel.py:resize(): call SetVirtualSize().
libgui/GuiCanvasWxBackend.py:_{draw{Brush,Char}Patch,_get{Brush,Char}PatchColours,xlatePoint}(): updated.
libgui/GuiCanvasWxBackend.py:{draw{CursorMaskWithJournal,Patch},getDeviceContext,xlateEventPoint}(): receive and/or pass viewRect.
libgui/GuiCanvasWxBackend.py:getDeviceContext(): return ClientDC() if viewRect > (0, 0)
libgui/GuiCanvasWxBackend.py:onPanelPaintEvent(): blit subset of canvasBitmap into BufferedPaintDC() if viewRect > (0, 0).
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py: receive & pass viewRect to dispatchFn().
2019-09-09 10:30:25 +00:00
|
|
|
dispatchFn(eventDc, True, patch, viewRect)
|
2019-09-01 14:34:00 +00:00
|
|
|
if lineD > 0:
|
|
|
|
lineD -= pointDelta[0]; lineY += 1;
|
|
|
|
lineD += pointDelta[1]
|
|
|
|
# }}}
|
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
|
|
|
|
|
|
|
#
|
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
|
|
|
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
|
|
|
def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
2019-09-01 14:34:00 +00:00
|
|
|
brushColours = brushColours.copy()
|
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
|
|
|
|
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect)
|
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)
|
|
|
|
self._getLine(self.toolColours, brushSize, dispatchFn, eventDc, mouseLeftDown or mouseRightDown, originPoint, targetPoint, viewRect)
|
|
|
|
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:
|
|
|
|
return False
|
|
|
|
return True
|
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
|