diff --git a/src/js/tools/transform/Transform.js b/src/js/tools/transform/AbstractTransformTool.js similarity index 70% rename from src/js/tools/transform/Transform.js rename to src/js/tools/transform/AbstractTransformTool.js index 3d7bdb95..7dac651a 100644 --- a/src/js/tools/transform/Transform.js +++ b/src/js/tools/transform/AbstractTransformTool.js @@ -1,21 +1,17 @@ (function () { var ns = $.namespace('pskl.tools.transform'); - ns.Transform = function () { - this.toolId = 'tool-transform'; - this.helpText = 'Transform tool'; - this.tooltipDescriptors = []; - }; + ns.AbstractTransformTool = function () {}; - pskl.utils.inherit(ns.Transform, pskl.tools.Tool); + pskl.utils.inherit(ns.AbstractTransformTool, pskl.tools.Tool); - ns.Transform.prototype.apply = function (evt) { + ns.AbstractTransformTool.prototype.apply = function (evt) { var allFrames = evt.shiftKey; var allLayers = evt.ctrlKey; this.applyTool_(evt.altKey, allFrames, allLayers); }; - ns.Transform.prototype.applyTool_ = function (altKey, allFrames, allLayers) { + ns.AbstractTransformTool.prototype.applyTool_ = function (altKey, allFrames, allLayers) { var currentFrameIndex = pskl.app.piskelController.getCurrentFrameIndex(); var layers = allLayers ? pskl.app.piskelController.getLayers() : [pskl.app.piskelController.getCurrentLayer()]; layers.forEach(function (layer) { diff --git a/src/js/tools/transform/Clone.js b/src/js/tools/transform/Clone.js index 5f2ddfad..9a6698e9 100644 --- a/src/js/tools/transform/Clone.js +++ b/src/js/tools/transform/Clone.js @@ -7,7 +7,7 @@ this.tooltipDescriptors = []; }; - pskl.utils.inherit(ns.Clone, ns.Transform); + pskl.utils.inherit(ns.Clone, ns.AbstractTransformTool); ns.Clone.prototype.apply = function (evt) { var ref = pskl.app.piskelController.getCurrentFrame(); diff --git a/src/js/tools/transform/Flip.js b/src/js/tools/transform/Flip.js index 71a054c9..b7e7e236 100644 --- a/src/js/tools/transform/Flip.js +++ b/src/js/tools/transform/Flip.js @@ -11,18 +11,18 @@ ]; }; - pskl.utils.inherit(ns.Flip, ns.Transform); + pskl.utils.inherit(ns.Flip, ns.AbstractTransformTool); ns.Flip.prototype.applyToolOnFrame_ = function (frame, altKey) { var axis; if (altKey) { - axis = pskl.utils.FrameTransform.HORIZONTAL; + axis = ns.TransformUtils.HORIZONTAL; } else { - axis = pskl.utils.FrameTransform.VERTICAL; + axis = ns.TransformUtils.VERTICAL; } - pskl.utils.FrameTransform.flip(frame, axis); + ns.TransformUtils.flip(frame, axis); }; })(); diff --git a/src/js/tools/transform/Rotate.js b/src/js/tools/transform/Rotate.js index 71144a31..b9287889 100644 --- a/src/js/tools/transform/Rotate.js +++ b/src/js/tools/transform/Rotate.js @@ -10,18 +10,18 @@ {key : 'shift', description : 'Apply to all frames'}]; }; - pskl.utils.inherit(ns.Rotate, ns.Transform); + pskl.utils.inherit(ns.Rotate, ns.AbstractTransformTool); ns.Rotate.prototype.applyToolOnFrame_ = function (frame, altKey) { var direction; if (altKey) { - direction = pskl.utils.FrameTransform.CLOCKWISE; + direction = ns.TransformUtils.CLOCKWISE; } else { - direction = pskl.utils.FrameTransform.COUNTERCLOCKWISE; + direction = ns.TransformUtils.COUNTERCLOCKWISE; } - pskl.utils.FrameTransform.rotate(frame, direction); + ns.TransformUtils.rotate(frame, direction); }; })(); diff --git a/src/js/utils/FrameTransform.js b/src/js/tools/transform/TransformUtils.js similarity index 81% rename from src/js/utils/FrameTransform.js rename to src/js/tools/transform/TransformUtils.js index eb2b46ca..03657f3e 100644 --- a/src/js/utils/FrameTransform.js +++ b/src/js/tools/transform/TransformUtils.js @@ -1,8 +1,8 @@ (function () { - var ns = $.namespace('pskl.utils'); + var ns = $.namespace('pskl.tools.transform'); - ns.FrameTransform = { - VERTICAL : 'vertical', + ns.TransformUtils = { + VERTICAL : 'VERTICAL', HORIZONTAL : 'HORIZONTAL', flip : function (frame, axis) { var clone = frame.clone(); @@ -10,9 +10,9 @@ var h = frame.getHeight(); clone.forEachPixel(function (color, x, y) { - if (axis === ns.FrameTransform.VERTICAL) { + if (axis === ns.TransformUtils.VERTICAL) { x = w - x - 1; - } else if (axis === ns.FrameTransform.HORIZONTAL) { + } else if (axis === ns.TransformUtils.HORIZONTAL) { y = h - y - 1; } frame.pixels[x][y] = color; @@ -43,10 +43,10 @@ // Perform the rotation var tmpX = x; var tmpY = y; - if (direction === ns.FrameTransform.CLOCKWISE) { + if (direction === ns.TransformUtils.CLOCKWISE) { x = tmpY; y = max - 1 - tmpX; - } else if (direction === ns.FrameTransform.COUNTERCLOCKWISE) { + } else if (direction === ns.TransformUtils.COUNTERCLOCKWISE) { y = tmpX; x = max - 1 - tmpY; } diff --git a/src/piskel-script-list.js b/src/piskel-script-list.js index 627c623f..bf118e73 100644 --- a/src/piskel-script-list.js +++ b/src/piskel-script-list.js @@ -27,7 +27,6 @@ "js/utils/Math.js", "js/utils/FileUtils.js", "js/utils/FileUtilsDesktop.js", - "js/utils/FrameTransform.js", "js/utils/FrameUtils.js", "js/utils/LayerUtils.js", "js/utils/ImageResizer.js", @@ -185,10 +184,11 @@ "js/tools/drawing/ColorPicker.js", "js/tools/drawing/ColorSwap.js", "js/tools/drawing/DitheringTool.js", - "js/tools/transform/Transform.js", + "js/tools/transform/AbstractTransformTool.js", "js/tools/transform/Clone.js", "js/tools/transform/Flip.js", "js/tools/transform/Rotate.js", + "js/tools/transform/TransformUtils.js", // Devtools "js/devtools/DrawingTestPlayer.js", diff --git a/test/js/utils/FrameTransformTest.js b/test/js/tools/transform/TransformUtilsTest.js similarity index 68% rename from test/js/utils/FrameTransformTest.js rename to test/js/tools/transform/TransformUtilsTest.js index 0a8455a6..0756548c 100644 --- a/test/js/utils/FrameTransformTest.js +++ b/test/js/tools/transform/TransformUtilsTest.js @@ -1,13 +1,13 @@ -describe("FrameTransform suite", function() { +describe("TransformUtils suite", function() { var A = '#000000'; var B = '#ff0000'; var O = Constants.TRANSPARENT_COLOR; - var HORIZONTAL = pskl.utils.FrameTransform.HORIZONTAL; - var VERTICAL = pskl.utils.FrameTransform.VERTICAL; + var HORIZONTAL = pskl.tools.transform.TransformUtils.HORIZONTAL; + var VERTICAL = pskl.tools.transform.TransformUtils.VERTICAL; - var CLOCKWISE = pskl.utils.FrameTransform.CLOCKWISE; - var COUNTERCLOCKWISE = pskl.utils.FrameTransform.COUNTERCLOCKWISE; + var CLOCKWISE = pskl.tools.transform.TransformUtils.CLOCKWISE; + var COUNTERCLOCKWISE = pskl.tools.transform.TransformUtils.COUNTERCLOCKWISE; // shortcuts var frameEqualsGrid = test.testutils.frameEqualsGrid; @@ -25,7 +25,7 @@ describe("FrameTransform suite", function() { ])); // should have flipped - pskl.utils.FrameTransform.flip(frame, VERTICAL); + pskl.tools.transform.TransformUtils.flip(frame, VERTICAL); frameEqualsGrid(frame, [ [O, A], [B, O] @@ -40,7 +40,7 @@ describe("FrameTransform suite", function() { ])); // should have flipped - pskl.utils.FrameTransform.flip(frame, HORIZONTAL); + pskl.tools.transform.TransformUtils.flip(frame, HORIZONTAL); frameEqualsGrid(frame, [ [O, B], [A, O] @@ -56,7 +56,7 @@ describe("FrameTransform suite", function() { ])); // should have flipped - pskl.utils.FrameTransform.flip(frame, VERTICAL); + pskl.tools.transform.TransformUtils.flip(frame, VERTICAL); frameEqualsGrid(frame, [ [O, A], [O, A], @@ -64,7 +64,7 @@ describe("FrameTransform suite", function() { ]); // should be the same - pskl.utils.FrameTransform.flip(frame, HORIZONTAL); + pskl.tools.transform.TransformUtils.flip(frame, HORIZONTAL); frameEqualsGrid(frame, [ [O, A], [O, A], @@ -84,28 +84,28 @@ describe("FrameTransform suite", function() { ])); // rotate once - pskl.utils.FrameTransform.rotate(frame, COUNTERCLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, COUNTERCLOCKWISE); frameEqualsGrid(frame, [ [O, B], [A, O] ]); // rotate twice - pskl.utils.FrameTransform.rotate(frame, COUNTERCLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, COUNTERCLOCKWISE); frameEqualsGrid(frame, [ [B, O], [O, A] ]); // rotate 3 - pskl.utils.FrameTransform.rotate(frame, COUNTERCLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, COUNTERCLOCKWISE); frameEqualsGrid(frame, [ [O, A], [B, O] ]); // rotate 4 - back to initial state - pskl.utils.FrameTransform.rotate(frame, COUNTERCLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, COUNTERCLOCKWISE); frameEqualsGrid(frame, [ [A, O], [O, B] @@ -120,28 +120,28 @@ describe("FrameTransform suite", function() { ])); // rotate once - pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE); frameEqualsGrid(frame, [ [O, A], [B, O] ]); // rotate twice - pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE); frameEqualsGrid(frame, [ [B, O], [O, A] ]); // rotate 3 - pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE); frameEqualsGrid(frame, [ [O, B], [A, O] ]); // rotate 4 - back to initial state - pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE); frameEqualsGrid(frame, [ [A, O], [O, B] @@ -158,7 +158,7 @@ describe("FrameTransform suite", function() { ])); // rotate once - pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE); frameEqualsGrid(frame, [ [O, O], [B, A], @@ -167,7 +167,7 @@ describe("FrameTransform suite", function() { ]); // rotate twice - pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE); frameEqualsGrid(frame, [ [O, O], [O, B], @@ -176,7 +176,7 @@ describe("FrameTransform suite", function() { ]); // rotate 3 - pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE); frameEqualsGrid(frame, [ [O, O], [O, O], @@ -185,7 +185,7 @@ describe("FrameTransform suite", function() { ]); // rotate 4 - pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE); frameEqualsGrid(frame, [ [O, O], [A, O], @@ -202,28 +202,28 @@ describe("FrameTransform suite", function() { ])); // rotate once - pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE); frameEqualsGrid(frame, [ [O, A, O, O], [O, B, O, O] ]); // rotate twice - pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE); frameEqualsGrid(frame, [ [O, B, A, O], [O, O, O, O] ]); // rotate 3 - pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE); frameEqualsGrid(frame, [ [O, O, B, O], [O, O, A, O] ]); // rotate 4 - pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); + pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE); frameEqualsGrid(frame, [ [O, O, O, O], [O, A, B, O]