mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-22 23:36:36 +00:00
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}(). libgui/GuiCanvasPanel.py:applyTool(): updated. libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch(). libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty. libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
This commit is contained in:
parent
d342a9d804
commit
1b31d34d25
@ -16,8 +16,21 @@ class Canvas():
|
|||||||
|
|
||||||
# {{{ dispatchPatch(self, isCursor, patch, commitUndo=True)
|
# {{{ dispatchPatch(self, isCursor, patch, commitUndo=True)
|
||||||
def dispatchPatch(self, isCursor, patch, commitUndo=True):
|
def dispatchPatch(self, isCursor, patch, commitUndo=True):
|
||||||
if (patch[0] >= self.size[0]) \
|
if (patch[0] >= self.size[0]) or (patch[1] >= self.size[1]):
|
||||||
or (patch[1] >= self.size[1]):
|
return False
|
||||||
|
else:
|
||||||
|
patchDeltaCell = self.map[patch[1]][patch[0]]; patchDelta = [*patch[0:2], *patchDeltaCell];
|
||||||
|
if isCursor:
|
||||||
|
self.journal.pushCursor(patchDelta)
|
||||||
|
else:
|
||||||
|
if commitUndo:
|
||||||
|
self.journal.begin(); self.journal.updateCurrentDeltas(patch, patchDelta); self.journal.end();
|
||||||
|
self._commitPatch(patch)
|
||||||
|
return True
|
||||||
|
# }}}
|
||||||
|
# {{{ dispatchPatchSingle(self, isCursor, patch, commitUndo=True)
|
||||||
|
def dispatchPatchSingle(self, isCursor, patch, commitUndo=True):
|
||||||
|
if (patch[0] >= self.size[0]) or (patch[1] >= self.size[1]):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
patchDeltaCell = self.map[patch[1]][patch[0]]; patchDelta = [*patch[0:2], *patchDeltaCell];
|
patchDeltaCell = self.map[patch[1]][patch[0]]; patchDelta = [*patch[0:2], *patchDeltaCell];
|
||||||
@ -25,8 +38,6 @@ class Canvas():
|
|||||||
self.journal.pushCursor(patchDelta)
|
self.journal.pushCursor(patchDelta)
|
||||||
else:
|
else:
|
||||||
if commitUndo:
|
if commitUndo:
|
||||||
if not self.dirtyJournal:
|
|
||||||
self.journal.pushDeltas([], []); self.dirtyJournal = True;
|
|
||||||
self.journal.updateCurrentDeltas(patch, patchDelta)
|
self.journal.updateCurrentDeltas(patch, patchDelta)
|
||||||
self._commitPatch(patch)
|
self._commitPatch(patch)
|
||||||
return True
|
return True
|
||||||
@ -34,7 +45,6 @@ class Canvas():
|
|||||||
# {{{ resize(self, newSize, commitUndo=True)
|
# {{{ resize(self, newSize, commitUndo=True)
|
||||||
def resize(self, newSize, commitUndo=True):
|
def resize(self, newSize, commitUndo=True):
|
||||||
if newSize != self.size:
|
if newSize != self.size:
|
||||||
self.dirtyJournal = False
|
|
||||||
if self.map == None:
|
if self.map == None:
|
||||||
self.map, oldSize = [], [0, 0]
|
self.map, oldSize = [], [0, 0]
|
||||||
else:
|
else:
|
||||||
@ -42,16 +52,13 @@ class Canvas():
|
|||||||
deltaSize = [b - a for a, b in zip(oldSize, newSize)]
|
deltaSize = [b - a for a, b in zip(oldSize, newSize)]
|
||||||
self.journal.resetCursor()
|
self.journal.resetCursor()
|
||||||
if commitUndo:
|
if commitUndo:
|
||||||
|
self.journal.begin()
|
||||||
undoPatches, redoPatches = ["resize", *oldSize], ["resize", *newSize]
|
undoPatches, redoPatches = ["resize", *oldSize], ["resize", *newSize]
|
||||||
if not self.dirtyJournal:
|
|
||||||
self.journal.pushDeltas([], []); self.dirtyJournal = True;
|
|
||||||
self.journal.updateCurrentDeltas(redoPatches, undoPatches)
|
self.journal.updateCurrentDeltas(redoPatches, undoPatches)
|
||||||
if deltaSize[0] < 0:
|
if deltaSize[0] < 0:
|
||||||
for numRow in range(oldSize[1]):
|
for numRow in range(oldSize[1]):
|
||||||
if commitUndo:
|
if commitUndo:
|
||||||
for numCol in range((oldSize[0] + deltaSize[0]), oldSize[0]):
|
for numCol in range((oldSize[0] + deltaSize[0]), oldSize[0]):
|
||||||
if not self.dirtyJournal:
|
|
||||||
self.journal.pushDeltas([], []); self.dirtyJournal = True;
|
|
||||||
self.journal.updateCurrentDeltas(None, [numCol, numRow, *self.map[numRow][numCol]])
|
self.journal.updateCurrentDeltas(None, [numCol, numRow, *self.map[numRow][numCol]])
|
||||||
del self.map[numRow][-1:(deltaSize[0]-1):-1]
|
del self.map[numRow][-1:(deltaSize[0]-1):-1]
|
||||||
else:
|
else:
|
||||||
@ -59,16 +66,12 @@ class Canvas():
|
|||||||
self.map[numRow].extend([[1, 1, 0, " "]] * deltaSize[0])
|
self.map[numRow].extend([[1, 1, 0, " "]] * deltaSize[0])
|
||||||
for numNewCol in range(oldSize[0], newSize[0]):
|
for numNewCol in range(oldSize[0], newSize[0]):
|
||||||
if commitUndo:
|
if commitUndo:
|
||||||
if not self.dirtyJournal:
|
|
||||||
self.journal.pushDeltas([], []); self.dirtyJournal = True;
|
|
||||||
self.journal.updateCurrentDeltas([numNewCol, numRow, 1, 1, 0, " "], None)
|
self.journal.updateCurrentDeltas([numNewCol, numRow, 1, 1, 0, " "], None)
|
||||||
self.dispatchPatch(False, [numNewCol, numRow, 1, 1, 0, " "], False)
|
self.dispatchPatch(False, [numNewCol, numRow, 1, 1, 0, " "], False)
|
||||||
if deltaSize[1] < 0:
|
if deltaSize[1] < 0:
|
||||||
if commitUndo:
|
if commitUndo:
|
||||||
for numRow in range((oldSize[1] + deltaSize[1]), oldSize[1]):
|
for numRow in range((oldSize[1] + deltaSize[1]), oldSize[1]):
|
||||||
for numCol in range(oldSize[0] + deltaSize[0]):
|
for numCol in range(oldSize[0] + deltaSize[0]):
|
||||||
if not self.dirtyJournal:
|
|
||||||
self.journal.pushDeltas([], []); self.dirtyJournal = True;
|
|
||||||
self.journal.updateCurrentDeltas(None, [numCol, numRow, *self.map[numRow][numCol]])
|
self.journal.updateCurrentDeltas(None, [numCol, numRow, *self.map[numRow][numCol]])
|
||||||
del self.map[-1:(deltaSize[1]-1):-1]
|
del self.map[-1:(deltaSize[1]-1):-1]
|
||||||
else:
|
else:
|
||||||
@ -76,11 +79,11 @@ class Canvas():
|
|||||||
self.map.extend([[[1, 1, 0, " "]] * newSize[0]])
|
self.map.extend([[[1, 1, 0, " "]] * newSize[0]])
|
||||||
for numNewCol in range(newSize[0]):
|
for numNewCol in range(newSize[0]):
|
||||||
if commitUndo:
|
if commitUndo:
|
||||||
if not self.dirtyJournal:
|
|
||||||
self.journal.pushDeltas([], []); self.dirtyJournal = True;
|
|
||||||
self.journal.updateCurrentDeltas([numNewCol, numNewRow, 1, 1, 0, " "], None)
|
self.journal.updateCurrentDeltas([numNewCol, numNewRow, 1, 1, 0, " "], None)
|
||||||
self.dispatchPatch(False, [numNewCol, numNewRow, 1, 1, 0, " "], False)
|
self.dispatchPatch(False, [numNewCol, numNewRow, 1, 1, 0, " "], False)
|
||||||
self.size = newSize
|
self.size = newSize
|
||||||
|
if commitUndo:
|
||||||
|
self.journal.end()
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
@ -98,7 +101,7 @@ class Canvas():
|
|||||||
#
|
#
|
||||||
# __init__(self, size): initialisation method
|
# __init__(self, size): initialisation method
|
||||||
def __init__(self, size):
|
def __init__(self, size):
|
||||||
self.dirtyJournal, self.dirtyCursor, self.map, self.size = False, False, None, size
|
self.dirtyCursor, self.map, self.size = False, None, size
|
||||||
self.exportStore, self.importStore, self.journal = CanvasExportStore(), CanvasImportStore(), CanvasJournal()
|
self.exportStore, self.importStore, self.journal = CanvasExportStore(), CanvasImportStore(), CanvasJournal()
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||||
|
@ -5,6 +5,17 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
class CanvasJournal():
|
class CanvasJournal():
|
||||||
|
# {{{ begin(self)
|
||||||
|
def begin(self):
|
||||||
|
if self.patchesUndoLevel > 0:
|
||||||
|
del self.patchesUndo[0:self.patchesUndoLevel]; self.patchesUndoLevel = 0;
|
||||||
|
deltaItem = [[], []]; self.patchesUndo.insert(0, deltaItem);
|
||||||
|
# }}}
|
||||||
|
# {{{ end(self)
|
||||||
|
def end(self):
|
||||||
|
if self.patchesUndo[0] == [[], []]:
|
||||||
|
del self.patchesUndo[0]
|
||||||
|
# }}}
|
||||||
# {{{ popCursor(self)
|
# {{{ popCursor(self)
|
||||||
def popCursor(self):
|
def popCursor(self):
|
||||||
if len(self.patchesCursor):
|
if len(self.patchesCursor):
|
||||||
@ -33,13 +44,6 @@ class CanvasJournal():
|
|||||||
def pushCursor(self, patches):
|
def pushCursor(self, patches):
|
||||||
self.patchesCursor.append(patches)
|
self.patchesCursor.append(patches)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ pushDeltas(self, redoPatches, undoPatches)
|
|
||||||
def pushDeltas(self, redoPatches, undoPatches):
|
|
||||||
if self.patchesUndoLevel > 0:
|
|
||||||
del self.patchesUndo[0:self.patchesUndoLevel]; self.patchesUndoLevel = 0;
|
|
||||||
deltaItem = [undoPatches, redoPatches]; self.patchesUndo.insert(0, deltaItem);
|
|
||||||
return deltaItem
|
|
||||||
# }}}
|
|
||||||
# {{{ resetCursor(self)
|
# {{{ resetCursor(self)
|
||||||
def resetCursor(self):
|
def resetCursor(self):
|
||||||
if self.patchesCursor != None:
|
if self.patchesCursor != None:
|
||||||
|
@ -30,18 +30,19 @@ class GuiCanvasPanel(wx.ScrolledWindow):
|
|||||||
|
|
||||||
# {{{ applyTool(self, eventDc, eventType, keyChar, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, tool, viewRect)
|
# {{{ 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):
|
def applyTool(self, eventDc, eventType, keyChar, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, tool, viewRect):
|
||||||
rc = False
|
dirty, self.canvas.dirtyCursor, rc = False, False, False
|
||||||
self.canvas.dirtyJournal, self.canvas.dirtyCursor, rc = False, False, False
|
self.canvas.journal.begin()
|
||||||
if eventType == wx.wxEVT_CHAR:
|
if eventType == wx.wxEVT_CHAR:
|
||||||
rc = tool.onKeyboardEvent(self.brushColours, self.brushSize, self.dispatchPatch, eventDc, keyChar, keyModifiers, self.brushPos, viewRect)
|
rc, dirty = tool.onKeyboardEvent(self.brushColours, self.brushSize, self.dispatchPatchSingle, eventDc, keyChar, keyModifiers, self.brushPos, viewRect)
|
||||||
else:
|
else:
|
||||||
if (mapPoint[0] < self.canvas.size[0]) \
|
if (mapPoint[0] < self.canvas.size[0]) \
|
||||||
and (mapPoint[1] < self.canvas.size[1]):
|
and (mapPoint[1] < self.canvas.size[1]):
|
||||||
self.brushPos = mapPoint
|
self.brushPos = mapPoint
|
||||||
rc = tool.onMouseEvent(self.brushColours, self.brushSize, self.dispatchPatch, eventDc, self.brushPos, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
rc, dirty = tool.onMouseEvent(self.brushColours, self.brushSize, self.dispatchPatchSingle, eventDc, self.brushPos, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
if self.canvas.dirtyJournal:
|
if dirty:
|
||||||
self.dirty = True
|
self.dirty = True
|
||||||
self.interface.update(dirty=self.dirty, cellPos=self.brushPos, undoLevel=self.canvas.journal.patchesUndoLevel)
|
self.interface.update(dirty=self.dirty, cellPos=self.brushPos, undoLevel=self.canvas.journal.patchesUndoLevel)
|
||||||
|
self.canvas.journal.end()
|
||||||
if eventType == wx.wxEVT_MOTION:
|
if eventType == wx.wxEVT_MOTION:
|
||||||
self.interface.update(cellPos=mapPoint)
|
self.interface.update(cellPos=mapPoint)
|
||||||
return rc
|
return rc
|
||||||
@ -62,6 +63,11 @@ class GuiCanvasPanel(wx.ScrolledWindow):
|
|||||||
if self.canvas.dispatchPatch(isCursor, patch, False if isCursor else True):
|
if self.canvas.dispatchPatch(isCursor, patch, False if isCursor else True):
|
||||||
self._drawPatch(eventDc, isCursor, patch, viewRect)
|
self._drawPatch(eventDc, isCursor, patch, viewRect)
|
||||||
# }}}
|
# }}}
|
||||||
|
# {{{ dispatchPatchSingle(self, eventDc, isCursor, patch, viewRect)
|
||||||
|
def dispatchPatchSingle(self, eventDc, isCursor, patch, viewRect):
|
||||||
|
if self.canvas.dispatchPatchSingle(isCursor, patch, False if isCursor else True):
|
||||||
|
self._drawPatch(eventDc, isCursor, patch, viewRect)
|
||||||
|
# }}}
|
||||||
# {{{ resize(self, newSize, commitUndo=True)
|
# {{{ resize(self, newSize, commitUndo=True)
|
||||||
def resize(self, newSize, commitUndo=True):
|
def resize(self, newSize, commitUndo=True):
|
||||||
oldSize = [0, 0] if self.canvas.map == None else self.canvas.size
|
oldSize = [0, 0] if self.canvas.map == None else self.canvas.size
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
class Tool():
|
class Tool():
|
||||||
parentCanvas = None
|
parentCanvas = None
|
||||||
|
|
||||||
# {{{ onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect):
|
# {{{ onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect)
|
||||||
def onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect):
|
def onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect):
|
||||||
pass
|
return False, False
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# {{{ onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
pass
|
return False, False
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -12,7 +12,7 @@ class ToolCircle(Tool):
|
|||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def 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()
|
brushColours, dirty = brushColours.copy(), False
|
||||||
if mouseLeftDown:
|
if mouseLeftDown:
|
||||||
brushColours[1] = brushColours[0]
|
brushColours[1] = brushColours[0]
|
||||||
elif mouseRightDown:
|
elif mouseRightDown:
|
||||||
@ -29,9 +29,11 @@ class ToolCircle(Tool):
|
|||||||
mapPoint[1] + int(originPoint[1] + brushY), \
|
mapPoint[1] + int(originPoint[1] + brushY), \
|
||||||
*brushColours, 0, " "]
|
*brushColours, 0, " "]
|
||||||
if mouseLeftDown or mouseRightDown:
|
if mouseLeftDown or mouseRightDown:
|
||||||
|
if not dirty:
|
||||||
|
dirty = True
|
||||||
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
|
return True, dirty
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||||
|
@ -12,8 +12,7 @@ class ToolFill(Tool):
|
|||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def 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)], []
|
dirty, pointsDone, pointStack, testColour, = False, [], [list(mapPoint)], self.parentCanvas.canvas.map[mapPoint[1]][mapPoint[0]][0:2]
|
||||||
testColour = self.parentCanvas.canvas.map[mapPoint[1]][mapPoint[0]][0:2]
|
|
||||||
if mouseLeftDown or mouseRightDown:
|
if mouseLeftDown or mouseRightDown:
|
||||||
if mouseRightDown:
|
if mouseRightDown:
|
||||||
brushColours = [brushColours[1], brushColours[0]]
|
brushColours = [brushColours[1], brushColours[0]]
|
||||||
@ -23,6 +22,8 @@ class ToolFill(Tool):
|
|||||||
if (pointCell[0:2] == testColour) \
|
if (pointCell[0:2] == testColour) \
|
||||||
or ((pointCell[3] == " ") and (pointCell[1] == testColour[1])):
|
or ((pointCell[3] == " ") and (pointCell[1] == testColour[1])):
|
||||||
if not point in pointsDone:
|
if not point in pointsDone:
|
||||||
|
if not dirty:
|
||||||
|
dirty = True
|
||||||
dispatchFn(eventDc, False, [*point, brushColours[0], brushColours[0], 0, " "], viewRect)
|
dispatchFn(eventDc, False, [*point, brushColours[0], brushColours[0], 0, " "], viewRect)
|
||||||
if point[0] > 0:
|
if point[0] > 0:
|
||||||
pointStack.append([point[0] - 1, point[1]])
|
pointStack.append([point[0] - 1, point[1]])
|
||||||
@ -36,6 +37,6 @@ class ToolFill(Tool):
|
|||||||
else:
|
else:
|
||||||
patch = [mapPoint[0], mapPoint[1], brushColours[0], brushColours[0], 0, " "]
|
patch = [mapPoint[0], mapPoint[1], brushColours[0], brushColours[0], 0, " "]
|
||||||
dispatchFn(eventDc, True, patch, viewRect)
|
dispatchFn(eventDc, True, patch, viewRect)
|
||||||
return True
|
return True, dirty
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||||
|
@ -13,6 +13,7 @@ class ToolLine(Tool):
|
|||||||
|
|
||||||
# {{{ _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint, viewRect)
|
# {{{ _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint, viewRect)
|
||||||
def _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint, viewRect):
|
def _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint, viewRect):
|
||||||
|
dirty = False
|
||||||
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;
|
||||||
@ -32,10 +33,13 @@ class ToolLine(Tool):
|
|||||||
if isCursor:
|
if isCursor:
|
||||||
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect);
|
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect);
|
||||||
else:
|
else:
|
||||||
|
if not dirty:
|
||||||
|
dirty = True
|
||||||
dispatchFn(eventDc, True, patch, viewRect)
|
dispatchFn(eventDc, True, patch, viewRect)
|
||||||
if lineD > 0:
|
if lineD > 0:
|
||||||
lineD -= pointDelta[0]; lineY += 1;
|
lineD -= pointDelta[0]; lineY += 1;
|
||||||
lineD += pointDelta[1]
|
lineD += pointDelta[1]
|
||||||
|
return dirty
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _pointDelta(self, a, b)
|
# {{{ _pointDelta(self, a, b)
|
||||||
def _pointDelta(self, a, b):
|
def _pointDelta(self, a, b):
|
||||||
@ -49,7 +53,7 @@ class ToolLine(Tool):
|
|||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def 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()
|
brushColours, dirty = brushColours.copy(), False
|
||||||
if mouseLeftDown:
|
if mouseLeftDown:
|
||||||
brushColours[1] = brushColours[0]
|
brushColours[1] = brushColours[0]
|
||||||
elif mouseRightDown:
|
elif mouseRightDown:
|
||||||
@ -62,12 +66,12 @@ class ToolLine(Tool):
|
|||||||
dispatchFn(eventDc, True, [*mapPoint, *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(mapPoint)
|
originPoint, targetPoint = self.toolOriginPoint, list(mapPoint)
|
||||||
self._getLine(self.toolColours, brushSize, dispatchFn, eventDc, mouseLeftDown or mouseRightDown, originPoint, targetPoint, viewRect)
|
dirty = self._getLine(self.toolColours, brushSize, dispatchFn, eventDc, mouseLeftDown or mouseRightDown, originPoint, targetPoint, viewRect)
|
||||||
if mouseLeftDown or mouseRightDown:
|
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:
|
else:
|
||||||
return False
|
return False, dirty
|
||||||
return True
|
return True, dirty
|
||||||
|
|
||||||
# __init__(self, *args): initialisation method
|
# __init__(self, *args): initialisation method
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
|
@ -12,7 +12,7 @@ class ToolRect(Tool):
|
|||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def 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()
|
brushColours, dirty = brushColours.copy(), False
|
||||||
if mouseLeftDown:
|
if mouseLeftDown:
|
||||||
brushColours[1] = brushColours[0]
|
brushColours[1] = brushColours[0]
|
||||||
elif mouseRightDown:
|
elif mouseRightDown:
|
||||||
@ -26,9 +26,11 @@ class ToolRect(Tool):
|
|||||||
for brushCol in range(brushSize[0]):
|
for brushCol in range(brushSize[0]):
|
||||||
patch = [mapPoint[0] + brushCol, mapPoint[1] + brushRow, *brushColours, 0, " "]
|
patch = [mapPoint[0] + brushCol, mapPoint[1] + brushRow, *brushColours, 0, " "]
|
||||||
if mouseLeftDown or mouseRightDown:
|
if mouseLeftDown or mouseRightDown:
|
||||||
|
if not dirty:
|
||||||
|
dirty = True
|
||||||
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
|
return True, dirty
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||||
|
@ -22,9 +22,10 @@ class ToolSelect(Tool):
|
|||||||
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, viewRect)
|
dirty = self.onSelectEvent(disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect)
|
||||||
self._drawSelectRect(newTargetRect, dispatchFn, eventDc, viewRect)
|
self._drawSelectRect(newTargetRect, dispatchFn, eventDc, viewRect)
|
||||||
self.targetRect = newTargetRect
|
self.targetRect = newTargetRect
|
||||||
|
return dirty
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect)
|
# {{{ _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect)
|
||||||
def _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect):
|
def _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect):
|
||||||
@ -49,6 +50,7 @@ class ToolSelect(Tool):
|
|||||||
self.targetRect, self.toolState = [list(mapPoint), []], self.TS_ORIGIN
|
self.targetRect, self.toolState = [list(mapPoint), []], self.TS_ORIGIN
|
||||||
else:
|
else:
|
||||||
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect)
|
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect)
|
||||||
|
return False
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _mouseEventTsOrigin(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# {{{ _mouseEventTsOrigin(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def _mouseEventTsOrigin(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def _mouseEventTsOrigin(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
@ -70,9 +72,11 @@ class ToolSelect(Tool):
|
|||||||
else:
|
else:
|
||||||
self.targetRect[1] = list(mapPoint)
|
self.targetRect[1] = list(mapPoint)
|
||||||
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
|
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
|
||||||
|
return False
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _mouseEventTsSelect(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# {{{ _mouseEventTsSelect(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def _mouseEventTsSelect(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def _mouseEventTsSelect(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
|
dirty = False
|
||||||
if mouseLeftDown \
|
if mouseLeftDown \
|
||||||
and (mapPoint[0] >= (self.targetRect[0][0] - 1)) \
|
and (mapPoint[0] >= (self.targetRect[0][0] - 1)) \
|
||||||
and (mapPoint[0] <= (self.targetRect[1][0] + 1)) \
|
and (mapPoint[0] <= (self.targetRect[1][0] + 1)) \
|
||||||
@ -80,37 +84,41 @@ class ToolSelect(Tool):
|
|||||||
and (mapPoint[1] <= (self.targetRect[1][1] + 1)):
|
and (mapPoint[1] <= (self.targetRect[1][1] + 1)):
|
||||||
self.lastAtPoint, self.toolState = list(mapPoint), self.TS_TARGET
|
self.lastAtPoint, self.toolState = list(mapPoint), self.TS_TARGET
|
||||||
elif mouseRightDown:
|
elif mouseRightDown:
|
||||||
self._dispatchSelectEvent(mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
dirty = 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(mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
dirty = self._dispatchSelectEvent(mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
||||||
|
return dirty
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _mouseEventTsTarget(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# {{{ _mouseEventTsTarget(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def _mouseEventTsTarget(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def _mouseEventTsTarget(self, mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
|
dirty = False
|
||||||
if mouseLeftDown:
|
if mouseLeftDown:
|
||||||
self.toolState = self.TS_TARGET
|
self.toolState = self.TS_TARGET
|
||||||
self._dispatchSelectEvent(mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
dirty = self._dispatchSelectEvent(mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
||||||
elif mouseRightDown:
|
elif mouseRightDown:
|
||||||
self._dispatchSelectEvent(mapPoint, dispatchFn, eventDc, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
dirty = 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
|
||||||
|
return dirty
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
|
dirty = False
|
||||||
if self.toolState == self.TS_NONE:
|
if self.toolState == self.TS_NONE:
|
||||||
self._mouseEventTsNone(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
dirty = self._mouseEventTsNone(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
elif self.toolState == self.TS_ORIGIN:
|
elif self.toolState == self.TS_ORIGIN:
|
||||||
self._mouseEventTsOrigin(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
dirty = self._mouseEventTsOrigin(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
elif self.toolState == self.TS_SELECT:
|
elif self.toolState == self.TS_SELECT:
|
||||||
self._mouseEventTsSelect(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
dirty = self._mouseEventTsSelect(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
elif self.toolState == self.TS_TARGET:
|
elif self.toolState == self.TS_TARGET:
|
||||||
self._mouseEventTsTarget(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
dirty = self._mouseEventTsTarget(mapPoint, brushColours, dispatchFn, eventDc, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
else:
|
else:
|
||||||
return False
|
return False, dirty
|
||||||
return True
|
return True, dirty
|
||||||
|
|
||||||
#
|
#
|
||||||
# onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect)
|
# onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect)
|
||||||
|
@ -12,11 +12,13 @@ class ToolSelectClone(ToolSelect):
|
|||||||
#
|
#
|
||||||
# onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect)
|
# onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect)
|
||||||
def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect):
|
def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect):
|
||||||
|
dirty = False
|
||||||
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
|
||||||
|
dirty = False if isCursor else True
|
||||||
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect)
|
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect)
|
||||||
return True
|
return dirty
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||||
|
@ -12,6 +12,7 @@ class ToolSelectMove(ToolSelect):
|
|||||||
#
|
#
|
||||||
# onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect)
|
# onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect)
|
||||||
def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect):
|
def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect):
|
||||||
|
dirty = False
|
||||||
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)
|
||||||
@ -19,7 +20,8 @@ class ToolSelectMove(ToolSelect):
|
|||||||
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
|
||||||
|
dirty = False if isCursor else True
|
||||||
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect)
|
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect)
|
||||||
return True
|
return dirty
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||||
|
@ -13,11 +13,14 @@ class ToolText(Tool):
|
|||||||
#
|
#
|
||||||
# onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect)
|
# onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect)
|
||||||
def onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect):
|
def onKeyboardEvent(self, brushColours, brushSize, dispatchFn, eventDc, keyChar, keyModifiers, mapPoint, viewRect):
|
||||||
|
dirty = False
|
||||||
if not keyModifiers in (wx.MOD_NONE, wx.MOD_SHIFT):
|
if not keyModifiers in (wx.MOD_NONE, wx.MOD_SHIFT):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
if self.textPos == None:
|
if self.textPos == None:
|
||||||
self.textPos = list(mapPoint)
|
self.textPos = list(mapPoint)
|
||||||
|
if not dirty:
|
||||||
|
dirty = True
|
||||||
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
|
||||||
@ -25,7 +28,7 @@ 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 True
|
return True, dirty
|
||||||
|
|
||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
@ -33,7 +36,7 @@ class ToolText(Tool):
|
|||||||
if mouseLeftDown or mouseRightDown:
|
if mouseLeftDown or mouseRightDown:
|
||||||
self.textPos = list(mapPoint)
|
self.textPos = list(mapPoint)
|
||||||
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, "_"], viewRect)
|
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, "_"], viewRect)
|
||||||
return True
|
return True, False
|
||||||
|
|
||||||
# __init__(self, *args): initialisation method
|
# __init__(self, *args): initialisation method
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
|
Loading…
Reference in New Issue
Block a user