mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
Merge pull request #996 from paulkaplan/fix-bubble-bounds
Position the speech bubble more tightly.
This commit is contained in:
commit
13641297fd
2 changed files with 14 additions and 2 deletions
|
@ -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();
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Reference in a new issue