Skip to content

Commit c9d1802

Browse files
committed
Add methods for costume width and height
1 parent d9a7b76 commit c9d1802

File tree

14 files changed

+134
-0
lines changed

14 files changed

+134
-0
lines changed

include/scratchcpp/ispritehandler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ class LIBSCRATCHCPP_EXPORT ISpriteHandler
6565
/*! Called when the bubble text changes. */
6666
virtual void onBubbleTextChanged(const std::string &text) = 0;
6767

68+
/*! Used to get the current costume width. */
69+
virtual int costumeWidth() const = 0;
70+
71+
/*! Used to get the current costume height. */
72+
virtual int costumeHeight() const = 0;
73+
6874
/*!
6975
* Used to get the bounding rectangle of the sprite.
7076
* \note The rectangle must be relative to the stage, so make sure to use the sprite's coordinates.

include/scratchcpp/istagehandler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ class LIBSCRATCHCPP_EXPORT IStageHandler
4646
/*! Called when the bubble text changes. */
4747
virtual void onBubbleTextChanged(const std::string &text) = 0;
4848

49+
/*! Used to get the current costume width. */
50+
virtual int costumeWidth() const = 0;
51+
52+
/*! Used to get the current costume height. */
53+
virtual int costumeHeight() const = 0;
54+
4955
/*! Used to get the bounding rectangle of the stage. */
5056
virtual Rect boundingRect() const = 0;
5157

include/scratchcpp/sprite.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class LIBSCRATCHCPP_EXPORT Sprite
5959

6060
void setCostumeIndex(int newCostumeIndex) override;
6161

62+
int currentCostumeWidth() const override;
63+
int currentCostumeHeight() const override;
64+
6265
double direction() const;
6366
void setDirection(double newDirection);
6467

include/scratchcpp/stage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class LIBSCRATCHCPP_EXPORT Stage : public Target
3333

3434
void setCostumeIndex(int newCostumeIndex) override;
3535

36+
int currentCostumeWidth() const override;
37+
int currentCostumeHeight() const override;
38+
3639
int tempo() const;
3740
void setTempo(int newTempo);
3841

include/scratchcpp/target.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class LIBSCRATCHCPP_EXPORT Target
6969
virtual void setCostumeIndex(int newCostumeIndex);
7070

7171
std::shared_ptr<Costume> currentCostume() const;
72+
virtual int currentCostumeWidth() const;
73+
virtual int currentCostumeHeight() const;
7274

7375
const std::vector<std::shared_ptr<Costume>> &costumes() const;
7476
int addCostume(std::shared_ptr<Costume> costume);

src/scratch/sprite.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,24 @@ void Sprite::setCostumeIndex(int newCostumeIndex)
288288
impl->iface->onCostumeChanged(costume.get());
289289
}
290290

291+
/*! Overrides Target#currentCostumeWidth(). */
292+
int Sprite::currentCostumeWidth() const
293+
{
294+
if (!impl->iface)
295+
return 0;
296+
297+
return impl->iface->costumeWidth();
298+
}
299+
300+
/*! Overrides Target#currentCostumeHeight(). */
301+
int Sprite::currentCostumeHeight() const
302+
{
303+
if (!impl->iface)
304+
return 0;
305+
306+
return impl->iface->costumeHeight();
307+
}
308+
291309
/*! Returns the direction. */
292310
double Sprite::direction() const
293311
{

src/scratch/stage.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ void Stage::setCostumeIndex(int newCostumeIndex)
4646
impl->iface->onCostumeChanged(costume.get());
4747
}
4848

49+
/*! Overrides Target#currentCostumeWidth(). */
50+
int Stage::currentCostumeWidth() const
51+
{
52+
if (!impl->iface)
53+
return 0;
54+
55+
return impl->iface->costumeWidth();
56+
}
57+
58+
/*! Overrides Target#currentCostumeHeight(). */
59+
int Stage::currentCostumeHeight() const
60+
{
61+
if (!impl->iface)
62+
return 0;
63+
64+
return impl->iface->costumeHeight();
65+
}
66+
4967
/*! Returns the tempo. */
5068
int Stage::tempo() const
5169
{

src/scratch/target.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ std::shared_ptr<Costume> Target::currentCostume() const
278278
return costumeAt(impl->costumeIndex);
279279
}
280280

281+
/*! Returns the width of the current costume. */
282+
int Target::currentCostumeWidth() const
283+
{
284+
return 0;
285+
}
286+
287+
/*! Returns the height of the current costume. */
288+
int Target::currentCostumeHeight() const
289+
{
290+
return 0;
291+
}
292+
281293
/*! Returns the list of costumes. */
282294
const std::vector<std::shared_ptr<Costume>> &Target::costumes() const
283295
{

test/mocks/spritehandlermock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class SpriteHandlerMock : public ISpriteHandler
2929
MOCK_METHOD(void, onBubbleTypeChanged, (Target::BubbleType), (override));
3030
MOCK_METHOD(void, onBubbleTextChanged, (const std::string &), (override));
3131

32+
MOCK_METHOD(int, costumeWidth, (), (const, override));
33+
MOCK_METHOD(int, costumeHeight, (), (const, override));
34+
3235
MOCK_METHOD(Rect, boundingRect, (), (const, override));
3336
MOCK_METHOD(Rect, fastBoundingRect, (), (const, override));
3437

test/mocks/stagehandlermock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class StageHandlerMock : public IStageHandler
2020
MOCK_METHOD(void, onBubbleTypeChanged, (Target::BubbleType), (override));
2121
MOCK_METHOD(void, onBubbleTextChanged, (const std::string &), (override));
2222

23+
MOCK_METHOD(int, costumeWidth, (), (const, override));
24+
MOCK_METHOD(int, costumeHeight, (), (const, override));
25+
2326
MOCK_METHOD(Rect, boundingRect, (), (const, override));
2427
MOCK_METHOD(Rect, fastBoundingRect, (), (const, override));
2528

0 commit comments

Comments
 (0)