diff --git a/assets/text/TODO b/assets/text/TODO index b8d85f3..ce7ba75 100644 --- a/assets/text/TODO +++ b/assets/text/TODO @@ -11,7 +11,7 @@ High-priority list: 1) unit tools: arrow, {cloud,speech bubble}, curve, measure, pick, polygon, triangle, unicode 2) text tool: a) honour RTL text flow b) navigating w/ cursor keys c) pasting text -3) operators: erase, invert, rotate, scale, shift, slice, tile +3) operators: erase, rotate, scale, shift, slice, tile 4) GUI: a) switch to GTK b) replace logo w/ canvas panel in About dialogue diff --git a/liboperators/OperatorInvert.py b/liboperators/OperatorInvert.py new file mode 100644 index 0000000..009e7d1 --- /dev/null +++ b/liboperators/OperatorInvert.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +# +# OperatorInvert.py +# Copyright (c) 2018, 2019 Lucio Andrés Illanes Albornoz +# + +from Operator import Operator + +class OperatorInvert(Operator): + name = "Invert colours" + + # + # apply(self, region) + def apply(self, region): + for numRow in range(len(region)): + for numCol in range(len(region[numRow])): + region[numRow][numCol][0:2] = [(~r & (16 - 1) if r > 0 else r) for r in region[numRow][numCol][0:2]] + return region + + # __init__(self, *args): initialisation method + def __init__(self, *args): + pass + +# vim:expandtab foldmethod=marker sw=4 ts=4 tw=120 diff --git a/libroar/RoarCanvasCommandsOperators.py b/libroar/RoarCanvasCommandsOperators.py index 9618279..55124a7 100644 --- a/libroar/RoarCanvasCommandsOperators.py +++ b/libroar/RoarCanvasCommandsOperators.py @@ -6,6 +6,7 @@ from OperatorFlipHorizontal import OperatorFlipHorizontal from OperatorFlipVertical import OperatorFlipVertical +from OperatorInvert import OperatorInvert from GuiFrame import GuiCommandListDecorator from ToolObject import ToolObject import copy, wx @@ -14,9 +15,10 @@ class RoarCanvasCommandsOperators(): # {{{ canvasOperator(self, f, idx) @GuiCommandListDecorator(0, "Flip", "&Flip", None, None, None) @GuiCommandListDecorator(1, "Flip horizontally", "Flip &horizontally", None, None, None) + @GuiCommandListDecorator(2, "Invert", "&Invert", None, None, None) def canvasOperator(self, f, idx): def canvasOperator_(event): - applyOperator = [OperatorFlipVertical, OperatorFlipHorizontal][idx]() + applyOperator = [OperatorFlipVertical, OperatorFlipHorizontal, OperatorInvert][idx]() if (self.currentTool.__class__ == ToolObject) \ and (self.currentTool.toolState >= self.currentTool.TS_SELECT): region = self.currentTool.getRegion(self.parentCanvas.canvas) @@ -56,7 +58,7 @@ class RoarCanvasCommandsOperators(): def __init__(self): self.menus = ( ("&Operators", - self.canvasOperator(self.canvasOperator, 0), self.canvasOperator(self.canvasOperator, 1), + self.canvasOperator(self.canvasOperator, 0), self.canvasOperator(self.canvasOperator, 1), self.canvasOperator(self.canvasOperator, 2), ), ) self.toolBars = ()