File tree Expand file tree Collapse file tree 4 files changed +69
-0
lines changed
Expand file tree Collapse file tree 4 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,12 @@ class TargetPrivate;
2424class 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
Original file line number Diff line number Diff 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. */
443473IEngine *Target::engine () const
444474{
Original file line number Diff line number Diff line change 88#include < unordered_map>
99#include < scratchcpp/costume.h>
1010#include < scratchcpp/sound.h>
11+ #include < scratchcpp/target.h>
1112
1213namespace 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
Original file line number Diff line number Diff 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+
584608TEST (TargetTest, Engine)
585609{
586610 Target target;
You can’t perform that action at this time.
0 commit comments