Skip to content

Commit 6221223

Browse files
committed
Use CPU texture in getBounds()
1 parent a8c0cbe commit 6221223

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

src/renderedtarget.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,13 @@ void RenderedTarget::setHeight(qreal height)
359359
Rect RenderedTarget::getBounds() const
360360
{
361361
// https://github.com/scratchfoundation/scratch-render/blob/c3ede9c3d54769730c7b023021511e2aba167b1f/src/Rectangle.js#L33-L55
362-
if (!m_costume || !m_skin || !m_texture.isValid())
362+
if (!m_costume || !m_skin || !m_texture.isValid() || !m_cpuTexture.isValid())
363363
return Rect(m_x, m_y, m_x, m_y);
364364

365-
const double width = m_texture.width() * m_size / scale() / m_costume->bitmapResolution();
366-
const double height = m_texture.height() * m_size / scale() / m_costume->bitmapResolution();
367-
const double originX = m_stageScale * m_costume->rotationCenterX() * m_size / scale() / m_costume->bitmapResolution() - width / 2;
368-
const double originY = m_stageScale * -m_costume->rotationCenterY() * m_size / scale() / m_costume->bitmapResolution() + height / 2;
365+
const double width = m_cpuTexture.width() * m_size / m_costume->bitmapResolution();
366+
const double height = m_cpuTexture.height() * m_size / m_costume->bitmapResolution();
367+
const double originX = m_costume->rotationCenterX() * m_size / m_costume->bitmapResolution() - width / 2;
368+
const double originY = -m_costume->rotationCenterY() * m_size / m_costume->bitmapResolution() + height / 2;
369369
const double rot = -rotation() * pi / 180;
370370
double left = std::numeric_limits<double>::infinity();
371371
double top = -std::numeric_limits<double>::infinity();
@@ -376,8 +376,8 @@ Rect RenderedTarget::getBounds() const
376376

377377
for (const QPointF &point : points) {
378378
QPointF transformed = transformPoint(point.x() - width / 2, height / 2 - point.y(), originX, originY, rot);
379-
const double x = transformed.x() * scale() / m_stageScale * (m_mirrorHorizontally ? -1 : 1);
380-
const double y = transformed.y() * scale() / m_stageScale;
379+
const double x = transformed.x() * (m_mirrorHorizontally ? -1 : 1);
380+
const double y = transformed.y();
381381

382382
if (x < left)
383383
left = x;

test/renderedtarget/renderedtarget_test.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -662,64 +662,64 @@ TEST_F(RenderedTargetTest, GetBounds)
662662
target.beforeRedraw();
663663

664664
Rect bounds = target.getBounds();
665-
ASSERT_EQ(std::round(bounds.left() * 100) / 100, 66.13);
666-
ASSERT_EQ(std::round(bounds.top() * 100) / 100, -124.52);
667-
ASSERT_EQ(std::round(bounds.right() * 100) / 100, 66.72);
668-
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, -125.11);
665+
ASSERT_EQ(std::round(bounds.left() * 100) / 100, 64.96);
666+
ASSERT_EQ(std::round(bounds.top() * 100) / 100, -121.16);
667+
ASSERT_EQ(std::round(bounds.right() * 100) / 100, 67.79);
668+
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, -123.99);
669669

670670
QRectF bubbleBounds = target.getBoundsForBubble();
671-
ASSERT_EQ(std::round(bubbleBounds.left() * 100) / 100, 66.13);
672-
ASSERT_EQ(std::round(bubbleBounds.top() * 100) / 100, -124.52);
673-
ASSERT_EQ(std::round(bubbleBounds.right() * 100) / 100, 66.72);
674-
ASSERT_EQ(std::round(bubbleBounds.bottom() * 100) / 100, -125.11);
671+
ASSERT_EQ(std::round(bubbleBounds.left() * 100) / 100, 64.96);
672+
ASSERT_EQ(std::round(bubbleBounds.top() * 100) / 100, -121.16);
673+
ASSERT_EQ(std::round(bubbleBounds.right() * 100) / 100, 67.79);
674+
ASSERT_EQ(std::round(bubbleBounds.bottom() * 100) / 100, -123.99);
675675

676676
EXPECT_CALL(engine, stageWidth()).WillOnce(Return(480));
677677
EXPECT_CALL(engine, stageHeight()).WillOnce(Return(360));
678678
target.updateRotationStyle(Sprite::RotationStyle::LeftRight);
679679

680680
bounds = target.getBounds();
681-
ASSERT_EQ(std::round(bounds.left() * 100) / 100, 71.87);
682-
ASSERT_EQ(std::round(bounds.top() * 100) / 100, -110.47);
683-
ASSERT_EQ(std::round(bounds.right() * 100) / 100, 72.29);
684-
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, -110.89);
681+
ASSERT_EQ(std::round(bounds.left() * 100) / 100, 69.5);
682+
ASSERT_EQ(std::round(bounds.top() * 100) / 100, -111.26);
683+
ASSERT_EQ(std::round(bounds.right() * 100) / 100, 71.5);
684+
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, -113.26);
685685

