Skip to content

Commit 008c920

Browse files
committed
Set engine of text bubbles in Target
1 parent 6461c47 commit 008c920

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

include/scratchcpp/drawable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LIBSCRATCHCPP_EXPORT Drawable
2929
virtual void setLayerOrder(int newLayerOrder);
3030

3131
IEngine *engine() const;
32-
void setEngine(IEngine *engine);
32+
virtual void setEngine(IEngine *engine);
3333

3434
private:
3535
spimpl::unique_impl_ptr<DrawablePrivate> impl;

include/scratchcpp/target.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class LIBSCRATCHCPP_EXPORT Target : public Drawable
103103
TextBubble *bubble();
104104
const TextBubble *bubble() const;
105105

106+
void setEngine(IEngine *engine) override final;
107+
106108
protected:
107109
/*! Override this method to set a custom data source for blocks, assets, comments, etc. */
108110
virtual Target *dataSource() const { return nullptr; }

src/scratch/target.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,10 @@ const TextBubble *Target::bubble() const
572572
{
573573
return &impl->bubble;
574574
}
575+
576+
/*! Overrides Drawable#setEngine(). */
577+
void Target::setEngine(IEngine *engine)
578+
{
579+
Drawable::setEngine(engine);
580+
impl->bubble.setEngine(engine);
581+
}

test/scratch_classes/target_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,18 @@ TEST(SpriteTest, BubbleTextRedraw)
797797
target.bubble()->setText("");
798798
}
799799

800+
TEST(TargetTest, Engine)
801+
{
802+
Target target;
803+
ASSERT_EQ(target.engine(), nullptr);
804+
ASSERT_EQ(target.bubble()->engine(), nullptr);
805+
806+
EngineMock engine;
807+
target.setEngine(&engine);
808+
ASSERT_EQ(target.engine(), &engine);
809+
ASSERT_EQ(target.bubble()->engine(), &engine);
810+
}
811+
800812
TEST(TargetTest, DataSource)
801813
{
802814
TargetMock target;

0 commit comments

Comments
 (0)