summaryrefslogtreecommitdiff
path: root/objects.js
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2013-05-15 13:04:55 +0200
committerjmoenig <jens@moenig.org>2013-05-15 13:04:55 +0200
commita1ff3bfec5b18d83491494a5538737d9e3ab7a87 (patch)
tree125a0913a75698417d959ef54481f47da3e343f1 /objects.js
parentc8029a03e9d7720999d02d751abf49d52ec85e16 (diff)
downloadsnap-a1ff3bfec5b18d83491494a5538737d9e3ab7a87.tar.gz
snap-a1ff3bfec5b18d83491494a5538737d9e3ab7a87.zip
Costume shrinkWrapping adjustments
Diffstat (limited to 'objects.js')
-rw-r--r--objects.js40
1 files changed, 22 insertions, 18 deletions
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());