From a1ff3bfec5b18d83491494a5538737d9e3ab7a87 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Wed, 15 May 2013 13:04:55 +0200 Subject: Costume shrinkWrapping adjustments --- history.txt | 6 +++++- objects.js | 40 ++++++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/history.txt b/history.txt index 4b47632..8e4b9ae 100755 --- a/history.txt +++ b/history.txt @@ -1701,7 +1701,11 @@ ______ ------ * Reset Password via e-mailed link (frontend only) -140514 +130514 ------ * paint.js: Paint editor, first version, contributed by Kartik Chandra, Yay!! * Threads, Objects, Blocks: Broadcast & message enhancements: When I receive , and getLastMessage reporter + watcher + +130515 +------ +* Objects: Costume shrinkWrap adjustments diff --git a/objects.js b/objects.js index 086b1f6..a0c5be2 100644 --- a/objects.js +++ b/objects.js @@ -123,7 +123,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2013-May-14'; +modules.objects = '2013-May-15'; var SpriteMorph; var StageMorph; @@ -4547,15 +4547,19 @@ Costume.prototype.bounds = function () { Costume.prototype.shrinkWrap = function () { // adjust my contents' bounds to my visible bounding box - var bb = this.boundingBox().expandBy(3), // tolerance for anti-aliasing - ext = bb.extent(), + // add a tolerance margin for Chrome's anti-aliasing issue + var bb = this.boundingBox(), + space = new Point(480, 360).subtract(bb.extent()).floorDivideBy(2), + margin = new Point(3, 3).min(space.max(new Point(0, 0))), + area = bb.expandBy(margin), + ext = area.extent(), pic = newCanvas(ext), ctx = pic.getContext('2d'); ctx.drawImage( this.contents, - bb.origin.x, - bb.origin.y, + area.origin.x, + area.origin.y, ext.x, ext.y, 0, @@ -4563,7 +4567,7 @@ Costume.prototype.shrinkWrap = function () { ext.x, ext.y ); - this.rotationCenter = this.rotationCenter.subtract(bb.origin); + this.rotationCenter = this.rotationCenter.subtract(area.origin); this.contents = pic; this.version = Date.now(); }; @@ -4583,8 +4587,8 @@ Costume.prototype.boundingBox = function () { } function getLeft() { - for (col = 0; col < w; col += 1) { - for (row = 0; row < h; row += 1) { + for (col = 0; col <= w; col += 1) { + for (row = 0; row <= h; row += 1) { if (getAlpha(col, row)) { return col; } @@ -4594,8 +4598,8 @@ Costume.prototype.boundingBox = function () { } function getTop() { - for (row = 0; row < h; row += 1) { - for (col = 0; col < h; col += 1) { + for (row = 0; row <= h; row += 1) { + for (col = 0; col <= h; col += 1) { if (getAlpha(col, row)) { return row; } @@ -4605,25 +4609,25 @@ Costume.prototype.boundingBox = function () { } function getRight() { - for (col = w - 1; col >= 0; col -= 1) { - for (row = h - 1; row > 0; row -= 1) { + for (col = w; col >= 0; col -= 1) { + for (row = h; row >= 0; row -= 1) { if (getAlpha(col, row)) { - return col; + return Math.min(col + 1, w); } } } - return w - 1; + return w; } function getBottom() { - for (row = h - 1; row >= 0; row -= 1) { - for (col = w - 1; col >= 0; col -= 1) { + for (row = h; row >= 0; row -= 1) { + for (col = w; col >= 0; col -= 1) { if (getAlpha(col, row)) { - return row; + return Math.min(row + 1, h); } } } - return h - 1; + return h; } return new Rectangle(getLeft(), getTop(), getRight(), getBottom()); -- cgit v1.3.1