Skip to content

Commit 06ff1e8

Browse files
committed
Request redraw when stage visual properties change
1 parent 174ba6b commit 06ff1e8

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/scratch/target.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <scratchcpp/variable.h>
55
#include <scratchcpp/list.h>
66
#include <scratchcpp/block.h>
7+
#include <scratchcpp/iengine.h>
78

89
#include "target_p.h"
910

@@ -209,6 +210,11 @@ void Target::setCostumeIndex(int newCostumeIndex)
209210
{
210211
if (newCostumeIndex >= 0 && newCostumeIndex < costumes().size())
211212
impl->costumeIndex = newCostumeIndex;
213+
214+
if (isStage()) {
215+
if (impl->engine)
216+
impl->engine->breakFrame();
217+
}
212218
}
213219

214220
/*! Returns the currently set costume. */

test/scratch_classes/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ add_executable(
5151
target_link_libraries(
5252
stage_test
5353
GTest::gtest_main
54+
GTest::gmock_main
5455
scratchcpp
56+
scratchcpp_mocks
5557
)
5658

5759
gtest_discover_tests(stage_test)

test/scratch_classes/stage_test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include <scratchcpp/stage.h>
2+
#include <scratchcpp/costume.h>
3+
#include <enginemock.h>
24

35
#include "../common.h"
46

@@ -10,6 +12,25 @@ TEST(StageTest, IsStage)
1012
ASSERT_TRUE(stage.isStage());
1113
}
1214

15+
TEST(SpriteTest, CostumeIndex)
16+
{
17+
Stage stage;
18+
EngineMock engine;
19+
stage.setEngine(&engine);
20+
EXPECT_CALL(engine, breakFrame()).Times(2);
21+
22+
auto c1 = std::make_shared<Costume>("", "", "");
23+
auto c2 = std::make_shared<Costume>("", "", "");
24+
stage.addCostume(c1);
25+
stage.addCostume(c2);
26+
27+
stage.setCostumeIndex(0);
28+
ASSERT_EQ(stage.costumeIndex(), 0);
29+
30+
stage.setCostumeIndex(1);
31+
ASSERT_EQ(stage.costumeIndex(), 1);
32+
}
33+
1334
TEST(StageTest, Tempo)
1435
{
1536
Stage stage;

0 commit comments

Comments
 (0)