roar/libtools/ToolFill.py

46 lines
2.2 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
#
# ToolFill.py
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
#
2019-09-03 16:58:50 +00:00
from Tool import Tool
2019-09-23 16:49:33 +00:00
import wx
2019-09-03 16:58:50 +00:00
class ToolFill(Tool):
name = "Fill"
#
# 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):
dirty, pointsDone, pointStack, testChar, testColour = False, [], [list(mapPoint)], canvas.map[mapPoint[1]][mapPoint[0]][3], canvas.map[mapPoint[1]][mapPoint[0]][0:2]
if mouseLeftDown or mouseRightDown:
2019-09-23 16:49:33 +00:00
if mouseLeftDown:
fillColour = brushColours[0]
else:
fillColour = brushColours[1]
while len(pointStack) > 0:
point = pointStack.pop()
pointCell = canvas.map[point[1]][point[0]]
2019-09-23 16:49:33 +00:00
if ((pointCell[1] == testColour[1]) and ((pointCell[3] == testChar) or (keyModifiers == wx.MOD_CONTROL))) \
or ((pointCell[3] == " ") and (pointCell[1] == testColour[1])):
if not point in pointsDone:
if not dirty:
dirty = True
2019-09-23 16:49:33 +00:00
dispatchFn(eventDc, False, [*point, fillColour, fillColour, 0, " "])
if point[0] > 0:
pointStack.append([point[0] - 1, point[1]])
if point[0] < (canvas.size[0] - 1):
pointStack.append([point[0] + 1, point[1]])
if point[1] > 0:
pointStack.append([point[0], point[1] - 1])
if point[1] < (canvas.size[1] - 1):
pointStack.append([point[0], point[1] + 1])
pointsDone += [point]
else:
patch = [mapPoint[0], mapPoint[1], brushColours[0], brushColours[0], 0, " "]
dispatchFn(eventDc, True, patch)
return True, dirty
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120