SVG: compensate for viewbox offset

In Scratch 2.0, an SVG costume's origin is stored relative to that SVG's
viewbox. In order to use the origin values correctly, then, we need to
compensate for the viewbox offset.
This commit is contained in:
Christopher Willis-Ford 2017-02-14 15:59:45 -08:00
parent 4d8b5da491
commit 959c635f58
2 changed files with 17 additions and 0 deletions

View File

@ -40,6 +40,16 @@ class SVGSkin extends Skin {
return this._svgRenderer.size; return this._svgRenderer.size;
} }
/**
* Set the origin, in object space, about which this Skin should rotate.
* @param {number} x - The x coordinate of the new rotation center.
* @param {number} y - The y coordinate of the new rotation center.
*/
setRotationCenter (x, y) {
const viewOffset = this._svgRenderer.viewOffset;
super.setRotationCenter(x - viewOffset[0], y - viewOffset[1]);
}
/** /**
* @param {[number,number]} scale - The scaling factors to be used. * @param {[number,number]} scale - The scaling factors to be used.
* @return {WebGLTexture} The GL texture representation of this skin when drawing at the given scale. * @return {WebGLTexture} The GL texture representation of this skin when drawing at the given scale.

View File

@ -80,6 +80,13 @@ class SvgRenderer {
return [this._measurements.width, this._measurements.height]; return [this._measurements.width, this._measurements.height];
} }
/**
* @return {[number,number]} the offset (upper left corner) of the SVG's view box.
*/
get viewOffset () {
return [this._measurements.x, this._measurements.y];
}
/** /**
* Transforms an SVG's text elements for Scratch 2.0 quirks. * Transforms an SVG's text elements for Scratch 2.0 quirks.
* These quirks include: * These quirks include: