Skip to content

Commit 3cdfe5c

Browse files
committed
Add type identification methods to Drawable
1 parent cc14eae commit 3cdfe5c

File tree

8 files changed

+58
-0
lines changed

8 files changed

+58
-0
lines changed

include/scratchcpp/drawable.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ class LIBSCRATCHCPP_EXPORT Drawable
1717
Drawable();
1818
Drawable(const Drawable &) = delete;
1919

20+
/*! Returns true if this Drawable is a Target. */
21+
virtual bool isTarget() const { return false; }
22+
23+
/*! Returns true if this Drawable is a TextBubble. */
24+
virtual bool isTextBubble() const { return false; }
25+
2026
int layerOrder() const;
2127
virtual void setLayerOrder(int newLayerOrder);
2228

include/scratchcpp/target.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class LIBSCRATCHCPP_EXPORT Target : public Drawable
3131
Target(const Target &) = delete;
3232
virtual ~Target() { }
3333

34+
bool isTarget() const override final;
35+
3436
/*! Returns true if this Target is the stage. */
3537
virtual bool isStage() const { return false; }
3638

include/scratchcpp/textbubble.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class TextBubble : public Drawable
2323
TextBubble();
2424
TextBubble(const TextBubble &) = delete;
2525

26+
bool isTextBubble() const override final;
27+
2628
Type type() const;
2729
virtual void setType(Type type);
2830
sigslot::signal<Type> &typeChanged() const;

src/scratch/target.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ Target::Target() :
2929
{
3030
}
3131

32+
/*! Returns true. */
33+
bool Target::isTarget() const
34+
{
35+
return true;
36+
}
37+
3238
/*! Returns the name of the target. */
3339
const std::string &Target::name() const
3440
{

src/scratch/textbubble.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ TextBubble::TextBubble() :
1313
{
1414
}
1515

16+
/*! Returns true. */
17+
bool TextBubble::isTextBubble() const
18+
{
19+
return true;
20+
}
21+
1622
/*! Returns the type of the TextBubble (say or think). */
1723
TextBubble::Type TextBubble::type() const
1824
{

test/scratch_classes/drawable_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
using namespace libscratchcpp;
66

7+
TEST(DrawableTest, IsTarget)
8+
{
9+
Drawable drawable;
10+
ASSERT_FALSE(drawable.isTarget());
11+
}
12+
13+
TEST(DrawableTest, IsTextBubble)
14+
{
15+
Drawable drawable;
16+
ASSERT_FALSE(drawable.isTextBubble());
17+
}
18+
719
TEST(DrawableTest, LayerOrder)
820
{
921
Drawable drawable;

test/scratch_classes/target_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ using ::testing::WithArgs;
2525
using ::testing::Invoke;
2626
using ::testing::_;
2727

28+
TEST(TargetTest, IsTarget)
29+
{
30+
Target target;
31+
ASSERT_TRUE(target.isTarget());
32+
}
33+
34+
TEST(TargetTest, IsTextBubble)
35+
{
36+
Target target;
37+
ASSERT_FALSE(target.isTextBubble());
38+
}
39+
2840
TEST(TargetTest, IsStage)
2941
{
3042
Target target;

test/scratch_classes/textbubble_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
using namespace libscratchcpp;
66

7+
TEST(TextBubbleTest, IsTarget)
8+
{
9+
TextBubble bubble;
10+
ASSERT_FALSE(bubble.isTarget());
11+
}
12+
13+
TEST(TextBubbleTest, IsTextBubble)
14+
{
15+
TextBubble bubble;
16+
ASSERT_TRUE(bubble.isTextBubble());
17+
}
18+
719
TEST(TextBubbleTest, BubbleType)
820
{
921
TextBubble bubble;

0 commit comments

Comments
 (0)