Refactor : move FrameTransform to transform package

This commit is contained in:
jdescottes 2015-09-19 17:56:32 +02:00
parent d6a85aaf6f
commit d8d7f1adea
7 changed files with 47 additions and 51 deletions

View File

@ -1,21 +1,17 @@
(function () { (function () {
var ns = $.namespace('pskl.tools.transform'); var ns = $.namespace('pskl.tools.transform');
ns.Transform = function () { ns.AbstractTransformTool = function () {};
this.toolId = 'tool-transform';
this.helpText = 'Transform tool';
this.tooltipDescriptors = [];
};
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 allFrames = evt.shiftKey;
var allLayers = evt.ctrlKey; var allLayers = evt.ctrlKey;
this.applyTool_(evt.altKey, allFrames, allLayers); 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 currentFrameIndex = pskl.app.piskelController.getCurrentFrameIndex();
var layers = allLayers ? pskl.app.piskelController.getLayers() : [pskl.app.piskelController.getCurrentLayer()]; var layers = allLayers ? pskl.app.piskelController.getLayers() : [pskl.app.piskelController.getCurrentLayer()];
layers.forEach(function (layer) { layers.forEach(function (layer) {

View File

@ -7,7 +7,7 @@
this.tooltipDescriptors = []; this.tooltipDescriptors = [];
}; };
pskl.utils.inherit(ns.Clone, ns.Transform); pskl.utils.inherit(ns.Clone, ns.AbstractTransformTool);
ns.Clone.prototype.apply = function (evt) { ns.Clone.prototype.apply = function (evt) {
var ref = pskl.app.piskelController.getCurrentFrame(); var ref = pskl.app.piskelController.getCurrentFrame();

View File

@ -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) { ns.Flip.prototype.applyToolOnFrame_ = function (frame, altKey) {
var axis; var axis;
if (altKey) { if (altKey) {
axis = pskl.utils.FrameTransform.HORIZONTAL; axis = ns.TransformUtils.HORIZONTAL;
} else { } else {
axis = pskl.utils.FrameTransform.VERTICAL; axis = ns.TransformUtils.VERTICAL;
} }
pskl.utils.FrameTransform.flip(frame, axis); ns.TransformUtils.flip(frame, axis);
}; };
})(); })();

View File

@ -10,18 +10,18 @@
{key : 'shift', description : 'Apply to all frames'}]; {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) { ns.Rotate.prototype.applyToolOnFrame_ = function (frame, altKey) {
var direction; var direction;
if (altKey) { if (altKey) {
direction = pskl.utils.FrameTransform.CLOCKWISE; direction = ns.TransformUtils.CLOCKWISE;
} else { } else {
direction = pskl.utils.FrameTransform.COUNTERCLOCKWISE; direction = ns.TransformUtils.COUNTERCLOCKWISE;
} }
pskl.utils.FrameTransform.rotate(frame, direction); ns.TransformUtils.rotate(frame, direction);
}; };
})(); })();

View File

