From 299d4fb8955c3fe1f4a177568d5aad3c084d4e17 Mon Sep 17 00:00:00 2001 From: Matt D Date: Thu, 12 May 2016 10:39:29 +1000 Subject: [PATCH] Renamed Align to Center --- .../{tool-align.png => tool-center.png} | Bin .../controller/TransformationsController.js | 2 +- src/js/tools/transform/Align.js | 19 ------------------ src/js/tools/transform/Center.js | 19 ++++++++++++++++++ src/js/tools/transform/TransformUtils.js | 18 ++++++++--------- src/piskel-script-list.js | 2 +- 6 files changed, 29 insertions(+), 31 deletions(-) rename src/img/icons/transform/{tool-align.png => tool-center.png} (100%) delete mode 100644 src/js/tools/transform/Align.js create mode 100644 src/js/tools/transform/Center.js 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",