2019-09-01 14:34:00 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2019-09-09 10:46:52 +00:00
|
|
|
# ToolFill.py
|
2019-09-04 14:23:59 +00:00
|
|
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
2019-09-01 14:34:00 +00:00
|
|
|
#
|
|
|
|
|
2019-09-03 16:58:50 +00:00
|
|
|
from Tool import Tool
|
2019-09-01 14:34:00 +00:00
|
|
|
|
2019-09-03 16:58:50 +00:00
|
|
|
class ToolFill(Tool):
|
2019-09-01 14:34:00 +00:00
|
|
|
name = "Fill"
|
|
|
|
|
|
|
|
#
|
2019-09-16 14:54:07 +00:00
|
|
|
# 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):
|
2019-09-16 06:45:03 +00:00
|
|
|
dirty, pointsDone, pointStack, testChar, testColour = False, [], [list(mapPoint)], canvas.map[mapPoint[1]][mapPoint[0]][3], canvas.map[mapPoint[1]][mapPoint[0]][0:2]
|
libgui/GuiCanvasInterface.py:canvasTool(): call applyTool() w/ new tool post-selection.
libgui/GuiCanvasPanel.py:{applyTool,onPanelInput}(): split from onPanelInput().
libtools/Tool{,Circle,Fill,Line,Rect,Select,Text}.py:on{Keyboard,Mouse}Event(): updated.
libtools/ToolFill.py:onMouseEvent(): display cursor.
libtools/ToolSelect{,Clone,Move}.py:onSelectEvent(): updated.
2019-09-09 16:18:54 +00:00
|
|
|
if mouseLeftDown or mouseRightDown:
|
2019-09-01 14:34:00 +00:00
|
|
|
while len(pointStack) > 0:
|
|
|
|
point = pointStack.pop()
|
2019-09-10 10:12:12 +00:00
|
|
|
pointCell = canvas.map[point[1]][point[0]]
|
2019-09-16 06:45:03 +00:00
|
|
|
if ((pointCell[1] == testColour[1]) and ((pointCell[3] == testChar) or mouseRightDown)) \
|
2019-09-07 08:39:26 +00:00
|
|
|
or ((pointCell[3] == " ") and (pointCell[1] == testColour[1])):
|
2019-09-01 14:34:00 +00:00
|
|
|
if not point in pointsDone:
|
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}().
libgui/GuiCanvasPanel.py:applyTool(): updated.
libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch().
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty.
libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
2019-09-09 16:43:33 +00:00
|
|
|
if not dirty:
|
|
|
|
dirty = True
|
2019-09-16 14:54:07 +00:00
|
|
|
dispatchFn(eventDc, False, [*point, brushColours[0], brushColours[0], 0, " "])
|
2019-09-01 14:34:00 +00:00
|
|
|
if point[0] > 0:
|
|
|
|
pointStack.append([point[0] - 1, point[1]])
|
2019-09-10 10:12:12 +00:00
|
|
|
if point[0] < (canvas.size[0] - 1):
|
2019-09-01 14:34:00 +00:00
|
|
|
pointStack.append([point[0] + 1, point[1]])
|
|
|
|
if point[1] > 0:
|
|
|
|
pointStack.append([point[0], point[1] - 1])
|
2019-09-10 10:12:12 +00:00
|
|
|
if point[1] < (canvas.size[1] - 1):
|
2019-09-01 14:34:00 +00:00
|
|
|
pointStack.append([point[0], point[1] + 1])
|
|
|
|
pointsDone += [point]
|
libgui/GuiCanvasInterface.py:canvasTool(): call applyTool() w/ new tool post-selection.
libgui/GuiCanvasPanel.py:{applyTool,onPanelInput}(): split from onPanelInput().
libtools/Tool{,Circle,Fill,Line,Rect,Select,Text}.py:on{Keyboard,Mouse}Event(): updated.
libtools/ToolFill.py:onMouseEvent(): display cursor.
libtools/ToolSelect{,Clone,Move}.py:onSelectEvent(): updated.
2019-09-09 16:18:54 +00:00
|
|
|
else:
|
|
|
|
patch = [mapPoint[0], mapPoint[1], brushColours[0], brushColours[0], 0, " "]
|
2019-09-16 14:54:07 +00:00
|
|
|
dispatchFn(eventDc, True, patch)
|
libcanvas/Canvas.py:dispatchPatchSingle(): cloned from dispatchPatch().
lib{canvas/Canvas{,Journal},gui/GuiCanvasPanel}.py: replace dirtyJournal & pushDeltas() w/ explicit {begin,end}().
libgui/GuiCanvasPanel.py:applyTool(): updated.
libgui/GuiCanvasPanel.py:dispatchPatchSingle(): cloned from dispatchPatch().
libtools/Tool{,Circle,Fill,Line,Rect,Select{,Clone,Move},Text}.py:on{Mouse,Keyboard}Event(): return rc, dirty.
libtools/ToolSelect{Clone,Move}.py:onSelectEvent(): return rc, dirty.
2019-09-09 16:43:33 +00:00
|
|
|
return True, dirty
|
2019-09-01 14:34:00 +00:00
|
|
|
|
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|