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 () {
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) {

View File

@ -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();

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) {
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);
};
})();

View File

@ -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);
};
})();

View File

@ -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;
}

View File

@ -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",
@ -184,10 +183,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",

View File

@ -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]