Skip to content

Commit ca60d5a

Browse files
committed
Add graphics effect methods to ISpriteHandler
1 parent 575a8ed commit ca60d5a

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

include/scratchcpp/ispritehandler.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ class LIBSCRATCHCPP_EXPORT ISpriteHandler
4141
/*! Called when the rotation style changes. */
4242
virtual void onRotationStyleChanged(Sprite::RotationStyle rotationStyle) = 0;
4343

44+
/*!
45+
* Called when the value of the given graphics effect changes.
46+
* \note This method isn't called when all effects are cleared, use onGraphicsEffectsCleared() for this.
47+
*/
48+
virtual void onGraphicsEffectChanged(IGraphicsEffect *effect, double value) = 0;
49+
50+
/*! Called when all graphics effects are cleared. */
51+
virtual void onGraphicsEffectsCleared() = 0;
52+
4453
/*!
4554
* Used to get the bounding rectangle of the sprite.
4655
* \note The rectangle must be relative to the stage, so make sure to use the sprite's coordinates.

src/scratch/sprite.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ void Sprite::setGraphicsEffectValue(IGraphicsEffect *effect, double value)
411411
if (eng)
412412
eng->requestRedraw();
413413
}
414+
415+
if (impl->iface)
416+
impl->iface->onGraphicsEffectChanged(effect, value);
414417
}
415418

416419
/*! Overrides Target#clearGraphicsEffects(). */
@@ -424,6 +427,9 @@ void Sprite::clearGraphicsEffects()
424427
if (eng)
425428
eng->requestRedraw();
426429
}
430+
431+
if (impl->iface)
432+
impl->iface->onGraphicsEffectsCleared();
427433
}
428434

429435
Target *Sprite::dataSource() const

test/mocks/spritehandlermock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ class SpriteHandlerMock : public ISpriteHandler
2020
MOCK_METHOD(void, onSizeChanged, (double), (override));
2121
MOCK_METHOD(void, onDirectionChanged, (double), (override));
2222
MOCK_METHOD(void, onRotationStyleChanged, (Sprite::RotationStyle), (override));
23+
MOCK_METHOD(void, onGraphicsEffectChanged, (IGraphicsEffect *, double), (override));
24+
MOCK_METHOD(void, onGraphicsEffectsCleared, (), (override));
25+
2326
MOCK_METHOD(Rect, boundingRect, (), (const, override));
2427
};

test/target_interfaces/ispritehandler_test.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <scratchcpp/rect.h>
33
#include <spritehandlermock.h>
44
#include <enginemock.h>
5+
#include <graphicseffectmock.h>
56

67
#include "../common.h"
78

@@ -130,6 +131,19 @@ TEST_F(ISpriteHandlerTest, Costume)
130131
m_sprite.setCostumeIndex(1);
131132
}
132133

134+
TEST_F(ISpriteHandlerTest, GraphicsEffects)
135+
{
136+
GraphicsEffectMock effect;
137+
138+
EXPECT_CALL(m_handler, onGraphicsEffectChanged(&effect, 16.7));
139+
EXPECT_CALL(m_engine, requestRedraw());
140+
m_sprite.setGraphicsEffectValue(&effect, 16.7);
141+
142+
EXPECT_CALL(m_handler, onGraphicsEffectsCleared());
143+
EXPECT_CALL(m_engine, requestRedraw());
144+
m_sprite.clearGraphicsEffects();
145+
}
146+
133147
TEST_F(ISpriteHandlerTest, BoundingRect)
134148
{
135149
EXPECT_CALL(m_handler, boundingRect()).WillOnce(Return(Rect(-44.6, 89.1, 20.5, -0.48)));

0 commit comments

Comments
 (0)