Position the speech bubble more tightly.

This commit is contained in:
Paul Kaplan 2018-03-14 11:33:36 -04:00
parent 5d658b5ecb
commit ea534b35ea
2 changed files with 14 additions and 2 deletions

View file

@ -119,7 +119,7 @@ class Scratch3LooksBlocks {
_positionBubble (target) {
const bubbleState = this._getBubbleState(target);
const [bubbleWidth, bubbleHeight] = this.runtime.renderer.getSkinSize(bubbleState.drawableId);
const targetBounds = target.getBounds();
const targetBounds = target.getBoundsForBubble();
const stageBounds = this.runtime.getTargetForStage().getBounds();
if (bubbleState.onSpriteRight && bubbleWidth + targetBounds.right > stageBounds.right &&
(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.min(stageBounds.top, targetBounds.top + bubbleHeight)
Math.min(stageBounds.top, targetBounds.bottom + bubbleHeight)
]
});
this.runtime.requestRedraw();

View file

@ -636,6 +636,18 @@ class RenderedTarget extends Target {
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.
* @param {number} x X coordinate of test point.