MiRCARTCanvas{,Journal,Store}.py: dispatch patches from tool event handlers directly.

MiRCARTTool{,Circle,Line,Rect,Text}.py: updated to new interface.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-10 00:25:42 +01:00
parent d3e67a7c18
commit bbec7d1eb1
8 changed files with 138 additions and 149 deletions

View File

@ -35,88 +35,79 @@ class MiRCARTCanvas(wx.Panel):
brushColours = brushPos = brushSize = None brushColours = brushPos = brushSize = None
canvasBackend = canvasCurTool = canvasJournal = canvasStore = None canvasBackend = canvasCurTool = canvasJournal = canvasStore = None
# {{{ _commitPatch(self, patch): # {{{ _commitPatch(self, patch): XXX
def _commitPatch(self, patch): def _commitPatch(self, patch):
self.canvasMap[patch[0][1]][patch[0][0]] = patch[1:] self.canvasMap[patch[0][1]][patch[0][0]] = patch[1:]
# }}} # }}}
# {{{ _dispatchInput(self, eventDc, patches): XXX # {{{ _dispatchDeltaPatches(self, deltaPatches): XXX
def _dispatchInput(self, eventDc, patches): def _dispatchDeltaPatches(self, deltaPatches):
self.canvasBackend.drawCursorMaskWithJournal( \ eventDc = self.canvasBackend.getDeviceContext(self)
self.canvasJournal, eventDc) for patch in deltaPatches:
cursorPatches = []; undoPatches = []; newPatches = []; if self.canvasBackend.drawPatch(eventDc, patch):
for patchDescr in patches: self._commitPatch(patch)
patchIsCursor = patchDescr[0] self.parentFrame.onCanvasUpdate()
for patch in patchDescr[1]: # }}}
if self.canvasBackend.drawPatch(eventDc, patch) == False: # {{{ _dispatchPatch(self, eventDc, isCursor, patch): XXX
continue def _dispatchPatch(self, eventDc, isCursor, patch):
else: if not self._canvasDirtyCursor:
patchDeltaCell = self.canvasMap[patch[0][1]][patch[0][0]] self.canvasBackend.drawCursorMaskWithJournal( \
if patchIsCursor == True: self.canvasJournal, eventDc)
cursorPatches.append([list(patch[0]), *patchDeltaCell.copy()]) self._canvasDirtyCursor = True
else: if self.canvasBackend.drawPatch(eventDc, patch):
undoPatches.append([list(patch[0]), *patchDeltaCell.copy()]) patchDeltaCell = self.canvasMap[patch[0][1]][patch[0][0]]
newPatches.append(patch) patchDelta = [list(patch[0]), *patchDeltaCell.copy()]
self._commitPatch(patch) if isCursor:
if len(cursorPatches): self.canvasJournal.pushCursor(patchDelta)
self.canvasJournal.pushCursor(cursorPatches) else:
if len(undoPatches): if not self._canvasDirty:
self.canvasJournal.pushDeltas(undoPatches, newPatches) self.canvasJournal.pushDeltas([], [])
self._canvasDirty = True
self.canvasJournal.updateCurrentDeltas(patchDelta, patch)
self._commitPatch(patch)
# }}} # }}}
# {{{ onPanelClose(self, event): XXX # {{{ onPanelClose(self, event): XXX
def onPanelClose(self, event): def onPanelClose(self, event):
self.Destroy() self.Destroy()
# }}} # }}}
# {{{ onPanelKeyboardInput(self, event): XXX # {{{ onPanelInput(self, event): XXX
def onPanelKeyboardInput(self, event): def onPanelInput(self, event):
eventDc = self.canvasBackend.getDeviceContext(self)
tool = self.canvasCurTool; mapPoint = self.brushPos;
keyModifiers = event.GetModifiers()
if keyModifiers != wx.MOD_NONE \
and keyModifiers != wx.MOD_SHIFT:
event.Skip()
else:
patches = tool.onKeyboardEvent( \
event, mapPoint, self.brushColours, self.brushSize, \
chr(event.GetUnicodeKey()))
if len(patches):
self._dispatchInput(eventDc, patches)
self.parentFrame.onCanvasUpdate()
# }}}
# {{{ onPanelMouseInput(self, event): XXX
def onPanelMouseInput(self, event):
eventDc = self.canvasBackend.getDeviceContext(self) eventDc = self.canvasBackend.getDeviceContext(self)
eventType = event.GetEventType()
self._canvasDirty = self._canvasDirtyCursor = False
tool = self.canvasCurTool tool = self.canvasCurTool
self.brushPos = mapPoint = \ if eventType == wx.wxEVT_CHAR:
self.canvasBackend.xlateEventPoint(event, eventDc) mapPoint = self.brushPos
patches = tool.onMouseEvent( \ doSkip = tool.onKeyboardEvent( \
event, mapPoint, self.brushColours, self.brushSize, \ event, mapPoint, self.brushColours, self.brushSize, \
event.Dragging(), event.LeftIsDown(), event.RightIsDown()) chr(event.GetUnicodeKey()), self._dispatchPatch, eventDc)
if len(patches): if doSkip:
self._dispatchInput(eventDc, patches) event.Skip(); return;
else:
mapPoint = self.canvasBackend.xlateEventPoint(event, eventDc)
self.brushPos = mapPoint
tool.onMouseEvent( \
event, mapPoint, self.brushColours, self.brushSize, \
event.Dragging(), event.LeftIsDown(), event.RightIsDown(), \
self._dispatchPatch, eventDc)
if self._canvasDirty:
self.parentFrame.onCanvasUpdate() self.parentFrame.onCanvasUpdate()
self.parentFrame.onCanvasMotion(event, mapPoint) self.parentFrame.onCanvasMotion(event, mapPoint)
# }}} # }}}
# {{{ onPanelFocus(self, event): XXX # {{{ onPanelLeaveWindow(self, event): XXX
def onPanelFocus(self, event): def onPanelLeaveWindow(self, event):
if event.GetEventType() == wx.wxEVT_LEAVE_WINDOW: eventDc = self.canvasBackend.getDeviceContext(self)
eventDc = self.canvasBackend.getDeviceContext(self) self.canvasBackend.drawCursorMaskWithJournal( \
self.canvasBackend.drawCursorMaskWithJournal( \ self.canvasJournal, eventDc)
self.canvasJournal, eventDc)
self.parentFrame.onCanvasMotion(event) self.parentFrame.onCanvasMotion(event)
# }}} # }}}
# {{{ onPanelPaint(self, event): XXX # {{{ onPanelPaint(self, event): XXX
def onPanelPaint(self, event): def onPanelPaint(self, event):
self.canvasBackend.onPanelPaintEvent(self, event) self.canvasBackend.onPanelPaintEvent(self, event)
# }}} # }}}
# {{{ onStoreUpdate(self, newCanvasSize, newCanvas=None): # {{{ onStoreUpdate(self, newCanvasSize, newCanvas=None): XXX
def onStoreUpdate(self, newCanvasSize, newCanvas=None): def onStoreUpdate(self, newCanvasSize, newCanvas=None):
self.resize(newCanvasSize=newCanvasSize) self.resize(newCanvasSize=newCanvasSize)
self.canvasBackend.reset(self.canvasSize, self.canvasBackend.cellSize)
self.canvasJournal.resetCursor(); self.canvasJournal.resetUndo();
self.canvasMap = [[[(1, 1), 0, " "] \
for x in range(self.canvasSize[0])] \
for y in range(self.canvasSize[1])]
eventDc = self.canvasBackend.getDeviceContext(self) eventDc = self.canvasBackend.getDeviceContext(self)
for numRow in range(self.canvasSize[1]): for numRow in range(self.canvasSize[1]):
for numCol in range(self.canvasSize[0]): for numCol in range(self.canvasSize[0]):
@ -130,45 +121,36 @@ class MiRCARTCanvas(wx.Panel):
*self.canvasMap[numRow][numCol])) *self.canvasMap[numRow][numCol]))
wx.SafeYield() wx.SafeYield()
# }}} # }}}
# {{{ popRedo(self): # {{{ popRedo(self): XXX
def popRedo(self): def popRedo(self):
eventDc = self.canvasBackend.getDeviceContext(self) self._dispatchDeltaPatches(self.canvasJournal.popRedo())
patches = self.canvasJournal.popRedo()
for patch in patches:
if self.canvasBackend.drawPatch(eventDc, patch) == False:
continue
else:
self._commitPatch(patch)
self.parentFrame.onCanvasUpdate()
# }}} # }}}
# {{{ popUndo(self): # {{{ popUndo(self): XXX
def popUndo(self): def popUndo(self):
eventDc = self.canvasBackend.getDeviceContext(self) self._dispatchDeltaPatches(self.canvasJournal.popUndo())
patches = self.canvasJournal.popUndo()
for patch in patches:
if self.canvasBackend.drawPatch(eventDc, patch) == False:
continue
else:
self._commitPatch(patch)
self.parentFrame.onCanvasUpdate()
# }}} # }}}
# {{{ resize(self, newCanvasSize): # {{{ resize(self, newCanvasSize): XXX
def resize(self, newCanvasSize): def resize(self, newCanvasSize):
if newCanvasSize != self.canvasSize: if newCanvasSize != self.canvasSize:
winSize = [a*b for a,b in \ if self.canvasMap == None:
zip(newCanvasSize, self.canvasBackend.cellSize)] self.canvasMap = [[[(1, 1), 0, " "] \
self.SetSize(*self.canvasPos, *winSize) for x in range(self.canvasSize[0])] \
for numRow in range(self.canvasSize[1]): for y in range(self.canvasSize[1])]
for numNewCol in range(self.canvasSize[0], newCanvasSize[0]): else:
self.canvasMap[numRow].append([[1, 1], 0, " "]) for numRow in range(self.canvasSize[1]):
for numNewRow in range(self.canvasSize[1], newCanvasSize[1]): for numNewCol in range(self.canvasSize[0], newCanvasSize[0]):
self.canvasMap.append([]) self.canvasMap[numRow].append([[1, 1], 0, " "])
for numNewCol in range(newCanvasSize[0]): for numNewRow in range(self.canvasSize[1], newCanvasSize[1]):
self.canvasMap[numNewRow].append([[1, 1], 0, " "]) self.canvasMap.append([])
for numNewCol in range(newCanvasSize[0]):
self.canvasMap[numNewRow].append([[1, 1], 0, " "])
self.canvasSize = newCanvasSize self.canvasSize = newCanvasSize
self.canvasBackend.reset(self.canvasSize, \ self.SetSize(*self.canvasPos, \
self.canvasBackend.cellSize) *[a*b for a,b in zip(self.canvasSize, \
self.parentFrame.onCanvasUpdate() self.canvasBackend.cellSize)])
self.canvasBackend.reset(self.canvasSize, self.canvasBackend.cellSize)
self.canvasJournal.resetCursor(); self.canvasJournal.resetUndo();
self.parentFrame.onCanvasUpdate()
# }}} # }}}
# #
@ -187,12 +169,11 @@ class MiRCARTCanvas(wx.Panel):
# Bind event handlers # Bind event handlers
self.Bind(wx.EVT_CLOSE, self.onPanelClose) self.Bind(wx.EVT_CLOSE, self.onPanelClose)
self.Bind(wx.EVT_ENTER_WINDOW, self.onPanelFocus) self.Bind(wx.EVT_LEAVE_WINDOW, self.onPanelLeaveWindow)
self.Bind(wx.EVT_LEAVE_WINDOW, self.onPanelFocus) self.parentFrame.Bind(wx.EVT_CHAR, self.onPanelInput)
self.parentFrame.Bind(wx.EVT_CHAR, self.onPanelKeyboardInput)
for eventType in( \ for eventType in( \
wx.EVT_LEFT_DOWN, wx.EVT_MOTION, wx.EVT_RIGHT_DOWN): wx.EVT_LEFT_DOWN, wx.EVT_MOTION, wx.EVT_RIGHT_DOWN):
self.Bind(eventType, self.onPanelMouseInput) self.Bind(eventType, self.onPanelInput)
self.Bind(wx.EVT_PAINT, self.onPanelPaint) self.Bind(wx.EVT_PAINT, self.onPanelPaint)
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -55,14 +55,16 @@ class MiRCARTCanvasJournal():
# }}} # }}}
# {{{ pushCursor(self, patches): XXX # {{{ pushCursor(self, patches): XXX
def pushCursor(self, patches): def pushCursor(self, patches):
self.patchesCursor += patches self.patchesCursor.append(patches)
# }}} # }}}
# {{{ pushDeltas(self, undoPatches, redoPatches): XXX # {{{ pushDeltas(self, undoPatches, redoPatches): XXX
def pushDeltas(self, undoPatches, redoPatches): def pushDeltas(self, undoPatches, redoPatches):
if self.patchesUndoLevel > 0: if self.patchesUndoLevel > 0:
del self.patchesUndo[0:self.patchesUndoLevel] del self.patchesUndo[0:self.patchesUndoLevel]
self.patchesUndoLevel = 0 self.patchesUndoLevel = 0
self.patchesUndo.insert(0, [undoPatches, redoPatches]) deltaItem = [undoPatches, redoPatches]
self.patchesUndo.insert(0, deltaItem)
return deltaItem
# }}} # }}}
# {{{ resetCursor(self): XXX # {{{ resetCursor(self): XXX
def resetCursor(self): def resetCursor(self):
@ -72,6 +74,11 @@ class MiRCARTCanvasJournal():
def resetUndo(self): def resetUndo(self):
self.patchesUndo = [None]; self.patchesUndoLevel = 0; self.patchesUndo = [None]; self.patchesUndoLevel = 0;
# }}} # }}}
# {{{ updateCurrentDeltas(self, undoPatches, redoPatches): XXX
def updateCurrentDeltas(self, undoPatches, redoPatches):
self.patchesUndo[0][0].append(undoPatches)
self.patchesUndo[0][1].append(redoPatches)
# }}}
# #
# __init__(self): initialisation method # __init__(self): initialisation method