686686
bubbleBounds = target.getBoundsForBubble();
687-
ASSERT_EQ(std::round(bubbleBounds.left() * 100) / 100, 71.87);
688-
ASSERT_EQ(std::round(bubbleBounds.top() * 100) / 100, -110.47);
689-
ASSERT_EQ(std::round(bubbleBounds.right() * 100) / 100, 72.29);
690-
ASSERT_EQ(std::round(bubbleBounds.bottom() * 100) / 100, -110.89);
687+
ASSERT_EQ(std::round(bubbleBounds.left() * 100) / 100, 69.5);
688+
ASSERT_EQ(std::round(bubbleBounds.top() * 100) / 100, -111.26);
689+
ASSERT_EQ(std::round(bubbleBounds.right() * 100) / 100, 71.5);
690+
ASSERT_EQ(std::round(bubbleBounds.bottom() * 100) / 100, -113.26);
691691

692692
EXPECT_CALL(engine, stageWidth()).WillOnce(Return(480));
693693
EXPECT_CALL(engine, stageHeight()).WillOnce(Return(360));
694694
target.setStageScale(20.75);
695695

696696
bounds = target.getBounds();
697-
ASSERT_EQ(std::round(bounds.left() * 100) / 100, 71.87);
698-
ASSERT_EQ(std::round(bounds.top() * 100) / 100, -110.47);
699-
ASSERT_EQ(std::round(bounds.right() * 100) / 100, 72.29);
700-
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, -110.89);
697+
ASSERT_EQ(std::round(bounds.left() * 100) / 100, 69.5);
698+
ASSERT_EQ(std::round(bounds.top() * 100) / 100, -111.26);
699+
ASSERT_EQ(std::round(bounds.right() * 100) / 100, 71.5);
700+
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, -113.26);
701701

702702
bubbleBounds = target.getBoundsForBubble();
703-
ASSERT_EQ(std::round(bubbleBounds.left() * 100) / 100, 71.87);
704-
ASSERT_EQ(std::round(bubbleBounds.top() * 100) / 100, -110.47);
705-
ASSERT_EQ(std::round(bubbleBounds.right() * 100) / 100, 72.29);
706-
ASSERT_EQ(std::round(bubbleBounds.bottom() * 100) / 100, -110.89);
703+
ASSERT_EQ(std::round(bubbleBounds.left() * 100) / 100, 69.5);
704+
ASSERT_EQ(std::round(bubbleBounds.top() * 100) / 100, -111.26);
705+
ASSERT_EQ(std::round(bubbleBounds.right() * 100) / 100, 71.5);
706+
ASSERT_EQ(std::round(bubbleBounds.bottom() * 100) / 100, -113.26);
707707

708708
EXPECT_CALL(engine, stageWidth()).WillOnce(Return(480));
709709
EXPECT_CALL(engine, stageHeight()).WillOnce(Return(360));
710710
target.updateSize(9780.6);
711711

712712
bounds = target.getBounds();
713-
ASSERT_EQ(std::round(bounds.left() * 100) / 100, -466.05);
714-
ASSERT_EQ(std::round(bounds.top() * 100) / 100, 1294.13);
715-
ASSERT_EQ(std::round(bounds.right() * 100) / 100, -405.87);
716-
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, 1233.94);
713+
ASSERT_EQ(std::round(bounds.left() * 100) / 100, -378.77);
714+
ASSERT_EQ(std::round(bounds.top() * 100) / 100, 1323.22);
715+
ASSERT_EQ(std::round(bounds.right() * 100) / 100, -376.77);
716+
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, 1321.22);
717717

718718
bubbleBounds = target.getBoundsForBubble();
719-
ASSERT_EQ(std::round(bubbleBounds.left() * 100) / 100, -466.05);
720-
ASSERT_EQ(std::round(bubbleBounds.top() * 100) / 100, 1294.13);
721-
ASSERT_EQ(std::round(bubbleBounds.right() * 100) / 100, -405.87);
722-
ASSERT_EQ(std::round(bubbleBounds.bottom() * 100) / 100, 1286.13);
719+
ASSERT_EQ(std::round(bubbleBounds.left() * 100) / 100, -378.77);
720+
ASSERT_EQ(std::round(bubbleBounds.top() * 100) / 100, 1323.22);
721+
ASSERT_EQ(std::round(bubbleBounds.right() * 100) / 100, -376.77);
722+
ASSERT_EQ(std::round(bubbleBounds.bottom() * 100) / 100, 1321.22);
723723

724724
context.doneCurrent();
725725
}

0 commit comments

Comments
 (0)