Merge pull request #996 from paulkaplan/fix-bubble-bounds

Position the speech bubble more tightly.
This commit is contained in:
Paul Kaplan 2018-03-23 14:36:52 -04:00 committed by GitHub
commit 13641297fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View file

@ -119,7 +119,7 @@ class Scratch3LooksBlocks {
_positionBubble (target) { _positionBubble (target) {
const bubbleState = this._getBubbleState(target); const bubbleState = this._getBubbleState(target);
const [bubbleWidth, bubbleHeight] = this.runtime.renderer.getSkinSize(bubbleState.drawableId); const [bubbleWidth, bubbleHeight] = this.runtime.renderer.getSkinSize(bubbleState.drawableId);
const targetBounds = target.getBounds(); const targetBounds = target.getBoundsForBubble();
const stageBounds = this.runtime.getTargetForStage().getBounds(); const stageBounds = this.runtime.getTargetForStage().getBounds();
if (bubbleState.onSpriteRight && bubbleWidth + targetBounds.right > stageBounds.right && if (bubbleState.onSpriteRight && bubbleWidth + targetBounds.right > stageBounds.right &&
(targetBounds.left - bubbleWidth > stageBounds.left)) { // Only flip if it would fit (targetBounds.left - bubbleWidth > stageBounds.left)) { // Only flip if it would fit
@ -137,7 +137,7 @@ class Scratch3LooksBlocks {
) : ( ) : (
Math.max(stageBounds.left, targetBounds.left - bubbleWidth) Math.max(stageBounds.left, targetBounds.left - bubbleWidth)
), ),
Math.min(stageBounds.top, targetBounds.top + bubbleHeight) Math.min(stageBounds.top, targetBounds.bottom + bubbleHeight)
] ]
}); });
this.runtime.requestRedraw(); this.runtime.requestRedraw();

View file

@ -645,6 +645,18 @@ class RenderedTarget extends Target {
return null; return null;
} }
/**
* Return the bounding box around a slice of the top 8px of the rendered target.
* Includes top, left, bottom, right attributes in Scratch coordinates.
* @return {?object} Tight bounding box, or null.
*/
getBoundsForBubble () {
if (this.renderer) {
return this.runtime.renderer.getBoundsForBubble(this.drawableID);
}
return null;
}
/** /**
* Return whether touching a point. * Return whether touching a point.
* @param {number} x X coordinate of test point. * @param {number} x X coordinate of test point.