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:
Lucio Andrés Illanes Albornoz 2019-09-16 16:54:07 +02:00
parent e68a46f196
commit cc3f6958c4
12 changed files with 158 additions and 143 deletions

View File

@ -19,13 +19,6 @@ High-priority list:
c) Settings/Settings window (e.g. autosave, hide cursor on leaving window, ...) 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) 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}} e) {copy,cut,delete,insert from,paste}, {edit asset in new canvas,import from {canvas,object}}
5) finish Arabic/RTL text implementation
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
vim:ff=dos tw=0 vim:ff=dos tw=0

View File

@ -188,13 +188,13 @@ class GuiCanvasWxBackend():
return [a * b for a, b in zip(point, self.cellSize)] return [a * b for a, b in zip(point, self.cellSize)]
# }}} # }}}
# {{{ drawCursorMaskWithJournal(self, canvas, canvasJournal, eventDc, viewRect) # {{{ drawCursorMaskWithJournal(self, canvas, canvasJournal, eventDc)
def drawCursorMaskWithJournal(self, canvas, canvasJournal, eventDc, viewRect): def drawCursorMaskWithJournal(self, canvas, canvasJournal, eventDc):
[self.drawPatch(canvas, eventDc, patch, viewRect) for patch in canvasJournal.popCursor()] [self.drawPatch(canvas, eventDc, patch) for patch in canvasJournal.popCursor()]
# }}} # }}}
# {{{ drawPatch(self, canvas, eventDc, patch, viewRect) # {{{ drawPatch(self, canvas, eventDc, patch)
def drawPatch(self, canvas, eventDc, patch, viewRect): def drawPatch(self, canvas, eventDc, patch):
point = [m - n for m, n in zip(patch[:2], viewRect)] point = patch[:2]
if [(c >= 0) and (c < s) for c, s in zip(point, self.canvasSize)] == [True, True]: if [(c >= 0) and (c < s) for c, s in zip(point, self.canvasSize)] == [True, True]:
if patch[5] == " ": if patch[5] == " ":
if patch[3] == -1: if patch[3] == -1:
@ -211,8 +211,10 @@ class GuiCanvasWxBackend():
else: else:
return False return False
# }}} # }}}
# {{{ getDeviceContext(self, clientSize, parentWindow, viewRect) # {{{ getDeviceContext(self, clientSize, parentWindow, viewRect=None)
def getDeviceContext(self, clientSize, parentWindow, viewRect): def getDeviceContext(self, clientSize, parentWindow, viewRect=None):
if viewRect == None:
viewRect = parentWindow.GetViewStart()
if viewRect == (0, 0): if viewRect == (0, 0):
eventDc = wx.BufferedDC(wx.ClientDC(parentWindow), self.canvasBitmap) eventDc = wx.BufferedDC(wx.ClientDC(parentWindow), self.canvasBitmap)
else: else:

View File

