MiRCART{CanvasInterface,Frame}.py: adds clone & move (selection) tools.

MiRCARTTool{Clone,Move}Select.py: initial implementation.
assets/tool{Clone,Move}.png: added.
MiRCART.png: updated.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-10 15:56:17 +01:00
parent c9d6b90e68
commit ad761d658e
8 changed files with 287 additions and 22 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -24,6 +24,8 @@
from MiRCARTToolCircle import MiRCARTToolCircle from MiRCARTToolCircle import MiRCARTToolCircle
from MiRCARTToolLine import MiRCARTToolLine from MiRCARTToolLine import MiRCARTToolLine
from MiRCARTToolSelectClone import MiRCARTToolSelectClone
from MiRCARTToolSelectMove import MiRCARTToolSelectMove
from MiRCARTToolRect import MiRCARTToolRect from MiRCARTToolRect import MiRCARTToolRect
from MiRCARTToolText import MiRCARTToolText from MiRCARTToolText import MiRCARTToolText
@ -267,6 +269,16 @@ class MiRCARTCanvasInterface():
self.canvasTool = MiRCARTToolLine(self.parentCanvas) self.canvasTool = MiRCARTToolLine(self.parentCanvas)
self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name) self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name)
# }}} # }}}
# {{{ canvasToolSelectClone(self, event): XXX
def canvasToolSelectClone(self, event):
self.canvasTool = MiRCARTToolSelectClone(self.parentCanvas)
self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name)
# }}}
# {{{ canvasToolSelectMove(self, event): XXX
def canvasToolSelectMove(self, event):
self.canvasTool = MiRCARTToolSelectMove(self.parentCanvas)
self.parentFrame.onCanvasUpdate(toolName=self.canvasTool.name)
# }}}
# {{{ canvasToolRect(self, event): XXX # {{{ canvasToolRect(self, event): XXX
def canvasToolRect(self, event): def canvasToolRect(self, event):
self.canvasTool = MiRCARTToolRect(self.parentCanvas) self.canvasTool = MiRCARTToolRect(self.parentCanvas)

View File

