Skip to content

Commit 6aeaef2

Browse files
committed
Add mask param to touchingColor() in target handlers
1 parent eea2f63 commit 6aeaef2

File tree

6 files changed

+20
-10
lines changed

6 files changed

+20
-10
lines changed

include/scratchcpp/ispritehandler.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "global.h"
66
#include "sprite.h"
7+
#include "value.h"
78

89
namespace libscratchcpp
910
{
@@ -90,8 +91,11 @@ class LIBSCRATCHCPP_EXPORT ISpriteHandler
9091
/*! Used to check whether the sprite touches the given point (in Scratch coordinates). */
9192
virtual bool touchingPoint(double x, double y) const = 0;
9293

93-
/*! Used to check whether the sprite touches the given color. */
94-
virtual bool touchingColor(const Value &color) const = 0;
94+
/*!
95+
* Used to check whether the sprite touches the given color.
96+
* \param[in] mask Optionally mask the check to this part of the Target.
97+
*/
98+
virtual bool touchingColor(const Value &color, const Value &mask = 0) const = 0;
9599
};
96100

97101
} // namespace libscratchcpp

include/scratchcpp/istagehandler.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "global.h"
66
#include "stage.h"
7+
#include "value.h"
78

89
namespace libscratchcpp
910
{
@@ -67,8 +68,11 @@ class LIBSCRATCHCPP_EXPORT IStageHandler
6768
/*! Used to check whether the stage touches the given point (in Scratch coordinates). */
6869
virtual bool touchingPoint(double x, double y) const = 0;
6970

70-
/*! Used to check whether the stage touches the given color. */
71-
virtual bool touchingColor(const Value &color) const = 0;
71+
/*!
72+
* Used to check whether the sprite touches the given color.
73+
* \param[in] mask Optionally mask the check to this part of the Target.
74+
*/
75+
virtual bool touchingColor(const Value &color, const Value &mask = 0) const = 0;
7276
};
7377

7478
} // namespace libscratchcpp

test/mocks/spritehandlermock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ class SpriteHandlerMock : public ISpriteHandler
3737

3838
MOCK_METHOD(bool, touchingClones, (const std::vector<Sprite *> &), (const, override));
3939
MOCK_METHOD(bool, touchingPoint, (double, double), (const, override));
40-
MOCK_METHOD(bool, touchingColor, (const Value &), (const, override));
40+
MOCK_METHOD(bool, touchingColor, (const Value &, const Value &), (const, override));
4141
};

test/mocks/stagehandlermock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ class StageHandlerMock : public IStageHandler
2828

2929
MOCK_METHOD(bool, touchingClones, (const std::vector<Sprite *> &), (const, override));
3030
MOCK_METHOD(bool, touchingPoint, (double, double), (const, override));
31-
MOCK_METHOD(bool, touchingColor, (const Value &), (const, override));
31+
MOCK_METHOD(bool, touchingColor, (const Value &, const Value &), (const, override));
3232
};

test/scratch_classes/sprite_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,12 @@ TEST(SpriteTest, TouchingColor)
830830
EXPECT_CALL(iface, init);
831831
sprite.setInterface(&iface);
832832

833+
Value zero = 0;
833834
Value v1 = 4278228630, v2 = "#FF00FA";
834-
EXPECT_CALL(iface, touchingColor(v1)).WillOnce(Return(false));
835+
EXPECT_CALL(iface, touchingColor(v1, zero)).WillOnce(Return(false));
835836
ASSERT_FALSE(sprite.touchingColor(v1));
836837

837-
EXPECT_CALL(iface, touchingColor(v2)).WillOnce(Return(true));
838+
EXPECT_CALL(iface, touchingColor(v2, zero)).WillOnce(Return(true));
838839
ASSERT_TRUE(sprite.touchingColor(v2));
839840
}
840841

test/scratch_classes/stage_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,12 @@ TEST(SpriteTest, TouchingColor)
227227
EXPECT_CALL(iface, init);
228228
stage.setInterface(&iface);
229229

230+
Value zero = 0;
230231
Value v1 = 4278228630, v2 = "#FF00FA";
231-
EXPECT_CALL(iface, touchingColor(v1)).WillOnce(Return(false));
232+
EXPECT_CALL(iface, touchingColor(v1, zero)).WillOnce(Return(false));
232233
ASSERT_FALSE(stage.touchingColor(v1));
233234

234-
EXPECT_CALL(iface, touchingColor(v2)).WillOnce(Return(true));
235+
EXPECT_CALL(iface, touchingColor(v2, zero)).WillOnce(Return(true));
235236
ASSERT_TRUE(stage.touchingColor(v2));
236237
}
237238

0 commit comments

Comments
 (0)