MiRCART{CanvasInterface,Frame}.py: adds (flood) fill tool.

MiRCARTToolFill.py: initial implementation.
assets/toolFill.png: added.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-11 00:26:46 +01:00
parent 426c1f990f
commit 24de84093d
4 changed files with 67 additions and 7 deletions

View File

@ -23,6 +23,7 @@
# #
from MiRCARTToolCircle import MiRCARTToolCircle from MiRCARTToolCircle import MiRCARTToolCircle
from MiRCARTToolFill import MiRCARTToolFill
from MiRCARTToolLine import MiRCARTToolLine from MiRCARTToolLine import MiRCARTToolLine
from MiRCARTToolSelectClone import MiRCARTToolSelectClone from MiRCARTToolSelectClone import MiRCARTToolSelectClone
from MiRCARTToolSelectMove import MiRCARTToolSelectMove from MiRCARTToolSelectMove import MiRCARTToolSelectMove
@ -264,6 +265,11 @@ class MiRCARTCanvasInterface():
self.canvasTool = MiRCARTToolCircle(self.parentCanvas) self.canvasTool = MiRCARTToolCircle(self.parentCanvas)
self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name) 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 # {{{ canvasToolLine(self, event): XXX
def canvasToolLine(self, event): def canvasToolLine(self, event):
self.canvasTool = MiRCARTToolLine(self.parentCanvas) self.canvasTool = MiRCARTToolLine(self.parentCanvas)

View File

@ -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_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_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_FILL = [0x152, TID_SELECT, "Fill", "&Fill", ["toolFill.png"], [wx.ACCEL_CTRL, ord("F")], False, MiRCARTCanvasInterface.canvasToolFill]
CID_TEXT = [0x153, TID_SELECT, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False, MiRCARTCanvasInterface.canvasToolText] CID_LINE = [0x153, TID_SELECT, "Line", "&Line", ["toolLine.png"], [wx.ACCEL_CTRL, ord("L")], False, MiRCARTCanvasInterface.canvasToolLine]
CID_CLONE_SELECT = [0x154, TID_SELECT, "Clone", "Cl&one", ["toolClone.png"], [wx.ACCEL_CTRL, ord("E")], False, MiRCARTCanvasInterface.canvasToolSelectClone] CID_TEXT = [0x154, TID_SELECT, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False, MiRCARTCanvasInterface.canvasToolText]
CID_MOVE_SELECT = [0x155, TID_SELECT, "Move", "&Move", ["toolMove.png"], [wx.ACCEL_CTRL, ord("M")], False, MiRCARTCanvasInterface.canvasToolSelectMove] 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_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] 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_INCRW_CANVAS, CID_DECRW_CANVAS, CID_INCRH_CANVAS, CID_DECRH_CANVAS, NID_MENU_SEP, \
CID_INCR_BRUSH, CID_DECR_BRUSH, CID_SOLID_BRUSH)) CID_INCR_BRUSH, CID_DECR_BRUSH, CID_SOLID_BRUSH))
MID_TOOLS = (0x302, TID_MENU, "Tools", "&Tools", ( \ 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 # {{{ Toolbars
BID_TOOLBAR = (0x400, TID_TOOLBAR, ( \ BID_TOOLBAR = (0x400, TID_TOOLBAR, ( \
@ -111,7 +112,7 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
CID_UNDO, CID_REDO, NID_TOOLBAR_HSEP, \ CID_UNDO, CID_REDO, NID_TOOLBAR_HSEP, \
CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_TOOLBAR_HSEP, \ CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_TOOLBAR_HSEP, \
CID_INCR_BRUSH, CID_DECR_BRUSH, 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, \ NID_TOOLBAR_VSEP, \
CID_COLOUR00, CID_COLOUR01, CID_COLOUR02, CID_COLOUR03, CID_COLOUR04, \ CID_COLOUR00, CID_COLOUR01, CID_COLOUR02, CID_COLOUR03, CID_COLOUR04, \
CID_COLOUR05, CID_COLOUR06, CID_COLOUR07, CID_COLOUR08, CID_COLOUR09, \ 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_NEW, CID_OPEN, CID_SAVE, CID_UNDO, CID_REDO, \
CID_INCRW_CANVAS, CID_DECRW_CANVAS, CID_INCRH_CANVAS, CID_DECRH_CANVAS, \ CID_INCRW_CANVAS, CID_DECRW_CANVAS, CID_INCRH_CANVAS, CID_DECRH_CANVAS, \
CID_INCR_BRUSH, CID_DECR_BRUSH, \ 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 # {{{ Lists
LID_ACCELS = (0x600, TID_LIST, (AID_EDIT)) LID_ACCELS = (0x600, TID_LIST, (AID_EDIT))

53
MiRCARTToolFill.py Normal file
View File

@ -0,0 +1,53 @@
#!/usr/bin/env python3
#
# MiRCARTToolFill.py -- XXX
# Copyright (c) 2018 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
#
# 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

BIN
assets/toolFill.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B