@ -72,6 +72,8 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
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_LINE = [0x152, TID_SELECT, "Line", "&Line", ["toolLine.png"], [wx.ACCEL_CTRL, ord("L")], False, MiRCARTCanvasInterface.canvasToolLine]
CID_TEXT = [0x153, TID_SELECT, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False, MiRCARTCanvasInterface.canvasToolText] CID_TEXT = [0x153, TID_SELECT, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False, MiRCARTCanvasInterface.canvasToolText]
CID_CLONE_SELECT = [0x154, TID_SELECT, "Clone", "Cl&one", ["toolClone.png"], [wx.ACCEL_CTRL, ord("E")], False, MiRCARTCanvasInterface.canvasToolSelectClone]
CID_MOVE_SELECT = [0x155, 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]
@ -101,7 +103,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_RECT, CID_CIRCLE, CID_LINE, CID_TEXT, CID_CLONE_SELECT, CID_MOVE_SELECT))
# }}} # }}}
# {{{ Toolbars # {{{ Toolbars
BID_TOOLBAR = (0x400, TID_TOOLBAR, ( \ BID_TOOLBAR = (0x400, TID_TOOLBAR, ( \
@ -109,7 +111,7 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
CID_UNDO, CID_REDO, NID_TOOLBAR_SEP, \ CID_UNDO, CID_REDO, NID_TOOLBAR_SEP, \
CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_TOOLBAR_SEP, \ CID_CUT, CID_COPY, CID_PASTE, CID_DELETE, NID_TOOLBAR_SEP, \
CID_INCR_BRUSH, CID_DECR_BRUSH, NID_TOOLBAR_SEP, \ CID_INCR_BRUSH, CID_DECR_BRUSH, NID_TOOLBAR_SEP, \
CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT, NID_TOOLBAR_SEP, \ CID_RECT, CID_CIRCLE, CID_LINE, CID_TEXT, CID_CLONE_SELECT, CID_MOVE_SELECT, NID_TOOLBAR_SEP, \
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, \
CID_COLOUR10, CID_COLOUR11, CID_COLOUR12, CID_COLOUR13, CID_COLOUR14, \ CID_COLOUR10, CID_COLOUR11, CID_COLOUR12, CID_COLOUR13, CID_COLOUR14, \
@ -119,7 +121,8 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
AID_EDIT = (0x500, TID_ACCELS, ( \ AID_EDIT = (0x500, TID_ACCELS, ( \
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))
# }}} # }}}
# {{{ Lists # {{{ Lists
LID_ACCELS = (0x600, TID_LIST, (AID_EDIT)) LID_ACCELS = (0x600, TID_LIST, (AID_EDIT))

129
MiRCARTToolSelect.py Normal file
View File

@ -0,0 +1,129 @@
#!/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, \
[list(atPoint), brushColours.copy(), 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

60
MiRCARTToolSelectClone.py Normal file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env python3
#
# MiRCARTToolSelectClone.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 MiRCARTToolSelect import MiRCARTToolSelect
class MiRCARTToolSelectClone(MiRCARTToolSelect):
"""XXX"""
name = "Clone selection"
#
# onSelectEvent(self, event, atPoint, selectRect, brushColours, brushSize, isLeftDown, isRightDown, dispatchFn, eventDc): XXX
def onSelectEvent(self, event, atPoint, selectRect, brushColours, brushSize, isLeftDown, isRightDown, dispatchFn, eventDc):
if isLeftDown:
atPoint = list(atPoint)
disp = [atPoint[0]-self.toolLastAtPoint[0], \
atPoint[1]-self.toolLastAtPoint[1]]
self.toolLastAtPoint = atPoint
newToolRect = [ \
[selectRect[0][0]+disp[0], selectRect[0][1]+disp[1]], \
[selectRect[1][0]+disp[0], selectRect[1][1]+disp[1]]]
isCursor = True
elif isRightDown:
disp = [0, 0]
newToolRect = selectRect.copy()
isCursor = False
else:
disp = [0, 0]
newToolRect = selectRect.copy()
isCursor = True
for numRow in range(len(self.toolSelectMap)):
for numCol in range(len(self.toolSelectMap[numRow])):
cellOld = self.toolSelectMap[numRow][numCol]
rectY = selectRect[0][1] + numRow
rectX = selectRect[0][0] + numCol
dispatchFn(eventDc, isCursor, [[rectX+disp[0], rectY+disp[1]], *cellOld])
self._drawSelectRect(newToolRect, dispatchFn, eventDc)
self.toolRect = newToolRect
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

61
MiRCARTToolSelectMove.py Normal file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env python3
#
# MiRCARTToolSelectMove.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 MiRCARTToolSelect import MiRCARTToolSelect
class MiRCARTToolSelectMove(MiRCARTToolSelect):
"""XXX"""
name = "Move selection"
#
# onSelectEvent(self, event, atPoint, selectRect, brushColours, brushSize, isLeftDown, isRightDown, dispatchFn, eventDc): XXX
def onSelectEvent(self, event, atPoint, selectRect, brushColours, brushSize, isLeftDown, isRightDown, dispatchFn, eventDc):
if isLeftDown:
atPoint = list(atPoint)
disp = [atPoint[0]-self.toolLastAtPoint[0], \
atPoint[1]-self.toolLastAtPoint[1]]
self.toolLastAtPoint = atPoint
newToolRect = [ \
[selectRect[0][0]+disp[0], selectRect[0][1]+disp[1]], \
[selectRect[1][0]+disp[0], selectRect[1][1]+disp[1]]]
isCursor = True
elif isRightDown:
disp = [0, 0]
newToolRect = selectRect.copy()
isCursor = False
else:
disp = [0, 0]
newToolRect = selectRect.copy()
isCursor = True
for numRow in range(len(self.toolSelectMap)):
for numCol in range(len(self.toolSelectMap[numRow])):
cellOld = self.toolSelectMap[numRow][numCol]
rectY = selectRect[0][1] + numRow
rectX = selectRect[0][0] + numCol
dispatchFn(eventDc, isCursor, [[self.srcRect[0] + numCol, self.srcRect[1] + numRow], [1, 1], 0, " "])
dispatchFn(eventDc, isCursor, [[rectX+disp[0], rectY+disp[1]], *cellOld])
self._drawSelectRect(newToolRect, dispatchFn, eventDc)
self.toolRect = newToolRect
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120

BIN
assets/toolClone.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

BIN
assets/toolMove.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B