From 51498169e0de68680ea3476e4565d6c66494540f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Mon, 23 Sep 2019 21:59:41 +0200 Subject: [PATCH] Implements erase tool. assets/text/TODO: updated. --- assets/images/toolErase.png | Bin 0 -> 278 bytes assets/text/TODO | 11 +++++----- assets/text/hotkeys.txt | 2 +- libroar/RoarCanvasCommands.py | 2 +- libroar/RoarCanvasCommandsTools.py | 16 ++++++++------ libtools/ToolErase.py | 34 +++++++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 assets/images/toolErase.png create mode 100644 libtools/ToolErase.py diff --git a/assets/images/toolErase.png b/assets/images/toolErase.png new file mode 100644 index 0000000000000000000000000000000000000000..39c523343e1937f54dde257e81ddd88a5356d7b0 GIT binary patch literal 278 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=DinK$vl=HlH+5kiEpy*OmP-r?{{Q)Af0dnn0n&o-U3d7N?W{{QqyytlH4o=;UyL z!OiX1|DK*6i@7JAJU+kQx%pwvj3591|CfB2RnW?~DXrwdtT|lfEuAuF**9N$pqHfN zZhX!`C2aHGEs+KK8x*qtZLig2o}6yN3<8@RcbF_@QBqcZ{C~f={sB|N*U|@W?l5`m z%U-V^m*8L~FgvX$qoq~HY 0-9, 0-5, 6 Set foreground colour to #0-9, #10-15, transparent colour, resp. 0-9, 0-5, 6 Set background colour to #0-9, #10-15, transparent colour, resp. - C, U, F, L, R, E, T Switch to circle, cursor, fill, line, rectangle, object, text tool + C, U, E, F, L, R, E, T Switch to circle, cursor, erase, fill, line, rectangle, object, text tool I Flip colours N New canvas O Open mIRC art file diff --git a/libroar/RoarCanvasCommands.py b/libroar/RoarCanvasCommands.py index eb50996..b64323d 100644 --- a/libroar/RoarCanvasCommands.py +++ b/libroar/RoarCanvasCommands.py @@ -129,7 +129,7 @@ class RoarCanvasCommands(RoarCanvasCommandsFile, RoarCanvasCommandsEdit, RoarCan self.canvasUndo, self.canvasRedo, NID_TOOLBAR_HSEP, self.canvasCut, self.canvasCopy, self.canvasPaste, self.canvasDelete, NID_TOOLBAR_HSEP, self.canvasAssetsWindowHide, self.canvasAssetsWindowShow, NID_TOOLBAR_HSEP, - self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 2), self.canvasTool(self.canvasTool, 3), self.canvasTool(self.canvasTool, 6), self.canvasTool(self.canvasTool, 4), + self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 6), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 3), self.canvasTool(self.canvasTool, 4), self.canvasTool(self.canvasTool, 7), self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 2), ]) toolBars.append( [self.canvasColour(self.canvasColour, 0), self.canvasColour(self.canvasColour, 1), self.canvasColour(self.canvasColour, 2), self.canvasColour(self.canvasColour, 3), diff --git a/libroar/RoarCanvasCommandsTools.py b/libroar/RoarCanvasCommandsTools.py index 3343296..18bde4b 100644 --- a/libroar/RoarCanvasCommandsTools.py +++ b/libroar/RoarCanvasCommandsTools.py @@ -6,6 +6,7 @@ from GuiFrame import GuiSelectDecorator from ToolCircle import ToolCircle +from ToolErase import ToolErase from ToolFill import ToolFill from ToolLine import ToolLine from ToolObject import ToolObject @@ -16,18 +17,19 @@ import wx class RoarCanvasCommandsTools(): @GuiSelectDecorator(0, "Circle", "&Circle", ["toolCircle.png"], [wx.ACCEL_CTRL, ord("C")], False) @GuiSelectDecorator(1, "Cursor", "C&ursor", ["toolCursor.png"], [wx.ACCEL_CTRL, ord("U")], False) - @GuiSelectDecorator(2, "Fill", "&Fill", ["toolFill.png"], [wx.ACCEL_CTRL, ord("F")], False) - @GuiSelectDecorator(3, "Line", "&Line", ["toolLine.png"], [wx.ACCEL_CTRL, ord("L")], False) - @GuiSelectDecorator(4, "Object", "&Object", ["toolObject.png"], [wx.ACCEL_CTRL, ord("E")], False) - @GuiSelectDecorator(5, "Rectangle", "&Rectangle", ["toolRect.png"], [wx.ACCEL_CTRL, ord("R")], True) - @GuiSelectDecorator(6, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False) + @GuiSelectDecorator(2, "Erase", "&Erase", ["toolErase.png"], [wx.ACCEL_CTRL, ord("A")], False) + @GuiSelectDecorator(3, "Fill", "&Fill", ["toolFill.png"], [wx.ACCEL_CTRL, ord("F")], False) + @GuiSelectDecorator(4, "Line", "&Line", ["toolLine.png"], [wx.ACCEL_CTRL, ord("L")], False) + @GuiSelectDecorator(5, "Object", "&Object", ["toolObject.png"], [wx.ACCEL_CTRL, ord("E")], False) + @GuiSelectDecorator(6, "Rectangle", "&Rectangle", ["toolRect.png"], [wx.ACCEL_CTRL, ord("R")], True) + @GuiSelectDecorator(7, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False) def canvasTool(self, f, idx): def canvasTool_(event): if (self.currentTool.__class__ == ToolObject) \ and (self.currentTool.toolState > self.currentTool.TS_NONE) \ and self.currentTool.external: self.parentCanvas.dropTarget.done() - self.lastTool, self.currentTool = self.currentTool, [ToolCircle, None, ToolFill, ToolLine, ToolObject, ToolRect, ToolText][idx] + self.lastTool, self.currentTool = self.currentTool, [ToolCircle, None, ToolErase, ToolFill, ToolLine, ToolObject, ToolRect, ToolText][idx] if self.currentTool != None: self.currentTool = self.currentTool() self.currentOperator, self.operatorState = None, None @@ -51,7 +53,7 @@ class RoarCanvasCommandsTools(): self.accels = () self.menus = ( ("&Tools", - self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 2), self.canvasTool(self.canvasTool, 3), self.canvasTool(self.canvasTool, 6), self.canvasTool(self.canvasTool, 4), + self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 6), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 3), self.canvasTool(self.canvasTool, 4), self.canvasTool(self.canvasTool, 7), self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 2), ), ) self.toolBars = () diff --git a/libtools/ToolErase.py b/libtools/ToolErase.py new file mode 100644 index 0000000..4d865fb --- /dev/null +++ b/libtools/ToolErase.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# +# ToolErase.py +# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz +# + +from Tool import Tool + +class ToolErase(Tool): + name = "Erase" + + # + # 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, brushSize, dirty = list(brushColours), list(brushSize), False + if mouseRightDown: + brushColours = [brushColours[0], brushColours[0]] + else: + brushColours = [brushColours[1], brushColours[1]] + if brushSize[0] > 1: + brushSize[0] *= 2 + for brushRow in range(brushSize[1]): + for brushCol in range(brushSize[0]): + patchColours = [brushColours[1]] * 2 + patch = [mapPoint[0] + brushCol, mapPoint[1] + brushRow, *patchColours, 0, " "] + if mouseLeftDown or mouseRightDown: + if not dirty: + dirty = True + dispatchFn(eventDc, False, patch); dispatchFn(eventDc, True, patch); + else: + dispatchFn(eventDc, True, patch) + return True, dirty + +# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120