mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-22 15:26:37 +00:00
Implements merged object tool & flip operators.
assets/images/toolObject.png: added. liboperators/Operator{,Flip{Horizontal,Vertical}}.py: initial implementation. libroar/RoarCanvasCommands.py: adds RoarCanvasCommandsOperators. libroar/RoarCanvasCommandsOperators.py: initial implementation. libroar/Roar{CanvasCommands{,Tools},Client}.py: replaces ToolSelect{Clone,Move} w/ ToolObject. libroar/RoarCanvasWindow.py:RoarCanvasWindowDropTarget.OnDropText(): update ToolObject() invocation. libroar/RoarCanvasWindow.py:{applyTool,onMouseInput}(): pass keyModifiers to Tool.onMouseEvent(). libroar/RoarCanvasWindow.py:applyTool(): only switch back to lastTool if current object tool contains an external object. libroar/RoarCanvasWindow.py:onLeaveWindow(): disable hiding cursor for now. libtools/Tool{,Circle,Fill,Line,Rect,Text}.py:onMouseEvent(): update type signature. libtools/Tool{Object,Select{,Clone,Move}}.py: merged into libtools/ToolObject.py. roar.py: add liboperators to sys.path[]. assets/text/TODO: updated.
This commit is contained in:
parent
d67dd317a1
commit
e2f413e4ba
BIN
assets/images/toolObject.png
Normal file
BIN
assets/images/toolObject.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 206 B |
@ -5,14 +5,19 @@
|
|||||||
5) Client-Server or Peer-to-Peer realtime collaboration
|
5) Client-Server or Peer-to-Peer realtime collaboration
|
||||||
6) Arbitrary {format,palette}s ({4,8} bit ANSI/mIRC, etc.)
|
6) Arbitrary {format,palette}s ({4,8} bit ANSI/mIRC, etc.)
|
||||||
7) Incremental auto{load,save} & {backup,restore} (needs Settings window)
|
7) Incremental auto{load,save} & {backup,restore} (needs Settings window)
|
||||||
8) Sprites & scripted (Python?) animation on the basis of asset traits and {composable,parametrised} patterns (metric flow, particle system, rigging, ...)
|
8) Composition, parametrisation & keying of tools from higher-order operators (brushes, filters, outlines, patterns & shaders) and unit tools
|
||||||
9) Composition, parametrisation & keying of tools from higher-order operators (brushes, filters, outlines, patterns & shaders) and unit tools
|
9) Sprites & scripted (Python?) animation on the basis of asset traits and {composable,parametrised} patterns (metric flow, particle system, rigging, ...)
|
||||||
10) GUI: a) switch to GTK b) replace logo w/ canvas panel in About dialogue c) {copy,cut,insert from,paste}, {edit asset in new canvas,import from canvas} d) replace resize buttons w/ {-,edit box,+} buttons & lock button re: ratio (ty lol3)
|
|
||||||
|
|
||||||
High-priority list:
|
High-priority list:
|
||||||
1) geometric primitives: arrow, circle, cloud/speech bubble, curve, heart, hexagon, line, pentagon, polygon, rhombus, triangle, square, star
|
1) unit tools: arrow, {cloud,speech bubble}, curve, measure, pick, polygon, triangle, unicode
|
||||||
2) region filters: crop, duplicate, erase, fill, invert, measure, pick, rotate, scale, select, shift, slice, tile, translate
|
2) text tool: a) honour RTL text flow b) navigating w/ cursor keys c) pasting text
|
||||||
3) text tool: a) allow navigating w/ cursor keys b) Unicode set key & GUI w/ MRU
|
3) operators: erase, invert, rotate, scale, shift, slice, tile
|
||||||
4) cleanup & refactor
|
4) GUI:
|
||||||
|
a) switch to GTK
|
||||||
|
b) {hide,show} cursor
|
||||||
|
c) replace logo w/ canvas panel in About dialogue
|
||||||
|
d) replace resize buttons w/ {-,edit box,+} buttons & lock button re: ratio (ty lol3)
|
||||||
|
e) {copy,cut,insert from,paste}, {edit asset in new canvas,import from {canvas,object}}
|
||||||
|
5) cleanup & refactor
|
||||||
|
|
||||||
vim:ff=dos tw=0
|
vim:ff=dos tw=0
|
||||||
|
17
liboperators/Operator.py
Normal file
17
liboperators/Operator.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# Operator.py
|
||||||
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
||||||
|
#
|
||||||
|
|
||||||
|
class Operator(object):
|
||||||
|
#
|
||||||
|
# apply(self, region)
|
||||||
|
def apply(self, region):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# __init__(self, *args): initialisation method
|
||||||
|
def __init__(self, *args):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
21
liboperators/OperatorFlipHorizontal.py
Normal file
21
liboperators/OperatorFlipHorizontal.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# OperatorFlipHorizontal.py
|
||||||
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
||||||
|
#
|
||||||
|
|
||||||
|
from Operator import Operator
|
||||||
|
|
||||||
|
class OperatorFlipHorizontal(Operator):
|
||||||
|
name = "Flip horizontally"
|
||||||
|
|
||||||
|
#
|
||||||
|
# apply(self, region)
|
||||||
|
def apply(self, region):
|
||||||
|
region.reverse(); return region;
|
||||||
|
|
||||||
|
# __init__(self, *args): initialisation method
|
||||||
|
def __init__(self, *args):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
23
liboperators/OperatorFlipVertical.py
Normal file
23
liboperators/OperatorFlipVertical.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# OperatorFlipVertical.py
|
||||||
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
||||||
|
#
|
||||||
|
|
||||||
|
from Operator import Operator
|
||||||
|
|
||||||
|
class OperatorFlipVertical(Operator):
|
||||||
|
name = "Flip"
|
||||||
|
|
||||||
|
#
|
||||||
|
# apply(self, region)
|
||||||
|
def apply(self, region):
|
||||||
|
for numRow in range(len(region)):
|
||||||
|
region[numRow].reverse()
|
||||||
|
return region
|
||||||
|
|
||||||
|
# __init__(self, *args): initialisation method
|
||||||
|
def __init__(self, *args):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
@ -9,10 +9,11 @@ from GuiFrame import NID_TOOLBAR_HSEP
|
|||||||
from RoarCanvasCommandsEdit import RoarCanvasCommandsEdit
|
from RoarCanvasCommandsEdit import RoarCanvasCommandsEdit
|
||||||
from RoarCanvasCommandsFile import RoarCanvasCommandsFile
|
from RoarCanvasCommandsFile import RoarCanvasCommandsFile
|
||||||
from RoarCanvasCommandsHelp import RoarCanvasCommandsHelp
|
from RoarCanvasCommandsHelp import RoarCanvasCommandsHelp
|
||||||
|
from RoarCanvasCommandsOperators import RoarCanvasCommandsOperators
|
||||||
from RoarCanvasCommandsTools import RoarCanvasCommandsTools
|
from RoarCanvasCommandsTools import RoarCanvasCommandsTools
|
||||||
import os, wx
|
import os, wx
|
||||||
|
|
||||||
class RoarCanvasCommands(RoarCanvasCommandsFile, RoarCanvasCommandsEdit, RoarCanvasCommandsTools, RoarCanvasCommandsHelp):
|
class RoarCanvasCommands(RoarCanvasCommandsFile, RoarCanvasCommandsEdit, RoarCanvasCommandsTools, RoarCanvasCommandsOperators, RoarCanvasCommandsHelp):
|
||||||
# {{{ _initColourBitmaps(self)
|
# {{{ _initColourBitmaps(self)
|
||||||
def _initColourBitmaps(self):
|
def _initColourBitmaps(self):
|
||||||
for numColour in range(len(RoarCanvasCommandsEdit.canvasColour.attrList)):
|
for numColour in range(len(RoarCanvasCommandsEdit.canvasColour.attrList)):
|
||||||
@ -104,7 +105,7 @@ class RoarCanvasCommands(RoarCanvasCommandsFile, RoarCanvasCommandsEdit, RoarCan
|
|||||||
self.canvasCut, self.canvasCopy, self.canvasPaste, self.canvasDelete, NID_TOOLBAR_HSEP,
|
self.canvasCut, self.canvasCopy, self.canvasPaste, self.canvasDelete, NID_TOOLBAR_HSEP,
|
||||||
self.canvasCanvasSize(self.canvasCanvasSize, 1, True), self.canvasCanvasSize(self.canvasCanvasSize, 1, False), self.canvasCanvasSize(self.canvasCanvasSize, 0, True), self.canvasCanvasSize(self.canvasCanvasSize, 0, False), NID_TOOLBAR_HSEP,
|
self.canvasCanvasSize(self.canvasCanvasSize, 1, True), self.canvasCanvasSize(self.canvasCanvasSize, 1, False), self.canvasCanvasSize(self.canvasCanvasSize, 0, True), self.canvasCanvasSize(self.canvasCanvasSize, 0, False), NID_TOOLBAR_HSEP,
|
||||||
self.canvasCanvasSize(self.canvasCanvasSize, 2, True), self.canvasCanvasSize(self.canvasCanvasSize, 2, False), NID_TOOLBAR_HSEP,
|
self.canvasCanvasSize(self.canvasCanvasSize, 2, True), self.canvasCanvasSize(self.canvasCanvasSize, 2, False), NID_TOOLBAR_HSEP,
|
||||||
self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 2), self.canvasTool(self.canvasTool, 3), self.canvasTool(self.canvasTool, 6), self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 4),
|
self.canvasTool(self.canvasTool, 4), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 2), self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 3),
|
||||||
])
|
])
|
||||||
# XXX
|
# XXX
|
||||||
toolBars.append(
|
toolBars.append(
|
||||||
|
58
libroar/RoarCanvasCommandsOperators.py
Normal file
58
libroar/RoarCanvasCommandsOperators.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# RoarCanvasCommandsOperators.py
|
||||||
|
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
||||||
|
#
|
||||||
|
|
||||||
|
from OperatorFlipHorizontal import OperatorFlipHorizontal
|
||||||
|
from OperatorFlipVertical import OperatorFlipVertical
|
||||||
|
from GuiFrame import GuiCommandListDecorator
|
||||||
|
from ToolObject import ToolObject
|
||||||
|
import copy, wx
|
||||||
|
|
||||||
|
class RoarCanvasCommandsOperators():
|
||||||
|
# {{{ canvasOperator(self, f, idx)
|
||||||
|
@GuiCommandListDecorator(0, "Flip", "&Flip", None, None, None)
|
||||||
|
@GuiCommandListDecorator(1, "Flip horizontally", "Flip &horizontally", None, None, None)
|
||||||
|
def canvasOperator(self, f, idx):
|
||||||
|
def canvasOperator_(event):
|
||||||
|
applyOperator = [OperatorFlipVertical, OperatorFlipHorizontal][idx]()
|
||||||
|
if (self.currentTool.__class__ == ToolObject) \
|
||||||
|
and (self.currentTool.toolState >= self.currentTool.TS_SELECT):
|
||||||
|
region = self.currentTool.getRegion(self.parentCanvas.canvas)
|
||||||
|
else:
|
||||||
|
region = self.parentCanvas.canvas.map
|
||||||
|
region = applyOperator.apply(copy.deepcopy(region))
|
||||||
|
if (self.currentTool.__class__ == ToolObject) \
|
||||||
|
and (self.currentTool.toolState >= self.currentTool.TS_SELECT):
|
||||||
|
viewRect = self.parentCanvas.GetViewStart()
|
||||||
|
eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas.GetClientSize(), self.parentCanvas, viewRect)
|
||||||
|
self.currentTool.setRegion(self.parentCanvas.canvas, None, region, [len(region[0]), len(region)], self.currentTool.external)
|
||||||
|
self.currentTool.onSelectEvent(self.parentCanvas.canvas, (0, 0), self.parentCanvas.dispatchPatchSingle, eventDc, True, wx.MOD_NONE, None, self.currentTool.targetRect, viewRect)
|
||||||
|
else:
|
||||||
|
viewRect = self.parentCanvas.GetViewStart()
|
||||||
|
eventDc = self.parentCanvas.backend.getDeviceContext(self.parentCanvas.GetClientSize(), self.parentCanvas, viewRect)
|
||||||
|
self.parentCanvas.canvas.journal.begin()
|
||||||
|
dirty = False
|
||||||
|
for numRow in range(len(region)):
|
||||||
|
for numCol in range(len(region[numRow])):
|
||||||
|
if not dirty:
|
||||||
|
dirty = True
|
||||||
|
self.parentCanvas.dispatchPatchSingle(eventDc, False, [numCol, numRow, *region[numRow][numCol]], viewRect)
|
||||||
|
self.parentCanvas.canvas.journal.end()
|
||||||
|
self.parentCanvas.commands.update(dirty=dirty, undoLevel=self.parentCanvas.canvas.journal.patchesUndoLevel)
|
||||||
|
setattr(canvasOperator_, "attrDict", f.attrList[idx])
|
||||||
|
return canvasOperator_
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
#
|
||||||
|
# __init__(self)
|
||||||
|
def __init__(self):
|
||||||
|
self.menus = (
|
||||||
|
("&Operators",
|
||||||
|
self.canvasOperator(self.canvasOperator, 0), self.canvasOperator(self.canvasOperator, 1),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
self.toolBars = ()
|
||||||
|
|
||||||
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=0
|
@ -8,24 +8,22 @@ from GuiFrame import GuiSelectDecorator
|
|||||||
from ToolCircle import ToolCircle
|
from ToolCircle import ToolCircle
|
||||||
from ToolFill import ToolFill
|
from ToolFill import ToolFill
|
||||||
from ToolLine import ToolLine
|
from ToolLine import ToolLine
|
||||||
|
from ToolObject import ToolObject
|
||||||
from ToolRect import ToolRect
|
from ToolRect import ToolRect
|
||||||
from ToolSelectClone import ToolSelectClone
|
|
||||||
from ToolSelectMove import ToolSelectMove
|
|
||||||
from ToolText import ToolText
|
from ToolText import ToolText
|
||||||
import wx
|
import wx
|
||||||
|
|
||||||
class RoarCanvasCommandsTools():
|
class RoarCanvasCommandsTools():
|
||||||
# {{{ canvasTool(self, f, idx)
|
# {{{ canvasTool(self, f, idx)
|
||||||
@GuiSelectDecorator(0, "Circle", "&Circle", ["toolCircle.png"], [wx.ACCEL_CTRL, ord("C")], False)
|
@GuiSelectDecorator(0, "Circle", "&Circle", ["toolCircle.png"], [wx.ACCEL_CTRL, ord("C")], False)
|
||||||
@GuiSelectDecorator(1, "Clone", "Cl&one", ["toolClone.png"], [wx.ACCEL_CTRL, ord("E")], False)
|
@GuiSelectDecorator(1, "Fill", "&Fill", ["toolFill.png"], [wx.ACCEL_CTRL, ord("F")], False)
|
||||||
@GuiSelectDecorator(2, "Fill", "&Fill", ["toolFill.png"], [wx.ACCEL_CTRL, ord("F")], False)
|
@GuiSelectDecorator(2, "Line", "&Line", ["toolLine.png"], [wx.ACCEL_CTRL, ord("L")], False)
|
||||||
@GuiSelectDecorator(3, "Line", "&Line", ["toolLine.png"], [wx.ACCEL_CTRL, ord("L")], False)
|
@GuiSelectDecorator(3, "Object", "&Object", ["toolObject.png"], [wx.ACCEL_CTRL, ord("E")], False)
|
||||||
@GuiSelectDecorator(4, "Move", "&Move", ["toolMove.png"], [wx.ACCEL_CTRL, ord("M")], False)
|
@GuiSelectDecorator(4, "Rectangle", "&Rectangle", ["toolRect.png"], [wx.ACCEL_CTRL, ord("R")], True)
|
||||||
@GuiSelectDecorator(5, "Rectangle", "&Rectangle", ["toolRect.png"], [wx.ACCEL_CTRL, ord("R")], True)
|
@GuiSelectDecorator(5, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False)
|
||||||
@GuiSelectDecorator(6, "Text", "&Text", ["toolText.png"], [wx.ACCEL_CTRL, ord("T")], False)
|
|
||||||
def canvasTool(self, f, idx):
|
def canvasTool(self, f, idx):
|
||||||
def canvasTool_(event):
|
def canvasTool_(event):
|
||||||
self.lastTool, self.currentTool = self.currentTool, [ToolCircle, ToolSelectClone, ToolFill, ToolLine, ToolSelectMove, ToolRect, ToolText][idx]()
|
self.lastTool, self.currentTool = self.currentTool, [ToolCircle, ToolFill, ToolLine, ToolObject, ToolRect, ToolText][idx]()
|
||||||
self.parentFrame.menuItemsById[self.canvasTool.attrList[idx]["id"]].Check(True)
|
self.parentFrame.menuItemsById[self.canvasTool.attrList[idx]["id"]].Check(True)
|
||||||
toolBar = self.parentFrame.toolBarItemsById[self.canvasTool.attrList[idx]["id"]].GetToolBar()
|
toolBar = self.parentFrame.toolBarItemsById[self.canvasTool.attrList[idx]["id"]].GetToolBar()
|
||||||
toolBar.ToggleTool(self.canvasTool.attrList[idx]["id"], True)
|
toolBar.ToggleTool(self.canvasTool.attrList[idx]["id"], True)
|
||||||
@ -43,7 +41,7 @@ class RoarCanvasCommandsTools():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.menus = (
|
self.menus = (
|
||||||
("&Tools",
|
("&Tools",
|
||||||
self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 2), self.canvasTool(self.canvasTool, 3), self.canvasTool(self.canvasTool, 6), self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 4),
|
self.canvasTool(self.canvasTool, 4), self.canvasTool(self.canvasTool, 0), self.canvasTool(self.canvasTool, 1), self.canvasTool(self.canvasTool, 2), self.canvasTool(self.canvasTool, 5), self.canvasTool(self.canvasTool, 3),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
self.toolBars = ()
|
self.toolBars = ()
|
||||||
|
@ -19,7 +19,8 @@ class RoarCanvasWindowDropTarget(wx.TextDropTarget):
|
|||||||
rectX, rectY = x - (x % self.parent.backend.cellSize[0]), y - (y % self.parent.backend.cellSize[1])
|
rectX, rectY = x - (x % self.parent.backend.cellSize[0]), y - (y % self.parent.backend.cellSize[1])
|
||||||
mapX, mapY = int(rectX / self.parent.backend.cellSize[0] if rectX else 0), int(rectY / self.parent.backend.cellSize[1] if rectY else 0)
|
mapX, mapY = int(rectX / self.parent.backend.cellSize[0] if rectX else 0), int(rectY / self.parent.backend.cellSize[1] if rectY else 0)
|
||||||
mapPoint = [m + n for m, n in zip((mapX, mapY), viewRect)]
|
mapPoint = [m + n for m, n in zip((mapX, mapY), viewRect)]
|
||||||
self.parent.commands.lastTool, self.parent.commands.currentTool = self.parent.commands.currentTool, ToolObject(self.parent.canvas, mapPoint, dropMap, dropSize)
|
self.parent.commands.lastTool, self.parent.commands.currentTool = self.parent.commands.currentTool, ToolObject()
|
||||||
|
self.parent.commands.currentTool.setRegion(self.parent.canvas, mapPoint, dropMap, dropSize, external=True)
|
||||||
self.parent.commands.update(toolName=self.parent.commands.currentTool.name)
|
self.parent.commands.update(toolName=self.parent.commands.currentTool.name)
|
||||||
eventDc = self.parent.backend.getDeviceContext(self.parent.GetClientSize(), self.parent, viewRect)
|
eventDc = self.parent.backend.getDeviceContext(self.parent.GetClientSize(), self.parent, viewRect)
|
||||||
self.parent.applyTool(eventDc, True, None, None, self.parent.brushPos, False, False, False, self.parent.commands.currentTool, viewRect)
|
self.parent.applyTool(eventDc, True, None, None, self.parent.brushPos, False, False, False, self.parent.commands.currentTool, viewRect)
|
||||||
@ -58,7 +59,7 @@ class RoarCanvasWindow(GuiWindow):
|
|||||||
or (self.lastCellState != [list(mapPoint), mouseDragging, mouseLeftDown, mouseRightDown, list(viewRect)])):
|
or (self.lastCellState != [list(mapPoint), mouseDragging, mouseLeftDown, mouseRightDown, list(viewRect)])):
|
||||||
self.brushPos = list(mapPoint)
|
self.brushPos = list(mapPoint)
|
||||||
self.lastCellState = [list(mapPoint), mouseDragging, mouseLeftDown, mouseRightDown, list(viewRect)]
|
self.lastCellState = [list(mapPoint), mouseDragging, mouseLeftDown, mouseRightDown, list(viewRect)]
|
||||||
rc, dirty = tool.onMouseEvent(self.brushColours, self.brushSize, self.canvas, self.dispatchPatchSingle, eventDc, self.brushPos, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
rc, dirty = tool.onMouseEvent(self.brushColours, self.brushSize, self.canvas, self.dispatchPatchSingle, eventDc, keyModifiers, self.brushPos, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
else:
|
else:
|
||||||
rc, dirty = tool.onKeyboardEvent(self.brushColours, self.brushSize, self.canvas, self.dispatchPatchSingle, eventDc, keyChar, keyModifiers, self.brushPos, viewRect)
|
rc, dirty = tool.onKeyboardEvent(self.brushColours, self.brushSize, self.canvas, self.dispatchPatchSingle, eventDc, keyChar, keyModifiers, self.brushPos, viewRect)
|
||||||
if dirty:
|
if dirty:
|
||||||
@ -67,7 +68,9 @@ class RoarCanvasWindow(GuiWindow):
|
|||||||
else:
|
else:
|
||||||
self.commands.update(cellPos=mapPoint if mapPoint else self.brushPos)
|
self.commands.update(cellPos=mapPoint if mapPoint else self.brushPos)
|
||||||
self.canvas.journal.end()
|
self.canvas.journal.end()
|
||||||
if rc and (tool.__class__ == ToolObject) and (tool.toolState == tool.TS_NONE):
|
if rc and (tool.__class__ == ToolObject) \
|
||||||
|
and (tool.toolState == tool.TS_NONE) \
|
||||||
|
and tool.external:
|
||||||
self.commands.currentTool, self.commands.lastTool = self.commands.lastTool, self.commands.currentTool
|
self.commands.currentTool, self.commands.lastTool = self.commands.lastTool, self.commands.currentTool
|
||||||
self.commands.update(toolName=self.commands.currentTool.name)
|
self.commands.update(toolName=self.commands.currentTool.name)
|
||||||
return rc
|
return rc
|
||||||
@ -138,6 +141,7 @@ class RoarCanvasWindow(GuiWindow):
|
|||||||
# }}}
|
# }}}
|
||||||
# {{{ onLeaveWindow(self, event)
|
# {{{ onLeaveWindow(self, event)
|
||||||
def onLeaveWindow(self, event):
|
def onLeaveWindow(self, event):
|
||||||
|
if False:
|
||||||
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, self.GetViewStart())
|
eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, self.GetViewStart())
|
||||||
self.backend.drawCursorMaskWithJournal(self.canvas.journal, eventDc, self.GetViewStart())
|
self.backend.drawCursorMaskWithJournal(self.canvas.journal, eventDc, self.GetViewStart())
|
||||||
self.lastCellState = None
|
self.lastCellState = None
|
||||||
@ -147,7 +151,7 @@ class RoarCanvasWindow(GuiWindow):
|
|||||||
viewRect = self.GetViewStart(); eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, viewRect);
|
viewRect = self.GetViewStart(); eventDc = self.backend.getDeviceContext(self.GetClientSize(), self, viewRect);
|
||||||
mouseDragging, mouseLeftDown, mouseRightDown = event.Dragging(), event.LeftIsDown(), event.RightIsDown()
|
mouseDragging, mouseLeftDown, mouseRightDown = event.Dragging(), event.LeftIsDown(), event.RightIsDown()
|
||||||
mapPoint = self.backend.xlateEventPoint(event, eventDc, viewRect)
|
mapPoint = self.backend.xlateEventPoint(event, eventDc, viewRect)
|
||||||
if not self.applyTool(eventDc, True, None, None, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, self.commands.currentTool, viewRect):
|
if not self.applyTool(eventDc, True, None, event.GetModifiers(), mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, self.commands.currentTool, viewRect):
|
||||||
event.Skip()
|
event.Skip()
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ onMouseWheel(self, event)
|
# {{{ onMouseWheel(self, event)
|
||||||
|
@ -49,7 +49,7 @@ class RoarClient(GuiFrame):
|
|||||||
self.loadToolBars(self.canvasPanel.commands.toolBars)
|
self.loadToolBars(self.canvasPanel.commands.toolBars)
|
||||||
|
|
||||||
self.canvasPanel.commands.canvasNew(None)
|
self.canvasPanel.commands.canvasNew(None)
|
||||||
self.canvasPanel.commands.canvasTool(self.canvasPanel.commands.canvasTool, 5)(None)
|
self.canvasPanel.commands.canvasTool(self.canvasPanel.commands.canvasTool, 4)(None)
|
||||||
self.canvasPanel.commands.update(brushSize=self.canvasPanel.brushSize, colours=self.canvasPanel.brushColours)
|
self.canvasPanel.commands.update(brushSize=self.canvasPanel.brushSize, colours=self.canvasPanel.brushColours)
|
||||||
self.addWindow(self.canvasPanel, expand=True)
|
self.addWindow(self.canvasPanel, expand=True)
|
||||||
self.assetsWindow = RoarAssetsWindow(GuiCanvasWxBackend, defaultCellSize, self)
|
self.assetsWindow = RoarAssetsWindow(GuiCanvasWxBackend, defaultCellSize, self)
|
||||||
|
@ -10,7 +10,7 @@ class Tool(object):
|
|||||||
return False, False
|
return False, False
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# {{{ onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
return False, False
|
return False, False
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
@ -10,8 +10,8 @@ class ToolCircle(Tool):
|
|||||||
name = "Circle"
|
name = "Circle"
|
||||||
|
|
||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
brushColours, dirty = brushColours.copy(), False
|
brushColours, dirty = brushColours.copy(), False
|
||||||
if mouseLeftDown:
|
if mouseLeftDown:
|
||||||
brushColours[1] = brushColours[0]
|
brushColours[1] = brushColours[0]
|
||||||
|
@ -10,8 +10,8 @@ class ToolFill(Tool):
|
|||||||
name = "Fill"
|
name = "Fill"
|
||||||
|
|
||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
dirty, pointsDone, pointStack, testColour, = False, [], [list(mapPoint)], canvas.map[mapPoint[1]][mapPoint[0]][0:2]
|
dirty, pointsDone, pointStack, testColour, = False, [], [list(mapPoint)], canvas.map[mapPoint[1]][mapPoint[0]][0:2]
|
||||||
if mouseLeftDown or mouseRightDown:
|
if mouseLeftDown or mouseRightDown:
|
||||||
if mouseRightDown:
|
if mouseRightDown:
|
||||||
|
@ -51,8 +51,8 @@ class ToolLine(Tool):
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
brushColours, dirty = brushColours.copy(), False
|
brushColours, dirty = brushColours.copy(), False
|
||||||
if mouseLeftDown:
|
if mouseLeftDown:
|
||||||
brushColours[1] = brushColours[0]
|
brushColours[1] = brushColours[0]
|
||||||
|
@ -5,15 +5,17 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from Tool import Tool
|
from Tool import Tool
|
||||||
|
import wx
|
||||||
|
|
||||||
class ToolObject(Tool):
|
class ToolObject(Tool):
|
||||||
name = "External object"
|
name = "Object"
|
||||||
TS_NONE = 0
|
TS_NONE = 0
|
||||||
TS_SELECT = 1
|
TS_ORIGIN = 1
|
||||||
TS_TARGET = 2
|
TS_SELECT = 2
|
||||||
|
TS_TARGET = 3
|
||||||
|
|
||||||
# {{{ _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect)
|
# {{{ _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect)
|
||||||
def _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect):
|
def _dispatchSelectEvent(self, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect):
|
||||||
if mouseLeftDown:
|
if mouseLeftDown:
|
||||||
disp, isCursor = [mapPoint[m] - self.lastAtPoint[m] for m in [0, 1]], True
|
disp, isCursor = [mapPoint[m] - self.lastAtPoint[m] for m in [0, 1]], True
|
||||||
newTargetRect = [[selectRect[n][m] + disp[m] for m in [0, 1]] for n in [0, 1]]
|
newTargetRect = [[selectRect[n][m] + disp[m] for m in [0, 1]] for n in [0, 1]]
|
||||||
@ -22,7 +24,7 @@ class ToolObject(Tool):
|
|||||||
disp, isCursor, newTargetRect = [0, 0], False, selectRect.copy()
|
disp, isCursor, newTargetRect = [0, 0], False, selectRect.copy()
|
||||||
else:
|
else:
|
||||||
disp, isCursor, newTargetRect = [0, 0], True, selectRect.copy()
|
disp, isCursor, newTargetRect = [0, 0], True, selectRect.copy()
|
||||||
dirty = self.onSelectEvent(canvas, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect)
|
dirty = self.onSelectEvent(canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect, viewRect)
|
||||||
self._drawSelectRect(newTargetRect, dispatchFn, eventDc, viewRect)
|
self._drawSelectRect(newTargetRect, dispatchFn, eventDc, viewRect)
|
||||||
self.targetRect = newTargetRect
|
self.targetRect = newTargetRect
|
||||||
return dirty
|
return dirty
|
||||||
@ -44,13 +46,42 @@ class ToolObject(Tool):
|
|||||||
dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "], viewRect)
|
dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "], viewRect)
|
||||||
dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "], viewRect)
|
dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "], viewRect)
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# {{{ _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
|
self.substract = False
|
||||||
|
if self.external:
|
||||||
|
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect)
|
||||||
|
else:
|
||||||
|
if mouseLeftDown:
|
||||||
|
self.targetRect, self.toolState = [list(mapPoint), []], self.TS_ORIGIN
|
||||||
|
else:
|
||||||
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect)
|
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect)
|
||||||
return False
|
return False
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# {{{ _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
|
if mouseLeftDown:
|
||||||
|
self.targetRect[1] = list(mapPoint)
|
||||||
|
if self.targetRect[0][0] > self.targetRect[1][0]:
|
||||||
|
self.targetRect[0][0], self.targetRect[1][0] = self.targetRect[1][0], self.targetRect[0][0]
|
||||||
|
if self.targetRect[0][1] > self.targetRect[1][1]:
|
||||||
|
self.targetRect[0][1], self.targetRect[1][1] = self.targetRect[1][1], self.targetRect[0][1]
|
||||||
|
self.lastAtPoint, self.srcRect, self.objectMap, self.toolState = list(mapPoint), self.targetRect, [], self.TS_SELECT
|
||||||
|
for numRow in range((self.targetRect[1][1] - self.targetRect[0][1]) + 1):
|
||||||
|
self.objectMap.append([])
|
||||||
|
for numCol in range((self.targetRect[1][0] - self.targetRect[0][0]) + 1):
|
||||||
|
rectX, rectY = self.targetRect[0][0] + numCol, self.targetRect[0][1] + numRow
|
||||||
|
self.objectMap[numRow].append(canvas.map[rectY][rectX])
|
||||||
|
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
|
||||||
|
elif mouseRightDown:
|
||||||
|
self.targetRect, self.toolState = None, self.TS_NONE
|
||||||
|
else:
|
||||||
|
self.targetRect[1] = list(mapPoint)
|
||||||
|
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
|
||||||
|
return False
|
||||||
|
# }}}
|
||||||
|
# {{{ _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
|
def _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
dirty = False
|
dirty = False
|
||||||
if mouseLeftDown \
|
if mouseLeftDown \
|
||||||
and (mapPoint[0] >= (self.targetRect[0][0] - 1)) \
|
and (mapPoint[0] >= (self.targetRect[0][0] - 1)) \
|
||||||
@ -59,43 +90,52 @@ class ToolObject(Tool):
|
|||||||
and (mapPoint[1] <= (self.targetRect[1][1] + 1)):
|
and (mapPoint[1] <= (self.targetRect[1][1] + 1)):
|
||||||
self.lastAtPoint, self.toolState = list(mapPoint), self.TS_TARGET
|
self.lastAtPoint, self.toolState = list(mapPoint), self.TS_TARGET
|
||||||
elif mouseRightDown:
|
elif mouseRightDown:
|
||||||
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
||||||
self.targetRect, self.toolState = None, self.TS_NONE
|
self.targetRect, self.toolState = None, self.TS_NONE
|
||||||
else:
|
else:
|
||||||
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
||||||
return dirty
|
return dirty
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# {{{ _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
|
if not self.substract \
|
||||||
|
and (keyModifiers == wx.MOD_CONTROL) \
|
||||||
|
and (self.srcRect == self.targetRect):
|
||||||
|
self.substract = True
|
||||||
dirty = False
|
dirty = False
|
||||||
if mouseLeftDown:
|
if mouseLeftDown:
|
||||||
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
||||||
elif mouseRightDown:
|
elif mouseRightDown:
|
||||||
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
dirty = self._dispatchSelectEvent(canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
||||||
self.targetRect, self.toolState = None, self.TS_NONE
|
self.targetRect, self.toolState = None, self.TS_NONE
|
||||||
else:
|
else:
|
||||||
self.toolState = self.TS_SELECT
|
self.toolState = self.TS_SELECT
|
||||||
return True, dirty
|
return True, dirty
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
#
|
# {{{ getRegion(self, canvas)
|
||||||
# onMouseEvent(self, brushColours, brushSize, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
def getRegion(self, canvas):
|
||||||
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
return self.objectMap
|
||||||
|
# }}}
|
||||||
|
# {{{ onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
|
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
dirty = False
|
dirty = False
|
||||||
if self.toolState == self.TS_NONE:
|
if self.toolState == self.TS_NONE:
|
||||||
dirty = self._mouseEventTsNone(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
dirty = self._mouseEventTsNone(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
elif self.toolState == self.TS_SELECT:
|
elif self.toolState == self.TS_SELECT:
|
||||||
dirty = self._mouseEventTsSelect(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
dirty = self._mouseEventTsSelect(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
|
elif self.toolState == self.TS_ORIGIN:
|
||||||
|
dirty = self._mouseEventTsOrigin(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
elif self.toolState == self.TS_TARGET:
|
elif self.toolState == self.TS_TARGET:
|
||||||
dirty = self._mouseEventTsTarget(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
dirty = self._mouseEventTsTarget(brushColours, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
else:
|
else:
|
||||||
return False, dirty
|
return False, dirty
|
||||||
return True, dirty
|
return True, dirty
|
||||||
|
# }}}
|
||||||
#
|
# {{{ onSelectEvent(self, canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect, viewRect)
|
||||||
# onSelectEvent(self, canvas, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect)
|
def onSelectEvent(self, canvas, disp, dispatchFn, eventDc, isCursor, keyModifiers, newTargetRect, selectRect, viewRect):
|
||||||
def onSelectEvent(self, canvas, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect):
|
|
||||||
dirty = False
|
dirty = False
|
||||||
|
if self.external:
|
||||||
for numRow in range(len(self.objectMap)):
|
for numRow in range(len(self.objectMap)):
|
||||||
for numCol in range(len(self.objectMap[numRow])):
|
for numCol in range(len(self.objectMap[numRow])):
|
||||||
rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow
|
rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow
|
||||||
@ -105,22 +145,43 @@ class ToolObject(Tool):
|
|||||||
if ((rectY + disp[1]) < canvas.size[1]) and ((rectX + disp[0]) < canvas.size[0]):
|
if ((rectY + disp[1]) < canvas.size[1]) and ((rectX + disp[0]) < canvas.size[0]):
|
||||||
cellNew = canvas.map[rectY + disp[1]][rectX + disp[0]]
|
cellNew = canvas.map[rectY + disp[1]][rectX + disp[0]]
|
||||||
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellNew], viewRect)
|
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellNew], viewRect)
|
||||||
return dirty
|
|
||||||
|
|
||||||
# __init__(self, canvas, mapPoint, objectMap, objectSize): initialisation method
|
|
||||||
def __init__(self, canvas, mapPoint, objectMap, objectSize):
|
|
||||||
super().__init__()
|
|
||||||
self.lastAtPoint, self.srcRect = list(mapPoint), list(mapPoint)
|
|
||||||
self.objectMap, self.objectSize = objectMap, objectSize
|
|
||||||
self.targetRect = [list(mapPoint), [(a + b) - (0 if a == b else 1) for a, b in zip(mapPoint, objectSize)]]
|
|
||||||
self.toolSelectMap, self.toolState = [], self.TS_SELECT
|
|
||||||
for numRow in range((self.targetRect[1][1] - self.targetRect[0][1]) + 1):
|
|
||||||
self.toolSelectMap.append([])
|
|
||||||
for numCol in range((self.targetRect[1][0] - self.targetRect[0][0]) + 1):
|
|
||||||
rectX, rectY = self.targetRect[0][0] + numCol, self.targetRect[0][1] + numRow
|
|
||||||
if (rectX < canvas.size[0]) and (rectY < canvas.size[1]):
|
|
||||||
self.toolSelectMap[numRow].append(canvas.map[rectY][rectX])
|
|
||||||
else:
|
else:
|
||||||
self.toolSelectMap[numRow].append([1, 1, 0, " "])
|
if self.substract:
|
||||||
|
for numRow in range(self.srcRect[0][1], self.srcRect[1][1]):
|
||||||
|
for numCol in range(self.srcRect[0][0], self.srcRect[1][0]):
|
||||||
|
if ((numCol < selectRect[0][0]) or (numCol > selectRect[1][0])) \
|
||||||
|
or ((numRow < selectRect[0][1]) or (numRow > selectRect[1][1])):
|
||||||
|
dirty = False if isCursor else True
|
||||||
|
dispatchFn(eventDc, isCursor, [numCol, numRow, 1, 1, 0, " "], viewRect)
|
||||||
|
for numRow in range(len(self.objectMap)):
|
||||||
|
for numCol in range(len(self.objectMap[numRow])):
|
||||||
|
cellOld = self.objectMap[numRow][numCol]
|
||||||
|
rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow
|
||||||
|
dirty = False if isCursor else True
|
||||||
|
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect)
|
||||||
|
return dirty
|
||||||
|
# }}}
|
||||||
|
# {{{ setRegion(self, canvas, mapPoint, objectMap, objectSize, external=True)
|
||||||
|
def setRegion(self, canvas, mapPoint, objectMap, objectSize, external=True):
|
||||||
|
self.external, self.toolState = external, self.TS_SELECT
|
||||||
|
if mapPoint != None:
|
||||||
|
self.lastAtPoint = list(mapPoint)
|
||||||
|
if self.targetRect == None:
|
||||||
|
self.targetRect = [list(self.lastAtPoint), [(a + b) - (0 if a == b else 1) for a, b in zip(self.lastAtPoint, objectSize)]]
|
||||||
|
elif self.objectSize != objectSize:
|
||||||
|
if self.objectSize == None:
|
||||||
|
self.objectSize = objectSize
|
||||||
|
self.targetRect[1] = [t + d for t, d in zip(self.targetRect[1], (a - b for a, b in zip(self.objectSize, objectSize)))]
|
||||||
|
if self.srcRect == None:
|
||||||
|
self.srcRect = self.targetRect
|
||||||
|
self.objectMap, self.objectSize = objectMap, objectSize
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
# __init__(self, *args): initialisation method
|
||||||
|
def __init__(self, *args):
|
||||||
|
super().__init__(*args)
|
||||||
|
self.external, self.lastAtPoint, self.srcRect, self.substract, \
|
||||||
|
self.targetRect, self.objectMap, self.objectSize, self.toolState = \
|
||||||
|
False, None, None, False, None, [], None, self.TS_NONE
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
||||||
|
@ -10,8 +10,8 @@ class ToolRect(Tool):
|
|||||||
name = "Rectangle"
|
name = "Rectangle"
|
||||||
|
|
||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
brushColours, dirty = brushColours.copy(), False
|
brushColours, dirty = brushColours.copy(), False
|
||||||
if mouseLeftDown:
|
if mouseLeftDown:
|
||||||
brushColours[1] = brushColours[0]
|
brushColours[1] = brushColours[0]
|
||||||
|
@ -1,135 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
#
|
|
||||||
# ToolSelect.py
|
|
||||||
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
|
||||||
#
|
|
||||||
|
|
||||||
from Tool import Tool
|
|
||||||
|
|
||||||
class ToolSelect(Tool):
|
|
||||||
TS_NONE = 0
|
|
||||||
TS_ORIGIN = 1
|
|
||||||
TS_SELECT = 2
|
|
||||||
TS_TARGET = 3
|
|
||||||
|
|
||||||
# {{{ _dispatchSelectEvent(self, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect)
|
|
||||||
def _dispatchSelectEvent(self, dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, selectRect, viewRect):
|
|
||||||
if mouseLeftDown:
|
|
||||||
disp, isCursor = [mapPoint[m] - self.lastAtPoint[m] for m in [0, 1]], True
|
|
||||||
newTargetRect = [[selectRect[n][m] + disp[m] for m in [0, 1]] for n in [0, 1]]
|
|
||||||
self.lastAtPoint = list(mapPoint)
|
|
||||||
elif mouseRightDown:
|
|
||||||
disp, isCursor, newTargetRect = [0, 0], False, selectRect.copy()
|
|
||||||
else:
|
|
||||||
disp, isCursor, newTargetRect = [0, 0], True, selectRect.copy()
|
|
||||||
dirty = self.onSelectEvent(disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect)
|
|
||||||
self._drawSelectRect(newTargetRect, dispatchFn, eventDc, viewRect)
|
|
||||||
self.targetRect = newTargetRect
|
|
||||||
return dirty
|
|
||||||
# }}}
|
|
||||||
# {{{ _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect)
|
|
||||||
def _drawSelectRect(self, rect, dispatchFn, eventDc, viewRect):
|
|
||||||
rectFrame = [[rect[m[0]][n] + m[1] for n in [0, 1]] for m in [[0, -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):
|
|
||||||
curColours = [1, 1] if curColours == [0, 0] else [0, 0]
|
|
||||||
dispatchFn(eventDc, True, [rectX, rectFrame[0][1], *curColours, 0, " "], viewRect)
|
|
||||||
dispatchFn(eventDc, True, [rectX, rectFrame[1][1], *curColours, 0, " "], viewRect)
|
|
||||||
for rectY in range(rectFrame[0][1], rectFrame[1][1] + 1):
|
|
||||||
curColours = [1, 1] if curColours == [0, 0] else [0, 0]
|
|
||||||
dispatchFn(eventDc, True, [rectFrame[0][0], rectY, *curColours, 0, " "], viewRect)
|
|
||||||
dispatchFn(eventDc, True, [rectFrame[1][0], rectY, *curColours, 0, " "], viewRect)
|
|
||||||
# }}}
|
|
||||||
# {{{ _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
|
||||||
def _mouseEventTsNone(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
|
||||||
if mouseLeftDown:
|
|
||||||
self.targetRect, self.toolState = [list(mapPoint), []], self.TS_ORIGIN
|
|
||||||
else:
|
|
||||||
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, " "], viewRect)
|
|
||||||
return False
|
|
||||||
# }}}
|
|
||||||
# {{{ _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
|
||||||
def _mouseEventTsOrigin(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
|
||||||
if mouseLeftDown:
|
|
||||||
self.targetRect[1] = list(mapPoint)
|
|
||||||
if self.targetRect[0][0] > self.targetRect[1][0]:
|
|
||||||
self.targetRect[0][0], self.targetRect[1][0] = self.targetRect[1][0], self.targetRect[0][0]
|
|
||||||
if self.targetRect[0][1] > self.targetRect[1][1]:
|
|
||||||
self.targetRect[0][1], self.targetRect[1][1] = self.targetRect[1][1], self.targetRect[0][1]
|
|
||||||
self.lastAtPoint, self.srcRect, self.toolSelectMap, self.toolState = list(mapPoint), self.targetRect, [], self.TS_SELECT
|
|
||||||
for numRow in range((self.targetRect[1][1] - self.targetRect[0][1]) + 1):
|
|
||||||
self.toolSelectMap.append([])
|
|
||||||
for numCol in range((self.targetRect[1][0] - self.targetRect[0][0]) + 1):
|
|
||||||
rectX, rectY = self.targetRect[0][0] + numCol, self.targetRect[0][1] + numRow
|
|
||||||
self.toolSelectMap[numRow].append(canvas.map[rectY][rectX])
|
|
||||||
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
|
|
||||||
elif mouseRightDown:
|
|
||||||
self.targetRect, self.toolState = None, self.TS_NONE
|
|
||||||
else:
|
|
||||||
self.targetRect[1] = list(mapPoint)
|
|
||||||
self._drawSelectRect(self.targetRect, dispatchFn, eventDc, viewRect)
|
|
||||||
return False
|
|
||||||
# }}}
|
|
||||||
# {{{ _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
|
||||||
def _mouseEventTsSelect(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
|
||||||
dirty = False
|
|
||||||
if mouseLeftDown \
|
|
||||||
and (mapPoint[0] >= (self.targetRect[0][0] - 1)) \
|
|
||||||
and (mapPoint[0] <= (self.targetRect[1][0] + 1)) \
|
|
||||||
and (mapPoint[1] >= (self.targetRect[0][1] - 1)) \
|
|
||||||
and (mapPoint[1] <= (self.targetRect[1][1] + 1)):
|
|
||||||
self.lastAtPoint, self.toolState = list(mapPoint), self.TS_TARGET
|
|
||||||
elif mouseRightDown:
|
|
||||||
dirty = self._dispatchSelectEvent(dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
|
||||||
self.targetRect, self.toolState = None, self.TS_NONE
|
|
||||||
else:
|
|
||||||
dirty = self._dispatchSelectEvent(dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
|
||||||
return dirty
|
|
||||||
# }}}
|
|
||||||
# {{{ _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
|
||||||
def _mouseEventTsTarget(self, brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
|
||||||
dirty = False
|
|
||||||
if mouseLeftDown:
|
|
||||||
self.toolState = self.TS_TARGET
|
|
||||||
dirty = self._dispatchSelectEvent(dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
|
||||||
elif mouseRightDown:
|
|
||||||
dirty = self._dispatchSelectEvent(dispatchFn, eventDc, mapPoint, mouseLeftDown, mouseRightDown, self.targetRect, viewRect)
|
|
||||||
self.targetRect, self.toolState = None, self.TS_NONE
|
|
||||||
else:
|
|
||||||
self.toolState = self.TS_SELECT
|
|
||||||
return dirty
|
|
||||||
# }}}
|
|
||||||
|
|
||||||
#
|
|
||||||
# onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
|
||||||
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
|
||||||
dirty = False
|
|
||||||
if self.toolState == self.TS_NONE:
|
|
||||||
dirty = self._mouseEventTsNone(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
|
||||||
elif self.toolState == self.TS_ORIGIN:
|
|
||||||
dirty = self._mouseEventTsOrigin(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
|
||||||
elif self.toolState == self.TS_SELECT:
|
|
||||||
dirty = self._mouseEventTsSelect(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
|
||||||
elif self.toolState == self.TS_TARGET:
|
|
||||||
dirty = self._mouseEventTsTarget(brushColours, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
|
||||||
else:
|
|
||||||
return False, dirty
|
|
||||||
return True, dirty
|
|
||||||
|
|
||||||
#
|
|
||||||
# onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect)
|
|
||||||
def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newTargetRect, selectRect, viewRect):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# __init__(self, *args): initialisation method
|
|
||||||
def __init__(self, *args):
|
|
||||||
super().__init__(*args)
|
|
||||||
self.lastAtPoint, self.srcRect, self.targetRect, \
|
|
||||||
self.toolSelectMap, self.toolState = \
|
|
||||||
None, None, None, None, self.TS_NONE
|
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
|
@ -1,24 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
#
|
|
||||||
# ToolSelectClone.py
|
|
||||||
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
|
||||||
#
|
|
||||||
|
|
||||||
from ToolSelect import ToolSelect
|
|
||||||
|
|
||||||
class ToolSelectClone(ToolSelect):
|
|
||||||
name = "Clone selection"
|
|
||||||
|
|
||||||
#
|
|
||||||
# onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect)
|
|
||||||
def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect):
|
|
||||||
dirty = False
|
|
||||||
for numRow in range(len(self.toolSelectMap)):
|
|
||||||
for numCol in range(len(self.toolSelectMap[numRow])):
|
|
||||||
cellOld = self.toolSelectMap[numRow][numCol]
|
|
||||||
rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow
|
|
||||||
dirty = False if isCursor else True
|
|
||||||
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect)
|
|
||||||
return dirty
|
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
|
@ -1,30 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
#
|
|
||||||
# ToolSelectMove.py
|
|
||||||
# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de>
|
|
||||||
#
|
|
||||||
|
|
||||||
from ToolSelect import ToolSelect
|
|
||||||
|
|
||||||
class ToolSelectMove(ToolSelect):
|
|
||||||
name = "Move selection"
|
|
||||||
|
|
||||||
#
|
|
||||||
# onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect)
|
|
||||||
def onSelectEvent(self, disp, dispatchFn, eventDc, isCursor, newToolRect, selectRect, viewRect):
|
|
||||||
dirty = False
|
|
||||||
for numRow in range(self.srcRect[0][1], self.srcRect[1][1]):
|
|
||||||
for numCol in range(self.srcRect[0][0], self.srcRect[1][0]):
|
|
||||||
if ((numCol < selectRect[0][0]) or (numCol > selectRect[1][0])) \
|
|
||||||
or ((numRow < selectRect[0][1]) or (numRow > selectRect[1][1])):
|
|
||||||
dirty = False if isCursor else True
|
|
||||||
dispatchFn(eventDc, isCursor, [numCol, numRow, 1, 1, 0, " "], viewRect)
|
|
||||||
for numRow in range(len(self.toolSelectMap)):
|
|
||||||
for numCol in range(len(self.toolSelectMap[numRow])):
|
|
||||||
cellOld = self.toolSelectMap[numRow][numCol]
|
|
||||||
rectX, rectY = selectRect[0][0] + numCol, selectRect[0][1] + numRow
|
|
||||||
dirty = False if isCursor else True
|
|
||||||
dispatchFn(eventDc, isCursor, [rectX + disp[0], rectY + disp[1], *cellOld], viewRect)
|
|
||||||
return dirty
|
|
||||||
|
|
||||||
# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120
|
|
@ -32,8 +32,8 @@ class ToolText(Tool):
|
|||||||
return rc, dirty
|
return rc, dirty
|
||||||
|
|
||||||
#
|
#
|
||||||
# onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
# onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect)
|
||||||
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
def onMouseEvent(self, brushColours, brushSize, canvas, dispatchFn, eventDc, keyModifiers, mapPoint, mouseDragging, mouseLeftDown, mouseRightDown, viewRect):
|
||||||
if mouseLeftDown or mouseRightDown:
|
if mouseLeftDown or mouseRightDown:
|
||||||
self.textPos = list(mapPoint)
|
self.textPos = list(mapPoint)
|
||||||
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, "_"], viewRect)
|
dispatchFn(eventDc, True, [*mapPoint, *brushColours, 0, "_"], viewRect)
|
||||||
|
2
roar.py
2
roar.py
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
[sys.path.append(os.path.join(os.getcwd(), path)) for path in \
|
[sys.path.append(os.path.join(os.getcwd(), path)) for path in \
|
||||||
["libcanvas", "libgui", "libroar", "librtl", "libtools"]]
|
["libcanvas", "libgui", "libroar", "librtl", "liboperators", "libtools"]]
|
||||||
|
|
||||||
from RoarClient import RoarClient
|
from RoarClient import RoarClient
|
||||||
from RtlPlatform import getLocalConfPathName
|
from RtlPlatform import getLocalConfPathName
|
||||||
|
Loading…
Reference in New Issue
Block a user