From d26a3226129c1bbb76c7e31d4c607639c436e7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Thu, 11 Jan 2018 00:26:46 +0100 Subject: [PATCH] MiRCART{CanvasInterface,Frame}.py: adds (flood) fill tool. MiRCARTToolFill.py: initial implementation. assets/toolFill.png: added. --- MiRCARTCanvasInterface.py | 6 +++++ MiRCARTFrame.py | 15 ++++++----- MiRCARTToolFill.py | 53 ++++++++++++++++++++++++++++++++++++++ assets/toolFill.png | Bin 0 -> 527 bytes 4 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 MiRCARTToolFill.py create mode 100644 assets/toolFill.png diff --git a/MiRCARTCanvasInterface.py b/MiRCARTCanvasInterface.py index ce29216..43dcd8c 100644 --- a/MiRCARTCanvasInterface.py +++ b/MiRCARTCanvasInterface.py @@ -23,6 +23,7 @@ # from MiRCARTToolCircle import MiRCARTToolCircle +from MiRCARTToolFill import MiRCARTToolFill from MiRCARTToolLine import MiRCARTToolLine from MiRCARTToolSelectClone import MiRCARTToolSelectClone from MiRCARTToolSelectMove import MiRCARTToolSelectMove @@ -264,6 +265,11 @@ class MiRCARTCanvasInterface(): self.canvasTool = MiRCARTToolCircle(self.parentCanvas) self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name) # }}} + # {{{ canvasToolFill(self, event): XXX + def canvasToolFill(self, event): + self.canvasTool = MiRCARTToolFill(self.parentCanvas) + self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name) + # }}} # {{{ canvasToolLine(self, event): XXX def canvasToolLine(self, event): self.canvasTool = MiRCARTToolLine(self.parentCanvas) diff --git a/MiRCARTFrame.py b/MiRCARTFrame.py index 95665f0..e357e48 100644 --- a/MiRCARTFrame.py +++ b/MiRCARTFrame.py @@ -70,10 +70,11 @@ class MiRCARTFrame(MiRCARTGeneralFrame): CID_RECT = [0x150, TID_SELECT, "Rectangle", "&Rectangle", ["toolRect.png"], [wx.ACCEL_CTRL, ord("R")], True, MiRCARTCanvasInterface.canvasToolRect] CID_CIRCLE = [0x151, TID_SELECT, "Circle", "&Circle", ["toolCircle.png"], [wx.ACCEL_CTRL, ord("C")], False, MiRCARTCanvasInterface.canvasToolCircle] - CID_LINE = [0x152, TID_SELECT, "Line", "&Line", ["toolLine.png"], [wx.ACCEL_CTRL, ord("L")], False, MiRCARTCanvasInterface.canvasToolLine] - CID_TEXT = [0x153, TID_SELECT, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False, MiRCARTCanvasInterface.canvasToolText] - CID_CLONE_SELECT = [0x154, TID_SELECT, "Clone", "Cl&one", ["toolClone.png"], [wx.ACCEL_CTRL, ord("E")], False, MiRCARTCanvasInterface.canvasToolSelectClone] - CID_MOVE_SELECT = [0x155, TID_SELECT, "Move", "&Move", ["toolMove.png"], [wx.ACCEL_CTRL, ord("M")], False, MiRCARTCanvasInterface.canvasToolSelectMove] + CID_FILL = [0x152, TID_SELECT, "Fill", "&Fill", ["toolFill.png"], [wx.ACCEL_CTRL, ord("F")], False, MiRCARTCanvasInterface.canvasToolFill] + CID_LINE = [0x153, TID_SELECT, "Line", "&Line", ["toolLine.png"], [wx.ACCEL_CTRL, ord("L")], False, MiRCARTCanvasInterface.canvasToolLine] + CID_TEXT = [0x154, TID_SELECT, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False, MiRCARTCanvasInterface.canvasToolText] + CID_CLONE_SELECT = [0x155, TID_SELECT, "Clone", "Cl&one", ["toolClone.png"], [wx.ACCEL_CTRL, ord("E")], False, MiRCARTCanvasInterface.canvasToolSelectClone] + CID_MOVE_SELECT = [0x156, TID_SELECT, "Move", "&Move", ["toolMove.png"], [wx.ACCEL_CTRL, ord("M")], False, MiRCARTCanvasInterface.canvasToolSelectMove] CID_COLOUR00 = [0x1a0, TID_COMMAND, "Colour #00", "Colour #00", None, None, None, MiRCARTCanvasInterface.canvasColour] CID_COLOUR01 = [0x1a1, TID_COMMAND, "Colour #01", "Colour #01", None, None, None, MiRCARTCanvasInterface.canvasColour] @@ -103,7 +104,7 @@ class MiRCARTFrame(MiRCARTGeneralFrame): CID_INCRW_CANVAS, CID_DECRW_CANVAS, CID_INCRH_CANVAS, CID_DECRH_CANVAS, NID_MENU_SEP, \ CID_INCR_BRUSH, CID_DECR_BRUSH, CID_SOLID_BRUSH)) MID_TOOLS = (0x302, TID_MENU, "Tools", "&Tools", ( \ - CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT, CID_CLONE_SELECT, CID_MOVE_SELECT)) + CID_RECT, CID_CIRCLE, CID_FILL, CID_LINE, CID_TEXT, CID_CLONE_SELECT, CID_MOVE_SELECT)) # }}} # {{{ Toolbars BID_TOOLBAR = (0x400, TID_TOOLBAR, ( \ @@ -111,7 +112,7 @@ class MiRCARTFrame(MiRCARTGeneralFrame): CID_UNDO, CID_REDO, NID_TOOLBAR_HSEP, \ CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_TOOLBAR_HSEP, \ CID_INCR_BRUSH, CID_DECR_BRUSH, NID_TOOLBAR_HSEP, \ - CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT, CID_CLONE_SELECT, CID_MOVE_SELECT, \ + CID_RECT, CID_CIRCLE, CID_FILL, CID_LINE, CID_TEXT, CID_CLONE_SELECT, CID_MOVE_SELECT, \ NID_TOOLBAR_VSEP, \ CID_COLOUR00, CID_COLOUR01, CID_COLOUR02, CID_COLOUR03, CID_COLOUR04, \ CID_COLOUR05, CID_COLOUR06, CID_COLOUR07, CID_COLOUR08, CID_COLOUR09, \ @@ -123,7 +124,7 @@ class MiRCARTFrame(MiRCARTGeneralFrame): CID_NEW, CID_OPEN, CID_SAVE, CID_UNDO, CID_REDO, \ CID_INCRW_CANVAS, CID_DECRW_CANVAS, CID_INCRH_CANVAS, CID_DECRH_CANVAS, \ CID_INCR_BRUSH, CID_DECR_BRUSH, \ - CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT, CID_CLONE_SELECT, CID_MOVE_SELECT)) + CID_RECT, CID_CIRCLE, CID_FILL, CID_LINE, CID_TEXT, CID_CLONE_SELECT, CID_MOVE_SELECT)) # }}} # {{{ Lists LID_ACCELS = (0x600, TID_LIST, (AID_EDIT)) diff --git a/MiRCARTToolFill.py b/MiRCARTToolFill.py new file mode 100644 index 0000000..3a7ef22 --- /dev/null +++ b/MiRCARTToolFill.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 +# +# MiRCARTToolFill.py -- XXX +# Copyright (c) 2018 Lucio Andrés Illanes Albornoz +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +from MiRCARTTool import MiRCARTTool + +class MiRCARTToolFill(MiRCARTTool): + """XXX""" + name = "Fill" + + # + # onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc): XXX + def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc): + pointStack = [list(atPoint)] + if isLeftDown or isRightDown: + if isRightDown: + brushColours = [brushColours[1], brushColours[0]] + while len(pointStack) > 0: + point = pointStack.pop() + pointCell = self.parentCanvas.canvasMap[point[1]][point[0]] + if pointCell[0][1] == brushColours[1]: + dispatchFn(eventDc, False, [point.copy(), \ + [brushColours[0], brushColours[0]], 0, " "]) + if point[0] > 0: + pointStack.append([point[0] - 1, point[1]]) + if point[0] < (self.parentCanvas.canvasSize[0] - 1): + pointStack.append([point[0] + 1, point[1]]) + if point[1] > 0: + pointStack.append([point[0], point[1] - 1]) + if point[1] < (self.parentCanvas.canvasSize[1] - 1): + pointStack.append([point[0], point[1] + 1]) + +# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/assets/toolFill.png b/assets/toolFill.png new file mode 100644 index 0000000000000000000000000000000000000000..54b87375fee3affffea33f859879b0b1a91bbf55 GIT binary patch literal 527 zcmV+q0`UEbP)N2bZe?^J zG%heMF*(%MvSa`N0gOpRK~y+Tg_1!_0znvt_XqS3`Uyg}ZguWbM>`aBtxH`+=(4yJ zDISatD~KYof~?`8z(n?t)Is#1C@8U|EQX=%Li7XP<{Q{$)^+XheDlpaI}ba|NC4JS zsZ`jodW~?KV=;6|r_*c*<|0%M8QWs$BFi##U1x1@&4tPyBO-=`s;Y>^VsIR1t%S2a?Go+iW49*HJ8L zTtK(rN@lZJK*Gz>r3E=zf@wM^m7bByJwTRk(CKuL$z)&{h9{X$r#^{vs=Q1WiaXnf!PX`V%@%wfYn)ks=3=AV}a! zOw;~XG9HgnC=?)V?%soN1+HW`{0^10+iiBVEZ-wtt8Hv--SLTtrfKN+zXFna{RQF^ z=S9AK^8yiijlG`bNp#)dS1o?y+pr2nQMjbp9I&gES>#{$O~RlDMJ(q4q(AFc0+ZY6 ReRBW+002ovPDHLkV1jBW;cEZ@ literal 0 HcmV?d00001