libroar/RoarCanvas{CommandsTools,Window}.py: explicitly pass canvas.

libtools/Tool{,Circle,Fill,Line,Rect,Select,Text}.py: explicitly receive canvas.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2019-09-10 12:12:12 +02:00
parent 723b1e86d0
commit 0f29c7d3b0
9 changed files with 19 additions and 26 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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]

View File

@ -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:

View File

@ -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]

View File

@ -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]

View File

@ -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)

View File

@ -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)