Skip to content

Commit 7cbc2ec

Browse files
committed
Add bubble API to Target
1 parent 89240e7 commit 7cbc2ec

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

include/scratchcpp/target.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ class TargetPrivate;
2424
class LIBSCRATCHCPP_EXPORT Target
2525
{
2626
public:
27+
enum class BubbleType
28+
{
29+
Say,
30+
Think
31+
};
32+
2733
Target();
2834
Target(const Target &) = delete;
2935
virtual ~Target() { }
@@ -83,6 +89,12 @@ class LIBSCRATCHCPP_EXPORT Target
8389

8490
virtual void clearGraphicsEffects();
8591

92+
BubbleType bubbleType() const;
93+
virtual void setBubbleType(BubbleType type);
94+
95+
const std::string &bubbleText() const;
96+
virtual void setBubbleText(const std::string &text);
97+
8698
IEngine *engine() const;
8799
void setEngine(IEngine *engine);
88100

src/scratch/target.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,36 @@ void Target::clearGraphicsEffects()
439439
impl->graphicsEffects.clear();
440440
}
441441

442+
/*! Returns the type of the bubble (say or think). */
443+
Target::BubbleType Target::bubbleType() const
444+
{
445+
return impl->bubbleType;
446+
}
447+
448+
/*! Sets the type of the bubble (say or think). */
449+
void Target::setBubbleType(BubbleType type)
450+
{
451+
impl->bubbleType = type;
452+
}
453+
454+
/*!
455+
* Returns the text of the bubble.
456+
* \note If the text is an empty string, the bubble is supposed to be hidden.
457+
*/
458+
const std::string &Target::bubbleText() const
459+
{
460+
return impl->bubbleText;
461+
}
462+
463+
/*!
464+
* Sets the text of the bubble.
465+
* \note If the text is an empty string, the bubble is supposed to be hidden.
466+
*/
467+
void Target::setBubbleText(const std::string &text)
468+
{
469+
impl->bubbleText = text;
470+
}
471+
442472
/*! Returns the engine. */
443473
IEngine *Target::engine() const
444474
{

src/scratch/target_p.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <unordered_map>
99
#include <scratchcpp/costume.h>
1010
#include <scratchcpp/sound.h>
11+
#include <scratchcpp/target.h>
1112

1213
namespace libscratchcpp
1314
{
@@ -36,6 +37,8 @@ struct TargetPrivate
3637
int layerOrder = 0;
3738
double volume = 100;
3839
std::unordered_map<IGraphicsEffect *, double> graphicsEffects;
40+
Target::BubbleType bubbleType = Target::BubbleType::Say;
41+
std::string bubbleText;
3942
};
4043

4144
} // namespace libscratchcpp

test/scratch_classes/target_test.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,30 @@ TEST(TargetTest, GraphicsEffects)
581581
ASSERT_EQ(target.graphicsEffectValue(&effect2), 0);
582582
}
583583

584+
TEST(TargetTest, BubbleType)
585+
{
586+
Target target;
587+
ASSERT_EQ(target.bubbleType(), Target::BubbleType::Say);
588+
589+
target.setBubbleType(Target::BubbleType::Think);
590+
ASSERT_EQ(target.bubbleType(), Target::BubbleType::Think);
591+
592+
target.setBubbleType(Target::BubbleType::Say);
593+
ASSERT_EQ(target.bubbleType(), Target::BubbleType::Say);
594+
}
595+
596+
TEST(TargetTest, BubbleText)
597+
{
598+
Target target;
599+
ASSERT_TRUE(target.bubbleText().empty());
600+
601+
target.setBubbleText("hello");
602+
ASSERT_EQ(target.bubbleText(), "hello");
603+
604+
target.setBubbleText("world");
605+
ASSERT_EQ(target.bubbleText(), "world");
606+
}
607+
584608
TEST(TargetTest, Engine)
585609
{
586610
Target target;

0 commit comments

Comments
 (0)