mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-26 16:56:37 +00:00
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:
parent
d3e67a7c18
commit
bbec7d1eb1
139
MiRCARTCanvas.py
139
MiRCARTCanvas.py
@ -35,71 +35,67 @@ 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):
|
||||||
|
eventDc = self.canvasBackend.getDeviceContext(self)
|
||||||
|
for patch in deltaPatches:
|
||||||
|
if self.canvasBackend.drawPatch(eventDc, patch):
|
||||||
|
self._commitPatch(patch)
|
||||||
|
self.parentFrame.onCanvasUpdate()
|
||||||
|
# }}}
|
||||||
|
# {{{ _dispatchPatch(self, eventDc, isCursor, patch): XXX
|
||||||
|
def _dispatchPatch(self, eventDc, isCursor, patch):
|
||||||
|
if not self._canvasDirtyCursor:
|
||||||
self.canvasBackend.drawCursorMaskWithJournal( \
|
self.canvasBackend.drawCursorMaskWithJournal( \
|
||||||
self.canvasJournal, eventDc)
|
self.canvasJournal, eventDc)
|
||||||
cursorPatches = []; undoPatches = []; newPatches = [];
|
self._canvasDirtyCursor = True
|
||||||
for patchDescr in patches:
|
if self.canvasBackend.drawPatch(eventDc, patch):
|
||||||
patchIsCursor = patchDescr[0]
|
|
||||||
for patch in patchDescr[1]:
|
|
||||||
if self.canvasBackend.drawPatch(eventDc, patch) == False:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
patchDeltaCell = self.canvasMap[patch[0][1]][patch[0][0]]
|
patchDeltaCell = self.canvasMap[patch[0][1]][patch[0][0]]
|
||||||
if patchIsCursor == True:
|
patchDelta = [list(patch[0]), *patchDeltaCell.copy()]
|
||||||
cursorPatches.append([list(patch[0]), *patchDeltaCell.copy()])
|
if isCursor:
|
||||||
|
self.canvasJournal.pushCursor(patchDelta)
|
||||||
else:
|
else:
|
||||||
undoPatches.append([list(patch[0]), *patchDeltaCell.copy()])
|
if not self._canvasDirty:
|
||||||
newPatches.append(patch)
|
self.canvasJournal.pushDeltas([], [])
|
||||||
|
self._canvasDirty = True
|
||||||
|
self.canvasJournal.updateCurrentDeltas(patchDelta, patch)
|
||||||
self._commitPatch(patch)
|
self._commitPatch(patch)
|
||||||
if len(cursorPatches):
|
|
||||||
self.canvasJournal.pushCursor(cursorPatches)
|
|
||||||
if len(undoPatches):
|
|
||||||
self.canvasJournal.pushDeltas(undoPatches, newPatches)
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# {{{ 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)
|
||||||
@ -109,14 +105,9 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
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,34 +121,22 @@ 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 y in range(self.canvasSize[1])]
|
||||||
|
else:
|
||||||
for numRow in range(self.canvasSize[1]):
|
for numRow in range(self.canvasSize[1]):
|
||||||
for numNewCol in range(self.canvasSize[0], newCanvasSize[0]):
|
for numNewCol in range(self.canvasSize[0], newCanvasSize[0]):
|
||||||
self.canvasMap[numRow].append([[1, 1], 0, " "])
|
self.canvasMap[numRow].append([[1, 1], 0, " "])
|
||||||
@ -166,8 +145,11 @@ class MiRCARTCanvas(wx.Panel):
|
|||||||
for numNewCol in range(newCanvasSize[0]):
|
for numNewCol in range(newCanvasSize[0]):
|
||||||
self.canvasMap[numNewRow].append([[1, 1], 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.canvasBackend.cellSize)])
|
||||||
|
self.canvasBackend.reset(self.canvasSize, self.canvasBackend.cellSize)
|
||||||
|
self.canvasJournal.resetCursor(); self.canvasJournal.resetUndo();
|
||||||
self.parentFrame.onCanvasUpdate()
|
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
|
||||||
|
@ -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
|
||||||
|
@ -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)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -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 ()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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):
|
||||||
|
@ -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, \
|
|
||||||
atPoint[1] + brushRow], \
|
|
||||||
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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user