mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-25 08:36:38 +00:00
130 lines
6.0 KiB
Python
130 lines
6.0 KiB
Python
#!/usr/bin/env python3
|
|
#
|
|
# MiRCARTToolSelect.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 MiRCARTToolSelect(MiRCARTTool):
|
|
"""XXX"""
|
|
toolColours = toolRect = toolState = None
|
|
toolLastAtPoint = None
|
|
toolSelectMap = None
|
|
srcRect = None
|
|
|
|
TS_NONE = 0
|
|
TS_ORIGIN = 1
|
|
TS_TARGET = 2
|
|
|
|
# {{{ _drawSelectRect(self, rect, dispatchFn, eventDc): XXX
|
|
def _drawSelectRect(self, rect, dispatchFn, eventDc):
|
|
rectFrame = [ \
|
|
[rect[0][0]-1, rect[0][1]-1], \
|
|
[rect[1][0]+1, rect[1][1]+1]]
|
|
if rectFrame[0][0] > rectFrame[1][0]:
|
|
rectFrame[0][0], rectFrame[1][0] = \
|
|
rectFrame[1][0], rectFrame[0][0]
|
|
if rectFrame[0][1] > rectFrame[1][1]:
|
|
rectFrame[0][1], rectFrame[1][1] = \
|
|
rectFrame[1][1], rectFrame[0][1]
|
|
curColours = [0, 0]
|
|
for rectX in range(rectFrame[0][0], rectFrame[1][0]+1):
|
|
if curColours == [0, 0]:
|
|
curColours = [1, 1]
|
|
else:
|
|
curColours = [0, 0]
|
|
dispatchFn(eventDc, True, \
|
|
[rectX, rectFrame[0][1], *curColours, 0, " "])
|
|
dispatchFn(eventDc, True, \
|
|
[rectX, rectFrame[1][1], *curColours, 0, " "])
|
|
for rectY in range(rectFrame[0][1], rectFrame[1][1]+1):
|
|
if curColours == [0, 0]:
|
|
curColours = [1, 1]
|
|
else:
|
|
curColours = [0, 0]
|
|
dispatchFn(eventDc, True, \
|
|
[rectFrame[0][0], rectY, *curColours, 0, " "])
|
|
dispatchFn(eventDc, True, \
|
|
[rectFrame[1][0], rectY, *curColours, 0, " "])
|
|
# }}}
|
|
|
|
#
|
|
# onSelectEvent(self, event, atPoint, selectRect, brushColours, brushSize, isLeftDown, isRightDown, dispatchFn, eventDc): XXX
|
|
def onSelectEvent(self, event, atPoint, selectRect, brushColours, brushSize, isLeftDown, isRightDown, dispatchFn, eventDc):
|
|
pass
|
|
|
|
#
|
|
# onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc): XXX
|
|
def onMouseEvent(self, event, atPoint, brushColours, brushSize, isDragging, isLeftDown, isRightDown, dispatchFn, eventDc):
|
|
if self.toolState == self.TS_NONE:
|
|
if isLeftDown or isRightDown:
|
|
self.toolColours = [0, 1]
|
|
self.toolRect = [list(atPoint), []]
|
|
self.toolState = self.TS_ORIGIN
|
|
else:
|
|
dispatchFn(eventDc, True, \
|
|
[*atPoint, *brushColours, 0, " "])
|
|
elif self.toolState == self.TS_ORIGIN:
|
|
self.toolRect[1] = list(atPoint)
|
|
if isLeftDown or isRightDown:
|
|
if self.toolRect[0][0] > self.toolRect[1][0]:
|
|
self.toolRect[0][0], self.toolRect[1][0] = \
|
|
self.toolRect[1][0], self.toolRect[0][0]
|
|
if self.toolRect[0][1] > self.toolRect[1][1]:
|
|
self.toolRect[0][1], self.toolRect[1][1] = \
|
|
self.toolRect[1][1], self.toolRect[0][1]
|
|
self.srcRect = self.toolRect[0]
|
|
self.toolLastAtPoint = list(atPoint)
|
|
self.toolState = self.TS_TARGET
|
|
self.toolSelectMap = []
|
|
for numRow in range((self.toolRect[1][1] - self.toolRect[0][1]) + 1):
|
|
self.toolSelectMap.append([])
|
|
for numCol in range((self.toolRect[1][0] - self.toolRect[0][0]) + 1):
|
|
rectY = self.toolRect[0][1] + numRow
|
|
rectX = self.toolRect[0][0] + numCol
|
|
self.toolSelectMap[numRow].append( \
|
|
self.parentCanvas.canvasMap[rectY][rectX])
|
|
self._drawSelectRect(self.toolRect, dispatchFn, eventDc)
|
|
elif self.toolState == self.TS_TARGET:
|
|
if isRightDown:
|
|
self.onSelectEvent(event, atPoint, self.toolRect, \
|
|
brushColours, brushSize, isLeftDown, isRightDown, \
|
|
dispatchFn, eventDc)
|
|
self.toolColours = None
|
|
self.toolRect = None
|
|
self.toolState = self.TS_NONE
|
|
else:
|
|
self.onSelectEvent(event, atPoint, self.toolRect, \
|
|
brushColours, brushSize, isLeftDown, isRightDown, \
|
|
dispatchFn, eventDc)
|
|
|
|
# __init__(self, *args): initialisation method
|
|
def __init__(self, *args):
|
|
super().__init__(*args)
|
|
self.toolColours = None
|
|
self.toolRect = None
|
|
self.toolState = self.TS_NONE
|
|
self.toolLastAtPoint = None
|
|
self.toolSelectMap = None
|
|
|
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|