@ -1,8 +1,8 @@
(function () { (function () {
var ns = $.namespace('pskl.utils'); var ns = $.namespace('pskl.tools.transform');
ns.FrameTransform = { ns.TransformUtils = {
VERTICAL : 'vertical', VERTICAL : 'VERTICAL',
HORIZONTAL : 'HORIZONTAL', HORIZONTAL : 'HORIZONTAL',
flip : function (frame, axis) { flip : function (frame, axis) {
var clone = frame.clone(); var clone = frame.clone();
@ -10,9 +10,9 @@
var h = frame.getHeight(); var h = frame.getHeight();
clone.forEachPixel(function (color, x, y) { clone.forEachPixel(function (color, x, y) {
if (axis === ns.FrameTransform.VERTICAL) { if (axis === ns.TransformUtils.VERTICAL) {
x = w - x - 1; x = w - x - 1;
} else if (axis === ns.FrameTransform.HORIZONTAL) { } else if (axis === ns.TransformUtils.HORIZONTAL) {
y = h - y - 1; y = h - y - 1;
} }
frame.pixels[x][y] = color; frame.pixels[x][y] = color;
@ -43,10 +43,10 @@
// Perform the rotation // Perform the rotation
var tmpX = x; var tmpX = x;
var tmpY = y; var tmpY = y;
if (direction === ns.FrameTransform.CLOCKWISE) { if (direction === ns.TransformUtils.CLOCKWISE) {
x = tmpY; x = tmpY;
y = max - 1 - tmpX; y = max - 1 - tmpX;
} else if (direction === ns.FrameTransform.COUNTERCLOCKWISE) { } else if (direction === ns.TransformUtils.COUNTERCLOCKWISE) {
y = tmpX; y = tmpX;
x = max - 1 - tmpY; x = max - 1 - tmpY;
} }

View File

@ -27,7 +27,6 @@
"js/utils/Math.js", "js/utils/Math.js",
"js/utils/FileUtils.js", "js/utils/FileUtils.js",
"js/utils/FileUtilsDesktop.js", "js/utils/FileUtilsDesktop.js",
"js/utils/FrameTransform.js",
"js/utils/FrameUtils.js", "js/utils/FrameUtils.js",
"js/utils/LayerUtils.js", "js/utils/LayerUtils.js",
"js/utils/ImageResizer.js", "js/utils/ImageResizer.js",
@ -184,10 +183,11 @@
"js/tools/drawing/ColorPicker.js", "js/tools/drawing/ColorPicker.js",
"js/tools/drawing/ColorSwap.js", "js/tools/drawing/ColorSwap.js",
"js/tools/drawing/DitheringTool.js", "js/tools/drawing/DitheringTool.js",
"js/tools/transform/Transform.js", "js/tools/transform/AbstractTransformTool.js",
"js/tools/transform/Clone.js", "js/tools/transform/Clone.js",
"js/tools/transform/Flip.js", "js/tools/transform/Flip.js",
"js/tools/transform/Rotate.js", "js/tools/transform/Rotate.js",
"js/tools/transform/TransformUtils.js",
// Devtools // Devtools
"js/devtools/DrawingTestPlayer.js", "js/devtools/DrawingTestPlayer.js",

View File

@ -1,13 +1,13 @@
describe("FrameTransform suite", function() { describe("TransformUtils suite", function() {
var A = '#000000'; var A = '#000000';
var B = '#ff0000'; var B = '#ff0000';
var O = Constants.TRANSPARENT_COLOR; var O = Constants.TRANSPARENT_COLOR;
var HORIZONTAL = pskl.utils.FrameTransform.HORIZONTAL; var HORIZONTAL = pskl.tools.transform.TransformUtils.HORIZONTAL;
var VERTICAL = pskl.utils.FrameTransform.VERTICAL; var VERTICAL = pskl.tools.transform.TransformUtils.VERTICAL;
var CLOCKWISE = pskl.utils.FrameTransform.CLOCKWISE; var CLOCKWISE = pskl.tools.transform.TransformUtils.CLOCKWISE;
var COUNTERCLOCKWISE = pskl.utils.FrameTransform.COUNTERCLOCKWISE; var COUNTERCLOCKWISE = pskl.tools.transform.TransformUtils.COUNTERCLOCKWISE;
// shortcuts // shortcuts
var frameEqualsGrid = test.testutils.frameEqualsGrid; var frameEqualsGrid = test.testutils.frameEqualsGrid;
@ -25,7 +25,7 @@ describe("FrameTransform suite", function() {
])); ]));
// should have flipped // should have flipped
pskl.utils.FrameTransform.flip(frame, VERTICAL); pskl.tools.transform.TransformUtils.flip(frame, VERTICAL);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, A], [O, A],
[B, O] [B, O]
@ -40,7 +40,7 @@ describe("FrameTransform suite", function() {
])); ]));
// should have flipped // should have flipped
pskl.utils.FrameTransform.flip(frame, HORIZONTAL); pskl.tools.transform.TransformUtils.flip(frame, HORIZONTAL);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, B], [O, B],
[A, O] [A, O]
@ -56,7 +56,7 @@ describe("FrameTransform suite", function() {
])); ]));
// should have flipped // should have flipped
pskl.utils.FrameTransform.flip(frame, VERTICAL); pskl.tools.transform.TransformUtils.flip(frame, VERTICAL);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, A], [O, A],
[O, A], [O, A],
@ -64,7 +64,7 @@ describe("FrameTransform suite", function() {
]); ]);
// should be the same // should be the same
pskl.utils.FrameTransform.flip(frame, HORIZONTAL); pskl.tools.transform.TransformUtils.flip(frame, HORIZONTAL);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, A], [O, A],
[O, A], [O, A],
@ -84,28 +84,28 @@ describe("FrameTransform suite", function() {
])); ]));
// rotate once // rotate once
pskl.utils.FrameTransform.rotate(frame, COUNTERCLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, COUNTERCLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, B], [O, B],
[A, O] [A, O]
]); ]);
// rotate twice // rotate twice
pskl.utils.FrameTransform.rotate(frame, COUNTERCLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, COUNTERCLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[B, O], [B, O],
[O, A] [O, A]
]); ]);
// rotate 3 // rotate 3
pskl.utils.FrameTransform.rotate(frame, COUNTERCLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, COUNTERCLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, A], [O, A],
[B, O] [B, O]
]); ]);
// rotate 4 - back to initial state // rotate 4 - back to initial state
pskl.utils.FrameTransform.rotate(frame, COUNTERCLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, COUNTERCLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[A, O], [A, O],
[O, B] [O, B]
@ -120,28 +120,28 @@ describe("FrameTransform suite", function() {
])); ]));
// rotate once // rotate once
pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, A], [O, A],
[B, O] [B, O]
]); ]);
// rotate twice // rotate twice
pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[B, O], [B, O],
[O, A] [O, A]
]); ]);
// rotate 3 // rotate 3
pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, B], [O, B],
[A, O] [A, O]
]); ]);
// rotate 4 - back to initial state // rotate 4 - back to initial state
pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[A, O], [A, O],
[O, B] [O, B]
@ -158,7 +158,7 @@ describe("FrameTransform suite", function() {
])); ]));
// rotate once // rotate once
pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, O], [O, O],
[B, A], [B, A],
@ -167,7 +167,7 @@ describe("FrameTransform suite", function() {
]); ]);
// rotate twice // rotate twice
pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, O], [O, O],
[O, B], [O, B],
@ -176,7 +176,7 @@ describe("FrameTransform suite", function() {
]); ]);
// rotate 3 // rotate 3
pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, O], [O, O],
[O, O], [O, O],
@ -185,7 +185,7 @@ describe("FrameTransform suite", function() {
]); ]);
// rotate 4 // rotate 4
pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, O], [O, O],
[A, O], [A, O],
@ -202,28 +202,28 @@ describe("FrameTransform suite", function() {
])); ]));
// rotate once // rotate once
pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, A, O, O], [O, A, O, O],
[O, B, O, O] [O, B, O, O]
]); ]);
// rotate twice // rotate twice
pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, B, A, O], [O, B, A, O],
[O, O, O, O] [O, O, O, O]
]); ]);
// rotate 3 // rotate 3
pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, O, B, O], [O, O, B, O],
[O, O, A, O] [O, O, A, O]
]); ]);
// rotate 4 // rotate 4
pskl.utils.FrameTransform.rotate(frame, CLOCKWISE); pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
frameEqualsGrid(frame, [ frameEqualsGrid(frame, [
[O, O, O, O], [O, O, O, O],
[O, A, B, O] [O, A, B, O]