mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-22 23:36:36 +00:00
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:
parent
723b1e86d0
commit
0f29c7d3b0
@ -25,7 +25,7 @@ class RoarCanvasCommandsTools():
|
|||||||
@GuiSelectDecorator(6, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False)
|
@GuiSelectDecorator(6, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False)
|
||||||
def canvasTool(self, f, idx):
|
def canvasTool(self, f, idx):
|
||||||
def canvasTool_(event):
|
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)
|
self.parentFrame.menuItemsById[self.canvasTool.attrList[idx]["id"]].Check(True)
|
||||||
toolBar = self.parentFrame.toolBarItemsById[self.canvasTool.attrList[idx]["id"]].GetToolBar()
|
toolBar = self.parentFrame.toolBarItemsById[self.canvasTool.attrList[idx]["id"]].GetToolBar()
|
||||||
toolBar.ToggleTool(self.canvasTool.attrList[idx]["id"], True)
|
toolBar.ToggleTool(self.canvasTool.attrList[idx]["id"], True)
|
||||||
|
@ -25,9 +25,9 @@ class RoarCanvasWindow(GuiWindow):
|
|||||||
if (mapPoint[0] < self.canvas.size[0]) \
|
if (mapPoint[0] < self.canvas.size[0]) \
|
||||||
and (mapPoint[1] < self.canvas.size[1]):
|
and (mapPoint[1] < self.canvas.size[1]):
|
||||||
self.brushPos = mapPoint
|
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:
|
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:
|
if dirty:
|
||||||
self.dirty = True
|
self.dirty = True
|
||||||
self.commands.update(dirty=self.dirty, cellPos=self.brushPos, undoLevel=self.canvas.journal.patchesUndoLevel)
|
self.commands.update(dirty=self.dirty, cellPos=self.brushPos, undoLevel=self.canvas.journal.patchesUndoLevel)
|
||||||
|
@ -5,20 +5,13 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
class Tool():
|
class Tool():
|
||||||
parentCanvas = None
|
|
||||||
|
|
||||||
# {{{ onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect)
|
# {{{ 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
|
return False, False
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# {{{ 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
|
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
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||||
|
@ -11,7 +11,7 @@ class ToolCircle(Tool):
|
|||||||
|
|
||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# 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
|
brushColours, dirty = brushColours.copy(), False
|
||||||
if mouseLeftDown:
|
if mouseLeftDown:
|
||||||
brushColours[1] = brushColours[0]
|
brushColours[1] = brushColours[0]
|
||||||
|
@ -11,14 +11,14 @@ class ToolFill(Tool):
|
|||||||
|
|
||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# 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, pointsDone, pointStack, testColour, = False, [], [list(mapPoint)], self.parentCanvas.canvas.map[mapPoint[1]][mapPoint[0]][0:2]
|
dirty, pointsDone, pointStack, testColour, = False, [], [list(mapPoint)], canvas.map[mapPoint[1]][mapPoint[0]][0:2]
|
||||||
if mouseLeftDown or mouseRightDown:
|
if mouseLeftDown or mouseRightDown:
|
||||||
if mouseRightDown:
|
if mouseRightDown:
|
||||||
brushColours = [brushColours[1], brushColours[0]]
|
brushColours = [brushColours[1], brushColours[0]]
|
||||||
while len(pointStack) > 0:
|
while len(pointStack) > 0:
|
||||||
point = pointStack.pop()
|
point = pointStack.pop()
|
||||||
pointCell = self.parentCanvas.canvas.map[point[1]][point[0]]
|
pointCell = canvas.map[point[1]][point[0]]
|
||||||
if (pointCell[0:2] == testColour) \
|
if (pointCell[0:2] == testColour) \
|
||||||
or ((pointCell[3] == " ") and (pointCell[1] == testColour[1])):
|
or ((pointCell[3] == " ") and (pointCell[1] == testColour[1])):
|
||||||
if not point in pointsDone:
|
if not point in pointsDone:
|
||||||
@ -27,11 +27,11 @@ class ToolFill(Tool):
|
|||||||
dispatchFn(eventDc, False, [*point, brushColours[0], brushColours[0], 0, " "], viewRect)
|
dispatchFn(eventDc, False, [*point, brushColours[0], brushColours[0], 0, " "], viewRect)
|
||||||
if point[0] > 0:
|
if point[0] > 0:
|
||||||
pointStack.append([point[0] - 1, point[1]])
|
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]])
|
pointStack.append([point[0] + 1, point[1]])
|
||||||
if point[1] > 0:
|
if point[1] > 0:
|
||||||
pointStack.append([point[0], point[1] - 1])
|
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])
|
pointStack.append([point[0], point[1] + 1])
|
||||||
pointsDone += [point]
|
pointsDone += [point]
|
||||||
else:
|
else:
|
||||||
|
@ -52,7 +52,7 @@ class ToolLine(Tool):
|
|||||||
|
|
||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# 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
|
brushColours, dirty = brushColours.copy(), False
|
||||||
if mouseLeftDown:
|
if mouseLeftDown:
|
||||||
brushColours[1] = brushColours[0]
|
brushColours[1] = brushColours[0]
|
||||||
|
@ -11,7 +11,7 @@ class ToolRect(Tool):
|
|||||||
|
|
||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# 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
|
brushColours, dirty = brushColours.copy(), False
|
||||||
if mouseLeftDown:
|
if mouseLeftDown:
|
||||||
brushColours[1] = brushColours[0]
|
brushColours[1] = brushColours[0]
|
||||||
|
@ -65,7 +65,7 @@ class ToolSelect(Tool):
|
|||||||
self.toolSelectMap.append([])
|
self.toolSelectMap.append([])
|
||||||
for numCol in range((self.targetRect[1][0] - self.targetRect[0][0]) + 1):
|
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
|
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)
|
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
|
||||||
elif mouseRightDown:
|
elif mouseRightDown:
|
||||||
self.targetRect, self.toolState = None, self.TS_NONE
|
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)
|
# 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
|
dirty = False
|
||||||
if self.toolState == self.TS_NONE:
|
if self.toolState == self.TS_NONE:
|
||||||
dirty = self._mouseEventTsNone(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
dirty = self._mouseEventTsNone(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
|
@ -12,7 +12,7 @@ class ToolText(Tool):
|
|||||||
|
|
||||||
#
|
#
|
||||||
# onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect)
|
# 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
|
dirty = False
|
||||||
if not keyModifiers in (wx.MOD_NONE, wx.MOD_SHIFT):
|
if not keyModifiers in (wx.MOD_NONE, wx.MOD_SHIFT):
|
||||||
return False
|
return False
|
||||||
@ -22,9 +22,9 @@ class ToolText(Tool):
|
|||||||
if not dirty:
|
if not dirty:
|
||||||
dirty = True
|
dirty = True
|
||||||
dispatchFn(eventDc, False, [*self.textPos, *brushColours, 0, keyChar], viewRect)
|
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
|
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;
|
self.textPos[0] = 0; self.textPos[1] += 1;
|
||||||
else:
|
else:
|
||||||
self.textPos = [0, 0]
|
self.textPos = [0, 0]
|
||||||
@ -32,7 +32,7 @@ class ToolText(Tool):
|
|||||||
|
|
||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# 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:
|
if mouseLeftDown or mouseRightDown:
|
||||||
self.textPos = list(mapPoint)
|
self.textPos = list(mapPoint)
|
||||||
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, "_"], viewRect)
|
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, "_"], viewRect)
|
||||||
|
Loading…
Reference in New Issue
Block a user