Renamed Align to Center

This commit is contained in:
Matt D 2016-05-12 10:39:29 +10:00
parent 7c4d03b105
commit 299d4fb895
6 changed files with 29 additions and 31 deletions

View File

Before

Width:  |  Height:  |  Size: 521 B

After

Width:  |  Height:  |  Size: 521 B

View File

@ -6,7 +6,7 @@
new pskl.tools.transform.Flip(),
new pskl.tools.transform.Rotate(),
new pskl.tools.transform.Clone(),
new pskl.tools.transform.Align()
new pskl.tools.transform.Center()
];
this.toolIconBuilder = new pskl.tools.ToolIconBuilder();

View File

@ -1,19 +0,0 @@
(function () {
var ns = $.namespace('pskl.tools.transform');
ns.Align = function () {
this.toolId = 'tool-align';
this.helpText = 'Align selection to the center';
this.tooltipDescriptors = [
{key : 'ctrl', description : 'Apply to all layers'},
{key : 'shift', description : 'Apply to all frames'}
];
};
pskl.utils.inherit(ns.Align, ns.AbstractTransformTool);
ns.Align.prototype.applyToolOnFrame_ = function (frame, altKey) {
ns.TransformUtils.align(frame);
};
})();

View File

@ -0,0 +1,19 @@
(function () {
var ns = $.namespace('pskl.tools.transform');
ns.Center = function () {
this.toolId = 'tool-center';
this.helpText = 'Align image to the center';
this.tooltipDescriptors = [
{key : 'ctrl', description : 'Apply to all layers'},
{key : 'shift', description : 'Apply to all frames'}
];
};
pskl.utils.inherit(ns.Center, ns.AbstractTransformTool);
ns.Center.prototype.applyToolOnFrame_ = function (frame) {
ns.TransformUtils.center(frame);
};
})();

View File

@ -64,22 +64,20 @@
return frame;
},
align : function(frame) {
center : function(frame) {
// Figure out the boundary
var minx = frame.width;
var miny = frame.height;
var maxx = 0;
var maxy = 0;
for (var col = 0; col < frame.width; col++) {
for (var row = 0; row < frame.height; row++) {
if (frame.pixels[col][row] !== Constants.TRANSPARENT_COLOR) {
miny = Math.min(miny, row);
maxy = Math.max(maxy, row);
minx = Math.min(minx, col);
maxx = Math.max(maxx, col);
}
frame.forEachPixel(function (color, x, y) {
if (color !== Constants.TRANSPARENT_COLOR) {
minx = Math.min(minx, x);
maxx = Math.max(maxx, x);
miny = Math.min(miny, y);
maxy = Math.max(maxy, y);
}
}
});
// Calculate how much to move the pixels
var bw = (maxx - minx + 1) / 2;

View File

@ -201,7 +201,7 @@
"js/tools/drawing/ColorSwap.js",
"js/tools/drawing/DitheringTool.js",
"js/tools/transform/AbstractTransformTool.js",
"js/tools/transform/Align.js",
"js/tools/transform/Center.js",
"js/tools/transform/Clone.js",
"js/tools/transform/Flip.js",
"js/tools/transform/Rotate.js",