From fb274c0d667c69451d6bd474738a93506f0805c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Tue, 10 Sep 2019 12:12:12 +0200 Subject: [PATCH] libroar/RoarCanvas{CommandsTools,Window}.py: explicitly pass canvas. libtools/Tool{,Circle,Fill,Line,Rect,Select,Text}.py: explicitly receive canvas. --- libroar/RoarCanvasCommandsTools.py | 2 +- libroar/RoarCanvasWindow.py | 4 ++-- libtools/Tool.py | 11 ++--------- libtools/ToolCircle.py | 2 +- libtools/ToolFill.py | 10 +++++----- libtools/ToolLine.py | 2 +- libtools/ToolRect.py | 2 +- libtools/ToolSelect.py | 4 ++-- libtools/ToolText.py | 8 ++++---- 9 files changed, 19 insertions(+), 26 deletions(-) diff --git a/libroar/RoarCanvasCommandsTools.py b/libroar/RoarCanvasCommandsTools.py index 6da3906..cd7d0c0 100644 --- a/libroar/RoarCanvasCommandsTools.py +++ b/libroar/RoarCanvasCommandsTools.py @@ -25,7 +25,7 @@ class RoarCanvasCommandsTools(): @GuiSelectDecorator(6, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False) def canvasTool(self, f, idx): def canvasTool_(event): - self.currentTool = [ToolCircle, ToolSelectClone, ToolFill, ToolLine, ToolSelectMove, ToolRect, ToolText][idx](self.parentCanvas) + self.currentTool = [ToolCircle, ToolSelectClone, ToolFill, ToolLine, ToolSelectMove, 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) diff --git a/libroar/RoarCanvasWindow.py b/libroar/RoarCanvasWindow.py index dbf46ed..78a75c5 100644 --- a/libroar/RoarCanvasWindow.py +++ b/libroar/RoarCanvasWindow.py @@ -25,9 +25,9 @@ class RoarCanvasWindow(GuiWindow): if (mapPoint[0] < self.canvas.size[0]) \ and (mapPoint[1] < self.canvas.size[1]): self.brushPos = mapPoint - rc, dirty = tool.onMouseEvent(self.brushColours, self.brushSize, self.dispatchPatchSingle, eventDc, self.brushPos, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + rc, dirty = tool.onMouseEvent(self.brushColours, self.brushSize, self.canvas, self.dispatchPatchSingle, eventDc, self.brushPos, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) else: - rc, dirty = tool.onKeyboardEvent(self.brushColours, self.brushSize, self.dispatchPatchSingle, eventDc, keyChar, keyModifiers, self.brushPos, viewRect) + rc, dirty = tool.onKeyboardEvent(self.brushColours, self.brushSize, self.canvas, self.dispatchPatchSingle, eventDc, keyChar, keyModifiers, self.brushPos, viewRect) if dirty: self.dirty = True self.commands.update(dirty=self.dirty, cellPos=self.brushPos, undoLevel=self.canvas.journal.patchesUndoLevel) diff --git a/libtools/Tool.py b/libtools/Tool.py index e5e146a..8b4c01e 100644 --- a/libtools/Tool.py +++ b/libtools/Tool.py @@ -5,20 +5,13 @@ # class Tool(): - parentCanvas = None - # {{{ onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect) - def onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect): + def onKeyboardEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect): return False, False # }}} # {{{ onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): return False, False # }}} - # - # __init__(self, parentCanvas): initialisation method - def __init__(self, parentCanvas): - self.parentCanvas = parentCanvas - # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/libtools/ToolCircle.py b/libtools/ToolCircle.py index 6c615f4..47667be 100644 --- a/libtools/ToolCircle.py +++ b/libtools/ToolCircle.py @@ -11,7 +11,7 @@ class ToolCircle(Tool): # # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, 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 fe78c77..ddbc6cb 100644 --- a/libtools/ToolFill.py +++ b/libtools/ToolFill.py @@ -11,14 +11,14 @@ class ToolFill(Tool): # # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): - dirty, pointsDone, pointStack, testColour, = False, [], [list(mapPoint)], self.parentCanvas.canvas.map[mapPoint[1]][mapPoint[0]][0:2] + def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, 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: brushColours = [brushColours[1], brushColours[0]] while len(pointStack) > 0: point = pointStack.pop() - pointCell = self.parentCanvas.canvas.map[point[1]][point[0]] + pointCell = canvas.map[point[1]][point[0]] if (pointCell[0:2] == testColour) \ or ((pointCell[3] == " ") and (pointCell[1] == testColour[1])): if not point in pointsDone: @@ -27,11 +27,11 @@ class ToolFill(Tool): dispatchFn(eventDc, False, [*point, brushColours[0], brushColours[0], 0, " "], viewRect) if point[0] > 0: pointStack.append([point[0] - 1, point[1]]) - if point[0] < (self.parentCanvas.canvas.size[0] - 1): + if point[0] < (canvas.size[0] - 1): pointStack.append([point[0] + 1, point[1]]) if point[1] > 0: pointStack.append([point[0], point[1] - 1]) - if point[1] < (self.parentCanvas.canvas.size[1] - 1): + if point[1] < (canvas.size[1] - 1): pointStack.append([point[0], point[1] + 1]) pointsDone += [point] else: diff --git a/libtools/ToolLine.py b/libtools/ToolLine.py index 5b13956..535cf21 100644 --- a/libtools/ToolLine.py +++ b/libtools/ToolLine.py @@ -52,7 +52,7 @@ class ToolLine(Tool): # # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): brushColours, dirty = brushColours.copy(), False if mouseLeftDown: brushColours[1] = brushColours[0] diff --git a/libtools/ToolRect.py b/libtools/ToolRect.py index 5dfaaca..b92b38c 100644 --- a/libtools/ToolRect.py +++ b/libtools/ToolRect.py @@ -11,7 +11,7 @@ class ToolRect(Tool): # # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, 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 index 0a23e3d..9da808a 100644 --- a/libtools/ToolSelect.py +++ b/libtools/ToolSelect.py @@ -65,7 +65,7 @@ class ToolSelect(Tool): 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(self.parentCanvas.canvas.map[rectY][rectX]) + 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 @@ -106,7 +106,7 @@ class ToolSelect(Tool): # # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, 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(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) diff --git a/libtools/ToolText.py b/libtools/ToolText.py index e364d55..5c21311 100644 --- a/libtools/ToolText.py +++ b/libtools/ToolText.py @@ -12,7 +12,7 @@ class ToolText(Tool): # # onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect) - def onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect): + def onKeyboardEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect): dirty = False if not keyModifiers in (wx.MOD_NONE, wx.MOD_SHIFT): return False @@ -22,9 +22,9 @@ class ToolText(Tool): if not dirty: dirty = True dispatchFn(eventDc, False, [*self.textPos, *brushColours, 0, keyChar], viewRect) - if self.textPos[0] < (self.parentCanvas.canvas.size[0] - 1): + if self.textPos[0] < (canvas.size[0] - 1): self.textPos[0] += 1 - elif self.textPos[1] < (self.parentCanvas.canvas.size[1] - 1): + elif self.textPos[1] < (canvas.size[1] - 1): self.textPos[0] = 0; self.textPos[1] += 1; else: self.textPos = [0, 0] @@ -32,7 +32,7 @@ class ToolText(Tool): # # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) - def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): if mouseLeftDown or mouseRightDown: self.textPos = list(mapPoint) dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, "_"], viewRect)