Skip to content

Commit 515809d

Browse files
committed
Add costume width and height methods
1 parent 6d77ca3 commit 515809d

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

src/irenderedtarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class IRenderedTarget : public QNanoQuickItem
7878
virtual bool mirrorHorizontally() const = 0;
7979

8080
virtual Texture texture() const = 0;
81+
virtual int costumeWidth() const = 0;
82+
virtual int costumeHeight() const = 0;
8183

8284
virtual const std::unordered_map<ShaderManager::Effect, double> &graphicEffects() const = 0;
8385
virtual void setGraphicEffect(ShaderManager::Effect effect, double value) = 0;

src/renderedtarget.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,22 @@ Texture RenderedTarget::texture() const
529529
return m_texture;
530530
}
531531

532+
int RenderedTarget::costumeWidth() const
533+
{
534+
if (!m_skin || !m_costume)
535+
return 0;
536+
537+
return m_skin->getTexture(1).width() / m_costume->bitmapResolution();
538+
}
539+
540+
int RenderedTarget::costumeHeight() const
541+
{
542+
if (!m_skin || !m_costume)
543+
return 0;
544+
545+
return m_skin->getTexture(1).height() / m_costume->bitmapResolution();
546+
}
547+
532548
const std::unordered_map<ShaderManager::Effect, double> &RenderedTarget::graphicEffects() const
533549
{
534550
return m_graphicEffects;
@@ -591,7 +607,7 @@ bool RenderedTarget::contains(const QPointF &point) const
591607

592608
bool RenderedTarget::containsScratchPoint(double x, double y) const
593609
{
594-
if (!m_engine)
610+
if (!m_engine || !m_skin || !m_costume)
595611
return false;
596612

597613
return containsLocalPoint(mapFromScratchToLocal(QPointF(x, y)));

src/renderedtarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class RenderedTarget : public IRenderedTarget
8686
bool mirrorHorizontally() const override;
8787

8888
Texture texture() const override;
89+
int costumeWidth() const override;
90+
int costumeHeight() const override;
8991

9092
const std::unordered_map<ShaderManager::Effect, double> &graphicEffects() const override;
9193
void setGraphicEffect(ShaderManager::Effect effect, double value) override;

test/mocks/renderedtargetmock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class RenderedTargetMock : public IRenderedTarget
6262
MOCK_METHOD(bool, mirrorHorizontally, (), (const, override));
6363

6464
MOCK_METHOD(Texture, texture, (), (const, override));
65+
MOCK_METHOD(int, costumeWidth, (), (const, override));
66+
MOCK_METHOD(int, costumeHeight, (), (const, override));
6567

6668
MOCK_METHOD((const std::unordered_map<ShaderManager::Effect, double> &), graphicEffects, (), (const, override));
6769
MOCK_METHOD(void, setGraphicEffect, (ShaderManager::Effect effect, double value), (override));

test/renderedtarget/renderedtarget_test.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ TEST_F(RenderedTargetTest, UpdateMethods)
8787
target.beforeRedraw();
8888
ASSERT_EQ(target.width(), 4);
8989
ASSERT_EQ(target.height(), 6);
90+
ASSERT_EQ(target.costumeWidth(), 1);
91+
ASSERT_EQ(target.costumeHeight(), 2);
9092
ASSERT_EQ(target.x(), 263);
9193
ASSERT_EQ(target.y(), 108);
9294
ASSERT_EQ(target.z(), 0);
@@ -125,6 +127,8 @@ TEST_F(RenderedTargetTest, UpdateMethods)
125127

126128
ASSERT_EQ(target.width(), 4);
127129
ASSERT_EQ(target.height(), 6);
130+
ASSERT_EQ(target.costumeWidth(), 1);
131+
ASSERT_EQ(target.costumeHeight(), 2);
128132
ASSERT_EQ(target.x(), 263);
129133
ASSERT_EQ(target.y(), 108);
130134
ASSERT_EQ(target.z(), 3);
@@ -171,6 +175,8 @@ TEST_F(RenderedTargetTest, UpdateMethods)
171175
target.beforeRedraw();
172176
ASSERT_EQ(target.width(), 4);
173177
ASSERT_EQ(target.height(), 6);
178+
ASSERT_EQ(target.costumeWidth(), 1);
179+
ASSERT_EQ(target.costumeHeight(), 2);
174180
ASSERT_EQ(target.x(), 276);
175181
ASSERT_EQ(target.y(), 184);
176182
ASSERT_EQ(target.transformOriginPoint().x(), -23);
@@ -241,6 +247,8 @@ TEST_F(RenderedTargetTest, UpdateMethods)
241247
target.beforeRedraw();
242248
ASSERT_EQ(target.width(), 4);
243249
ASSERT_EQ(target.height(), 6);
250+
ASSERT_EQ(target.costumeWidth(), 1);
251+
ASSERT_EQ(target.costumeHeight(), 2);
244252
ASSERT_EQ(target.x(), 379.5);
245253
ASSERT_EQ(target.y(), 384);
246254
ASSERT_EQ(target.transformOriginPoint().x(), 0);
@@ -263,6 +271,8 @@ TEST_F(RenderedTargetTest, UpdateMethods)
263271

264272
ASSERT_EQ(target.width(), 26);
265273
ASSERT_EQ(target.height(), 26);
274+
ASSERT_EQ(target.costumeWidth(), 13);
275+
ASSERT_EQ(target.costumeHeight(), 13);
266276
ASSERT_EQ(target.x(), 329.5);
267277
ASSERT_EQ(target.y(), 400);
268278
ASSERT_EQ(target.z(), 3);
@@ -277,13 +287,17 @@ TEST_F(RenderedTargetTest, UpdateMethods)
277287
ASSERT_TRUE(texture.isValid());
278288
ASSERT_EQ(texture.width(), 26);
279289
ASSERT_EQ(texture.height(), 26);
290+
ASSERT_EQ(target.costumeWidth(), 13);
291+
ASSERT_EQ(target.costumeHeight(), 13);
280292

281293
// Stage scale (SVG) - should update width and height
282294
EXPECT_CALL(engine, stageWidth()).WillOnce(Return(480));
283295
EXPECT_CALL(engine, stageHeight()).WillOnce(Return(360));
284296
target.setStageScale(3.5);
285297
ASSERT_EQ(target.width(), 52);
286298
ASSERT_EQ(target.height(), 52);
299+
ASSERT_EQ(target.costumeWidth(), 13);
300+
ASSERT_EQ(target.costumeHeight(), 13);
287301

288302
context.doneCurrent();
289303
}

0 commit comments

Comments
 (0)