Replace RMB w/ LMB outside of region as end selection UI.

libtools/ToolObject.py: cleanup.
assets/text/TODO: updated.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2019-09-15 11:55:59 +02:00
parent e2f413e4ba
commit 7226639977
2 changed files with 34 additions and 43 deletions

View File

@ -14,10 +14,10 @@ High-priority list:
3) operators: erase, invert, rotate, scale, shift, slice, tile 3) operators: erase, invert, rotate, scale, shift, slice, tile
4) GUI: 4) GUI:
a) switch to GTK a) switch to GTK
b) {hide,show} cursor b) replace logo w/ canvas panel in About dialogue
c) replace logo w/ canvas panel in About dialogue c) 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) d) {copy,cut,insert from,paste}, {edit asset in new canvas,import from {canvas,object}}
e) {copy,cut,insert from,paste}, {edit asset in new canvas,import from {canvas,object}}
5) cleanup & refactor 5) cleanup & refactor
6) object tool: reset {clone,move} state on each transition to target state
vim:ff=dos tw=0 vim:ff=dos tw=0

View File

@ -14,14 +14,12 @@ class ToolObject(Tool):
TS_SELECT = 2 TS_SELECT = 2
TS_TARGET = 3 TS_TARGET = 3
# {{{ _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect) # {{{ _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, selectRect, viewRect)
def _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect): def _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, selectRect, viewRect):
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)
elif mouseRightDown:
disp, isCursor, newTargetRect = [0, 0], False, selectRect.copy()
else: else:
disp, isCursor, newTargetRect = [0, 0], True, selectRect.copy() disp, isCursor, newTargetRect = [0, 0], True, selectRect.copy()
dirty = self.onSelectEvent(canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect, viewRect) dirty = self.onSelectEvent(canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect, viewRect)
@ -31,12 +29,12 @@ class ToolObject(Tool):
# }}} # }}}
# {{{ _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect) # {{{ _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect)
def _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect): def _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect):
rectFrame = [[rect[m[0]][n] + m[1] for n in [0, 1]] for m in [[0, -1], [1, +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]
if rectFrame[0][1] > rectFrame[1][1]: if rectFrame[0][1] > rectFrame[1][1]:
rectFrame[0][1], rectFrame[1][1] = rectFrame[1][1], rectFrame[0][1] rectFrame[0][1], rectFrame[1][1] = rectFrame[1][1], rectFrame[0][1]
curColours = [0, 0] 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, " "], viewRect)
@ -46,8 +44,8 @@ class ToolObject(Tool):
dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "], viewRect) dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "], viewRect)
dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "], viewRect) dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "], viewRect)
# }}} # }}}
# {{{ _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) # {{{ _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
def _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): def _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect):
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, " "], viewRect)
@ -58,10 +56,10 @@ class ToolObject(Tool):
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect) dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect)
return False return False
# }}} # }}}
# {{{ _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) # {{{ _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
def _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): def _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect):
self.targetRect[1] = list(mapPoint)
if mouseLeftDown: if mouseLeftDown:
self.targetRect[1] = list(mapPoint)
if self.targetRect[0][0] > self.targetRect[1][0]: if self.targetRect[0][0] > self.targetRect[1][0]:
self.targetRect[0][0], self.targetRect[1][0] = self.targetRect[1][0], self.targetRect[0][0] self.targetRect[0][0], self.targetRect[1][0] = self.targetRect[1][0], self.targetRect[0][0]
if self.targetRect[0][1] > self.targetRect[1][1]: if self.targetRect[0][1] > self.targetRect[1][1]:
@ -73,41 +71,34 @@ class ToolObject(Tool):
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, viewRect)
elif mouseRightDown:
self.targetRect, self.toolState = None, self.TS_NONE
else: else:
self.targetRect[1] = list(mapPoint)
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect) self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
return False return False
# }}} # }}}
# {{{ _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) # {{{ _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
def _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): def _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect):
dirty = False dirty = False
if mouseLeftDown \ if mouseLeftDown:
and (mapPoint[0] >= (self.targetRect[0][0] - 1)) \ if (mapPoint[0] >= (self.targetRect[0][0] - 1)) \
and (mapPoint[0] <= (self.targetRect[1][0] + 1)) \ and (mapPoint[0] <= (self.targetRect[1][0] + 1)) \
and (mapPoint[1] >= (self.targetRect[0][1] - 1)) \ and (mapPoint[1] >= (self.targetRect[0][1] - 1)) \
and (mapPoint[1] <= (self.targetRect[1][1] + 1)): and (mapPoint[1] <= (self.targetRect[1][1] + 1)):
self.lastAtPoint, self.toolState = list(mapPoint), self.TS_TARGET self.lastAtPoint, self.toolState = list(mapPoint), self.TS_TARGET
elif mouseRightDown: else:
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) dirty = self.onSelectEvent(canvas, (0, 0), dispatchFn, eventDc, False, keyModifiers, self.targetRect.copy(), self.targetRect, viewRect)
self.targetRect, self.toolState = None, self.TS_NONE self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
self.targetRect, self.toolState = None, self.TS_NONE
else: else:
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect) dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, self.targetRect, viewRect)
return dirty return dirty
# }}} # }}}
# {{{ _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) # {{{ _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
def _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): def _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect):
if not self.substract \ if (keyModifiers == wx.MOD_CONTROL) and (self.srcRect == self.targetRect):
and (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, mouseRightDown, self.targetRect, viewRect) dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, self.targetRect, viewRect)
elif mouseRightDown:
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
self.targetRect, self.toolState = None, self.TS_NONE
else: else:
self.toolState = self.TS_SELECT self.toolState = self.TS_SELECT
return True, dirty return True, dirty
@ -121,13 +112,13 @@ class ToolObject(Tool):
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect): def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
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, mouseRightDown, viewRect) dirty = self._mouseEventTsNone(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
elif self.toolState == self.TS_SELECT: elif self.toolState == self.TS_SELECT:
dirty = self._mouseEventTsSelect(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) dirty = self._mouseEventTsSelect(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
elif self.toolState == self.TS_ORIGIN: elif self.toolState == self.TS_ORIGIN:
dirty = self._mouseEventTsOrigin(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) dirty = self._mouseEventTsOrigin(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
elif self.toolState == self.TS_TARGET: elif self.toolState == self.TS_TARGET:
dirty = self._mouseEventTsTarget(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect) dirty = self._mouseEventTsTarget(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, viewRect)
else: else:
return False, dirty return False, dirty
return True, dirty return True, dirty