Fix bounding box rotation mode with placement other than top left.

This commit is contained in:
Antoine Vandecreme 2016-03-31 16:53:19 -04:00
parent 15a0db045e
commit 05a7e5e467

View File

@ -287,6 +287,34 @@
// private // private
_getOverlayPositionAndSize: function(viewport) { _getOverlayPositionAndSize: function(viewport) {
var position = viewport.pixelFromPoint(this.location, true); var position = viewport.pixelFromPoint(this.location, true);
var size = this._getSizeinPixels(viewport);
this.adjust(position, size);
var rotate = 0;
if (viewport.degrees &&
this.rotationMode !== $.OverlayRotationMode.NO_ROTATION) {
// BOUNDING_BOX is only valid if both directions get scaled.
// Get replaced by EXACT otherwise.
if (this.rotationMode === $.OverlayRotationMode.BOUNDING_BOX &&
this.width !== null && this.height !== null) {
var rect = new $.Rect(position.x, position.y, size.x, size.y);
var boundingBox = this._getBoundingBox(rect, viewport.degrees);
position = boundingBox.getTopLeft();
size = boundingBox.getSize();
} else {
rotate = viewport.degrees;
}
}
return {
position: position,
size: size,
rotate: rotate
};
},
// private
_getSizeinPixels: function(viewport) {
var width = this.size.x; var width = this.size.x;
var height = this.size.y; var height = this.size.y;
if (this.width !== null || this.height !== null) { if (this.width !== null || this.height !== null) {
@ -309,36 +337,30 @@
height = eltSize.y; height = eltSize.y;
} }
} }
var size = new $.Point(width, height); return new $.Point(width, height);
this.adjust(position, size); },
var rotate = 0; // private
// BOUNDING_BOX is only valid if both directions get scaled. _getBoundingBox: function(rect, degrees) {
// Get replaced by EXACT otherwise. var refPoint = new $.Point(rect.x, rect.y);
if (this.rotationMode === $.OverlayRotationMode.BOUNDING_BOX && var properties = $.Placement.properties[this.placement];
this.width !== null && this.height !== null) { if (properties) {
var boundingBox = new $.Rect( if (properties.isHorizontallyCentered) {
position.x, position.y, size.x, size.y, viewport.degrees) refPoint.x += rect.width / 2;
.getBoundingBox(); } else if (properties.isRight) {
position = boundingBox.getTopLeft(); refPoint.x += rect.width;
size = boundingBox.getSize(); }
} else if (this.rotationMode !== $.OverlayRotationMode.NO_ROTATION) { if (properties.isVerticallyCentered) {
rotate = viewport.degrees; refPoint.y += rect.height / 2;
} else if (properties.isBottom) {
refPoint.y += rect.height;
}
} }
return rect.rotate(degrees, refPoint).getBoundingBox();
return {
position: position,
size: size,
rotate: rotate
};
}, },
// private // private
_getTransformOrigin: function() { _getTransformOrigin: function() {
if (this.scales) {
return "top left";
}
var result = ""; var result = "";
var properties = $.Placement.properties[this.placement]; var properties = $.Placement.properties[this.placement];
if (!properties) { if (!properties) {