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.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2019-09-09 18:18:54 +02:00
parent dc84921d47
commit d342a9d804
11 changed files with 145 additions and 118 deletions

View File

@ -331,6 +331,9 @@ class GuiCanvasInterface():
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)
self.update(toolName=self.currentTool.name) 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_, "attrDict", f.attrList[idx])
setattr(canvasTool_, "isSelect", True) setattr(canvasTool_, "isSelect", True)
return canvasTool_ return canvasTool_

View File

@ -28,6 +28,24 @@ class GuiCanvasPanel(wx.ScrolledWindow):
self.scrollFlag = False; super().SetVirtualSize((0, 0)); 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) # {{{ dispatchDeltaPatches(self, deltaPatches)
def dispatchDeltaPatches(self, deltaPatches): def dispatchDeltaPatches(self, deltaPatches):
eventDc = self.backend.getDeviceContext(self, self.GetViewStart()) eventDc = self.backend.getDeviceContext(self, self.GetViewStart())
@ -82,24 +100,17 @@ class GuiCanvasPanel(wx.ScrolledWindow):
# }}} # }}}
# {{{ onPanelInput(self, event) # {{{ onPanelInput(self, event)
def onPanelInput(self, event): def onPanelInput(self, event):
self.canvas.dirtyJournal, self.canvas.dirtyCursor = False, False eventType, viewRect = event.GetEventType(), self.GetViewStart()
eventType, tool, viewRect = event.GetEventType(), self.interface.currentTool, self.GetViewStart() eventDc = self.backend.getDeviceContext(self, viewRect)
eventDc = self.backend.getDeviceContext(self, self.GetViewStart())
if eventType == wx.wxEVT_CHAR: if eventType == wx.wxEVT_CHAR:
mapPoint = self.brushPos keyChar, keyModifiers = chr(event.GetUnicodeKey()), event.GetModifiers()
if tool.onKeyboardEvent(event, mapPoint, self.brushColours, self.brushSize, chr(event.GetUnicodeKey()), self.dispatchPatch, eventDc, viewRect): mapPoint, mouseDragging, mouseLeftDown, mouseRightDown = None, None, None, None
event.Skip(); return;
else: else:
keyChar, keyModifiers = None, None
mouseDragging, mouseLeftDown, mouseRightDown = event.Dragging(), event.LeftIsDown(), event.RightIsDown()
mapPoint = self.backend.xlateEventPoint(event, eventDc, viewRect) mapPoint = self.backend.xlateEventPoint(event, eventDc, viewRect)
if (mapPoint[0] < self.canvas.size[0]) \ if not self.applyTool(eventDc, eventType, keyChar, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, self.interface.currentTool, self.GetViewStart()):
and (mapPoint[1] < self.canvas.size[1]): event.Skip()
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)
# }}} # }}}
# {{{ onPanelLeaveWindow(self, event) # {{{ onPanelLeaveWindow(self, event)
def onPanelLeaveWindow(self, event): def onPanelLeaveWindow(self, event):

View File

@ -7,13 +7,13 @@
class Tool(): class Tool():
parentCanvas = None parentCanvas = None
# {{{ onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc, viewRect): # {{{ onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect):
def onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc, viewRect): def onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect):
return True pass
# }}} # }}}
# {{{ 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, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
return () pass
# }}} # }}}
# #

View File