@ -10,10 +10,10 @@ from GuiWindow import GuiWindow
import json, os, sys, wx import json, os, sys, wx
class RoarAssetsWindow(GuiMiniFrame): class RoarAssetsWindow(GuiMiniFrame):
# {{{ _drawPatch(self, canvas, eventDc, isCursor, patch, viewRect) # {{{ _drawPatch(self, canvas, eventDc, isCursor, patch)
def _drawPatch(self, canvas, eventDc, isCursor, patch, viewRect): def _drawPatch(self, canvas, eventDc, isCursor, patch):
if not isCursor: if not isCursor:
self.backend.drawPatch(canvas, eventDc, patch, viewRect) self.backend.drawPatch(canvas, eventDc, patch)
# }}} # }}}
# {{{ _import(self, f, pathName) # {{{ _import(self, f, pathName)
def _import(self, f, pathName): def _import(self, f, pathName):
@ -109,11 +109,12 @@ class RoarAssetsWindow(GuiMiniFrame):
while curWindow != None: while curWindow != None:
curWindow.Layout(); curWindow = curWindow.GetParent(); curWindow.Layout(); curWindow = curWindow.GetParent();
self.backend.resize(canvas.size, self.cellSize) self.backend.resize(canvas.size, self.cellSize)
viewRect = self.panelCanvas.GetViewStart(); eventDc = self.backend.getDeviceContext(self.panelCanvas.GetClientSize(), self.panelCanvas)
eventDc = self.backend.getDeviceContext(self.panelCanvas.GetClientSize(), self.panelCanvas, viewRect) eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
for numRow in range(canvas.size[1]): for numRow in range(canvas.size[1]):
for numCol in range(canvas.size[0]): 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) # {{{ onPaint(self, event)
def onPaint(self, event): def onPaint(self, event):
@ -149,25 +150,28 @@ class RoarAssetsWindow(GuiMiniFrame):
while curWindow != None: while curWindow != None:
curWindow.Layout(); curWindow = curWindow.GetParent(); curWindow.Layout(); curWindow = curWindow.GetParent();
self.backend.resize(newSize, self.cellSize) 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: if deltaSize[0] > 0:
for numRow in range(oldSize[1]): for numRow in range(oldSize[1]):
for numNewCol in range(oldSize[0], newSize[0]): 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: if deltaSize[1] > 1:
for numNewRow in range(oldSize[1], newSize[1]): for numNewRow in range(oldSize[1], newSize[1]):
for numNewCol in range(newSize[0]): 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) # {{{ update(self, canvas, newSize, newCanvas=None)
def update(self, canvas, newSize, newCanvas=None): def update(self, canvas, newSize, newCanvas=None):
self.resize(canvas, newSize); self.resize(canvas, newSize);
canvas.update(newSize, newCanvas); viewRect = self.panelCanvas.GetViewStart(); canvas.update(newSize, newCanvas);
viewRect = self.panelCanvas.GetViewStart(); eventDc = self.backend.getDeviceContext(self.panelCanvas.GetClientSize(), self.panelCanvas)
eventDc = self.backend.getDeviceContext(self.panelCanvas.GetClientSize(), self.panelCanvas, viewRect) eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
for numRow in range(canvas.size[1]): for numRow in range(canvas.size[1]):
for numCol in range(canvas.size[0]): 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) # {{{ onImportAnsi(self, event)

View File

@ -27,28 +27,30 @@ class RoarCanvasCommandsOperators():
region = applyOperator.apply(copy.deepcopy(region)) region = applyOperator.apply(copy.deepcopy(region))
if (self.currentTool.__class__ == ToolObject) \ if (self.currentTool.__class__ == ToolObject) \
and (self.currentTool.toolState >= self.currentTool.TS_SELECT): and (self.currentTool.toolState >= self.currentTool.TS_SELECT):
viewRect = self.parentCanvas.GetViewStart()
if self.parentCanvas.popupEventDc == None: 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: else:
eventDc = self.parentCanvas.popupEventDc 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.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: else:
viewRect = self.parentCanvas.GetViewStart()
if self.parentCanvas.popupEventDc == None: 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: else:
eventDc = self.parentCanvas.popupEventDc eventDc = self.parentCanvas.popupEventDc
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
self.parentCanvas.canvas.journal.begin() self.parentCanvas.canvas.journal.begin()
dirty = False dirty = False
for numRow in range(len(region)): for numRow in range(len(region)):
for numCol in range(len(region[numRow])): for numCol in range(len(region[numRow])):
if not dirty: if not dirty:
self.parentCanvas.dirty = True 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.canvas.journal.end()
self.parentCanvas.commands.update(dirty=self.parentCanvas.dirty, undoLevel=self.parentCanvas.canvas.journal.patchesUndoLevel) self.parentCanvas.commands.update(dirty=self.parentCanvas.dirty, undoLevel=self.parentCanvas.canvas.journal.patchesUndoLevel)
eventDc.SetDeviceOrigin(*eventDcOrigin)
setattr(canvasOperator_, "attrDict", f.attrList[idx]) setattr(canvasOperator_, "attrDict", f.attrList[idx])
return canvasOperator_ return canvasOperator_
# }}} # }}}

