From b3f587fc7307c80072e3840d8f3e950042706298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Mon, 9 Sep 2019 18:18:54 +0200 Subject: [PATCH] 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. --- libgui/GuiCanvasInterface.py | 3 ++ libgui/GuiCanvasPanel.py | 41 ++++++++------ libtools/Tool.py | 12 ++--- libtools/ToolCircle.py | 15 +++--- libtools/ToolFill.py | 16 +++--- libtools/ToolLine.py | 27 +++++----- libtools/ToolRect.py | 13 ++--- libtools/ToolSelect.py | 101 ++++++++++++++++++----------------- libtools/ToolSelectClone.py | 5 +- libtools/ToolSelectMove.py | 5 +- libtools/ToolText.py | 25 +++++---- 11 files changed, 145 insertions(+), 118 deletions(-) diff --git a/libgui/GuiCanvasInterface.py b/libgui/GuiCanvasInterface.py index e66ec60..d6b23a8 100644 --- a/libgui/GuiCanvasInterface.py +++ b/libgui/GuiCanvasInterface.py @@ -331,6 +331,9 @@ class GuiCanvasInterface(): toolBar = self.parentFrame.toolBarItemsById[self.canvasTool.attrList[idx]["id"]].GetToolBar() toolBar.ToggleTool(self.canvasTool.attrList[idx]["id"], True) self.update(toolName=self.currentTool.name) + viewRect = self.parentCanvas.GetViewStart() + eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas, viewRect) + self.parentCanvas.applyTool(eventDc, wx.wxEVT_MOTION, None, None, self.parentCanvas.brushPos, False, False, False, self.currentTool, viewRect) setattr(canvasTool_, "attrDict", f.attrList[idx]) setattr(canvasTool_, "isSelect", True) return canvasTool_ diff --git a/libgui/GuiCanvasPanel.py b/libgui/GuiCanvasPanel.py index 0afe743..94edefc 100644 --- a/libgui/GuiCanvasPanel.py +++ b/libgui/GuiCanvasPanel.py @@ -28,6 +28,24 @@ class GuiCanvasPanel(wx.ScrolledWindow): self.scrollFlag = False; super().SetVirtualSize((0, 0)); # }}} + # {{{ applyTool(self, eventDc, eventType, keyChar, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, tool, viewRect) + def applyTool(self, eventDc, eventType, keyChar, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, tool, viewRect): + rc = False + self.canvas.dirtyJournal, self.canvas.dirtyCursor, rc = False, False, False + if eventType == wx.wxEVT_CHAR: + rc = tool.onKeyboardEvent(self.brushColours, self.brushSize, self.dispatchPatch, eventDc, keyChar, keyModifiers, self.brushPos, viewRect) + else: + if (mapPoint[0] < self.canvas.size[0]) \ + and (mapPoint[1] < self.canvas.size[1]): + self.brushPos = mapPoint + rc = tool.onMouseEvent(self.brushColours, self.brushSize, self.dispatchPatch, eventDc, self.brushPos, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + if self.canvas.dirtyJournal: + self.dirty = True + self.interface.update(dirty=self.dirty, cellPos=self.brushPos, undoLevel=self.canvas.journal.patchesUndoLevel) + if eventType == wx.wxEVT_MOTION: + self.interface.update(cellPos=mapPoint) + return rc + # }}} # {{{ dispatchDeltaPatches(self, deltaPatches) def dispatchDeltaPatches(self, deltaPatches): eventDc = self.backend.getDeviceContext(self, self.GetViewStart()) @@ -82,24 +100,17 @@ class GuiCanvasPanel(wx.ScrolledWindow): # }}} # {{{ onPanelInput(self, event) def onPanelInput(self, event): - self.canvas.dirtyJournal, self.canvas.dirtyCursor = False, False - eventType, tool, viewRect = event.GetEventType(), self.interface.currentTool, self.GetViewStart() - eventDc = self.backend.getDeviceContext(self, self.GetViewStart()) + eventType, viewRect = event.GetEventType(), self.GetViewStart() + eventDc = self.backend.getDeviceContext(self, viewRect) if eventType == wx.wxEVT_CHAR: - mapPoint = self.brushPos - if tool.onKeyboardEvent(event, mapPoint, self.brushColours, self.brushSize, chr(event.GetUnicodeKey()), self.dispatchPatch, eventDc, viewRect): - event.Skip(); return; + keyChar, keyModifiers = chr(event.GetUnicodeKey()), event.GetModifiers() + mapPoint, mouseDragging, mouseLeftDown, mouseRightDown = None, None, None, None else: + keyChar, keyModifiers = None, None + mouseDragging, mouseLeftDown, mouseRightDown = event.Dragging(), event.LeftIsDown(), event.RightIsDown() mapPoint = self.backend.xlateEventPoint(event, eventDc, viewRect) - if (mapPoint[0] < self.canvas.size[0]) \ - and (mapPoint[1] < self.canvas.size[1]): - self.brushPos = mapPoint - tool.onMouseEvent(event, self.brushPos, self.brushColours, self.brushSize, event.Dragging(), event.LeftIsDown(), event.RightIsDown(), self.dispatchPatch, eventDc, viewRect) - if self.canvas.dirtyJournal: - self.dirty = True - self.interface.update(dirty=self.dirty, cellPos=self.brushPos, undoLevel=self.canvas.journal.patchesUndoLevel) - if eventType == wx.wxEVT_MOTION: - self.interface.update(cellPos=mapPoint) + if not self.applyTool(eventDc, eventType, keyChar, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, self.interface.currentTool, self.GetViewStart()): + event.Skip() # }}} # {{{ onPanelLeaveWindow(self, event) def onPanelLeaveWindow(self, event): diff --git a/libtools/Tool.py b/libtools/Tool.py index 3c5029c..84c3a62 100644 --- a/libtools/Tool.py +++ b/libtools/Tool.py @@ -7,13 +7,13 @@ class Tool(): parentCanvas = None - # {{{ onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc, viewRect): - def onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc, viewRect): - return True + # {{{ onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect): + def onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect): + pass # }}} - # {{{ onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect) - def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): - return () + # {{{ onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + pass # }}} # diff --git a/libtools/ToolCircle.py b/libtools/ToolCircle.py index 3ebf68f..6050de2 100644 --- a/libtools/ToolCircle.py +++ b/libtools/ToolCircle.py @@ -10,12 +10,12 @@ class ToolCircle(Tool): name = "Circle" # - # onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect) - def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): + # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): brushColours = brushColours.copy() - if isLeftDown: + if mouseLeftDown: brushColours[1] = brushColours[0] - elif isRightDown: + elif mouseRightDown: brushColours[0] = brushColours[1] else: brushColours[1] = brushColours[0] @@ -25,12 +25,13 @@ class ToolCircle(Tool): for brushX in range(-radius, radius + 1): if ((brushX ** 2) + (brushY ** 2) < (((radius ** 2) + radius) * 0.8)): patch = [ \ - atPoint[0] + int(originPoint[0] + brushX), \ - atPoint[1] + int(originPoint[1] + brushY), \ + mapPoint[0] + int(originPoint[0] + brushX), \ + mapPoint[1] + int(originPoint[1] + brushY), \ *brushColours, 0, " "] - if isLeftDown or isRightDown: + if mouseLeftDown or mouseRightDown: dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect); else: dispatchFn(eventDc, True, patch, viewRect) + return True # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/libtools/ToolFill.py b/libtools/ToolFill.py index 05654f0..72d7da2 100644 --- a/libtools/ToolFill.py +++ b/libtools/ToolFill.py @@ -10,12 +10,12 @@ class ToolFill(Tool): name = "Fill" # - # onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect) - def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): - pointStack, pointsDone = [list(atPoint)], [] - testColour = self.parentCanvas.canvas.map[atPoint[1]][atPoint[0]][0:2] - if isLeftDown or isRightDown: - if isRightDown: + # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + pointStack, pointsDone = [list(mapPoint)], [] + testColour = self.parentCanvas.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() @@ -33,5 +33,9 @@ class ToolFill(Tool): if point[1] < (self.parentCanvas.canvas.size[1] - 1): pointStack.append([point[0], point[1] + 1]) pointsDone += [point] + else: + patch = [mapPoint[0], mapPoint[1], brushColours[0], brushColours[0], 0, " "] + dispatchFn(eventDc, True, patch, viewRect) + return True # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/libtools/ToolLine.py b/libtools/ToolLine.py index 82b201f..8bd1829 100644 --- a/libtools/ToolLine.py +++ b/libtools/ToolLine.py @@ -11,8 +11,8 @@ class ToolLine(Tool): TS_NONE = 0 TS_ORIGIN = 1 - # {{{ _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint) - def _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint): + # {{{ _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint, viewRect) + def _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint, viewRect): originPoint, targetPoint = originPoint.copy(), targetPoint.copy() pointDelta = self._pointDelta(originPoint, targetPoint) lineXSign = 1 if pointDelta[0] > 0 else -1; lineYSign = 1 if pointDelta[1] > 0 else -1; @@ -47,24 +47,27 @@ class ToolLine(Tool): # }}} # - # onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect) - def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): + # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): brushColours = brushColours.copy() - if isLeftDown: + if mouseLeftDown: brushColours[1] = brushColours[0] - elif isRightDown: + elif mouseRightDown: brushColours[0] = brushColours[1] else: brushColours[1] = brushColours[0] if self.toolState == self.TS_NONE: - if isLeftDown or isRightDown: - self.toolColours, self.toolOriginPoint, self.toolState = brushColours, list(atPoint), self.TS_ORIGIN - dispatchFn(eventDc, True, [*atPoint, *brushColours, 0, " "], viewRect) + if mouseLeftDown or mouseRightDown: + self.toolColours, self.toolOriginPoint, self.toolState = brushColours, list(mapPoint), self.TS_ORIGIN + dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect) elif self.toolState == self.TS_ORIGIN: - originPoint, targetPoint = self.toolOriginPoint, list(atPoint) - self._getLine(self.toolColours, brushSize, dispatchFn, eventDc, isLeftDown or isRightDown, originPoint, targetPoint) - if isLeftDown or isRightDown: + originPoint, targetPoint = self.toolOriginPoint, list(mapPoint) + self._getLine(self.toolColours, brushSize, dispatchFn, eventDc, mouseLeftDown or mouseRightDown, originPoint, targetPoint, viewRect) + if mouseLeftDown or mouseRightDown: self.toolColours, self.toolOriginPoint, self.toolState = None, None, self.TS_NONE + else: + return False + return True # __init__(self, *args): initialisation method def __init__(self, *args): diff --git a/libtools/ToolRect.py b/libtools/ToolRect.py index d086a2c..4f17797 100644 --- a/libtools/ToolRect.py +++ b/libtools/ToolRect.py @@ -10,12 +10,12 @@ class ToolRect(Tool): name = "Rectangle" # - # onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect) - def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): + # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): brushColours = brushColours.copy() - if isLeftDown: + if mouseLeftDown: brushColours[1] = brushColours[0] - elif isRightDown: + elif mouseRightDown: brushColours[0] = brushColours[1] else: brushColours[1] = brushColours[0] @@ -24,10 +24,11 @@ class ToolRect(Tool): brushSize[0] *= 2 for brushRow in range(brushSize[1]): for brushCol in range(brushSize[0]): - patch = [atPoint[0] + brushCol, atPoint[1] + brushRow, *brushColours, 0, " "] - if isLeftDown or isRightDown: + patch = [mapPoint[0] + brushCol, mapPoint[1] + brushRow, *brushColours, 0, " "] + if mouseLeftDown or mouseRightDown: dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect); else: dispatchFn(eventDc, True, patch, viewRect) + return True # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/libtools/ToolSelect.py b/libtools/ToolSelect.py index 886ef7e..1ec9e34 100644 --- a/libtools/ToolSelect.py +++ b/libtools/ToolSelect.py @@ -12,22 +12,22 @@ class ToolSelect(Tool): TS_SELECT = 2 TS_TARGET = 3 - # {{{ _dispatchSelectEvent(self, atPoint, dispatchFn, eventDc, isLeftDown, isRightDown, selectRect) - def _dispatchSelectEvent(self, atPoint, dispatchFn, eventDc, isLeftDown, isRightDown, selectRect): - if isLeftDown: - disp, isCursor = [atPoint[m] - self.lastAtPoint[m] for m in [0, 1]], True + # {{{ _dispatchSelectEvent(self, mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, selectRect, viewRect) + def _dispatchSelectEvent(self, mapPoint, dispatchFn, eventDc, 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(atPoint) - elif isRightDown: + self.lastAtPoint = list(mapPoint) + elif mouseRightDown: disp, isCursor, newTargetRect = [0, 0], False, selectRect.copy() else: disp, isCursor, newTargetRect = [0, 0], True, selectRect.copy() - self.onSelectEvent(disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect) - self._drawSelectRect(newTargetRect, dispatchFn, eventDc) + self.onSelectEvent(disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect) + self._drawSelectRect(newTargetRect, dispatchFn, eventDc, viewRect) self.targetRect = newTargetRect # }}} - # {{{ _drawSelectRect(self, rect, dispatchFn, eventDc) - def _drawSelectRect(self, rect, dispatchFn, eventDc): + # {{{ _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] @@ -43,75 +43,78 @@ class ToolSelect(Tool): dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "], viewRect) dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "], viewRect) # }}} - # {{{ _mouseEventTsNone(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown) - def _mouseEventTsNone(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown): - if isLeftDown: - self.targetRect, self.toolState = [list(atPoint), []], self.TS_ORIGIN + # {{{ _mouseEventTsNone(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def _mouseEventTsNone(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + if mouseLeftDown: + self.targetRect, self.toolState = [list(mapPoint), []], self.TS_ORIGIN else: - dispatchFn(eventDc, True, [*atPoint, *brushColours, 0, " "], viewRect) + dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect) # }}} - # {{{ _mouseEventTsOrigin(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown) - def _mouseEventTsOrigin(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown): - if isLeftDown: - self.targetRect[1] = list(atPoint) + # {{{ _mouseEventTsOrigin(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def _mouseEventTsOrigin(self, mapPoint, brushColours, dispatchFn, eventDc, 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.srcRect, self.lastAtPoint, self.toolSelectMap, self.toolState = self.targetRect[0], list(atPoint), [], self.TS_SELECT + self.srcRect, self.lastAtPoint, self.toolSelectMap, self.toolState = self.targetRect[0], list(mapPoint), [], 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(self.parentCanvas.canvas.map[rectY][rectX]) - self._drawSelectRect(self.targetRect, dispatchFn, eventDc) - elif isRightDown: + self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect) + elif mouseRightDown: self.targetRect, self.toolState = None, self.TS_NONE else: - self.targetRect[1] = list(atPoint) - self._drawSelectRect(self.targetRect, dispatchFn, eventDc) + self.targetRect[1] = list(mapPoint) + self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect) # }}} - # {{{ _mouseEventTsSelect(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown) - def _mouseEventTsSelect(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown): - if isLeftDown \ - and (atPoint[0] >= (self.targetRect[0][0] - 1)) \ - and (atPoint[0] <= (self.targetRect[1][0] + 1)) \ - and (atPoint[1] >= (self.targetRect[0][1] - 1)) \ - and (atPoint[1] <= (self.targetRect[1][1] + 1)): - self.lastAtPoint, self.toolState = list(atPoint), self.TS_TARGET - elif isRightDown: - self._dispatchSelectEvent(atPoint, dispatchFn, eventDc, isLeftDown, isRightDown, self.targetRect) + # {{{ _mouseEventTsSelect(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def _mouseEventTsSelect(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + 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: + self._dispatchSelectEvent(mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) self.targetRect, self.toolState = None, self.TS_NONE else: - self._dispatchSelectEvent(atPoint, dispatchFn, eventDc, isLeftDown, isRightDown, self.targetRect) + self._dispatchSelectEvent(mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) # }}} - # {{{ _mouseEventTsTarget(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown) - def _mouseEventTsTarget(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown): - if isLeftDown: + # {{{ _mouseEventTsTarget(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def _mouseEventTsTarget(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + if mouseLeftDown: self.toolState = self.TS_TARGET - self._dispatchSelectEvent(atPoint, dispatchFn, eventDc, isLeftDown, isRightDown, self.targetRect) - elif isRightDown: - self._dispatchSelectEvent(atPoint, dispatchFn, eventDc, isLeftDown, isRightDown, self.targetRect) + self._dispatchSelectEvent(mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) + elif mouseRightDown: + self._dispatchSelectEvent(mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) self.targetRect, self.toolState = None, self.TS_NONE else: self.toolState = self.TS_SELECT # }}} # - # onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect) - def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): + # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): if self.toolState == self.TS_NONE: - self._mouseEventTsNone(atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown) + self._mouseEventTsNone(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) elif self.toolState == self.TS_ORIGIN: - self._mouseEventTsOrigin(atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown) + self._mouseEventTsOrigin(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) elif self.toolState == self.TS_SELECT: - self._mouseEventTsSelect(atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown) + self._mouseEventTsSelect(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) elif self.toolState == self.TS_TARGET: - self._mouseEventTsTarget(atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown) + self._mouseEventTsTarget(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + else: + return False + return True # - # onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect) - def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect): + # 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 diff --git a/libtools/ToolSelectClone.py b/libtools/ToolSelectClone.py index 56415d3..bd853fa 100644 --- a/libtools/ToolSelectClone.py +++ b/libtools/ToolSelectClone.py @@ -10,12 +10,13 @@ class ToolSelectClone(ToolSelect): name = "Clone selection" # - # onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect) - def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect): + # onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect) + def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, 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 dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect) + return True # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/libtools/ToolSelectMove.py b/libtools/ToolSelectMove.py index 828854c..ad3cd85 100644 --- a/libtools/ToolSelectMove.py +++ b/libtools/ToolSelectMove.py @@ -10,8 +10,8 @@ class ToolSelectMove(ToolSelect): name = "Move selection" # - # onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect) - def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect): + # onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect) + def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect): for numRow in range(len(self.toolSelectMap)): for numCol in range(len(self.toolSelectMap[numRow])): dispatchFn(eventDc, isCursor, [self.srcRect[0] + numCol, self.srcRect[1] + numRow, 1, 1, 0, " "], viewRect) @@ -20,5 +20,6 @@ class ToolSelectMove(ToolSelect): cellOld = self.toolSelectMap[numRow][numCol] rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect) + return True # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/libtools/ToolText.py b/libtools/ToolText.py index ccaa3a8..1051853 100644 --- a/libtools/ToolText.py +++ b/libtools/ToolText.py @@ -11,15 +11,13 @@ class ToolText(Tool): name = "Text" # - # onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc, viewRect) - def onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc, viewRect): - keyModifiers = event.GetModifiers() - if keyModifiers != wx.MOD_NONE \ - and keyModifiers != wx.MOD_SHIFT: - return True + # onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect) + def onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect): + if not keyModifiers in (wx.MOD_NONE, wx.MOD_SHIFT): + return False else: if self.textPos == None: - self.textPos = list(atPoint) + self.textPos = list(mapPoint) dispatchFn(eventDc, False, [*self.textPos, *brushColours, 0, keyChar], viewRect) if self.textPos[0] < (self.parentCanvas.canvas.size[0] - 1): self.textPos[0] += 1 @@ -27,14 +25,15 @@ class ToolText(Tool): self.textPos[0] = 0; self.textPos[1] += 1; else: self.textPos = [0, 0] - return False + return True # - # onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect) - def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): - if isLeftDown or isRightDown: - self.textPos = list(atPoint) - dispatchFn(eventDc, True, [*atPoint, *brushColours, 0, "_"], viewRect) + # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) + def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): + if mouseLeftDown or mouseRightDown: + self.textPos = list(mapPoint) + dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, "_"], viewRect) + return True # __init__(self, *args): initialisation method def __init__(self, *args):