From b024dd855a18d50412a355595a1bd87ce12ba07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Sun, 15 Sep 2019 11:06:25 +0200 Subject: [PATCH] Implements merged object tool & flip operators. assets/images/toolObject.png: added. liboperators/Operator{,Flip{Horizontal,Vertical}}.py: initial implementation. libroar/RoarCanvasCommands.py: adds RoarCanvasCommandsOperators. libroar/RoarCanvasCommandsOperators.py: initial implementation. libroar/Roar{CanvasCommands{,Tools},Client}.py: replaces ToolSelect{Clone,Move} w/ ToolObject. libroar/RoarCanvasWindow.py:RoarCanvasWindowDropTarget.OnDropText(): update ToolObject() invocation. libroar/RoarCanvasWindow.py:{applyTool,onMouseInput}(): pass keyModifiers to Tool.onMouseEvent(). libroar/RoarCanvasWindow.py:applyTool(): only switch back to lastTool if current object tool contains an external object. libroar/RoarCanvasWindow.py:onLeaveWindow(): disable hiding cursor for now. libtools/Tool{,Circle,Fill,Line,Rect,Text}.py:onMouseEvent(): update type signature. libtools/Tool{Object,Select{,Clone,Move}}.py: merged into libtools/ToolObject.py. roar.py: add liboperators to sys.path[]. assets/text/TODO: updated. --- assets/images/toolObject.png | Bin 0 -> 206 bytes assets/text/TODO | 19 +-- liboperators/Operator.py | 17 +++ liboperators/OperatorFlipHorizontal.py | 21 ++++ liboperators/OperatorFlipVertical.py | 23 ++++ libroar/RoarCanvasCommands.py | 5 +- libroar/RoarCanvasCommandsOperators.py | 58 +++++++++ libroar/RoarCanvasCommandsTools.py | 18 ++- libroar/RoarCanvasWindow.py | 16 ++- libroar/RoarClient.py | 2 +- libtools/Tool.py | 2 +- libtools/ToolCircle.py | 4 +- libtools/ToolFill.py | 4 +- libtools/ToolLine.py | 4 +- libtools/ToolObject.py | 163 +++++++++++++++++-------- libtools/ToolRect.py | 4 +- libtools/ToolSelect.py | 135 -------------------- libtools/ToolSelectClone.py | 24 ---- libtools/ToolSelectMove.py | 30 ----- libtools/ToolText.py | 4 +- roar.py | 2 +- 21 files changed, 277 insertions(+), 278 deletions(-) create mode 100644 assets/images/toolObject.png create mode 100644 liboperators/Operator.py create mode 100644 liboperators/OperatorFlipHorizontal.py create mode 100644 liboperators/OperatorFlipVertical.py create mode 100644 libroar/RoarCanvasCommandsOperators.py delete mode 100644 libtools/ToolSelect.py delete mode 100644 libtools/ToolSelectClone.py delete mode 100644 libtools/ToolSelectMove.py diff --git a/assets/images/toolObject.png b/assets/images/toolObject.png new file mode 100644 index 0000000000000000000000000000000000000000..fc6d46499d5b1fdf05c5347cba765270cca42491 GIT binary patch literal 206 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=Dh+K$tP>S|=w^kiEpy*OmP-C!c^3^UWy*r9h!*PZ!4!i_=FZ2l5?I;Bc99$S3j3^P6 +# + +class Operator(object): + # + # apply(self, region) + def apply(self, region): + pass + + # __init__(self, *args): initialisation method + def __init__(self, *args): + pass + +# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/liboperators/OperatorFlipHorizontal.py b/liboperators/OperatorFlipHorizontal.py new file mode 100644 index 0000000..833c511 --- /dev/null +++ b/liboperators/OperatorFlipHorizontal.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +# +# OperatorFlipHorizontal.py +# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz +# + +from Operator import Operator + +class OperatorFlipHorizontal(Operator): + name = "Flip horizontally" + + # + # apply(self, region) + def apply(self, region): + region.reverse(); return region; + + # __init__(self, *args): initialisation method + def __init__(self, *args): + pass + +# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/liboperators/OperatorFlipVertical.py b/liboperators/OperatorFlipVertical.py new file mode 100644 index 0000000..856b0e0 --- /dev/null +++ b/liboperators/OperatorFlipVertical.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# +# OperatorFlipVertical.py +# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz +# + +from Operator import Operator + +class OperatorFlipVertical(Operator): + name = "Flip" + + # + # apply(self, region) + def apply(self, region): + for numRow in range(len(region)): + region[numRow].reverse() + return region + + # __init__(self, *args): initialisation method + def __init__(self, *args): + pass + +# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/libroar/RoarCanvasCommands.py b/libroar/RoarCanvasCommands.py index a79e62b..1932739 100644 --- a/libroar/RoarCanvasCommands.py +++ b/libroar/RoarCanvasCommands.py @@ -9,10 +9,11 @@ from GuiFrame import NID_TOOLBAR_HSEP from RoarCanvasCommandsEdit import RoarCanvasCommandsEdit from RoarCanvasCommandsFile import RoarCanvasCommandsFile from RoarCanvasCommandsHelp import RoarCanvasCommandsHelp +from RoarCanvasCommandsOperators import RoarCanvasCommandsOperators from RoarCanvasCommandsTools import RoarCanvasCommandsTools import os, wx -class RoarCanvasCommands(RoarCanvasCommandsFile, RoarCanvasCommandsEdit, RoarCanvasCommandsTools, RoarCanvasCommandsHelp): +class RoarCanvasCommands(RoarCanvasCommandsFile, RoarCanvasCommandsEdit, RoarCanvasCommandsTools, RoarCanvasCommandsOperators, RoarCanvasCommandsHelp): # {{{ _initColourBitmaps(self) def _initColourBitmaps(self): for numColour in range(len(RoarCanvasCommandsEdit.canvasColour.attrList)): @@ -104,7 +105,7 @@ class RoarCanvasCommands(RoarCanvasCommandsFile, RoarCanvasCommandsEdit, RoarCan self.canvasCut, self.canvasCopy, self.canvasPaste, self.canvasDelete, NID_TOOLBAR_HSEP, self.canvasCanvasSize(self.canvasCanvasSize, 1, True), self.canvasCanvasSize(self.canvasCanvasSize, 1, False), self.canvasCanvasSize(self.canvasCanvasSize, 0, True), self.canvasCanvasSize(self.canvasCanvasSize, 0, False), NID_TOOLBAR_HSEP, self.canvasCanvasSize(self.canvasCanvasSize, 2, True), self.canvasCanvasSize(self.canvasCanvasSize, 2, False), NID_TOOLBAR_HSEP, - self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 2), self.canvasTool(self.canvasTool, 3), self.canvasTool(self.canvasTool, 6), self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 4), + self.canvasTool(self.canvasTool, 4), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 2), self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 3), ]) # XXX toolBars.append( diff --git a/libroar/RoarCanvasCommandsOperators.py b/libroar/RoarCanvasCommandsOperators.py new file mode 100644 index 0000000..153554d --- /dev/null +++ b/libroar/RoarCanvasCommandsOperators.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# +# RoarCanvasCommandsOperators.py +# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz +# + +from OperatorFlipHorizontal import OperatorFlipHorizontal +from OperatorFlipVertical import OperatorFlipVertical +from GuiFrame import GuiCommandListDecorator +from ToolObject import ToolObject +import copy, wx + +class RoarCanvasCommandsOperators(): + # {{{ canvasOperator(self, f, idx) + @GuiCommandListDecorator(0, "Flip", "&Flip", None, None, None) + @GuiCommandListDecorator(1, "Flip horizontally", "Flip &horizontally", None, None, None) + def canvasOperator(self, f, idx): + def canvasOperator_(event): + applyOperator = [OperatorFlipVertical, OperatorFlipHorizontal][idx]() + if (self.currentTool.__class__ == ToolObject) \ + and (self.currentTool.toolState >= self.currentTool.TS_SELECT): + region = self.currentTool.getRegion(self.parentCanvas.canvas) + else: + region = self.parentCanvas.canvas.map + region = applyOperator.apply(copy.deepcopy(region)) + if (self.currentTool.__class__ == ToolObject) \ + and (self.currentTool.toolState >= self.currentTool.TS_SELECT): + viewRect = self.parentCanvas.GetViewStart() + eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas.GetClientSize(), self.parentCanvas, viewRect) + self.currentTool.setRegion(self.parentCanvas.canvas, None, region, [len(region[0]), len(region)], self.currentTool.external) + self.currentTool.onSelectEvent(self.parentCanvas.canvas, (0, 0), self.parentCanvas.dispatchPatchSingle, eventDc, True, wx.MOD_NONE, None, self.currentTool.targetRect, viewRect) + else: + viewRect = self.parentCanvas.GetViewStart() + eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas.GetClientSize(), self.parentCanvas, viewRect) + self.parentCanvas.canvas.journal.begin() + dirty = False + for numRow in range(len(region)): + for numCol in range(len(region[numRow])): + if not dirty: + dirty = True + self.parentCanvas.dispatchPatchSingle(eventDc, False, [numCol, numRow, *region[numRow][numCol]], viewRect) + self.parentCanvas.canvas.journal.end() + self.parentCanvas.commands.update(dirty=dirty, undoLevel=self.parentCanvas.canvas.journal.patchesUndoLevel) + setattr(canvasOperator_, "attrDict", f.attrList[idx]) + return canvasOperator_ + # }}} + + # + # __init__(self) + def __init__(self): + self.menus = ( + ("&Operators", + self.canvasOperator(self.canvasOperator, 0), self.canvasOperator(self.canvasOperator, 1), + ), + ) + self.toolBars = () + +# vim:expandtab foldmethod=marker sw=4 ts=4 tw=0 diff --git a/libroar/RoarCanvasCommandsTools.py b/libroar/RoarCanvasCommandsTools.py index 2d9fa23..54c7011 100644 --- a/libroar/RoarCanvasCommandsTools.py +++ b/libroar/RoarCanvasCommandsTools.py @@ -8,24 +8,22 @@ from GuiFrame import GuiSelectDecorator from ToolCircle import ToolCircle from ToolFill import ToolFill from ToolLine import ToolLine +from ToolObject import ToolObject from ToolRect import ToolRect -from ToolSelectClone import ToolSelectClone -from ToolSelectMove import ToolSelectMove from ToolText import ToolText import wx class RoarCanvasCommandsTools(): # {{{ canvasTool(self, f, idx) @GuiSelectDecorator(0, "Circle", "&Circle", ["toolCircle.png"], [wx.ACCEL_CTRL, ord("C")], False) - @GuiSelectDecorator(1, "Clone", "Cl&one", ["toolClone.png"], [wx.ACCEL_CTRL, ord("E")], False) - @GuiSelectDecorator(2, "Fill", "&Fill", ["toolFill.png"], [wx.ACCEL_CTRL, ord("F")], False) - @GuiSelectDecorator(3, "Line", "&Line", ["toolLine.png"], [wx.ACCEL_CTRL, ord("L")], False) - @GuiSelectDecorator(4, "Move", "&Move", ["toolMove.png"], [wx.ACCEL_CTRL, ord("M")], False) - @GuiSelectDecorator(5, "Rectangle", "&Rectangle", ["toolRect.png"], [wx.ACCEL_CTRL, ord("R")], True) - @GuiSelectDecorator(6, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False) + @GuiSelectDecorator(1, "Fill", "&Fill", ["toolFill.png"], [wx.ACCEL_CTRL, ord("F")], False) + @GuiSelectDecorator(2, "Line", "&Line", ["toolLine.png"], [wx.ACCEL_CTRL, ord("L")], False) + @GuiSelectDecorator(3, "Object", "&Object", ["toolObject.png"], [wx.ACCEL_CTRL, ord("E")], False) + @GuiSelectDecorator(4, "Rectangle", "&Rectangle", ["toolRect.png"], [wx.ACCEL_CTRL, ord("R")], True) + @GuiSelectDecorator(5, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False) def canvasTool(self, f, idx): def canvasTool_(event): - self.lastTool, self.currentTool = self.currentTool, [ToolCircle, ToolSelectClone, ToolFill, ToolLine, ToolSelectMove, ToolRect, ToolText][idx]() + self.lastTool, self.currentTool = self.currentTool, [ToolCircle, ToolFill, ToolLine, ToolObject, ToolRect, ToolText][idx]() self.parentFrame.menuItemsById[self.canvasTool.attrList[idx]["id"]].Check(True) toolBar = self.parentFrame.toolBarItemsById[self.canvasTool.attrList[idx]["id"]].GetToolBar() toolBar.ToggleTool(self.canvasTool.attrList[idx]["id"], True) @@ -43,7 +41,7 @@ class RoarCanvasCommandsTools(): def __init__(self): self.menus = ( ("&Tools", - self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 2), self.canvasTool(self.canvasTool, 3), self.canvasTool(self.canvasTool, 6), self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 4), + self.canvasTool(self.canvasTool, 4), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 2), self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 3), ), ) self.toolBars = () diff --git a/libroar/RoarCanvasWindow.py b/libroar/RoarCanvasWindow.py index f0eaea8..2490791 100644 --- a/libroar/RoarCanvasWindow.py +++ b/libroar/RoarCanvasWindow.py @@ -19,7 +19,8 @@ class RoarCanvasWindowDropTarget(wx.TextDropTarget): rectX, rectY = x - (x % self.parent.backend.cellSize[0]), y - (y % self.parent.backend.cellSize[1]) mapX, mapY = int(rectX / self.parent.backend.cellSize[0] if rectX else 0), int(rectY / self.parent.backend.cellSize[1] if rectY else 0) mapPoint = [m + n for m, n in zip((mapX, mapY), viewRect)] - self.parent.commands.lastTool, self.parent.commands.currentTool = self.parent.commands.currentTool, ToolObject(self.parent.canvas, mapPoint, dropMap, dropSize) + self.parent.commands.lastTool, self.parent.commands.currentTool = self.parent.commands.currentTool, ToolObject() + self.parent.commands.currentTool.setRegion(self.parent.canvas, mapPoint, dropMap, dropSize, external=True) self.parent.commands.update(toolName=self.parent.commands.currentTool.name) eventDc = self.parent.backend.getDeviceContext(self.parent.GetClientSize(), self.parent, viewRect) self.parent.applyTool(eventDc, True, None, None, self.parent.brushPos, False, False, False, self.parent.commands.currentTool, viewRect) @@ -58,7 +59,7 @@ class RoarCanvasWindow(GuiWindow): or (self.lastCellState != [list(mapPoint), mouseDragging, mouseLeftDown, mouseRightDown, list(viewRect)])): self.brushPos = list(mapPoint) self.lastCellState = [list(mapPoint), mouseDragging, mouseLeftDown, mouseRightDown, list(viewRect)] - rc, dirty = tool.onMouseEvent(self.brushColours, self.brushSize, self.canvas, self.dispatchPatchSingle, eventDc, self.brushPos, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + rc, dirty = tool.onMouseEvent(self.brushColours, self.brushSize, self.canvas, self.dispatchPatchSingle, eventDc, keyModifiers, self.brushPos, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) else: rc, dirty = tool.onKeyboardEvent(self.brushColours, self.brushSize, self.canvas, self.dispatchPatchSingle, eventDc, keyChar, keyModifiers, self.brushPos, viewRect) if dirty: @@ -67,7 +68,9 @@ class RoarCanvasWindow(GuiWindow): else: self.commands.update(cellPos=mapPoint if mapPoint else self.brushPos) self.canvas.journal.end() - if rc and (tool.__class__ == ToolObject) and (tool.toolState == tool.TS_NONE): + if rc and (tool.__class__ == ToolObject) \ + and (tool.toolState == tool.TS_NONE) \ + and tool.external: self.commands.currentTool, self.commands.lastTool = self.commands.lastTool, self.commands.currentTool self.commands.update(toolName=self.commands.currentTool.name) return rc @@ -138,8 +141,9 @@ class RoarCanvasWindow(GuiWindow): # }}} # {{{ onLeaveWindow(self, event) def onLeaveWindow(self, event): - eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, self.GetViewStart()) - self.backend.drawCursorMaskWithJournal(self.canvas.journal, eventDc, self.GetViewStart()) + if False: + eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, self.GetViewStart()) + self.backend.drawCursorMaskWithJournal(self.canvas.journal, eventDc, self.GetViewStart()) self.lastCellState = None # }}} # {{{ onMouseInput(self, event) @@ -147,7 +151,7 @@ class RoarCanvasWindow(GuiWindow): viewRect = self.GetViewStart(); eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, viewRect); mouseDragging, mouseLeftDown, mouseRightDown = event.Dragging(), event.LeftIsDown(), event.RightIsDown() mapPoint = self.backend.xlateEventPoint(event, eventDc, viewRect) - if not self.applyTool(eventDc, True, None, None, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, self.commands.currentTool, viewRect): + if not self.applyTool(eventDc, True, None, event.GetModifiers(), mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, self.commands.currentTool, viewRect): event.Skip() # }}} # {{{ onMouseWheel(self, event) diff --git a/libroar/RoarClient.py b/libroar/RoarClient.py index ee2bf92..aa02ff0 100644 --- a/libroar/RoarClient.py +++ b/libroar/RoarClient.py @@ -49,7 +49,7 @@ class RoarClient(GuiFrame): self.loadToolBars(self.canvasPanel.commands.toolBars) self.canvasPanel.commands.canvasNew(None) - self.canvasPanel.commands.canvasTool(self.canvasPanel.commands.canvasTool, 5)(None) + self.canvasPanel.commands.canvasTool(self.canvasPanel.commands.canvasTool, 4)(None) self.canvasPanel.commands.update(brushSize=self.canvasPanel.brushSize, colours=self.canvasPanel.brushColours) self.addWindow(self.canvasPanel, expand=True) self.assetsWindow = RoarAssetsWindow(GuiCanvasWxBackend, defaultCellSize, self) diff --git a/libtools/Tool.py b/libtools/Tool.py index 67d4aaa..34ca94d 100644 --- a/libtools/Tool.py +++ b/libtools/Tool.py @@ -10,7 +10,7 @@ class Tool(object): return False, False # }}} # {{{ onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): return False, False # }}} diff --git a/libtools/ToolCircle.py b/libtools/ToolCircle.py index da87f18..87d48ae 100644 --- a/libtools/ToolCircle.py +++ b/libtools/ToolCircle.py @@ -10,8 +10,8 @@ class ToolCircle(Tool): name = "Circle" # - # onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + # onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): brushColours, dirty = brushColours.copy(), False if mouseLeftDown: brushColours[1] = brushColours[0] diff --git a/libtools/ToolFill.py b/libtools/ToolFill.py index a413830..469b472 100644 --- a/libtools/ToolFill.py +++ b/libtools/ToolFill.py @@ -10,8 +10,8 @@ class ToolFill(Tool): name = "Fill" # - # onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + # onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): dirty, pointsDone, pointStack, testColour, = False, [], [list(mapPoint)], canvas.map[mapPoint[1]][mapPoint[0]][0:2] if mouseLeftDown or mouseRightDown: if mouseRightDown: diff --git a/libtools/ToolLine.py b/libtools/ToolLine.py index d1d76e0..8f4716e 100644 --- a/libtools/ToolLine.py +++ b/libtools/ToolLine.py @@ -51,8 +51,8 @@ class ToolLine(Tool): # }}} # - # onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + # onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): brushColours, dirty = brushColours.copy(), False if mouseLeftDown: brushColours[1] = brushColours[0] diff --git a/libtools/ToolObject.py b/libtools/ToolObject.py index 9de2d88..5ef0bc8 100644 --- a/libtools/ToolObject.py +++ b/libtools/ToolObject.py @@ -5,15 +5,17 @@ # from Tool import Tool +import wx class ToolObject(Tool): - name = "External object" + name = "Object" TS_NONE = 0 - TS_SELECT = 1 - TS_TARGET = 2 + TS_ORIGIN = 1 + TS_SELECT = 2 + TS_TARGET = 3 - # {{{ _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect) - def _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect): + # {{{ _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect) + def _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect): if mouseLeftDown: disp, isCursor = [mapPoint[m] - self.lastAtPoint[m] for m in [0, 1]], True newTargetRect = [[selectRect[n][m] + disp[m] for m in [0, 1]] for n in [0, 1]] @@ -22,7 +24,7 @@ class ToolObject(Tool): disp, isCursor, newTargetRect = [0, 0], False, selectRect.copy() else: disp, isCursor, newTargetRect = [0, 0], True, selectRect.copy() - dirty = self.onSelectEvent(canvas, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect) + dirty = self.onSelectEvent(canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect, viewRect) self._drawSelectRect(newTargetRect, dispatchFn, eventDc, viewRect) self.targetRect = newTargetRect return dirty @@ -44,13 +46,42 @@ class ToolObject(Tool): dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "], viewRect) dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "], viewRect) # }}} - # {{{ _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): - dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect) + # {{{ _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + self.substract = False + if self.external: + dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect) + else: + if mouseLeftDown: + self.targetRect, self.toolState = [list(mapPoint), []], self.TS_ORIGIN + else: + dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect) return False # }}} - # {{{ _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + # {{{ _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + if mouseLeftDown: + self.targetRect[1] = list(mapPoint) + if self.targetRect[0][0] > self.targetRect[1][0]: + self.targetRect[0][0], self.targetRect[1][0] = self.targetRect[1][0], self.targetRect[0][0] + if self.targetRect[0][1] > self.targetRect[1][1]: + self.targetRect[0][1], self.targetRect[1][1] = self.targetRect[1][1], self.targetRect[0][1] + self.lastAtPoint, self.srcRect, self.objectMap, self.toolState = list(mapPoint), self.targetRect, [], self.TS_SELECT + for numRow in range((self.targetRect[1][1] - self.targetRect[0][1]) + 1): + self.objectMap.append([]) + for numCol in range((self.targetRect[1][0] - self.targetRect[0][0]) + 1): + rectX, rectY = self.targetRect[0][0] + numCol, self.targetRect[0][1] + numRow + self.objectMap[numRow].append(canvas.map[rectY][rectX]) + self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect) + elif mouseRightDown: + self.targetRect, self.toolState = None, self.TS_NONE + else: + self.targetRect[1] = list(mapPoint) + self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect) + return False + # }}} + # {{{ _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): dirty = False if mouseLeftDown \ and (mapPoint[0] >= (self.targetRect[0][0] - 1)) \ @@ -59,68 +90,98 @@ class ToolObject(Tool): and (mapPoint[1] <= (self.targetRect[1][1] + 1)): self.lastAtPoint, self.toolState = list(mapPoint), self.TS_TARGET elif mouseRightDown: - dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) + dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) self.targetRect, self.toolState = None, self.TS_NONE else: - dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) + dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) return dirty # }}} - # {{{ _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + # {{{ _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + if not self.substract \ + and (keyModifiers == wx.MOD_CONTROL) \ + and (self.srcRect == self.targetRect): + self.substract = True dirty = False if mouseLeftDown: - dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) + dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) elif mouseRightDown: - dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) + dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) self.targetRect, self.toolState = None, self.TS_NONE else: self.toolState = self.TS_SELECT return True, dirty # }}} - # - # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + # {{{ getRegion(self, canvas) + def getRegion(self, canvas): + return self.objectMap + # }}} + # {{{ onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): dirty = False if self.toolState == self.TS_NONE: - dirty = self._mouseEventTsNone(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + dirty = self._mouseEventTsNone(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) elif self.toolState == self.TS_SELECT: - dirty = self._mouseEventTsSelect(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + dirty = self._mouseEventTsSelect(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + elif self.toolState == self.TS_ORIGIN: + dirty = self._mouseEventTsOrigin(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) elif self.toolState == self.TS_TARGET: - dirty = self._mouseEventTsTarget(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + dirty = self._mouseEventTsTarget(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) else: return False, dirty return True, dirty - - # - # onSelectEvent(self, canvas, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect) - def onSelectEvent(self, canvas, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect): + # }}} + # {{{ onSelectEvent(self, canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect, viewRect) + def onSelectEvent(self, canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect, viewRect): dirty = False - for numRow in range(len(self.objectMap)): - for numCol in range(len(self.objectMap[numRow])): - rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow - dirty = False if isCursor else True - cellNew = self.objectMap[numRow][numCol] - if (cellNew[1] == -1) and (cellNew[3] == " "): - if ((rectY + disp[1]) < canvas.size[1]) and ((rectX + disp[0]) < canvas.size[0]): - cellNew = canvas.map[rectY + disp[1]][rectX + disp[0]] - dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellNew], viewRect) + if self.external: + for numRow in range(len(self.objectMap)): + for numCol in range(len(self.objectMap[numRow])): + rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow + dirty = False if isCursor else True + cellNew = self.objectMap[numRow][numCol] + if (cellNew[1] == -1) and (cellNew[3] == " "): + if ((rectY + disp[1]) < canvas.size[1]) and ((rectX + disp[0]) < canvas.size[0]): + cellNew = canvas.map[rectY + disp[1]][rectX + disp[0]] + dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellNew], viewRect) + else: + if self.substract: + for numRow in range(self.srcRect[0][1], self.srcRect[1][1]): + for numCol in range(self.srcRect[0][0], self.srcRect[1][0]): + if ((numCol < selectRect[0][0]) or (numCol > selectRect[1][0])) \ + or ((numRow < selectRect[0][1]) or (numRow > selectRect[1][1])): + dirty = False if isCursor else True + dispatchFn(eventDc, isCursor, [numCol, numRow, 1, 1, 0, " "], viewRect) + for numRow in range(len(self.objectMap)): + for numCol in range(len(self.objectMap[numRow])): + cellOld = self.objectMap[numRow][numCol] + rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow + dirty = False if isCursor else True + dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect) return dirty - - # __init__(self, canvas, mapPoint, objectMap, objectSize): initialisation method - def __init__(self, canvas, mapPoint, objectMap, objectSize): - super().__init__() - self.lastAtPoint, self.srcRect = list(mapPoint), list(mapPoint) + # }}} + # {{{ setRegion(self, canvas, mapPoint, objectMap, objectSize, external=True) + def setRegion(self, canvas, mapPoint, objectMap, objectSize, external=True): + self.external, self.toolState = external, self.TS_SELECT + if mapPoint != None: + self.lastAtPoint = list(mapPoint) + if self.targetRect == None: + self.targetRect = [list(self.lastAtPoint), [(a + b) - (0 if a == b else 1) for a, b in zip(self.lastAtPoint, objectSize)]] + elif self.objectSize != objectSize: + if self.objectSize == None: + self.objectSize = objectSize + self.targetRect[1] = [t + d for t, d in zip(self.targetRect[1], (a - b for a, b in zip(self.objectSize, objectSize)))] + if self.srcRect == None: + self.srcRect = self.targetRect self.objectMap, self.objectSize = objectMap, objectSize - self.targetRect = [list(mapPoint), [(a + b) - (0 if a == b else 1) for a, b in zip(mapPoint, objectSize)]] - self.toolSelectMap, self.toolState = [], self.TS_SELECT - for numRow in range((self.targetRect[1][1] - self.targetRect[0][1]) + 1): - self.toolSelectMap.append([]) - for numCol in range((self.targetRect[1][0] - self.targetRect[0][0]) + 1): - rectX, rectY = self.targetRect[0][0] + numCol, self.targetRect[0][1] + numRow - if (rectX < canvas.size[0]) and (rectY < canvas.size[1]): - self.toolSelectMap[numRow].append(canvas.map[rectY][rectX]) - else: - self.toolSelectMap[numRow].append([1, 1, 0, " "]) + # }}} + + # __init__(self, *args): initialisation method + def __init__(self, *args): + super().__init__(*args) + self.external, self.lastAtPoint, self.srcRect, self.substract, \ + self.targetRect, self.objectMap, self.objectSize, self.toolState = \ + False, None, None, False, None, [], None, self.TS_NONE # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/libtools/ToolRect.py b/libtools/ToolRect.py index 05fd693..b339b5f 100644 --- a/libtools/ToolRect.py +++ b/libtools/ToolRect.py @@ -10,8 +10,8 @@ class ToolRect(Tool): name = "Rectangle" # - # onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + # onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): brushColours, dirty = brushColours.copy(), False if mouseLeftDown: brushColours[1] = brushColours[0] diff --git a/libtools/ToolSelect.py b/libtools/ToolSelect.py deleted file mode 100644 index 932e6fe..0000000 --- a/libtools/ToolSelect.py +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/env python3 -# -# ToolSelect.py -# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz -# - -from Tool import Tool - -class ToolSelect(Tool): - TS_NONE = 0 - TS_ORIGIN = 1 - TS_SELECT = 2 - TS_TARGET = 3 - - # {{{ _dispatchSelectEvent(self, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect) - def _dispatchSelectEvent(self, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect): - if mouseLeftDown: - disp, isCursor = [mapPoint[m] - self.lastAtPoint[m] for m in [0, 1]], True - newTargetRect = [[selectRect[n][m] + disp[m] for m in [0, 1]] for n in [0, 1]] - self.lastAtPoint = list(mapPoint) - elif mouseRightDown: - disp, isCursor, newTargetRect = [0, 0], False, selectRect.copy() - else: - disp, isCursor, newTargetRect = [0, 0], True, selectRect.copy() - dirty = self.onSelectEvent(disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect) - self._drawSelectRect(newTargetRect, dispatchFn, eventDc, viewRect) - self.targetRect = newTargetRect - return dirty - # }}} - # {{{ _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect) - def _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect): - rectFrame = [[rect[m[0]][n] + m[1] for n in [0, 1]] for m in [[0, -1], [1, +1]]] - if rectFrame[0][0] > rectFrame[1][0]: - rectFrame[0][0], rectFrame[1][0] = rectFrame[1][0], rectFrame[0][0] - if rectFrame[0][1] > rectFrame[1][1]: - rectFrame[0][1], rectFrame[1][1] = rectFrame[1][1], rectFrame[0][1] - curColours = [0, 0] - for rectX in range(rectFrame[0][0], rectFrame[1][0] + 1): - curColours = [1, 1] if curColours == [0, 0] else [0, 0] - dispatchFn(eventDc, True, [rectX, rectFrame[0][1], *curColours, 0, " "], viewRect) - dispatchFn(eventDc, True, [rectX, rectFrame[1][1], *curColours, 0, " "], viewRect) - for rectY in range(rectFrame[0][1], rectFrame[1][1] + 1): - curColours = [1, 1] if curColours == [0, 0] else [0, 0] - dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "], viewRect) - dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "], viewRect) - # }}} - # {{{ _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): - if mouseLeftDown: - self.targetRect, self.toolState = [list(mapPoint), []], self.TS_ORIGIN - else: - dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect) - return False - # }}} - # {{{ _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): - if mouseLeftDown: - self.targetRect[1] = list(mapPoint) - if self.targetRect[0][0] > self.targetRect[1][0]: - self.targetRect[0][0], self.targetRect[1][0] = self.targetRect[1][0], self.targetRect[0][0] - if self.targetRect[0][1] > self.targetRect[1][1]: - self.targetRect[0][1], self.targetRect[1][1] = self.targetRect[1][1], self.targetRect[0][1] - self.lastAtPoint, self.srcRect, self.toolSelectMap, self.toolState = list(mapPoint), self.targetRect, [], self.TS_SELECT - for numRow in range((self.targetRect[1][1] - self.targetRect[0][1]) + 1): - self.toolSelectMap.append([]) - for numCol in range((self.targetRect[1][0] - self.targetRect[0][0]) + 1): - rectX, rectY = self.targetRect[0][0] + numCol, self.targetRect[0][1] + numRow - self.toolSelectMap[numRow].append(canvas.map[rectY][rectX]) - self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect) - elif mouseRightDown: - self.targetRect, self.toolState = None, self.TS_NONE - else: - self.targetRect[1] = list(mapPoint) - self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect) - return False - # }}} - # {{{ _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): - dirty = False - if mouseLeftDown \ - and (mapPoint[0] >= (self.targetRect[0][0] - 1)) \ - and (mapPoint[0] <= (self.targetRect[1][0] + 1)) \ - and (mapPoint[1] >= (self.targetRect[0][1] - 1)) \ - and (mapPoint[1] <= (self.targetRect[1][1] + 1)): - self.lastAtPoint, self.toolState = list(mapPoint), self.TS_TARGET - elif mouseRightDown: - dirty = self._dispatchSelectEvent(dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) - self.targetRect, self.toolState = None, self.TS_NONE - else: - dirty = self._dispatchSelectEvent(dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) - return dirty - # }}} - # {{{ _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): - dirty = False - if mouseLeftDown: - self.toolState = self.TS_TARGET - dirty = self._dispatchSelectEvent(dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) - elif mouseRightDown: - dirty = self._dispatchSelectEvent(dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) - self.targetRect, self.toolState = None, self.TS_NONE - else: - self.toolState = self.TS_SELECT - return dirty - # }}} - - # - # onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): - dirty = False - if self.toolState == self.TS_NONE: - dirty = self._mouseEventTsNone(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - elif self.toolState == self.TS_ORIGIN: - dirty = self._mouseEventTsOrigin(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - elif self.toolState == self.TS_SELECT: - dirty = self._mouseEventTsSelect(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - elif self.toolState == self.TS_TARGET: - dirty = self._mouseEventTsTarget(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - else: - return False, dirty - return True, dirty - - # - # onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect) - def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect): - pass - - # __init__(self, *args): initialisation method - def __init__(self, *args): - super().__init__(*args) - self.lastAtPoint, self.srcRect, self.targetRect, \ - self.toolSelectMap, self.toolState = \ - None, None, None, None, self.TS_NONE - -# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/libtools/ToolSelectClone.py b/libtools/ToolSelectClone.py deleted file mode 100644 index 84b08df..0000000 --- a/libtools/ToolSelectClone.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python3 -# -# ToolSelectClone.py -# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz -# - -from ToolSelect import ToolSelect - -class ToolSelectClone(ToolSelect): - name = "Clone selection" - - # - # onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect) - def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect): - dirty = False - for numRow in range(len(self.toolSelectMap)): - for numCol in range(len(self.toolSelectMap[numRow])): - cellOld = self.toolSelectMap[numRow][numCol] - rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow - dirty = False if isCursor else True - dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect) - return dirty - -# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/libtools/ToolSelectMove.py b/libtools/ToolSelectMove.py deleted file mode 100644 index 10058b3..0000000 --- a/libtools/ToolSelectMove.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python3 -# -# ToolSelectMove.py -# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz -# - -from ToolSelect import ToolSelect - -class ToolSelectMove(ToolSelect): - name = "Move selection" - - # - # onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect) - def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect): - dirty = False - for numRow in range(self.srcRect[0][1], self.srcRect[1][1]): - for numCol in range(self.srcRect[0][0], self.srcRect[1][0]): - if ((numCol < selectRect[0][0]) or (numCol > selectRect[1][0])) \ - or ((numRow < selectRect[0][1]) or (numRow > selectRect[1][1])): - dirty = False if isCursor else True - dispatchFn(eventDc, isCursor, [numCol, numRow, 1, 1, 0, " "], viewRect) - for numRow in range(len(self.toolSelectMap)): - for numCol in range(len(self.toolSelectMap[numRow])): - cellOld = self.toolSelectMap[numRow][numCol] - rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow - dirty = False if isCursor else True - dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect) - return dirty - -# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/libtools/ToolText.py b/libtools/ToolText.py index f32179e..0eba061 100644 --- a/libtools/ToolText.py +++ b/libtools/ToolText.py @@ -32,8 +32,8 @@ class ToolText(Tool): return rc, dirty # - # onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + # onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): if mouseLeftDown or mouseRightDown: self.textPos = list(mapPoint) dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, "_"], viewRect) diff --git a/roar.py b/roar.py index e886a69..da2d23a 100755 --- a/roar.py +++ b/roar.py @@ -6,7 +6,7 @@ import os, sys [sys.path.append(os.path.join(os.getcwd(), path)) for path in \ - ["libcanvas", "libgui", "libroar", "librtl", "libtools"]] + ["libcanvas", "libgui", "libroar", "librtl", "liboperators", "libtools"]] from RoarClient import RoarClient from RtlPlatform import getLocalConfPathName