mirror of
https://github.com/lalbornoz/roar.git
synced 2024-12-23 04:46:37 +00:00
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:
parent
dc84921d47
commit
d342a9d804
@ -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_
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
# }}}
|
||||
|
||||
#
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user