From 2592fa9ad8b389aa99c14d76be6642510fe25ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Fri, 27 Sep 2019 14:22:58 +0200 Subject: [PATCH] Tool bug fixes & usability improvements. 1) Circle, rectangle tool: initiate dragging with , conclude w/ <[LR]MB> release. 2) Circle tool: fix artifacts and radius inference from brush size. 3) Line tool: fix origin point artifacts. 4) Rectangle tool: correctly determine target point. --- assets/text/TODO | 10 ++++---- libtools/ToolCircle.py | 52 +++++++++++++++++++++--------------------- libtools/ToolLine.py | 2 +- libtools/ToolRect.py | 10 ++++---- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/assets/text/TODO b/assets/text/TODO index 7eb2ce2..bb8664a 100644 --- a/assets/text/TODO +++ b/assets/text/TODO @@ -19,10 +19,10 @@ Release roadmap: 1) {copy,cut,delete,insert from,paste}, edit asset in new canvas, import from {canvas,object} -2) floating/dockable toolbar https://wxpython.org/Phoenix/docs/html/wx.aui.AuiManager.html -3) reimplement cursor unmasking w/ simple list of points -4) operators: crop, scale, shift, slice -5) auto{load,save} & {backup,restore} -6) tools: unicode block elements +2) operators: crop, scale, shift, slice +3) tools: unicode block elements +4) floating/dockable toolbar https://wxpython.org/Phoenix/docs/html/wx.aui.AuiManager.html +5) reimplement cursor unmasking w/ simple list of points +6) auto{load,save} & {backup,restore} vim:ff=dos tw=0 diff --git a/libtools/ToolCircle.py b/libtools/ToolCircle.py index 0a03fb8..c231faf 100644 --- a/libtools/ToolCircle.py +++ b/libtools/ToolCircle.py @@ -23,43 +23,43 @@ class ToolCircle(Tool): del cells[-1] for numRow in range(len(cells)): for numCol in range(len(cells[numRow])): - if ((numRow == 0) or (numRow == (len(cells) - 1))) \ - or ((numCol == 0) or (numCol == (len(cells[numRow]) - 1))): - patch = [*cells[numRow][numCol], brushColours[0], brushColours[0], 0, " "] - elif ((numRow > 0) and (cells[numRow][numCol][0] < cells[numRow - 1][0][0])) \ - or ((numRow < len(cells)) and (cells[numRow][numCol][0] < cells[numRow + 1][0][0])): - patch = [*cells[numRow][numCol], brushColours[0], brushColours[0], 0, " "] - elif ((numRow > 0) and (cells[numRow][numCol][0] > cells[numRow - 1][-1][0])) \ - or ((numRow < len(cells)) and (cells[numRow][numCol][0] > cells[numRow + 1][-1][0])): - patch = [*cells[numRow][numCol], brushColours[0], brushColours[0], 0, " "] - elif brushColours[1] == -1: - if (cells[numRow][numCol][0] < canvas.size[0]) \ - and (cells[numRow][numCol][1] < canvas.size[1]): - patch = [cells[numRow][numCol][0], cells[numRow][numCol][1], *canvas.map[cells[numRow][numCol][1]][cells[numRow][numCol][0]]] + point = cells[numRow][numCol] + if ((point[0] >= 0) and (point[1] >= 0)) \ + and (point[0] < canvas.size[0]) and (point[1] < canvas.size[1]): + if ((numRow == 0) or (numRow == (len(cells) - 1))) \ + or ((numCol == 0) or (numCol == (len(cells[numRow]) - 1))): + patch = [*cells[numRow][numCol], brushColours[0], brushColours[0], 0, " "] + elif ((numRow > 0) and (cells[numRow][numCol][0] < cells[numRow - 1][0][0])) \ + or ((numRow < len(cells)) and (cells[numRow][numCol][0] < cells[numRow + 1][0][0])): + patch = [*cells[numRow][numCol], brushColours[0], brushColours[0], 0, " "] + elif ((numRow > 0) and (cells[numRow][numCol][0] > cells[numRow - 1][-1][0])) \ + or ((numRow < len(cells)) and (cells[numRow][numCol][0] > cells[numRow + 1][-1][0])): + patch = [*cells[numRow][numCol], brushColours[0], brushColours[0], 0, " "] + elif brushColours[1] == -1: + if (cells[numRow][numCol][0] < canvas.size[0]) \ + and (cells[numRow][numCol][1] < canvas.size[1]): + patch = [cells[numRow][numCol][0], cells[numRow][numCol][1], *canvas.map[cells[numRow][numCol][1]][cells[numRow][numCol][0]]] + else: + patch = [*cells[numRow][numCol], brushColours[1], brushColours[1], 0, " "] else: patch = [*cells[numRow][numCol], brushColours[1], brushColours[1], 0, " "] - else: - patch = [*cells[numRow][numCol], brushColours[1], brushColours[1], 0, " "] - patches += [patch] + patches += [patch] return patches def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown): - brushColours = [brushColours[1], brushColours[0]] if mouseRightDown else brushColours - brushSize = [brushSize[0] * 2, brushSize[1]] + brushColours, brushSize = [brushColours[1], brushColours[0]] if mouseRightDown else brushColours, brushSize[0] * 2 if self.toolState == self.TS_NONE: - originPoint, radius, targetPoint = list(mapPoint), brushSize[0], (brushSize[0] / 2, brushSize[0] / 2,) + originPoint, radius, targetPoint = list(mapPoint), brushSize, (brushSize / 2,) * 2 if (keyModifiers == wx.MOD_CONTROL) and (mouseLeftDown or mouseRightDown): - self.brushColours, isCursor, self.originPoint, self.toolState = list(brushColours), True, originPoint, self.TS_ORIGIN + self.brushColours, isCursor, self.originPoint, self.toolState = brushColours, True, originPoint, self.TS_ORIGIN else: isCursor = not (mouseLeftDown or mouseRightDown) elif self.toolState == self.TS_ORIGIN: - brushColours, originPoint = self.brushColours, self.originPoint if mapPoint[0] > self.originPoint[0]: - radius, targetPoint = brushSize[0] + (mapPoint[0] - self.originPoint[0]), ((brushSize[0] + (mapPoint[0] - self.originPoint[0])) / 2, (brushSize[0] + (mapPoint[0] - self.originPoint[0])) / 2,) - else: - radius, targetPoint = brushSize[0], (brushSize[0] / 2, brushSize[0] / 2,) - if keyModifiers != wx.MOD_CONTROL: - isCursor, self.brushColours, self.originPoint, self.toolState = False, None, None, self.TS_NONE + brushSize += (mapPoint[0] - self.originPoint[0]); brushSize = brushSize + (brushSize % 2); + brushColours, originPoint, radius, targetPoint = self.brushColours, self.originPoint, brushSize, (brushSize / 2,) * 2 + if not (mouseLeftDown or mouseRightDown): + self.brushColours, isCursor, self.originPoint, self.toolState = None, False, None, self.TS_NONE else: isCursor = True patches = self._drawCircle(brushColours, canvas, originPoint, targetPoint, radius) diff --git a/libtools/ToolLine.py b/libtools/ToolLine.py index e506344..a06b18e 100644 --- a/libtools/ToolLine.py +++ b/libtools/ToolLine.py @@ -53,7 +53,7 @@ class ToolLine(Tool): if self.toolState == self.TS_NONE: if mouseLeftDown or mouseRightDown: self.toolOriginPoint, self.toolState = list(mapPoint), self.TS_ORIGIN - patches, rc = [], True + isCursor, patches, rc = True, [], True for brushCol in range(brushSize[0]): if ((mapPoint[0] + brushCol) < canvas.size[0]) \ and (mapPoint[1] < canvas.size[1]): diff --git a/libtools/ToolRect.py b/libtools/ToolRect.py index 053707c..75539a0 100644 --- a/libtools/ToolRect.py +++ b/libtools/ToolRect.py @@ -14,9 +14,9 @@ class ToolRect(Tool): def _drawRect(self, brushColours, canvas, rect): patches = [] - for brushRow in range(rect[3] - rect[1]): - for brushCol in range(rect[2] - rect[0]): - if (brushCol in [0, (rect[2] - rect[0]) - 1]) or (brushRow in [0, (rect[3] - rect[1]) - 1]): + for brushRow in range((rect[3] - rect[1]) + 1): + for brushCol in range((rect[2] - rect[0]) + 1): + if (brushCol in [0, (rect[2] - rect[0])]) or (brushRow in [0, (rect[3] - rect[1])]): patchColours = [brushColours[0]] * 2 patch = [rect[0] + brushCol, rect[1] + brushRow, *patchColours, 0, " "] elif brushColours[1] == -1: @@ -39,10 +39,10 @@ class ToolRect(Tool): self.brushColours, isCursor, self.originPoint, self.toolState = list(brushColours), True, list(mapPoint), self.TS_ORIGIN else: isCursor = not (mouseLeftDown or mouseRightDown) - rect = [*mapPoint, *[a + b for a, b in zip(brushSize, mapPoint)]] + rect = [*mapPoint, *([a + b for a, b in zip(brushSize, mapPoint)] if brushSize[0] > 1 else mapPoint)] elif self.toolState == self.TS_ORIGIN: rect = [*self.originPoint, *mapPoint] - if keyModifiers != wx.MOD_CONTROL: + if not (mouseLeftDown or mouseRightDown): brushColours, isCursor, self.brushColours, self.originPoint, self.toolState = self.brushColours, False, None, None, self.TS_NONE else: isCursor = True