Skip to content

Commit d2e0478

Browse files
committed
Add clearGraphicsEffects method to Costume
1 parent f0b644f commit d2e0478

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

include/scratchcpp/costume.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class LIBSCRATCHCPP_EXPORT Costume : public Asset
4444
double graphicsEffectValue(IGraphicsEffect *effect) const;
4545
void setGraphicsEffectValue(IGraphicsEffect *effect, double value);
4646

47+
void clearGraphicsEffects();
48+
4749
Broadcast *broadcast();
4850

4951
protected:

src/scratch/costume.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ void Costume::setGraphicsEffectValue(IGraphicsEffect *effect, double value)
133133
impl->updateImage();
134134
}
135135

136+
/*! Clears all graphics effects (this is automatically called by the sprite). */
137+
void Costume::clearGraphicsEffects()
138+
{
139+
bool update = !impl->graphicsEffects.empty();
140+
impl->graphicsEffects.clear();
141+
142+
if (update)
143+
impl->updateImage();
144+
}
145+
136146
/*!
137147
* Returns the Broadcast linked with this costume.
138148
* \note This is used by the "switch backdrop to and wait" block.

test/assets/costume_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,12 @@ TEST_F(CostumeTest, BitmapWithGraphicsEffects)
408408
ASSERT_EQ(bitmap[3][3], 4);
409409
ASSERT_EQ(bitmap[3][4], 4);
410410
ASSERT_EQ(bitmap[3][5], 8);
411+
412+
EXPECT_CALL(*m_imageFormat, width()).WillOnce(Return(0));
413+
EXPECT_CALL(*m_imageFormat, height()).WillOnce(Return(0));
414+
costume.clearGraphicsEffects();
415+
ASSERT_EQ(costume.graphicsEffectValue(&effect1), 0);
416+
ASSERT_EQ(costume.graphicsEffectValue(&effect2), 0);
411417
}
412418

413419
TEST_F(CostumeTest, Broadcast)

0 commit comments

Comments
 (0)