Skip to content

Commit 0353b33

Browse files
committed
Add touchingColor() method
1 parent ff467df commit 0353b33

File tree

14 files changed

+79
-0
lines changed

14 files changed

+79
-0
lines changed

include/scratchcpp/ispritehandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class LIBSCRATCHCPP_EXPORT ISpriteHandler
8383

8484
/*! Used to check whether the sprite touches the given point (in Scratch coordinates). */
8585
virtual bool touchingPoint(double x, double y) const = 0;
86+
87+
/*! Used to check whether the sprite touches the given color. */
88+
virtual bool touchingColor(const Value &color) const = 0;
8689
};
8790

8891
} // namespace libscratchcpp

include/scratchcpp/istagehandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class LIBSCRATCHCPP_EXPORT IStageHandler
6060

6161
/*! Used to check whether the stage touches the given point (in Scratch coordinates). */
6262
virtual bool touchingPoint(double x, double y) const = 0;
63+
64+
/*! Used to check whether the stage touches the given color. */
65+
virtual bool touchingColor(const Value &color) const = 0;
6366
};
6467

6568
} // namespace libscratchcpp

include/scratchcpp/sprite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class LIBSCRATCHCPP_EXPORT Sprite
7373
void keepInFence(double newX, double newY, double *fencedX, double *fencedY) const;
7474

7575
bool touchingPoint(double x, double y) const override;
76+
bool touchingColor(const Value &color) const override;
7677

7778
void setGraphicsEffectValue(IGraphicsEffect *effect, double value) override;
7879

include/scratchcpp/stage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class LIBSCRATCHCPP_EXPORT Stage : public Target
5252
Rect fastBoundingRect() const override;
5353

5454
bool touchingPoint(double x, double y) const override;
55+
bool touchingColor(const Value &color) const override;
5556

5657
void setGraphicsEffectValue(IGraphicsEffect *effect, double value) override;
5758

include/scratchcpp/target.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class LIBSCRATCHCPP_EXPORT Target
9292
bool touchingSprite(Sprite *sprite) const;
9393
virtual bool touchingPoint(double x, double y) const;
9494
bool touchingEdge() const;
95+
virtual bool touchingColor(const Value &color) const;
9596

9697
double graphicsEffectValue(IGraphicsEffect *effect) const;
9798
virtual void setGraphicsEffectValue(IGraphicsEffect *effect, double value);

src/scratch/sprite.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,15 @@ bool Sprite::touchingPoint(double x, double y) const
415415
return impl->iface->touchingPoint(x, y);
416416
}
417417

418+
/*! Overrides Target#touchingColor(). */
419+
bool Sprite::touchingColor(const Value &color) const
420+
{
421+
if (!impl->iface)
422+
return false;
423+
424+
return impl->iface->touchingColor(color);
425+
}
426+
418427
/*! Overrides Target#setGraphicsEffectValue(). */
419428
void Sprite::setGraphicsEffectValue(IGraphicsEffect *effect, double value)
420429
{

src/scratch/stage.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ bool Stage::touchingPoint(double x, double y) const
158158
return impl->iface->touchingPoint(x, y);
159159
}
160160

161+
/*! Overrides Target#touchingColor(). */
162+
bool Stage::touchingColor(const Value &color) const
163+
{
164+
if (!impl->iface)
165+
return false;
166+
167+
return impl->iface->touchingColor(color);
168+
}
169+
161170
/*! Overrides Target#setGraphicsEffectValue(). */
162171
void Stage::setGraphicsEffectValue(IGraphicsEffect *effect, double value)
163172
{

src/scratch/target.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,12 @@ bool Target::touchingEdge() const
476476
return false;
477477
}
478478

479+
/*! Returns true if the Target is touching the given color (RGB triplet). */
480+
bool Target::touchingColor(const Value &color) const
481+
{
482+
return false;
483+
}
484+
479485
/*! Returns the value of the given graphics effect. */
480486
double Target::graphicsEffectValue(IGraphicsEffect *effect) const
481487
{

test/mocks/spritehandlermock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ class SpriteHandlerMock : public ISpriteHandler
3434

3535
MOCK_METHOD(bool, touchingClones, (const std::vector<Sprite *> &), (const, override));
3636
MOCK_METHOD(bool, touchingPoint, (double, double), (const, override));
37+
MOCK_METHOD(bool, touchingColor, (const Value &), (const, override));
3738
};

test/mocks/stagehandlermock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ class StageHandlerMock : public IStageHandler
2525

2626
MOCK_METHOD(bool, touchingClones, (const std::vector<Sprite *> &), (const, override));
2727
MOCK_METHOD(bool, touchingPoint, (double, double), (const, override));
28+
MOCK_METHOD(bool, touchingColor, (const Value &), (const, override));
2829
};

0 commit comments

Comments
 (0)