@ -10,12 +10,12 @@ class ToolCircle(Tool):
name = "Circle" name = "Circle"
# #
# 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, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
brushColours = brushColours.copy() brushColours = brushColours.copy()
if isLeftDown: if mouseLeftDown:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
elif isRightDown: elif mouseRightDown:
brushColours[0] = brushColours[1] brushColours[0] = brushColours[1]
else: else:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
@ -25,12 +25,13 @@ class ToolCircle(Tool):
for brushX in range(-radius, radius + 1): for brushX in range(-radius, radius + 1):
if ((brushX ** 2) + (brushY ** 2) < (((radius ** 2) + radius) * 0.8)): if ((brushX ** 2) + (brushY ** 2) < (((radius ** 2) + radius) * 0.8)):
patch = [ \ patch = [ \
atPoint[0] + int(originPoint[0] + brushX), \ mapPoint[0] + int(originPoint[0] + brushX), \
atPoint[1] + int(originPoint[1] + brushY), \ mapPoint[1] + int(originPoint[1] + brushY), \
*brushColours, 0, " "] *brushColours, 0, " "]
if isLeftDown or isRightDown: if mouseLeftDown or mouseRightDown:
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect); dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect);
else: else:
dispatchFn(eventDc, True, patch, viewRect) dispatchFn(eventDc, True, patch, viewRect)
return True
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -10,12 +10,12 @@ class ToolFill(Tool):
name = "Fill" name = "Fill"
# #
# 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, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
pointStack, pointsDone = [list(atPoint)], [] pointStack, pointsDone = [list(mapPoint)], []
testColour = self.parentCanvas.canvas.map[atPoint[1]][atPoint[0]][0:2] testColour = self.parentCanvas.canvas.map[mapPoint[1]][mapPoint[0]][0:2]
if isLeftDown or isRightDown: if mouseLeftDown or mouseRightDown:
if isRightDown: 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()
@ -33,5 +33,9 @@ class ToolFill(Tool):
if point[1] < (self.parentCanvas.canvas.size[1] - 1): if point[1] < (self.parentCanvas.canvas.size[1] - 1):
pointStack.append([point[0], point[1] + 1]) pointStack.append([point[0], point[1] + 1])
pointsDone += [point] 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 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -11,8 +11,8 @@ class ToolLine(Tool):
TS_NONE = 0 TS_NONE = 0
TS_ORIGIN = 1 TS_ORIGIN = 1
# {{{ _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): def _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint, viewRect):
originPoint, targetPoint = originPoint.copy(), targetPoint.copy() originPoint, targetPoint = originPoint.copy(), targetPoint.copy()
pointDelta = self._pointDelta(originPoint, targetPoint) pointDelta = self._pointDelta(originPoint, targetPoint)
lineXSign = 1 if pointDelta[0] > 0 else -1; lineYSign = 1 if pointDelta[1] > 0 else -1; 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) # onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
brushColours = brushColours.copy() brushColours = brushColours.copy()
if isLeftDown: if mouseLeftDown:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
elif isRightDown: elif mouseRightDown:
brushColours[0] = brushColours[1] brushColours[0] = brushColours[1]
else: else:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
if self.toolState == self.TS_NONE: if self.toolState == self.TS_NONE:
if isLeftDown or isRightDown: if mouseLeftDown or mouseRightDown:
self.toolColours, self.toolOriginPoint, self.toolState = brushColours, list(atPoint), self.TS_ORIGIN self.toolColours, self.toolOriginPoint, self.toolState = brushColours, list(mapPoint), self.TS_ORIGIN
dispatchFn(eventDc, True, [*atPoint, *brushColours, 0, " "], viewRect) dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect)
elif self.toolState == self.TS_ORIGIN: elif self.toolState == self.TS_ORIGIN:
originPoint, targetPoint = self.toolOriginPoint, list(atPoint) originPoint, targetPoint = self.toolOriginPoint, list(mapPoint)
self._getLine(self.toolColours, brushSize, dispatchFn, eventDc, isLeftDown or isRightDown, originPoint, targetPoint) self._getLine(self.toolColours, brushSize, dispatchFn, eventDc, mouseLeftDown or mouseRightDown, originPoint, targetPoint, viewRect)
if isLeftDown or isRightDown: if mouseLeftDown or mouseRightDown:
self.toolColours, self.toolOriginPoint, self.toolState = None, None, self.TS_NONE self.toolColours, self.toolOriginPoint, self.toolState = None, None, self.TS_NONE
else:
return False
return True
# __init__(self, *args): initialisation method # __init__(self, *args): initialisation method
def __init__(self, *args): def __init__(self, *args):

View File

