diff --git a/src/img/icons/transform/tool-align.png b/src/img/icons/transform/tool-center.png similarity index 100% rename from src/img/icons/transform/tool-align.png rename to src/img/icons/transform/tool-center.png diff --git a/src/js/controller/TransformationsController.js b/src/js/controller/TransformationsController.js index 90a28943..de89f322 100644 --- a/src/js/controller/TransformationsController.js +++ b/src/js/controller/TransformationsController.js @@ -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(); diff --git a/src/js/tools/transform/Align.js b/src/js/tools/transform/Align.js deleted file mode 100644 index 793c0132..00000000 --- a/src/js/tools/transform/Align.js +++ /dev/null @@ -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); - }; - -})(); diff --git a/src/js/tools/transform/Center.js b/src/js/tools/transform/Center.js new file mode 100644 index 00000000..7d08cb6f --- /dev/null +++ b/src/js/tools/transform/Center.js @@ -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); + }; + +})(); diff --git a/src/js/tools/transform/TransformUtils.js b/src/js/tools/transform/TransformUtils.js index eee5e307..042b58e0 100644 --- a/src/js/tools/transform/TransformUtils.js +++ b/src/js/tools/transform/TransformUtils.js @@ -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; diff --git a/src/piskel-script-list.js b/src/piskel-script-list.js index a1aa193f..ede3a844 100644 --- a/src/piskel-script-list.js +++ b/src/piskel-script-list.js @@ -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",