View File

@ -235,7 +235,10 @@ class MiRCARTCanvasStore():
# }}} # }}}
# {{{ importNew(self, newCanvasSize=None): XXX # {{{ importNew(self, newCanvasSize=None): XXX
def importNew(self, newCanvasSize=None): def importNew(self, newCanvasSize=None):
self.parentCanvas.onStoreUpdate(newCanvasSize) newMap = [[[(1, 1), 0, " "] \
for x in range(self.parentCanvas.canvasSize[0])] \
for y in range(self.parentCanvas.canvasSize[1])]
self.parentCanvas.onStoreUpdate(newCanvasSize, newMap)
# }}} # }}}
# #

View File

@ -26,12 +26,12 @@ class MiRCARTTool():
"""XXX""" """XXX"""
parentCanvas = None parentCanvas = None
# {{{ onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar): # {{{ onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc):
def onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar): def onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc):
return () return True
# }}} # }}}
# {{{ onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown): XXX # {{{ onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc): XXX
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown): def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc):
return () return ()
# }}} # }}}

View File

@ -28,8 +28,8 @@ class MiRCARTToolCircle(MiRCARTTool):
"""XXX""" """XXX"""
# #
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown): XXX # onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc): XXX
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown): def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc):
brushColours = brushColours.copy() brushColours = brushColours.copy()
if isLeftDown: if isLeftDown:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
@ -37,20 +37,19 @@ class MiRCARTToolCircle(MiRCARTTool):
brushColours[0] = brushColours[1] brushColours[0] = brushColours[1]
else: else:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
brushPatches = []
_brushSize = brushSize[0]*2 _brushSize = brushSize[0]*2
originPoint = (_brushSize/2, _brushSize/2) originPoint = (_brushSize/2, _brushSize/2)
radius = _brushSize radius = _brushSize
for brushY in range(-radius, radius + 1): for brushY in range(-radius, radius + 1):
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)):
brushPatches.append([ \ patch = [ \
[atPoint[0] + int(originPoint[0]+brushX), \ [atPoint[0] + int(originPoint[0]+brushX), \
atPoint[1] + int(originPoint[1]+brushY)], \ atPoint[1] + int(originPoint[1]+brushY)], \
brushColours, 0, " "]) brushColours, 0, " "]
if isLeftDown or isRightDown: if isLeftDown or isRightDown:
return [[False, brushPatches], [True, brushPatches]] dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
else: else:
return [[True, brushPatches]] dispatchFn(eventDc, True, patch)
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -39,8 +39,8 @@ class MiRCARTToolLine(MiRCARTTool):
def _pointSwap(self, a, b): def _pointSwap(self, a, b):
return [b, a] return [b, a]
# }}} # }}}
# {{{ _getLine(self, brushColours, originPoint, targetPoint): XXX # {{{ _getLine(self, brushColours, eventDc, isCursor, originPoint, targetPoint, dispatchFn): XXX
def _getLine(self, brushColours, originPoint, targetPoint): def _getLine(self, brushColours, eventDc, isCursor, originPoint, targetPoint, dispatchFn):
originPoint = originPoint.copy(); targetPoint = targetPoint.copy(); originPoint = originPoint.copy(); targetPoint = targetPoint.copy();
pointDelta = self._pointDelta(originPoint, targetPoint) pointDelta = self._pointDelta(originPoint, targetPoint)
lineXSign = 1 if pointDelta[0] > 0 else -1; lineXSign = 1 if pointDelta[0] > 0 else -1;
@ -52,21 +52,23 @@ class MiRCARTToolLine(MiRCARTTool):
pointDelta = [pointDelta[1], pointDelta[0]] pointDelta = [pointDelta[1], pointDelta[0]]
lineXX, lineXY, lineYX, lineYY = 0, lineYSign, lineXSign, 0 lineXX, lineXY, lineYX, lineYY = 0, lineYSign, lineXSign, 0
lineD = 2 * pointDelta[1] - pointDelta[0]; lineY = 0; lineD = 2 * pointDelta[1] - pointDelta[0]; lineY = 0;
linePatches = []
for lineX in range(pointDelta[0] + 1): for lineX in range(pointDelta[0] + 1):
linePatches.append([[ \ patch = [[ \
originPoint[0] + lineX*lineXX + lineY*lineYX, \ originPoint[0] + lineX*lineXX + lineY*lineYX, \
originPoint[1] + lineX*lineXY + lineY*lineYY], \ originPoint[1] + lineX*lineXY + lineY*lineYY], \
brushColours, 0, " "]) brushColours, 0, " "]
if isCursor:
dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
else:
dispatchFn(eventDc, True, patch)
if lineD > 0: if lineD > 0:
lineD -= pointDelta[0]; lineY += 1; lineD -= pointDelta[0]; lineY += 1;
lineD += pointDelta[1] lineD += pointDelta[1]
return linePatches
# }}} # }}}
# #
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown): XXX # onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc): XXX
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown): def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc):
brushColours = brushColours.copy() brushColours = brushColours.copy()
if isLeftDown: if isLeftDown:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
@ -74,22 +76,19 @@ class MiRCARTToolLine(MiRCARTTool):
brushColours[0] = brushColours[1] brushColours[0] = brushColours[1]
else: else:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
brushPatches = []; tmpPatches = [];
if self.toolState == self.TS_NONE: if self.toolState == self.TS_NONE:
if isLeftDown or isRightDown: if isLeftDown or isRightDown:
self.toolOriginPoint = list(atPoint) self.toolOriginPoint = list(atPoint)
self.toolState = self.TS_ORIGIN self.toolState = self.TS_ORIGIN
tmpPatches.append([atPoint, brushColours, 0, " "]) dispatchFn(eventDc, True, [atPoint, brushColours, 0, " "])
return [[True, tmpPatches]]
elif self.toolState == self.TS_ORIGIN: elif self.toolState == self.TS_ORIGIN:
targetPoint = list(atPoint) targetPoint = list(atPoint)
originPoint = self.toolOriginPoint originPoint = self.toolOriginPoint
brushPatches = self._getLine(brushColours, originPoint, targetPoint) self._getLine(brushColours, eventDc, \
isLeftDown or isRightDown, \
originPoint, targetPoint, dispatchFn)
if isLeftDown or isRightDown: if isLeftDown or isRightDown:
self.toolState = self.TS_NONE self.toolState = self.TS_NONE
return [[False, brushPatches], [True, brushPatches]]
else:
return [[True, brushPatches]]
# __init__(self, *args): initialisation method # __init__(self, *args): initialisation method
def __init__(self, *args): def __init__(self, *args):

