diff options
| author | jmoenig <jens@moenig.org> | 2013-05-15 13:04:55 +0200 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2013-05-15 13:04:55 +0200 |
| commit | a1ff3bfec5b18d83491494a5538737d9e3ab7a87 (patch) | |
| tree | 125a0913a75698417d959ef54481f47da3e343f1 | |
| parent | c8029a03e9d7720999d02d751abf49d52ec85e16 (diff) | |
| download | snap-yow-a1ff3bfec5b18d83491494a5538737d9e3ab7a87.tar.gz snap-yow-a1ff3bfec5b18d83491494a5538737d9e3ab7a87.zip | |
Costume shrinkWrapping adjustments
| -rwxr-xr-x | history.txt | 6 | ||||
| -rw-r--r-- | 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 <any msg>, and getLastMessage reporter + watcher + +130515 +------ +* Objects: Costume shrinkWrap adjustments @@ -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()); |