View File

@ -8,7 +8,6 @@ from GuiWindow import GuiWindow
from ToolObject import ToolObject from ToolObject import ToolObject
from ToolText import ToolText from ToolText import ToolText
import json, wx, sys import json, wx, sys
import time
class RoarCanvasWindowDropTarget(wx.TextDropTarget): class RoarCanvasWindowDropTarget(wx.TextDropTarget):
# {{{ done(self) # {{{ done(self)
@ -23,15 +22,16 @@ class RoarCanvasWindowDropTarget(wx.TextDropTarget):
and (not self.inProgress): and (not self.inProgress):
try: try:
dropMap, dropSize = json.loads(data) 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]) 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) 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.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.currentTool.setRegion(self.parent.canvas, mapPoint, dropMap, dropSize, external=True)
self.parent.commands.update(toolName=self.parent.commands.currentTool.name) self.parent.commands.update(toolName=self.parent.commands.currentTool.name)
eventDc = self.parent.backend.getDeviceContext(self.parent.GetClientSize(), self.parent, viewRect) 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) 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; rc = True; self.inProgress = True;
except: except:
with wx.MessageDialog(self.parent, "Error: {}".format(sys.exc_info()[1]), "", wx.OK | wx.OK_DEFAULT) as dialog: 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): class RoarCanvasWindow(GuiWindow):
# {{{ _drawPatch(self, eventDc, isCursor, patch, viewRect) # {{{ _drawPatch(self, eventDc, isCursor, patch)
def _drawPatch(self, eventDc, isCursor, patch, viewRect): def _drawPatch(self, eventDc, isCursor, patch):
if not self.canvas.dirtyCursor: 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 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]; patchDeltaCell = self.canvas.map[patch[1]][patch[0]]; patchDelta = [*patch[0:2], *patchDeltaCell];
self.canvas.journal.pushCursor(patchDelta) self.canvas.journal.pushCursor(patchDelta)
# }}} # }}}
# {{{ applyTool(self, eventDc, eventMouse, keyChar, keyCode, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, tool, viewRect) # {{{ 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): def applyTool(self, eventDc, eventMouse, keyChar, keyCode, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, tool, viewRect):
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
if mapPoint != None: if mapPoint != None:
mapPoint = [a + b for a, b in zip(mapPoint, viewRect)] mapPoint = [a + b for a, b in zip(mapPoint, viewRect)]
dirty, self.canvas.dirtyCursor, rc = False, False, False dirty, self.canvas.dirtyCursor, rc = False, False, False
@ -68,15 +69,15 @@ class RoarCanvasWindow(GuiWindow):
if tool.__class__ != ToolText: if tool.__class__ != ToolText:
self.brushPos = list(mapPoint) self.brushPos = list(mapPoint)
if tool != None: 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: 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)] self.lastCellState = [list(mapPoint), mouseDragging, mouseLeftDown, mouseRightDown, list(viewRect)]
else: else:
if tool != None: 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: 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: if dirty:
self.dirty = True self.dirty = True
self.commands.update(dirty=self.dirty, cellPos=self.brushPos, undoLevel=self.canvas.journal.patchesUndoLevel) 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) self.commands.update(toolName="Cursor", undoInhibit=False)
else: else:
self.commands.update(undoInhibit=False) self.commands.update(undoInhibit=False)
eventDc.SetDeviceOrigin(*eventDcOrigin)
return rc return rc
# }}} # }}}
# {{{ dispatchDeltaPatches(self, deltaPatches) # {{{ dispatchDeltaPatches(self, deltaPatches)
def dispatchDeltaPatches(self, deltaPatches): def dispatchDeltaPatches(self, deltaPatches):
viewRect = self.GetViewStart() eventDc = self.backend.getDeviceContext(self.GetClientSize(), self)
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, viewRect) eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
if self.canvas.dirtyCursor: 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 self.canvas.dirtyCursor = False
for patch in deltaPatches: for patch in deltaPatches:
if patch == None: if patch == None:
continue continue
elif patch[0] == "resize": 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: 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) # {{{ dispatchPatch(self, eventDc, isCursor, patch)
def dispatchPatch(self, eventDc, isCursor, patch, viewRect): def dispatchPatch(self, eventDc, isCursor, patch):
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)
# }}} # }}}
# {{{ dispatchPatchSingle(self, eventDc, isCursor, patch, viewRect) # {{{ dispatchPatchSingle(self, eventDc, isCursor, patch)
def dispatchPatchSingle(self, eventDc, isCursor, patch, viewRect): def dispatchPatchSingle(self, eventDc, isCursor, patch):
if self.canvas.dispatchPatchSingle(isCursor, patch, False if isCursor else True): 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) # {{{ resize(self, newSize, commitUndo=True)
def resize(self, newSize, commitUndo=True): def resize(self, newSize, commitUndo=True):
@ -130,15 +135,17 @@ class RoarCanvasWindow(GuiWindow):
if self.canvas.resize(newSize, commitUndo): if self.canvas.resize(newSize, commitUndo):
super().resize([a * b for a, b in zip(newSize, self.backend.cellSize)]) super().resize([a * b for a, b in zip(newSize, self.backend.cellSize)])
self.backend.resize(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: if deltaSize[0] > 0:
for numRow in range(oldSize[1]): for numRow in range(oldSize[1]):
for numNewCol in range(oldSize[0], newSize[0]): 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: if deltaSize[1] > 1:
for numNewRow in range(oldSize[1], newSize[1]): for numNewRow in range(oldSize[1], newSize[1]):
for numNewCol in range(newSize[0]): 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) self.commands.update(size=newSize, undoLevel=self.canvas.journal.patchesUndoLevel)
# }}} # }}}
# {{{ update(self, newSize, commitUndo=True, newCanvas=None) # {{{ update(self, newSize, commitUndo=True, newCanvas=None)
@ -146,9 +153,11 @@ class RoarCanvasWindow(GuiWindow):
self.resize(newSize, commitUndo) self.resize(newSize, commitUndo)
self.canvas.update(newSize, newCanvas) self.canvas.update(newSize, newCanvas)
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, self.GetViewStart()) eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, self.GetViewStart())
eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
for numRow in range(newSize[1]): for numRow in range(newSize[1]):
for numCol in range(newSize[0]): 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) # {{{ onKeyboardInput(self, event)
@ -193,7 +202,9 @@ class RoarCanvasWindow(GuiWindow):
def onLeaveWindow(self, event): def onLeaveWindow(self, event):
if False: if False:
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, self.GetViewStart()) 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 self.lastCellState = None
# }}} # }}}
# {{{ onMouseInput(self, event) # {{{ onMouseInput(self, event)
@ -217,18 +228,21 @@ class RoarCanvasWindow(GuiWindow):
self.backend.cellSize = newCellSize self.backend.cellSize = newCellSize
super().resize([a * b for a, b in zip(self.canvas.size, self.backend.cellSize)]) super().resize([a * b for a, b in zip(self.canvas.size, self.backend.cellSize)])
self.backend.resize(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 numRow in range(self.canvas.size[1]):
for numCol in range(len(self.canvas.map[numRow])): 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: else:
event.Skip() event.Skip()
# }}} # }}}
# {{{ onPaint(self, event) # {{{ onPaint(self, event)
def onPaint(self, event): def onPaint(self, event):
viewRect = self.GetViewStart() eventDc = self.backend.getDeviceContext(self.GetClientSize(), self)
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, viewRect) eventDcOrigin = eventDc.GetDeviceOrigin(); eventDc.SetDeviceOrigin(0, 0);
self.backend.drawCursorMaskWithJournal(self.canvas, self.canvas.journal, eventDc, viewRect) self.backend.drawCursorMaskWithJournal(self.canvas, self.canvas.journal, eventDc)
eventDc.SetDeviceOrigin(*eventDcOrigin)
self.backend.onPaint(self.GetClientSize(), self, self.GetViewStart()) self.backend.onPaint(self.GetClientSize(), self, self.GetViewStart())
# }}} # }}}