@ -10,12 +10,12 @@ class ToolRect(Tool):
name = "Rectangle" name = "Rectangle"
# #
# 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, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
brushColours = brushColours.copy() brushColours = brushColours.copy()
if isLeftDown: if mouseLeftDown:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
elif isRightDown: elif mouseRightDown:
brushColours[0] = brushColours[1] brushColours[0] = brushColours[1]
else: else:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
@ -24,10 +24,11 @@ class ToolRect(Tool):
brushSize[0] *= 2 brushSize[0] *= 2
for brushRow in range(brushSize[1]): for brushRow in range(brushSize[1]):
for brushCol in range(brushSize[0]): for brushCol in range(brushSize[0]):
patch = [atPoint[0] + brushCol, atPoint[1] + brushRow, *brushColours, 0, " "] patch = [mapPoint[0] + brushCol, mapPoint[1] + brushRow, *brushColours, 0, " "]
if isLeftDown or isRightDown: if mouseLeftDown or mouseRightDown:
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect); dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect);
else: else:
dispatchFn(eventDc, True, patch, viewRect) dispatchFn(eventDc, True, patch, viewRect)
return True
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -12,22 +12,22 @@ class ToolSelect(Tool):
TS_SELECT = 2 TS_SELECT = 2
TS_TARGET = 3 TS_TARGET = 3
# {{{ _dispatchSelectEvent(self, atPoint, dispatchFn, eventDc, isLeftDown, isRightDown, selectRect) # {{{ _dispatchSelectEvent(self, mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, selectRect, viewRect)
def _dispatchSelectEvent(self, atPoint, dispatchFn, eventDc, isLeftDown, isRightDown, selectRect): def _dispatchSelectEvent(self, mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, selectRect, viewRect):
if isLeftDown: if mouseLeftDown:
disp, isCursor = [atPoint[m] - self.lastAtPoint[m] for m in [0, 1]], True 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]] newTargetRect = [[selectRect[n][m] + disp[m] for m in [0, 1]] for n in [0, 1]]
self.lastAtPoint = list(atPoint) self.lastAtPoint = list(mapPoint)
elif isRightDown: elif mouseRightDown:
disp, isCursor, newTargetRect = [0, 0], False, selectRect.copy() disp, isCursor, newTargetRect = [0, 0], False, selectRect.copy()
else: else:
disp, isCursor, newTargetRect = [0, 0], True, selectRect.copy() disp, isCursor, newTargetRect = [0, 0], True, selectRect.copy()
self.onSelectEvent(disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect) self.onSelectEvent(disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect)
self._drawSelectRect(newTargetRect, dispatchFn, eventDc) self._drawSelectRect(newTargetRect, dispatchFn, eventDc, viewRect)
self.targetRect = newTargetRect self.targetRect = newTargetRect
# }}} # }}}
# {{{ _drawSelectRect(self, rect, dispatchFn, eventDc) # {{{ _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect)
def _drawSelectRect(self, rect, dispatchFn, eventDc): 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]]] 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]: if rectFrame[0][0] > rectFrame[1][0]:
rectFrame[0][0], rectFrame[1][0] = rectFrame[1][0], rectFrame[0][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[0][0], rectY, *curColours, 0, " "], viewRect)
dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "], viewRect) dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "], viewRect)
# }}} # }}}
# {{{ _mouseEventTsNone(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown) # {{{ _mouseEventTsNone(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
def _mouseEventTsNone(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown): def _mouseEventTsNone(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
if isLeftDown: if mouseLeftDown:
self.targetRect, self.toolState = [list(atPoint), []], self.TS_ORIGIN self.targetRect, self.toolState = [list(mapPoint), []], self.TS_ORIGIN
else: else:
dispatchFn(eventDc, True, [*atPoint, *brushColours, 0, " "], viewRect) dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect)
# }}} # }}}
# {{{ _mouseEventTsOrigin(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown) # {{{ _mouseEventTsOrigin(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
def _mouseEventTsOrigin(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown): def _mouseEventTsOrigin(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
if isLeftDown: if mouseLeftDown:
self.targetRect[1] = list(atPoint) self.targetRect[1] = list(mapPoint)
if self.targetRect[0][0] > self.targetRect[1][0]: 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] 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]: 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.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): for numRow in range((self.targetRect[1][1] - self.targetRect[0][1]) + 1):
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(self.parentCanvas.canvas.map[rectY][rectX])
self._drawSelectRect(self.targetRect, dispatchFn, eventDc) self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
elif isRightDown: elif mouseRightDown:
self.targetRect, self.toolState = None, self.TS_NONE self.targetRect, self.toolState = None, self.TS_NONE
else: else:
self.targetRect[1] = list(atPoint) self.targetRect[1] = list(mapPoint)
self._drawSelectRect(self.targetRect, dispatchFn, eventDc) self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
# }}} # }}}
# {{{ _mouseEventTsSelect(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown) # {{{ _mouseEventTsSelect(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
def _mouseEventTsSelect(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown): def _mouseEventTsSelect(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
if isLeftDown \ if mouseLeftDown \
and (atPoint[0] >= (self.targetRect[0][0] - 1)) \ and (mapPoint[0] >= (self.targetRect[0][0] - 1)) \
and (atPoint[0] <= (self.targetRect[1][0] + 1)) \ and (mapPoint[0] <= (self.targetRect[1][0] + 1)) \
and (atPoint[1] >= (self.targetRect[0][1] - 1)) \ and (mapPoint[1] >= (self.targetRect[0][1] - 1)) \
and (atPoint[1] <= (self.targetRect[1][1] + 1)): and (mapPoint[1] <= (self.targetRect[1][1] + 1)):
self.lastAtPoint, self.toolState = list(atPoint), self.TS_TARGET self.lastAtPoint, self.toolState = list(mapPoint), self.TS_TARGET
elif isRightDown: elif mouseRightDown:
self._dispatchSelectEvent(atPoint, dispatchFn, eventDc, isLeftDown, isRightDown, self.targetRect) self._dispatchSelectEvent(mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
self.targetRect, self.toolState = None, self.TS_NONE self.targetRect, self.toolState = None, self.TS_NONE
else: 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) # {{{ _mouseEventTsTarget(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
def _mouseEventTsTarget(self, atPoint, brushColours, dispatchFn, eventDc, isDragging, isLeftDown, isRightDown): def _mouseEventTsTarget(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
if isLeftDown: if mouseLeftDown:
self.toolState = self.TS_TARGET self.toolState = self.TS_TARGET
self._dispatchSelectEvent(atPoint, dispatchFn, eventDc, isLeftDown, isRightDown, self.targetRect) self._dispatchSelectEvent(mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
elif isRightDown: elif mouseRightDown:
self._dispatchSelectEvent(atPoint, dispatchFn, eventDc, isLeftDown, isRightDown, self.targetRect) self._dispatchSelectEvent(mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
self.targetRect, self.toolState = None, self.TS_NONE self.targetRect, self.toolState = None, self.TS_NONE
else: else:
self.toolState = self.TS_SELECT self.toolState = self.TS_SELECT
# }}} # }}}
# #
# 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, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
if self.toolState == self.TS_NONE: 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: 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: 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: 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) # onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect)
def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect): def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect):
pass pass
# __init__(self, *args): initialisation method # __init__(self, *args): initialisation method

View File

@ -10,12 +10,13 @@ class ToolSelectClone(ToolSelect):
name = "Clone selection" name = "Clone selection"
# #
# 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): def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect):
for numRow in range(len(self.toolSelectMap)): for numRow in range(len(self.toolSelectMap)):
for numCol in range(len(self.toolSelectMap[numRow])): for numCol in range(len(self.toolSelectMap[numRow])):
cellOld = self.toolSelectMap[numRow][numCol] cellOld = self.toolSelectMap[numRow][numCol]
rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect) dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect)
return True
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -10,8 +10,8 @@ class ToolSelectMove(ToolSelect):
name = "Move selection" name = "Move selection"
# #
# 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): def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect):
for numRow in range(len(self.toolSelectMap)): for numRow in range(len(self.toolSelectMap)):
for numCol in range(len(self.toolSelectMap[numRow])): for numCol in range(len(self.toolSelectMap[numRow])):
dispatchFn(eventDc, isCursor, [self.srcRect[0] + numCol, self.srcRect[1] + numRow, 1, 1, 0, " "], viewRect) 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] cellOld = self.toolSelectMap[numRow][numCol]
rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect) dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect)
return True
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -11,15 +11,13 @@ class ToolText(Tool):
name = "Text" name = "Text"
# #
# onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc, viewRect) # onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect)
def onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc, viewRect): def onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect):
keyModifiers = event.GetModifiers() if not keyModifiers in (wx.MOD_NONE, wx.MOD_SHIFT):
if keyModifiers != wx.MOD_NONE \ return False
and keyModifiers != wx.MOD_SHIFT:
return True
else: else:
if self.textPos == None: if self.textPos == None:
self.textPos = list(atPoint) self.textPos = list(mapPoint)
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] < (self.parentCanvas.canvas.size[0] - 1):
self.textPos[0] += 1 self.textPos[0] += 1
@ -27,14 +25,15 @@ class ToolText(Tool):
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]
return False return True
# #
# 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, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc, viewRect): def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
if isLeftDown or isRightDown: if mouseLeftDown or mouseRightDown:
self.textPos = list(atPoint) self.textPos = list(mapPoint)
dispatchFn(eventDc, True, [*atPoint, *brushColours, 0, "_"], viewRect) dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, "_"], viewRect)
return True
# __init__(self, *args): initialisation method # __init__(self, *args): initialisation method
def __init__(self, *args): def __init__(self, *args):