2019-09-23 19:59:41 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# ToolErase.py
|
|
|
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
|
|
|
#
|
|
|
|
|
|
|
|
from Tool import Tool
|
|
|
|
|
|
|
|
class ToolErase(Tool):
|
|
|
|
name = "Erase"
|
|
|
|
|
2019-09-26 20:38:28 +00:00
|
|
|
def onMouseEvent(self, atPoint, brushColours, brushPos, brushSize, canvas, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown):
|
|
|
|
brushColours, brushSize, isCursor, patches, patchesCursor = list(brushColours), list(brushSize), not (mouseLeftDown or mouseRightDown), [], []
|
2019-09-23 19:59:41 +00:00
|
|
|
if brushSize[0] > 1:
|
|
|
|
brushSize[0] *= 2
|
|
|
|
for brushRow in range(brushSize[1]):
|
|
|
|
for brushCol in range(brushSize[0]):
|
2019-09-24 13:44:54 +00:00
|
|
|
if mouseLeftDown:
|
2019-09-26 20:38:28 +00:00
|
|
|
patches += [[mapPoint[0] + brushCol, mapPoint[1] + brushRow, brushColours[1], brushColours[1], 0, " "]]
|
2019-09-24 13:44:54 +00:00
|
|
|
elif mouseRightDown \
|
|
|
|
and ((mapPoint[0] + brushCol) < canvas.size[0]) \
|
|
|
|
and ((mapPoint[1] + brushRow) < canvas.size[1]) \
|
|
|
|
and (canvas.map[mapPoint[1] + brushRow][mapPoint[0] + brushCol][1] == brushColours[1]):
|
2019-10-01 19:34:42 +00:00
|
|
|
if canvas.map[mapPoint[1] + brushRow][mapPoint[0] + brushCol][3] == " ":
|
|
|
|
patches += [[mapPoint[0] + brushCol, mapPoint[1] + brushRow, brushColours[0], brushColours[0], *canvas.map[mapPoint[1] + brushRow][mapPoint[0] + brushCol][2:]]]
|
|
|
|
else:
|
|
|
|
patches += [[mapPoint[0] + brushCol, mapPoint[1] + brushRow, canvas.map[mapPoint[1] + brushRow][mapPoint[0] + brushCol][0], brushColours[0], *canvas.map[mapPoint[1] + brushRow][mapPoint[0] + brushCol][2:]]]
|
2019-09-23 19:59:41 +00:00
|
|
|
else:
|
2019-09-26 20:38:28 +00:00
|
|
|
patchesCursor += [[mapPoint[0] + brushCol, mapPoint[1] + brushRow, brushColours[1], brushColours[1], 0, " "]]
|
|
|
|
return True, patches if not isCursor else None, patchesCursor
|
2019-09-23 19:59:41 +00:00
|
|
|
|
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|