Skip to content

Commit 7bcc078

Browse files
committed
Add clearGraphicsEffects method to Sprite
1 parent d2e0478 commit 7bcc078

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

include/scratchcpp/sprite.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class LIBSCRATCHCPP_EXPORT Sprite : public Target
6969
double graphicsEffectValue(IGraphicsEffect *effect) const;
7070
void setGraphicsEffectValue(IGraphicsEffect *effect, double value);
7171

72+
void clearGraphicsEffects();
73+
7274
private:
7375
Target *dataSource() const override;
7476
void setXY(double x, double y);

src/scratch/sprite.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,18 @@ void Sprite::setGraphicsEffectValue(IGraphicsEffect *effect, double value)
335335
costume->setGraphicsEffectValue(effect, value);
336336
}
337337

338+
/*! Sets the value of all graphics effects to 0 (clears them). */
339+
void Sprite::clearGraphicsEffects()
340+
{
341+
impl->graphicsEffects.clear();
342+
343+
// TODO: Make currentCostume() return the costume (not index)
344+
auto costume = costumeAt(currentCostume() - 1);
345+
346+
if (costume)
347+
costume->clearGraphicsEffects();
348+
}
349+
338350
Target *Sprite::dataSource() const
339351
{
340352
return impl->cloneRoot;

test/scratch_classes/sprite_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,4 +648,10 @@ TEST(SpriteTest, GraphicsEffects)
648648
sprite.setCurrentCostume(1);
649649
ASSERT_EQ(c1->graphicsEffectValue(&effect1), 48.21);
650650
ASSERT_EQ(c1->graphicsEffectValue(&effect2), -107.08);
651+
652+
sprite.clearGraphicsEffects();
653+
ASSERT_EQ(sprite.graphicsEffectValue(&effect1), 0);
654+
ASSERT_EQ(sprite.graphicsEffectValue(&effect2), 0);
655+
ASSERT_EQ(c1->graphicsEffectValue(&effect1), 0);
656+
ASSERT_EQ(c1->graphicsEffectValue(&effect2), 0);
651657
}

0 commit comments

Comments
 (0)