View File

@ -5,12 +5,12 @@
# #
class Tool(object): class Tool(object):
# {{{ 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, viewRect): def onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint):
return False, False return False, False
# }}} # }}}
# {{{ onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, dispatchFn, eventDc, 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, viewRect): def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
return False, False return False, False
# }}} # }}}

View File

@ -10,8 +10,8 @@ class ToolCircle(Tool):
name = "Circle" name = "Circle"
# #
# 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, viewRect): def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
brushColours, dirty = brushColours.copy(), False brushColours, dirty = brushColours.copy(), False
if mouseLeftDown: if mouseLeftDown:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
@ -31,9 +31,9 @@ class ToolCircle(Tool):
if mouseLeftDown or mouseRightDown: if mouseLeftDown or mouseRightDown:
if not dirty: if not dirty:
dirty = True dirty = True
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect); dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
else: else:
dispatchFn(eventDc, True, patch, viewRect) dispatchFn(eventDc, True, patch)
return True, dirty return True, dirty
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -10,8 +10,8 @@ class ToolFill(Tool):
name = "Fill" name = "Fill"
# #
# 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, viewRect): 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] 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: if mouseLeftDown or mouseRightDown:
while len(pointStack) > 0: while len(pointStack) > 0:
@ -22,7 +22,7 @@ class ToolFill(Tool):
if not point in pointsDone: if not point in pointsDone:
if not dirty: if not dirty:
dirty = True 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: if point[0] > 0:
pointStack.append([point[0] - 1, point[1]]) pointStack.append([point[0] - 1, point[1]])
if point[0] < (canvas.size[0] - 1): if point[0] < (canvas.size[0] - 1):
@ -34,7 +34,7 @@ class ToolFill(Tool):
pointsDone += [point] pointsDone += [point]
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)
return True, dirty return True, dirty
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -11,8 +11,8 @@ class ToolLine(Tool):
TS_NONE = 0 TS_NONE = 0
TS_ORIGIN = 1 TS_ORIGIN = 1
# {{{ _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, viewRect): def _getLine(self, brushColours, brushSize, dispatchFn, eventDc, isCursor, originPoint, targetPoint):
dirty = False dirty = False
originPoint, targetPoint = originPoint.copy(), targetPoint.copy() originPoint, targetPoint = originPoint.copy(), targetPoint.copy()
pointDelta = self._pointDelta(originPoint, targetPoint) pointDelta = self._pointDelta(originPoint, targetPoint)
@ -31,11 +31,11 @@ class ToolLine(Tool):
originPoint[1] + lineX * lineXY + lineY * lineYY, \ originPoint[1] + lineX * lineXY + lineY * lineYY, \
*brushColours, 0, " "] *brushColours, 0, " "]
if isCursor: if isCursor:
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect); dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
else: else:
if not dirty: if not dirty:
dirty = True dirty = True
dispatchFn(eventDc, True, patch, viewRect) 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]
@ -51,8 +51,8 @@ class ToolLine(Tool):
# }}} # }}}
# #
# 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, viewRect): def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
brushColours, dirty = brushColours.copy(), False brushColours, dirty = brushColours.copy(), False
if mouseLeftDown: if mouseLeftDown:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
@ -63,10 +63,10 @@ class ToolLine(Tool):
if self.toolState == self.TS_NONE: if self.toolState == self.TS_NONE:
if mouseLeftDown or mouseRightDown: if mouseLeftDown or mouseRightDown:
self.toolColours, self.toolOriginPoint, self.toolState = brushColours, list(mapPoint), self.TS_ORIGIN 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: elif self.toolState == self.TS_ORIGIN:
originPoint, targetPoint = self.toolOriginPoint, list(mapPoint) 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: 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:

View File

@ -14,21 +14,21 @@ class ToolObject(Tool):
TS_SELECT = 2 TS_SELECT = 2
TS_TARGET = 3 TS_TARGET = 3
# {{{ _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, viewRect): def _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, selectRect):
if mouseLeftDown: if mouseLeftDown:
disp, isCursor = [mapPoint[m] - self.lastAtPoint[m] for m in [0, 1]], True 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]] newTargetRect = [[selectRect[n][m] + disp[m] for m in [0, 1]] for n in [0, 1]]
self.lastAtPoint = list(mapPoint) self.lastAtPoint = list(mapPoint)
else: else:
disp, isCursor, newTargetRect = [0, 0], True, selectRect.copy() disp, isCursor, newTargetRect = [0, 0], True, selectRect.copy()
dirty = self.onSelectEvent(canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect, viewRect) dirty = self.onSelectEvent(canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect)
self._drawSelectRect(newTargetRect, dispatchFn, eventDc, viewRect) self._drawSelectRect(newTargetRect, dispatchFn, eventDc)
self.targetRect = newTargetRect self.targetRect = newTargetRect
return dirty return dirty
# }}} # }}}
# {{{ _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect) # {{{ _drawSelectRect(self, rect, dispatchFn, eventDc)
def _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect): def _drawSelectRect(self, rect, dispatchFn, eventDc):
rectFrame = [[rect[m][n] for n in [0, 1]] for m in (0, 1)] rectFrame = [[rect[m][n] for n in [0, 1]] for m in (0, 1)]
if rectFrame[0][0] > rectFrame[1][0]: if rectFrame[0][0] > rectFrame[1][0]:
rectFrame[0][0], rectFrame[1][0] = rectFrame[1][0], rectFrame[0][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]]] 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): for rectX in range(rectFrame[0][0], rectFrame[1][0] + 1):
curColours = [1, 1] if curColours == [0, 0] else [0, 0] 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[0][1], *curColours, 0, " "])
dispatchFn(eventDc, True, [rectX, rectFrame[1][1], *curColours, 0, " "], viewRect) dispatchFn(eventDc, True, [rectX, rectFrame[1][1], *curColours, 0, " "])
for rectY in range(rectFrame[0][1], rectFrame[1][1] + 1): for rectY in range(rectFrame[0][1], rectFrame[1][1] + 1):
curColours = [1, 1] if curColours == [0, 0] else [0, 0] curColours = [1, 1] if curColours == [0, 0] else [0, 0]
dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "], viewRect) dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "])
dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "], viewRect) dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "])
# }}} # }}}
# {{{ _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, viewRect): def _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown):
self.substract = False self.substract = False
if self.external: if self.external:
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect) dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "])
else: else:
if mouseLeftDown: if mouseLeftDown:
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, " "])
return False return False
# }}} # }}}
# {{{ _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, viewRect): def _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown):
self.targetRect[1] = list(mapPoint) self.targetRect[1] = list(mapPoint)
if mouseLeftDown: if mouseLeftDown:
if self.targetRect[0][0] > self.targetRect[1][0]: 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): 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 rectX, rectY = self.targetRect[0][0] + numCol, self.targetRect[0][1] + numRow
self.objectMap[numRow].append(canvas.map[rectY][rectX]) self.objectMap[numRow].append(canvas.map[rectY][rectX])
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect) self._drawSelectRect(self.targetRect, dispatchFn, eventDc)
else: else:
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect) self._drawSelectRect(self.targetRect, dispatchFn, eventDc)
return False return False
# }}} # }}}
# {{{ _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, viewRect): def _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown):
dirty = False dirty = False
if mouseLeftDown: if mouseLeftDown:
if (mapPoint[0] >= (self.targetRect[0][0] - 1)) \ if (mapPoint[0] >= (self.targetRect[0][0] - 1)) \
@ -85,20 +85,20 @@ class ToolObject(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
else: else:
dirty = self.onSelectEvent(canvas, (0, 0), dispatchFn, eventDc, False, keyModifiers, self.targetRect.copy(), self.targetRect, viewRect) dirty = self.onSelectEvent(canvas, (0, 0), dispatchFn, eventDc, False, keyModifiers, self.targetRect.copy(), self.targetRect)
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect) self._drawSelectRect(self.targetRect, dispatchFn, eventDc)
self.objectMap, self.objectSize, self.targetRect, self.toolState = None, None, None, self.TS_NONE self.objectMap, self.objectSize, self.targetRect, self.toolState = None, None, None, self.TS_NONE
else: 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 return dirty
# }}} # }}}
# {{{ _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, viewRect): def _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown):
if (keyModifiers == wx.MOD_CONTROL) and (self.srcRect == self.targetRect): if (keyModifiers == wx.MOD_CONTROL) and (self.srcRect == self.targetRect):
self.substract = True self.substract = True
dirty = False dirty = False
if mouseLeftDown: 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: else:
self.toolState = self.TS_SELECT self.toolState = self.TS_SELECT
return dirty return dirty
@ -108,23 +108,23 @@ class ToolObject(Tool):
def getRegion(self, canvas): def getRegion(self, canvas):
return self.objectMap return self.objectMap
# }}} # }}}
# {{{ 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, viewRect): def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
dirty = False dirty = False
if self.toolState == self.TS_NONE: 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: 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: 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: 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: else:
return False, dirty return False, dirty
return True, dirty return True, dirty
# }}} # }}}
# {{{ 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, viewRect): def onSelectEvent(self, canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect):
dirty = False dirty = False
if self.external: if self.external:
for numRow in range(len(self.objectMap)): for numRow in range(len(self.objectMap)):
@ -135,7 +135,7 @@ class ToolObject(Tool):
if (cellNew[1] == -1) and (cellNew[3] == " "): if (cellNew[1] == -1) and (cellNew[3] == " "):
if ((rectY + disp[1]) < canvas.size[1]) and ((rectX + disp[0]) < canvas.size[0]): if ((rectY + disp[1]) < canvas.size[1]) and ((rectX + disp[0]) < canvas.size[0]):
cellNew = canvas.map[rectY + disp[1]][rectX + disp[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: else:
if self.substract: if self.substract:
for numRow in range(self.srcRect[0][1], self.srcRect[1][1]): 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])) \ if ((numCol < selectRect[0][0]) or (numCol > selectRect[1][0])) \
or ((numRow < selectRect[0][1]) or (numRow > selectRect[1][1])): or ((numRow < selectRect[0][1]) or (numRow > selectRect[1][1])):
dirty = False if isCursor else True 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 numRow in range(len(self.objectMap)):
for numCol in range(len(self.objectMap[numRow])): for numCol in range(len(self.objectMap[numRow])):
cellOld = self.objectMap[numRow][numCol] cellOld = self.objectMap[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 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 return dirty
# }}} # }}}
# {{{ setRegion(self, canvas, mapPoint, objectMap, objectSize, external=True) # {{{ setRegion(self, canvas, mapPoint, objectMap, objectSize, external=True)

View File

@ -10,8 +10,8 @@ class ToolRect(Tool):
name = "Rectangle" name = "Rectangle"
# #
# 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, viewRect): def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
brushColours, dirty = brushColours.copy(), False brushColours, dirty = brushColours.copy(), False
if mouseLeftDown: if mouseLeftDown:
brushColours[1] = brushColours[0] brushColours[1] = brushColours[0]
@ -28,9 +28,9 @@ class ToolRect(Tool):
if mouseLeftDown or mouseRightDown: if mouseLeftDown or mouseRightDown:
if not dirty: if not dirty:
dirty = True dirty = True
dispatchFn(eventDc, False, patch, viewRect); dispatchFn(eventDc, True, patch, viewRect); dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch);
else: else:
dispatchFn(eventDc, True, patch, viewRect) dispatchFn(eventDc, True, patch)
return True, dirty return True, dirty
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

