Skip to content

Commit 512b151

Browse files
committed
RenderedTarget: Calculate position and rotation of hidden sprites
1 parent c101e4c commit 512b151

File tree

2 files changed

+34
-38
lines changed

2 files changed

+34
-38
lines changed

src/renderedtarget.cpp

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -683,56 +683,52 @@ void RenderedTarget::calculatePos()
683683
if (!m_skin || !m_costume || !m_engine)
684684
return;
685685

686-
if (isVisible() || m_stageModel) {
687-
double stageWidth = m_engine->stageWidth();
688-
double stageHeight = m_engine->stageHeight();
689-
setX(m_stageScale * (stageWidth / 2 + m_x - m_costume->rotationCenterX() * m_size / scale() / m_costume->bitmapResolution() * (m_mirrorHorizontally ? -1 : 1)));
690-
setY(m_stageScale * (stageHeight / 2 - m_y - m_costume->rotationCenterY() * m_size / scale() / m_costume->bitmapResolution()));
691-
qreal originX = m_costume->rotationCenterX() * m_stageScale * m_size / scale() / m_costume->bitmapResolution();
692-
qreal originY = m_costume->rotationCenterY() * m_stageScale * m_size / scale() / m_costume->bitmapResolution();
693-
setTransformOriginPoint(QPointF(originX, originY));
694-
695-
// Qt ignores the transform origin point if it's (0, 0),
696-
// so set the transform origin to top left in this case.
697-
if (originX == 0 && originY == 0)
698-
setTransformOrigin(QQuickItem::TopLeft);
699-
else
700-
setTransformOrigin(QQuickItem::Center);
701-
}
686+
double stageWidth = m_engine->stageWidth();
687+
double stageHeight = m_engine->stageHeight();
688+
setX(m_stageScale * (stageWidth / 2 + m_x - m_costume->rotationCenterX() * m_size / scale() / m_costume->bitmapResolution() * (m_mirrorHorizontally ? -1 : 1)));
689+
setY(m_stageScale * (stageHeight / 2 - m_y - m_costume->rotationCenterY() * m_size / scale() / m_costume->bitmapResolution()));
690+
qreal originX = m_costume->rotationCenterX() * m_stageScale * m_size / scale() / m_costume->bitmapResolution();
691+
qreal originY = m_costume->rotationCenterY() * m_stageScale * m_size / scale() / m_costume->bitmapResolution();
692+
setTransformOriginPoint(QPointF(originX, originY));
693+
694+
// Qt ignores the transform origin point if it's (0, 0),
695+
// so set the transform origin to top left in this case.
696+
if (originX == 0 && originY == 0)
697+
setTransformOrigin(QQuickItem::TopLeft);
698+
else
699+
setTransformOrigin(QQuickItem::Center);
702700

703701
m_transformedHullDirty = true;
704702
}
705703

706704
void RenderedTarget::calculateRotation()
707705
{
708-
if (isVisible()) {
709-
// Direction
710-
bool oldMirrorHorizontally = m_mirrorHorizontally;
706+
// Direction
707+
bool oldMirrorHorizontally = m_mirrorHorizontally;
711708

712-
switch (m_rotationStyle) {
713-
case Sprite::RotationStyle::AllAround:
714-
setRotation(m_direction - 90);
715-
m_mirrorHorizontally = (false);
709+
switch (m_rotationStyle) {
710+
case Sprite::RotationStyle::AllAround:
711+
setRotation(m_direction - 90);
712+
m_mirrorHorizontally = (false);
716713

717-
break;
714+
break;
718715

719-
case Sprite::RotationStyle::LeftRight: {
720-
setRotation(0);
721-
m_mirrorHorizontally = (m_direction < 0);
716+
case Sprite::RotationStyle::LeftRight: {
717+
setRotation(0);
718+
m_mirrorHorizontally = (m_direction < 0);
722719

723-
break;
724-
}
725-
726-
case Sprite::RotationStyle::DoNotRotate:
727-
setRotation(0);
728-
m_mirrorHorizontally = false;
729-
break;
720+
break;
730721
}
731722

732-
if (m_mirrorHorizontally != oldMirrorHorizontally)
733-
emit mirrorHorizontallyChanged();
723+
case Sprite::RotationStyle::DoNotRotate:
724+
setRotation(0);
725+
m_mirrorHorizontally = false;
726+
break;
734727
}
735728

729+
if (m_mirrorHorizontally != oldMirrorHorizontally)
730+
emit mirrorHorizontallyChanged();
731+
736732
m_transformedHullDirty = true;
737733
}
738734

test/renderedtarget/renderedtarget_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ TEST_F(RenderedTargetTest, UpdateMethods)
138138
SpriteModel spriteModel;
139139
sprite.setInterface(&spriteModel);
140140

141-
EXPECT_CALL(engine, stageWidth()).Times(2).WillRepeatedly(Return(480));
142-
EXPECT_CALL(engine, stageHeight()).Times(2).WillRepeatedly(Return(360));
141+
EXPECT_CALL(engine, stageWidth()).Times(3).WillRepeatedly(Return(480));
142+
EXPECT_CALL(engine, stageHeight()).Times(3).WillRepeatedly(Return(360));
143143
target.setSpriteModel(&spriteModel);
144144
target.loadCostumes();
145145
target.beforeRedraw();

0 commit comments

Comments
 (0)