Skip to content

Commit

Permalink
Use bitmap resolution to calculate coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
adazem009 committed Dec 11, 2023
1 parent 8bad035 commit 5655f81
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
16 changes: 8 additions & 8 deletions ScratchCPPGui/renderedtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ void RenderedTarget::loadProperties()

// Coordinates
double size = sprite->size() / 100;
m_x = static_cast<double>(m_engine->stageWidth()) / 2 + sprite->x() - m_costume->rotationCenterX() * size / 2 * (m_newMirrorHorizontally ? -1 : 1);
m_y = static_cast<double>(m_engine->stageHeight()) / 2 - sprite->y() - m_costume->rotationCenterY() * size / 2;
m_originX = m_costume->rotationCenterX() * size / 2.0;
m_originY = m_costume->rotationCenterY() * size / 2.0;
m_x = static_cast<double>(m_engine->stageWidth()) / 2 + sprite->x() - m_costume->rotationCenterX() * size / m_costume->bitmapResolution() * (m_newMirrorHorizontally ? -1 : 1);
m_y = static_cast<double>(m_engine->stageHeight()) / 2 - sprite->y() - m_costume->rotationCenterY() * size / m_costume->bitmapResolution();
m_originX = m_costume->rotationCenterX() * size / m_costume->bitmapResolution();
m_originY = m_costume->rotationCenterY() * size / m_costume->bitmapResolution();

// Layer
m_z = sprite->layerOrder();
}

mutex.unlock();
} else if (m_stageModel) {
m_x = static_cast<double>(m_engine->stageWidth()) / 2 - m_costume->rotationCenterX() / 2.0;
m_y = static_cast<double>(m_engine->stageHeight()) / 2 - m_costume->rotationCenterY() / 2.0;
m_originX = m_costume->rotationCenterX() / 2.0;
m_originY = m_costume->rotationCenterY() / 2.0;
m_x = static_cast<double>(m_engine->stageWidth()) / 2 - m_costume->rotationCenterX() / m_costume->bitmapResolution();
m_y = static_cast<double>(m_engine->stageHeight()) / 2 - m_costume->rotationCenterY() / m_costume->bitmapResolution();
m_originX = m_costume->rotationCenterX() / m_costume->bitmapResolution();
m_originY = m_costume->rotationCenterY() / m_costume->bitmapResolution();
}
}

Expand Down
13 changes: 7 additions & 6 deletions test/renderedtarget/renderedtarget_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ TEST(RenderedTargetTest, LoadAndUpdateProperties)
target.updateProperties();
ASSERT_EQ(target.width(), 4);
ASSERT_EQ(target.height(), 6);
ASSERT_EQ(target.x(), 283.5);
ASSERT_EQ(target.y(), 88.5);
ASSERT_EQ(target.x(), 295);
ASSERT_EQ(target.y(), 52.5);
ASSERT_EQ(target.z(), 0);
ASSERT_EQ(target.rotation(), 0);
ASSERT_EQ(target.transformOriginPoint(), QPointF(-11.5, 36));
ASSERT_EQ(target.transformOriginPoint(), QPointF(-23, 72));

target.setStageModel(nullptr);
ASSERT_TRUE(mirrorHorizontallySpy.empty());
Expand Down Expand Up @@ -107,11 +107,12 @@ TEST(RenderedTargetTest, LoadAndUpdateProperties)
target.updateProperties();
ASSERT_EQ(target.width(), 14.3);
ASSERT_EQ(target.height(), 5.8);
ASSERT_EQ(std::round(target.x() * 100) / 100, 220.62);
ASSERT_EQ(std::round(target.y() * 100) / 100, -49.09);
ASSERT_EQ(std::round(target.x() * 100) / 100, 237.18);
ASSERT_EQ(std::round(target.y() * 100) / 100, -100.93);
ASSERT_EQ(target.z(), 3);
ASSERT_EQ(target.rotation(), -157.16);
ASSERT_EQ(target.transformOriginPoint(), QPointF(-16.5577, 51.8328));
ASSERT_EQ(target.transformOriginPoint().x(), -33.1154);
ASSERT_EQ(std::round(target.transformOriginPoint().y() * 100) / 100, 103.67);
ASSERT_TRUE(mirrorHorizontallySpy.empty());

EXPECT_CALL(engine, stageWidth()).WillOnce(Return(544));
Expand Down

0 comments on commit 5655f81

Please sign in to comment.