View File

@ -42,13 +42,13 @@ class ToolText(Tool):
break break
return rtlFlag return rtlFlag
# }}} # }}}
# {{{ _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, viewRect): def _processKeyChar(self, brushColours, brushPos, canvas, dispatchFn, eventDc, keyChar, keyModifiers):
if (ord(keyChar) != wx.WXK_NONE) \ if (ord(keyChar) != wx.WXK_NONE) \
and (not keyChar in set("\t\n\v\f\r")) \ and (not keyChar in set("\t\n\v\f\r")) \
and ((ord(keyChar) >= 32) if ord(keyChar) < 127 else True) \ and ((ord(keyChar) >= 32) if ord(keyChar) < 127 else True) \
and (keyModifiers in (wx.MOD_NONE, wx.MOD_SHIFT)): 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 not self._checkRtl(canvas, brushPos, keyChar):
if brushPos[0] < (canvas.size[0] - 1): if brushPos[0] < (canvas.size[0] - 1):
brushPos[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) # 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, viewRect): def onKeyboardEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyChar, keyCode, keyModifiers, mapPoint):
if re.match(self.arabicCombiningRegEx, keyChar): if re.match(self.arabicCombiningRegEx, keyChar):
rc, dirty = True, False rc, dirty = True, False
elif keyCode == wx.WXK_CONTROL_V: elif keyCode == wx.WXK_CONTROL_V:
@ -82,10 +82,10 @@ class ToolText(Tool):
if wx.TheClipboard.GetData(inBuffer): if wx.TheClipboard.GetData(inBuffer):
for inBufferChar in list(inBuffer.GetText()): for inBufferChar in list(inBuffer.GetText()):
if not re.match(self.arabicCombiningRegEx, inBufferChar): 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; rc = True if rc_ else rc; dirty = True if dirty_ else dirty;
if rc: if rc:
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect) dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"])
wx.TheClipboard.Close() wx.TheClipboard.Close()
else: else:
rc, error = False, "Clipboard does not contain text data and/or cannot be opened" 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 brushPos[0], brushPos[1] = 0, brushPos[1] - 1
else: else:
brushPos[0], brushPos[1] = canvas.size[0] - 1, 0 brushPos[0], brushPos[1] = canvas.size[0] - 1, 0
rc, dirty = True, False; dispatchFn(eventDc, False, [*brushPos, *brushColours, 0, " "], viewRect); rc, dirty = True, False; dispatchFn(eventDc, False, [*brushPos, *brushColours, 0, " "]);
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect); dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"]);
elif keyCode == wx.WXK_RETURN: elif keyCode == wx.WXK_RETURN:
if brushPos[1] < (canvas.size[1] - 1): if brushPos[1] < (canvas.size[1] - 1):
brushPos[0], brushPos[1] = 0, brushPos[1] + 1 brushPos[0], brushPos[1] = 0, brushPos[1] + 1
else: else:
brushPos[0], brushPos[1] = 0, 0 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: 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: if rc:
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect) dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"])
return rc, dirty return rc, dirty
# #
# 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, viewRect): def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
if mouseLeftDown or mouseRightDown: if mouseLeftDown or mouseRightDown:
brushPos[0], brushPos[1] = atPoint[0], atPoint[1] brushPos[0], brushPos[1] = atPoint[0], atPoint[1]
dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"], viewRect) dispatchFn(eventDc, True, [*brushPos, *brushColours, 0, "_"])
return True, False return True, False
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 # vim:expandtab foldmethod=marker sw=4 ts=4 tw=120