View File

@ -28,8 +28,8 @@ class MiRCARTToolRect(MiRCARTTool):
"""XXX""" """XXX"""
# #
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown): XXX # onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc): XXX
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown): def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc):
brushColours = brushColours.copy() brushColours = brushColours.copy()
if isLeftDown: if isLeftDown:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
@ -40,16 +40,12 @@ class MiRCARTToolRect(MiRCARTTool):
brushSize = brushSize.copy() brushSize = brushSize.copy()
if brushSize[0] > 1: if brushSize[0] > 1:
brushSize[0] *= 2 brushSize[0] *= 2
brushPatches = []
for brushRow in range(brushSize[1]): for brushRow in range(brushSize[1]):
for brushCol in range(brushSize[0]): for brushCol in range(brushSize[0]):
brushPatches.append([[ \ patch = [[atPoint[0] + brushCol, atPoint[1] + brushRow],brushColours, 0, " "]
atPoint[0] + brushCol, \ if isLeftDown or isRightDown:
atPoint[1] + brushRow], \ dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
brushColours, 0, " "]) else:
if isLeftDown or isRightDown: dispatchFn(eventDc, True, patch)
return [[False, brushPatches], [True, brushPatches]]
else:
return [[True, brushPatches]]
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -23,23 +23,27 @@
# #
from MiRCARTTool import MiRCARTTool from MiRCARTTool import MiRCARTTool
import string import string, wx
class MiRCARTToolText(MiRCARTTool): class MiRCARTToolText(MiRCARTTool):
"""XXX""" """XXX"""
textColours = textPos = None textColours = textPos = None
# #
# onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar): XXX # onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc): XXX
def onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar): def onKeyboardEvent(self, event, atPoint, brushColours, brushSize, keyChar, dispatchFn, eventDc):
if not keyChar in string.printable: keyModifiers = event.GetModifiers()
return [] if keyModifiers != wx.MOD_NONE \
and keyModifiers != wx.MOD_SHIFT:
return True
elif not keyChar in string.printable:
return True
else: else:
if self.textColours == None: if self.textColours == None:
self.textColours = brushColours.copy() self.textColours = brushColours.copy()
if self.textPos == None: if self.textPos == None:
self.textPos = list(atPoint) self.textPos = list(atPoint)
patches = [[False, [[self.textPos, self.textColours, 0, keyChar]]]] dispatchFn(eventDc, False, [self.textPos, self.textColours, 0, keyChar])
if self.textPos[0] < (self.parentCanvas.canvasSize[0] - 1): if self.textPos[0] < (self.parentCanvas.canvasSize[0] - 1):
self.textPos[0] += 1 self.textPos[0] += 1
elif self.textPos[1] < (self.parentCanvas.canvasSize[1] - 1): elif self.textPos[1] < (self.parentCanvas.canvasSize[1] - 1):
@ -47,11 +51,11 @@ class MiRCARTToolText(MiRCARTTool):
self.textPos[1] += 1 self.textPos[1] += 1
else: else:
self.textPos = [0, 0] self.textPos = [0, 0]
return patches return False
# #
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown): XXX # onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc): XXX
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown): def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc):
if isLeftDown: if isLeftDown:
self.textColours = brushColours.copy() self.textColours = brushColours.copy()
self.textPos = list(atPoint) self.textPos = list(atPoint)
@ -62,6 +66,6 @@ class MiRCARTToolText(MiRCARTTool):
if self.textColours == None: if self.textColours == None:
self.textColours = brushColours.copy() self.textColours = brushColours.copy()
self.textPos = list(atPoint) self.textPos = list(atPoint)
return [[True, [[self.textPos, self.textColours, 0, "_"]]]] dispatchFn(eventDc, True, [self.textPos, self.textColours, 0, "_"])
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120