mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-22 07:16:38 +00:00
Decisively vanquish the lion's share of ftupid fucking fcrolling.
libgui/GuiCanvasWxBackend.py: rOAorAoARRAORA ROaroAR RAOAr roar RAOAAAR... libroar/Roar{AssetsWindow,Canvas{CommandsOperators,Window}}.py: RoaWORAROORAOARORARARRA!! libtools/Tool{,Circle,Fill,Line,Object,Rect,Text}.py: ROAOaRoaROAROAROOAAAARORORAOR? assets/text/TODO: updated.
This commit is contained in:
parent
187dfa6355
commit
3dae6dadde
@ -19,13 +19,6 @@ High-priority list:
|
||||
c) Settings/Settings window (e.g. autosave, hide cursor on leaving window, ...)
|
||||
d) replace resize buttons w/ {-,edit box,+} buttons & lock button re: ratio (ty lol3)
|
||||
e) {copy,cut,delete,insert from,paste}, {edit asset in new canvas,import from {canvas,object}}
|
||||
|
||||
Queue:
|
||||
1) scrolling bug: start @ top, down key til cursor below visible canvas, scroll down, cursor gone GRRRR
|
||||
2) scrolling bug: scroll down, apply operator to entire canvas, scroll up
|
||||
3) scrolling bug: scroll down, text tool, move cursor w/ arrow keys
|
||||
4) object tool: object size wrong occasionally w/ external objects
|
||||
5) scrolling bug: scroll down, un/redo, scroll up
|
||||
6) clone selection lag
|
||||
5) finish Arabic/RTL text implementation
|
||||
|
||||
vim:ff=dos tw=0
|
||||
|
@ -188,13 +188,13 @@ class GuiCanvasWxBackend():
|
||||
return [a * b for a, b in zip(point, self.cellSize)]
|
||||
# }}}
|
||||
|
||||
# {{{ drawCursorMaskWithJournal(self, canvas, canvasJournal, eventDc, viewRect)
|
||||
def drawCursorMaskWithJournal(self, canvas, canvasJournal, eventDc, viewRect):
|
||||
[self.drawPatch(canvas, eventDc, patch, viewRect) for patch in canvasJournal.popCursor()]
|
||||
# {{{ drawCursorMaskWithJournal(self, canvas, canvasJournal, eventDc)
|
||||
def drawCursorMaskWithJournal(self, canvas, canvasJournal, eventDc):
|
||||
[self.drawPatch(canvas, eventDc, patch) for patch in canvasJournal.popCursor()]
|
||||
# }}}
|
||||
# {{{ drawPatch(self, canvas, eventDc, patch, viewRect)
|
||||
def drawPatch(self, canvas, eventDc, patch, viewRect):
|
||||
point = [m - n for m, n in zip(patch[:2], viewRect)]
|
||||
# {{{ drawPatch(self, canvas, eventDc, patch)
|
||||
def drawPatch(self, canvas, eventDc, patch):
|
||||
point = patch[:2]
|
||||
if [(c >= 0) and (c < s) for c, s in zip(point, self.canvasSize)] == [True, True]:
|
||||
if patch[5] == " ":
|
||||
if patch[3] == -1:
|
||||
@ -211,8 +211,10 @@ class GuiCanvasWxBackend():
|
||||
else:
|
||||
return False
|
||||
# }}}
|
||||
# {{{ getDeviceContext(self, clientSize, parentWindow, viewRect)
|
||||
def getDeviceContext(self, clientSize, parentWindow, viewRect):
|
||||
# {{{ getDeviceContext(self, clientSize, parentWindow, viewRect=None)
|
||||
def getDeviceContext(self, clientSize, parentWindow, viewRect=None):
|
||||
if viewRect == None:
|
||||
viewRect = parentWindow.GetViewStart()
|
||||
if viewRect == (0, 0):
|
||||
eventDc = wx.BufferedDC(wx.ClientDC(parentWindow), self.canvasBitmap)
|
||||
else:
|
||||
|
@ -10,10 +10,10 @@ from GuiWindow import GuiWindow
|
||||
import json, os, sys, wx
|
||||
|
||||
class RoarAssetsWindow(GuiMiniFrame):
|
||||
# {{{ _drawPatch(self, canvas, eventDc, isCursor, patch, viewRect)
|
||||
def _drawPatch(self, canvas, eventDc, isCursor, patch, viewRect):
|
||||
# {{{ _drawPatch(self, canvas, eventDc, isCursor, patch)
|
||||
def _drawPatch(self, canvas, eventDc, isCursor, patch):
|
||||
if not isCursor:
|
||||
self.backend.drawPatch(canvas, eventDc, patch, viewRect)
|
||||
self.backend.drawPatch(canvas, eventDc, patch)
|
||||
# }}}
|
||||
# {{{ _import(self, f, pathName)
|
||||
def _import(self, f, pathName):
|
||||
@ -109,11 +109,12 @@ class RoarAssetsWindow(GuiMiniFrame):
|
||||
while curWindow != None:
|
||||
curWindow.Layout(); curWindow = curWindow.GetParent();
|
||||
self.backend.resize(canvas.size, self.cellSize)
|
||||
viewRect = self.panelCanvas.GetViewStart();
|
||||
eventDc = self.backend.getDeviceContext(self.panelCanvas.GetClientSize(), self.panelCanvas, viewRect)
|
||||
eventDc = self.backend.getDeviceContext(self.panelCanvas.GetClientSize(), self.panelCanvas)
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
for numRow in range(canvas.size[1]):
|
||||
for numCol in range(canvas.size[0]):
|
||||
self.backend.drawPatch(canvas, eventDc, [numCol, numRow, *canvas.map[numRow][numCol]], viewRect)
|
||||
self.backend.drawPatch(canvas, eventDc, [numCol, numRow, *canvas.map[numRow][numCol]])
|
||||
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
||||
# }}}
|
||||
# {{{ onPaint(self, event)
|
||||
def onPaint(self, event):
|
||||
@ -149,25 +150,28 @@ class RoarAssetsWindow(GuiMiniFrame):
|
||||
while curWindow != None:
|
||||
curWindow.Layout(); curWindow = curWindow.GetParent();
|
||||
self.backend.resize(newSize, self.cellSize)
|
||||
viewRect = self.panelCanvas.GetViewStart(); eventDc = self.backend.getDeviceContext(self.panelCanvas.GetClientSize(), self.panelCanvas, viewRect);
|
||||
eventDc = self.backend.getDeviceContext(self.panelCanvas.GetClientSize(), self.panelCanvas)
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
if deltaSize[0] > 0:
|
||||
for numRow in range(oldSize[1]):
|
||||
for numNewCol in range(oldSize[0], newSize[0]):
|
||||
self._drawPatch(canvas, eventDc, False, [numNewCol, numRow, 1, 1, 0, " "], viewRect)
|
||||
self._drawPatch(canvas, eventDc, False, [numNewCol, numRow, 1, 1, 0, " "])
|
||||
if deltaSize[1] > 1:
|
||||
for numNewRow in range(oldSize[1], newSize[1]):
|
||||
for numNewCol in range(newSize[0]):
|
||||
self._drawPatch(canvas, eventDc, False, [numNewCol, numNewRow, 1, 1, 0, " "], viewRect)
|
||||
self._drawPatch(canvas, eventDc, False, [numNewCol, numNewRow, 1, 1, 0, " "])
|
||||
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
||||
# }}}
|
||||
# {{{ update(self, canvas, newSize, newCanvas=None)
|
||||
def update(self, canvas, newSize, newCanvas=None):
|
||||
self.resize(canvas, newSize);
|
||||
canvas.update(newSize, newCanvas); viewRect = self.panelCanvas.GetViewStart();
|
||||
viewRect = self.panelCanvas.GetViewStart();
|
||||
eventDc = self.backend.getDeviceContext(self.panelCanvas.GetClientSize(), self.panelCanvas, viewRect)
|
||||
canvas.update(newSize, newCanvas);
|
||||
eventDc = self.backend.getDeviceContext(self.panelCanvas.GetClientSize(), self.panelCanvas)
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
for numRow in range(canvas.size[1]):
|
||||
for numCol in range(canvas.size[0]):
|
||||
self.backend.drawPatch(canvas, eventDc, [numCol, numRow, *canvas.map[numRow][numCol]], viewRect)
|
||||
self.backend.drawPatch(canvas, eventDc, [numCol, numRow, *canvas.map[numRow][numCol]])
|
||||
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
||||
# }}}
|
||||
|
||||
# {{{ onImportAnsi(self, event)
|
||||
|
@ -27,28 +27,30 @@ class RoarCanvasCommandsOperators():
|
||||
region = applyOperator.apply(copy.deepcopy(region))
|
||||
if (self.currentTool.__class__ == ToolObject) \
|
||||
and (self.currentTool.toolState >= self.currentTool.TS_SELECT):
|
||||
viewRect = self.parentCanvas.GetViewStart()
|
||||
if self.parentCanvas.popupEventDc == None:
|
||||
eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas.GetClientSize(), self.parentCanvas, viewRect)
|
||||
eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas.GetClientSize(), self.parentCanvas)
|
||||
else:
|
||||
eventDc = self.parentCanvas.popupEventDc
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
self.currentTool.setRegion(self.parentCanvas.canvas, None, region, [len(region[0]), len(region)], self.currentTool.external)
|
||||
self.currentTool.onSelectEvent(self.parentCanvas.canvas, (0, 0), self.parentCanvas.dispatchPatchSingle, eventDc, True, wx.MOD_NONE, None, self.currentTool.targetRect, viewRect)
|
||||
self.currentTool.onSelectEvent(self.parentCanvas.canvas, (0, 0), self.parentCanvas.dispatchPatchSingle, eventDc, True, wx.MOD_NONE, None, self.currentTool.targetRect)
|
||||
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
||||
else:
|
||||
viewRect = self.parentCanvas.GetViewStart()
|
||||
if self.parentCanvas.popupEventDc == None:
|
||||
eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas.GetClientSize(), self.parentCanvas, viewRect)
|
||||
eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas.GetClientSize(), self.parentCanvas)
|
||||
else:
|
||||
eventDc = self.parentCanvas.popupEventDc
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
self.parentCanvas.canvas.journal.begin()
|
||||
dirty = False
|
||||
for numRow in range(len(region)):
|
||||
for numCol in range(len(region[numRow])):
|
||||
if not dirty:
|
||||
self.parentCanvas.dirty = True
|
||||
self.parentCanvas.dispatchPatchSingle(eventDc, False, [numCol, numRow, *region[numRow][numCol]], viewRect)
|
||||
self.parentCanvas.dispatchPatchSingle(eventDc, False, [numCol, numRow, *region[numRow][numCol]])
|
||||
self.parentCanvas.canvas.journal.end()
|
||||
self.parentCanvas.commands.update(dirty=self.parentCanvas.dirty, undoLevel=self.parentCanvas.canvas.journal.patchesUndoLevel)
|
||||
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
||||
setattr(canvasOperator_, "attrDict", f.attrList[idx])
|
||||
return canvasOperator_
|
||||
# }}}
|
||||
|
@ -8,7 +8,6 @@ from GuiWindow import GuiWindow
|
||||
from ToolObject import ToolObject
|
||||
from ToolText import ToolText
|
||||
import json, wx, sys
|
||||
import time
|
||||
|
||||
class RoarCanvasWindowDropTarget(wx.TextDropTarget):
|
||||
# {{{ done(self)
|
||||
@ -23,15 +22,16 @@ class RoarCanvasWindowDropTarget(wx.TextDropTarget):
|
||||
and (not self.inProgress):
|
||||
try:
|
||||
dropMap, dropSize = json.loads(data)
|
||||
viewRect = self.parent.GetViewStart()
|
||||
rectX, rectY = x - (x % self.parent.backend.cellSize[0]), y - (y % self.parent.backend.cellSize[1])
|
||||
mapX, mapY = int(rectX / self.parent.backend.cellSize[0] if rectX else 0), int(rectY / self.parent.backend.cellSize[1] if rectY else 0)
|
||||
mapPoint = [m + n for m, n in zip((mapX, mapY), viewRect)]
|
||||
viewRect = self.parent.GetViewStart(); mapPoint = [m + n for m, n in zip((mapX, mapY), viewRect)];
|
||||
self.parent.commands.lastTool, self.parent.commands.currentTool = self.parent.commands.currentTool, ToolObject()
|
||||
self.parent.commands.currentTool.setRegion(self.parent.canvas, mapPoint, dropMap, dropSize, external=True)
|
||||
self.parent.commands.update(toolName=self.parent.commands.currentTool.name)
|
||||
eventDc = self.parent.backend.getDeviceContext(self.parent.GetClientSize(), self.parent, viewRect)
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
self.parent.applyTool(eventDc, True, None, None, None, self.parent.brushPos, False, False, False, self.parent.commands.currentTool, viewRect)
|
||||
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
||||
rc = True; self.inProgress = True;
|
||||
except:
|
||||
with wx.MessageDialog(self.parent, "Error: {}".format(sys.exc_info()[1]), "", wx.OK | wx.OK_DEFAULT) as dialog:
|
||||
@ -44,18 +44,19 @@ class RoarCanvasWindowDropTarget(wx.TextDropTarget):
|
||||
# }}}
|
||||
|
||||
class RoarCanvasWindow(GuiWindow):
|
||||
# {{{ _drawPatch(self, eventDc, isCursor, patch, viewRect)
|
||||
def _drawPatch(self, eventDc, isCursor, patch, viewRect):
|
||||
# {{{ _drawPatch(self, eventDc, isCursor, patch)
|
||||
def _drawPatch(self, eventDc, isCursor, patch):
|
||||
if not self.canvas.dirtyCursor:
|
||||
self.backend.drawCursorMaskWithJournal(self.canvas, self.canvas.journal, eventDc, viewRect)
|
||||
self.backend.drawCursorMaskWithJournal(self.canvas, self.canvas.journal, eventDc)
|
||||
self.canvas.dirtyCursor = True
|
||||
if self.backend.drawPatch(self.canvas, eventDc, patch, viewRect) and isCursor:
|
||||
if self.backend.drawPatch(self.canvas, eventDc, patch) and isCursor:
|
||||
patchDeltaCell = self.canvas.map[patch[1]][patch[0]]; patchDelta = [*patch[0:2], *patchDeltaCell];
|
||||
self.canvas.journal.pushCursor(patchDelta)
|
||||
# }}}
|
||||
|
||||
# {{{ applyTool(self, eventDc, eventMouse, keyChar, keyCode, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, tool, viewRect)
|
||||
def applyTool(self, eventDc, eventMouse, keyChar, keyCode, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, tool, viewRect):
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
if mapPoint != None:
|
||||
mapPoint = [a + b for a, b in zip(mapPoint, viewRect)]
|
||||
dirty, self.canvas.dirtyCursor, rc = False, False, False
|
||||
@ -68,15 +69,15 @@ class RoarCanvasWindow(GuiWindow):
|
||||
if tool.__class__ != ToolText:
|
||||
self.brushPos = list(mapPoint)
|
||||
if tool != None:
|
||||
rc, dirty = tool.onMouseEvent(mapPoint, self.brushColours, self.brushPos, self.brushSize, self.canvas, self.dispatchPatchSingle, eventDc, keyModifiers, self.brushPos, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||
rc, dirty = tool.onMouseEvent(mapPoint, self.brushColours, self.brushPos, self.brushSize, self.canvas, self.dispatchPatchSingle, eventDc, keyModifiers, self.brushPos, mouseDragging, mouseLeftDown, mouseRightDown)
|
||||
else:
|
||||
self.dispatchPatchSingle(eventDc, True, [*mapPoint, self.brushColours[0], self.brushColours[0], 0, " "] , viewRect)
|
||||
self.dispatchPatchSingle(eventDc, True, [*mapPoint, self.brushColours[0], self.brushColours[0], 0, " "])
|
||||
self.lastCellState = [list(mapPoint), mouseDragging, mouseLeftDown, mouseRightDown, list(viewRect)]
|
||||
else:
|
||||
if tool != None:
|
||||
rc, dirty = tool.onKeyboardEvent(mapPoint, self.brushColours, self.brushPos, self.brushSize, self.canvas, self.dispatchPatchSingle, eventDc, keyChar, keyCode, keyModifiers, self.brushPos, viewRect)
|
||||
rc, dirty = tool.onKeyboardEvent(mapPoint, self.brushColours, self.brushPos, self.brushSize, self.canvas, self.dispatchPatchSingle, eventDc, keyChar, keyCode, keyModifiers, self.brushPos)
|
||||
elif mapPoint != None:
|
||||
self.dispatchPatchSingle(eventDc, True, [*mapPoint, self.brushColours[0], self.brushColours[0], 0, " "] , viewRect)
|
||||
self.dispatchPatchSingle(eventDc, True, [*mapPoint, self.brushColours[0], self.brushColours[0], 0, " "])
|
||||
if dirty:
|
||||
self.dirty = True
|
||||
self.commands.update(dirty=self.dirty, cellPos=self.brushPos, undoLevel=self.canvas.journal.patchesUndoLevel)
|
||||
@ -96,32 +97,36 @@ class RoarCanvasWindow(GuiWindow):
|
||||
self.commands.update(toolName="Cursor", undoInhibit=False)
|
||||
else:
|
||||
self.commands.update(undoInhibit=False)
|
||||
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
||||
return rc
|
||||
# }}}
|
||||
# {{{ dispatchDeltaPatches(self, deltaPatches)
|
||||
def dispatchDeltaPatches(self, deltaPatches):
|
||||
viewRect = self.GetViewStart()
|
||||
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, viewRect)
|
||||
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self)
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
if self.canvas.dirtyCursor:
|
||||
self.backend.drawCursorMaskWithJournal(self.canvas, self.canvas.journal, eventDc, viewRect)
|
||||
self.backend.drawCursorMaskWithJournal(self.canvas, self.canvas.journal, eventDc)
|
||||
self.canvas.dirtyCursor = False
|
||||
for patch in deltaPatches:
|
||||
if patch == None:
|
||||
continue
|
||||
elif patch[0] == "resize":
|
||||
del eventDc; self.resize(patch[1:], False); eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, self.GetViewStart());
|
||||
del eventDc; self.resize(patch[1:], False);
|
||||
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self)
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
else:
|
||||
self.canvas._commitPatch(patch); self.backend.drawPatch(self.canvas, eventDc, patch, self.GetViewStart());
|
||||
self.canvas._commitPatch(patch); self.backend.drawPatch(self.canvas, eventDc, patch)
|
||||
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
||||
# }}}
|
||||
# {{{ dispatchPatch(self, eventDc, isCursor, patch, viewRect)
|
||||
def dispatchPatch(self, eventDc, isCursor, patch, viewRect):
|
||||
# {{{ dispatchPatch(self, eventDc, isCursor, patch)
|
||||
def dispatchPatch(self, eventDc, isCursor, patch):
|
||||
if self.canvas.dispatchPatch(isCursor, patch, False if isCursor else True):
|
||||
self._drawPatch(eventDc, isCursor, patch, viewRect)
|
||||
self._drawPatch(eventDc, isCursor, patch)
|
||||
# }}}
|
||||
# {{{ dispatchPatchSingle(self, eventDc, isCursor, patch, viewRect)
|
||||
def dispatchPatchSingle(self, eventDc, isCursor, patch, viewRect):
|
||||
# {{{ dispatchPatchSingle(self, eventDc, isCursor, patch)
|
||||
def dispatchPatchSingle(self, eventDc, isCursor, patch):
|
||||
if self.canvas.dispatchPatchSingle(isCursor, patch, False if isCursor else True):
|
||||
self._drawPatch(eventDc, isCursor, patch, viewRect)
|
||||
self._drawPatch(eventDc, isCursor, patch)
|
||||
# }}}
|
||||
# {{{ resize(self, newSize, commitUndo=True)
|
||||
def resize(self, newSize, commitUndo=True):
|
||||
@ -130,15 +135,17 @@ class RoarCanvasWindow(GuiWindow):
|
||||
if self.canvas.resize(newSize, commitUndo):
|
||||
super().resize([a * b for a, b in zip(newSize, self.backend.cellSize)])
|
||||
self.backend.resize(newSize, self.backend.cellSize)
|
||||
viewRect = self.GetViewStart(); eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, viewRect);
|
||||
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self)
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
if deltaSize[0] > 0:
|
||||
for numRow in range(oldSize[1]):
|
||||
for numNewCol in range(oldSize[0], newSize[0]):
|
||||
self._drawPatch(eventDc, False, [numNewCol, numRow, 1, 1, 0, " "], viewRect)
|
||||
self._drawPatch(eventDc, False, [numNewCol, numRow, 1, 1, 0, " "])
|
||||
if deltaSize[1] > 1:
|
||||
for numNewRow in range(oldSize[1], newSize[1]):
|
||||
for numNewCol in range(newSize[0]):
|
||||
self._drawPatch(eventDc, False, [numNewCol, numNewRow, 1, 1, 0, " "], viewRect)
|
||||
self._drawPatch(eventDc, False, [numNewCol, numNewRow, 1, 1, 0, " "])
|
||||
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
||||
self.commands.update(size=newSize, undoLevel=self.canvas.journal.patchesUndoLevel)
|
||||
# }}}
|
||||
# {{{ update(self, newSize, commitUndo=True, newCanvas=None)
|
||||
@ -146,9 +153,11 @@ class RoarCanvasWindow(GuiWindow):
|
||||
self.resize(newSize, commitUndo)
|
||||
self.canvas.update(newSize, newCanvas)
|
||||
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, self.GetViewStart())
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
for numRow in range(newSize[1]):
|
||||
for numCol in range(newSize[0]):
|
||||
self.backend.drawPatch(self.canvas, eventDc, [numCol, numRow, *self.canvas.map[numRow][numCol]], self.GetViewStart())
|
||||
self.backend.drawPatch(self.canvas, eventDc, [numCol, numRow, *self.canvas.map[numRow][numCol]])
|
||||
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
||||
# }}}
|
||||
|
||||
# {{{ onKeyboardInput(self, event)
|
||||
@ -193,7 +202,9 @@ class RoarCanvasWindow(GuiWindow):
|
||||
def onLeaveWindow(self, event):
|
||||
if False:
|
||||
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, self.GetViewStart())
|
||||
self.backend.drawCursorMaskWithJournal(self.canvas, self.canvas.journal, eventDc, self.GetViewStart())
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
self.backend.drawCursorMaskWithJournal(self.canvas, self.canvas.journal, eventDc)
|
||||
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
||||
self.lastCellState = None
|
||||
# }}}
|
||||
# {{{ onMouseInput(self, event)
|
||||
@ -217,18 +228,21 @@ class RoarCanvasWindow(GuiWindow):
|
||||
self.backend.cellSize = newCellSize
|
||||
super().resize([a * b for a, b in zip(self.canvas.size, self.backend.cellSize)])
|
||||
self.backend.resize(self.canvas.size, self.backend.cellSize)
|
||||
viewRect = self.GetViewStart(); eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, viewRect);
|
||||
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self)
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
for numRow in range(self.canvas.size[1]):
|
||||
for numCol in range(len(self.canvas.map[numRow])):
|
||||
self._drawPatch(eventDc, False, [numCol, numRow, *self.canvas.map[numRow][numCol]], viewRect)
|
||||
self._drawPatch(eventDc, False, [numCol, numRow, *self.canvas.map[numRow][numCol]])
|
||||
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
||||
else:
|
||||
event.Skip()
|
||||
# }}}
|
||||
# {{{ onPaint(self, event)
|
||||
def onPaint(self, event):
|
||||
viewRect = self.GetViewStart()
|
||||
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, viewRect)
|
||||
self.backend.drawCursorMaskWithJournal(self.canvas, self.canvas.journal, eventDc, viewRect)
|
||||
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self)
|
||||
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
|
||||
self.backend.drawCursorMaskWithJournal(self.canvas, self.canvas.journal, eventDc)
|
||||
eventDc.SetDeviceOrigin(*eventDcOrigin)
|
||||
self.backend.onPaint(self.GetClientSize(), self, self.GetViewStart())
|
||||
# }}}
|
||||
|
||||
|
@ -5,12 +5,12 @@
|
||||
#
|
||||
|
||||
class Tool(object):
|
||||
# {{{ onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint, viewRect)
|
||||
def onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint, viewRect):
|
||||
# {{{ onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint)
|
||||
def onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint):
|
||||
return False, False
|
||||
# }}}
|
||||
# {{{ onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||
# {{{ onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
|
||||
return False, False
|
||||
# }}}
|
||||
|
||||
|
@ -10,8 +10,8 @@ class ToolCircle(Tool):
|
||||
name = "Circle"
|
||||
|
||||
#
|
||||
# onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||
# onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
|
||||
brushColours, dirty = brushColours.copy(), False
|
||||
if mouseLeftDown:
|
||||
brushColours[1] = brushColours[0]
|
||||
@ -31,9 +31,9 @@ class ToolCircle(Tool):
|
||||
if mouseLeftDown or mouseRightDown:
|
||||
if not dirty:
|
||||
dirty = True
|
||||
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect);
|
||||
dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
|
||||
else:
|
||||
dispatchFn(eventDc, True, patch, viewRect)
|
||||
dispatchFn(eventDc, True, patch)
|
||||
return True, dirty
|
||||
|
||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||
|
@ -10,8 +10,8 @@ class ToolFill(Tool):
|
||||
name = "Fill"
|
||||
|
||||
#
|
||||
# onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||
# onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
|
||||
dirty, pointsDone, pointStack, testChar, testColour = False, [], [list(mapPoint)], canvas.map[mapPoint[1]][mapPoint[0]][3], canvas.map[mapPoint[1]][mapPoint[0]][0:2]
|
||||
if mouseLeftDown or mouseRightDown:
|
||||
while len(pointStack) > 0:
|
||||
@ -22,7 +22,7 @@ class ToolFill(Tool):
|
||||
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, " "])
|
||||
if point[0] > 0:
|
||||
pointStack.append([point[0] - 1, point[1]])
|
||||
if point[0] < (canvas.size[0] - 1):
|
||||
@ -34,7 +34,7 @@ class ToolFill(Tool):
|
||||
pointsDone += [point]
|
||||
else:
|
||||
patch = [mapPoint[0], mapPoint[1], brushColours[0], brushColours[0], 0, " "]
|
||||
dispatchFn(eventDc, True, patch, viewRect)
|
||||
dispatchFn(eventDc, True, patch)
|
||||
return True, dirty
|
||||
|
||||
# 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, viewRect)
|
||||
def _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint, viewRect):
|
||||
# {{{ _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint)
|
||||
def _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint):
|
||||
dirty = False
|
||||
originPoint, targetPoint = originPoint.copy(), targetPoint.copy()
|
||||
pointDelta = self._pointDelta(originPoint, targetPoint)
|
||||
@ -31,11 +31,11 @@ class ToolLine(Tool):
|
||||
originPoint[1] + lineX * lineXY + lineY * lineYY, \
|
||||
*brushColours, 0, " "]
|
||||
if isCursor:
|
||||
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect);
|
||||
dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
|
||||
else:
|
||||
if not dirty:
|
||||
dirty = True
|
||||
dispatchFn(eventDc, True, patch, viewRect)
|
||||
dispatchFn(eventDc, True, patch)
|
||||
if lineD > 0:
|
||||
lineD -= pointDelta[0]; lineY += 1;
|
||||
lineD += pointDelta[1]
|
||||
@ -51,8 +51,8 @@ class ToolLine(Tool):
|
||||
# }}}
|
||||
|
||||
#
|
||||
# onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||
# onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
|
||||
brushColours, dirty = brushColours.copy(), False
|
||||
if mouseLeftDown:
|
||||
brushColours[1] = brushColours[0]
|
||||
@ -63,10 +63,10 @@ class ToolLine(Tool):
|
||||
if self.toolState == self.TS_NONE:
|
||||
if mouseLeftDown or mouseRightDown:
|
||||
self.toolColours, self.toolOriginPoint, self.toolState = brushColours, list(mapPoint), self.TS_ORIGIN
|
||||
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect)
|
||||
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "])
|
||||
elif self.toolState == self.TS_ORIGIN:
|
||||
originPoint, targetPoint = self.toolOriginPoint, list(mapPoint)
|
||||
dirty = 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)
|
||||
if mouseLeftDown or mouseRightDown:
|
||||
self.toolColours, self.toolOriginPoint, self.toolState = None, None, self.TS_NONE
|
||||
else:
|
||||
|
@ -14,21 +14,21 @@ class ToolObject(Tool):
|
||||
TS_SELECT = 2
|
||||
TS_TARGET = 3
|
||||
|
||||
# {{{ _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, selectRect, viewRect)
|
||||
def _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, selectRect, viewRect):
|
||||
# {{{ _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, selectRect)
|
||||
def _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, selectRect):
|
||||
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(mapPoint)
|
||||
else:
|
||||
disp, isCursor, newTargetRect = [0, 0], True, selectRect.copy()
|
||||
dirty = self.onSelectEvent(canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect, viewRect)
|
||||
self._drawSelectRect(newTargetRect, dispatchFn, eventDc, viewRect)
|
||||
dirty = self.onSelectEvent(canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect)
|
||||
self._drawSelectRect(newTargetRect, dispatchFn, eventDc)
|
||||
self.targetRect = newTargetRect
|
||||
return dirty
|
||||
# }}}
|
||||
# {{{ _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect)
|
||||
def _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect):
|
||||
# {{{ _drawSelectRect(self, rect, dispatchFn, eventDc)
|
||||
def _drawSelectRect(self, rect, dispatchFn, eventDc):
|
||||
rectFrame = [[rect[m][n] for n in [0, 1]] for m in (0, 1)]
|
||||
if rectFrame[0][0] > rectFrame[1][0]:
|
||||
rectFrame[0][0], rectFrame[1][0] = rectFrame[1][0], rectFrame[0][0]
|
||||
@ -37,27 +37,27 @@ class ToolObject(Tool):
|
||||
curColours, rectFrame = [0, 0], [[rectFrame[m[0]][n] + m[1] for n in [0, 1]] for m in [[0, -1], [1, +1]]]
|
||||
for rectX in range(rectFrame[0][0], rectFrame[1][0] + 1):
|
||||
curColours = [1, 1] if curColours == [0, 0] else [0, 0]
|
||||
dispatchFn(eventDc, True, [rectX, rectFrame[0][1], *curColours, 0, " "], viewRect)
|
||||
dispatchFn(eventDc, True, [rectX, rectFrame[1][1], *curColours, 0, " "], viewRect)
|
||||
dispatchFn(eventDc, True, [rectX, rectFrame[0][1], *curColours, 0, " "])
|
||||
dispatchFn(eventDc, True, [rectX, rectFrame[1][1], *curColours, 0, " "])
|
||||
for rectY in range(rectFrame[0][1], rectFrame[1][1] + 1):
|
||||
curColours = [1, 1] if curColours == [0, 0] else [0, 0]
|
||||
dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "], viewRect)
|
||||
dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "], viewRect)
|
||||
dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "])
|
||||
dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "])
|
||||
# }}}
|
||||
# {{{ _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
|
||||
def _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect):
|
||||
# {{{ _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown)
|
||||
def _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown):
|
||||
self.substract = False
|
||||
if self.external:
|
||||
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect)
|
||||
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "])
|
||||
else:
|
||||
if mouseLeftDown:
|
||||
self.targetRect, self.toolState = [list(mapPoint), []], self.TS_ORIGIN
|
||||
else:
|
||||
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect)
|
||||
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "])
|
||||
return False
|
||||
# }}}
|
||||
# {{{ _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
|
||||
def _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect):
|
||||
# {{{ _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown)
|
||||
def _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown):
|
||||
self.targetRect[1] = list(mapPoint)
|
||||
if mouseLeftDown:
|
||||
if self.targetRect[0][0] > self.targetRect[1][0]:
|
||||
@ -70,13 +70,13 @@ class ToolObject(Tool):
|
||||
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.objectMap[numRow].append(canvas.map[rectY][rectX])
|
||||
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
|
||||
self._drawSelectRect(self.targetRect, dispatchFn, eventDc)
|
||||
else:
|
||||
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
|
||||
self._drawSelectRect(self.targetRect, dispatchFn, eventDc)
|
||||
return False
|
||||
# }}}
|
||||
# {{{ _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
|
||||
def _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect):
|
||||
# {{{ _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown)
|
||||
def _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown):
|
||||
dirty = False
|
||||
if mouseLeftDown:
|
||||
if (mapPoint[0] >= (self.targetRect[0][0] - 1)) \
|
||||
@ -85,20 +85,20 @@ class ToolObject(Tool):
|
||||
and (mapPoint[1] <= (self.targetRect[1][1] + 1)):
|
||||
self.lastAtPoint, self.toolState = list(mapPoint), self.TS_TARGET
|
||||
else:
|
||||
dirty = self.onSelectEvent(canvas, (0, 0), dispatchFn, eventDc, False, keyModifiers, self.targetRect.copy(), self.targetRect, viewRect)
|
||||
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
|
||||
dirty = self.onSelectEvent(canvas, (0, 0), dispatchFn, eventDc, False, keyModifiers, self.targetRect.copy(), self.targetRect)
|
||||
self._drawSelectRect(self.targetRect, dispatchFn, eventDc)
|
||||
self.objectMap, self.objectSize, self.targetRect, self.toolState = None, None, None, self.TS_NONE
|
||||
else:
|
||||
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, self.targetRect, viewRect)
|
||||
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, self.targetRect)
|
||||
return dirty
|
||||
# }}}
|
||||
# {{{ _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
|
||||
def _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect):
|
||||
# {{{ _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown)
|
||||
def _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown):
|
||||
if (keyModifiers == wx.MOD_CONTROL) and (self.srcRect == self.targetRect):
|
||||
self.substract = True
|
||||
dirty = False
|
||||
if mouseLeftDown:
|
||||
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, self.targetRect, viewRect)
|
||||
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, self.targetRect)
|
||||
else:
|
||||
self.toolState = self.TS_SELECT
|
||||
return dirty
|
||||
@ -108,23 +108,23 @@ class ToolObject(Tool):
|
||||
def getRegion(self, canvas):
|
||||
return self.objectMap
|
||||
# }}}
|
||||
# {{{ onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||
# {{{ onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
|
||||
dirty = False
|
||||
if self.toolState == self.TS_NONE:
|
||||
dirty = self._mouseEventTsNone(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
|
||||
dirty = self._mouseEventTsNone(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown)
|
||||
elif self.toolState == self.TS_SELECT:
|
||||
dirty = self._mouseEventTsSelect(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
|
||||
dirty = self._mouseEventTsSelect(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown)
|
||||
elif self.toolState == self.TS_ORIGIN:
|
||||
dirty = self._mouseEventTsOrigin(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
|
||||
dirty = self._mouseEventTsOrigin(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown)
|
||||
elif self.toolState == self.TS_TARGET:
|
||||
dirty = self._mouseEventTsTarget(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
|
||||
dirty = self._mouseEventTsTarget(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown)
|
||||
else:
|
||||
return False, dirty
|
||||
return True, dirty
|
||||
# }}}
|
||||
# {{{ onSelectEvent(self, canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect, viewRect)
|
||||
def onSelectEvent(self, canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect, viewRect):
|
||||
# {{{ onSelectEvent(self, canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect)
|
||||
def onSelectEvent(self, canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect):
|
||||
dirty = False
|
||||
if self.external:
|
||||
for numRow in range(len(self.objectMap)):
|
||||
@ -135,7 +135,7 @@ class ToolObject(Tool):
|
||||
if (cellNew[1] == -1) and (cellNew[3] == " "):
|
||||
if ((rectY + disp[1]) < canvas.size[1]) and ((rectX + disp[0]) < canvas.size[0]):
|
||||
cellNew = canvas.map[rectY + disp[1]][rectX + disp[0]]
|
||||
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellNew], viewRect)
|
||||
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellNew])
|
||||
else:
|
||||
if self.substract:
|
||||
for numRow in range(self.srcRect[0][1], self.srcRect[1][1]):
|
||||
@ -143,13 +143,13 @@ class ToolObject(Tool):
|
||||
if ((numCol < selectRect[0][0]) or (numCol > selectRect[1][0])) \
|
||||
or ((numRow < selectRect[0][1]) or (numRow > selectRect[1][1])):
|
||||
dirty = False if isCursor else True
|
||||
dispatchFn(eventDc, isCursor, [numCol, numRow, 1, 1, 0, " "], viewRect)
|
||||
dispatchFn(eventDc, isCursor, [numCol, numRow, 1, 1, 0, " "])
|
||||
for numRow in range(len(self.objectMap)):
|
||||
for numCol in range(len(self.objectMap[numRow])):
|
||||
cellOld = self.objectMap[numRow][numCol]
|
||||
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])
|
||||
return dirty
|
||||
# }}}
|
||||
# {{{ setRegion(self, canvas, mapPoint, objectMap, objectSize, external=True)
|
||||
|
@ -10,8 +10,8 @@ class ToolRect(Tool):
|
||||
name = "Rectangle"
|
||||
|
||||
#
|
||||
# onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||
# onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
|
||||
brushColours, dirty = brushColours.copy(), False
|
||||
if mouseLeftDown:
|
||||
brushColours[1] = brushColours[0]
|
||||
@ -28,9 +28,9 @@ class ToolRect(Tool):
|
||||
if mouseLeftDown or mouseRightDown:
|
||||
if not dirty:
|
||||
dirty = True
|
||||
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect);
|
||||
dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
|
||||
else:
|
||||
dispatchFn(eventDc, True, patch, viewRect)
|
||||
dispatchFn(eventDc, True, patch)
|
||||
return True, dirty
|
||||
|
||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||
|
@ -42,13 +42,13 @@ class ToolText(Tool):
|
||||
break
|
||||
return rtlFlag
|
||||
# }}}
|
||||
# {{{ _processKeyChar(self, brushColours, brushPos, canvas, dispatchFn, eventDc, keyChar, keyModifiers, viewRect)
|
||||
def _processKeyChar(self, brushColours, brushPos, canvas, dispatchFn, eventDc, keyChar, keyModifiers, viewRect):
|
||||
# {{{ _processKeyChar(self, brushColours, brushPos, canvas, dispatchFn, eventDc, keyChar, keyModifiers)
|
||||
def _processKeyChar(self, brushColours, brushPos, canvas, dispatchFn, eventDc, keyChar, keyModifiers):
|
||||
if (ord(keyChar) != wx.WXK_NONE) \
|
||||
and (not keyChar in set("\t\n\v\f\r")) \
|
||||
and ((ord(keyChar) >= 32) if ord(keyChar) < 127 else True) \
|
||||
and (keyModifiers in (wx.MOD_NONE, wx.MOD_SHIFT)):
|
||||
dispatchFn(eventDc, False, [*brushPos, *brushColours, 0, keyChar], viewRect);
|
||||
dispatchFn(eventDc, False, [*brushPos, *brushColours, 0, keyChar]);
|
||||
if not self._checkRtl(canvas, brushPos, keyChar):
|
||||
if brushPos[0] < (canvas.size[0] - 1):
|
||||
brushPos[0] += 1
|
||||
@ -70,8 +70,8 @@ class ToolText(Tool):
|
||||
# }}}
|
||||
|
||||
#
|
||||
# onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint, viewRect)
|
||||
def onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint, viewRect):
|
||||
# onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint)
|
||||
def onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint):
|
||||
if re.match(self.arabicCombiningRegEx, keyChar):
|
||||
rc, dirty = True, False
|
||||
elif keyCode == wx.WXK_CONTROL_V:
|
||||
@ -82,10 +82,10 @@ class ToolText(Tool):
|
||||
if wx.TheClipboard.GetData(inBuffer):
|
||||
for inBufferChar in list(inBuffer.GetText()):
|
||||
if not re.match(self.arabicCombiningRegEx, inBufferChar):
|
||||
rc_, dirty_ = self._processKeyChar(brushColours, brushPos, canvas, dispatchFn, eventDc, inBufferChar, 0, viewRect)
|
||||
rc_, dirty_ = self._processKeyChar(brushColours, brushPos, canvas, dispatchFn, eventDc, inBufferChar, 0)
|
||||
rc = True if rc_ else rc; dirty = True if dirty_ else dirty;
|
||||
if rc:
|
||||
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect)
|
||||
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"])
|
||||
wx.TheClipboard.Close()
|
||||
else:
|
||||
rc, error = False, "Clipboard does not contain text data and/or cannot be opened"
|
||||
@ -111,26 +111,26 @@ class ToolText(Tool):
|
||||
brushPos[0], brushPos[1] = 0, brushPos[1] - 1
|
||||
else:
|
||||
brushPos[0], brushPos[1] = canvas.size[0] - 1, 0
|
||||
rc, dirty = True, False; dispatchFn(eventDc, False, [*brushPos, *brushColours, 0, " "], viewRect);
|
||||
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect);
|
||||
rc, dirty = True, False; dispatchFn(eventDc, False, [*brushPos, *brushColours, 0, " "]);
|
||||
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"]);
|
||||
elif keyCode == wx.WXK_RETURN:
|
||||
if brushPos[1] < (canvas.size[1] - 1):
|
||||
brushPos[0], brushPos[1] = 0, brushPos[1] + 1
|
||||
else:
|
||||
brushPos[0], brushPos[1] = 0, 0
|
||||
rc, dirty = True, False; dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect);
|
||||
rc, dirty = True, False; dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"]);
|
||||
else:
|
||||
rc, dirty = self._processKeyChar(brushColours, brushPos, canvas, dispatchFn, eventDc, keyChar, keyModifiers, viewRect)
|
||||
rc, dirty = self._processKeyChar(brushColours, brushPos, canvas, dispatchFn, eventDc, keyChar, keyModifiers)
|
||||
if rc:
|
||||
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect)
|
||||
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"])
|
||||
return rc, dirty
|
||||
|
||||
#
|
||||
# onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||
# onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown)
|
||||
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
|
||||
if mouseLeftDown or mouseRightDown:
|
||||
brushPos[0], brushPos[1] = atPoint[0], atPoint[1]
|
||||
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect)
|
||||
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"])
|
||||
return True, False
|
||||
|
||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||
|
Loading…
Reference in New Issue
Block a user