Skip to content

Commit a6069ae

Browse files
committed
Use Rgb in touching methods
1 parent 09c2b0d commit a6069ae

File tree

16 files changed

+56
-54
lines changed

16 files changed

+56
-54
lines changed

include/scratchcpp/ispritehandler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ class LIBSCRATCHCPP_EXPORT ISpriteHandler
8585
virtual bool touchingPoint(double x, double y) const = 0;
8686

8787
/*! Used to check whether the sprite touches the given color. */
88-
virtual bool touchingColor(const Value &color) const = 0;
88+
virtual bool touchingColor(Rgb color) const = 0;
8989

9090
/*! Used to check whether the mask part of the sprite touches the given color. */
91-
virtual bool touchingColor(const Value &color, const Value &mask) const = 0;
91+
virtual bool touchingColor(Rgb color, Rgb mask) const = 0;
9292
};
9393

9494
} // namespace libscratchcpp

include/scratchcpp/istagehandler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ class LIBSCRATCHCPP_EXPORT IStageHandler
6262
virtual bool touchingPoint(double x, double y) const = 0;
6363

6464
/*! Used to check whether the stage touches the given color. */
65-
virtual bool touchingColor(const Value &color) const = 0;
65+
virtual bool touchingColor(Rgb color) const = 0;
6666

6767
/*! Used to check whether the mask part of the stage touches the given color. */
68-
virtual bool touchingColor(const Value &color, const Value &mask) const = 0;
68+
virtual bool touchingColor(Rgb color, Rgb mask) const = 0;
6969
};
7070

7171
} // namespace libscratchcpp

include/scratchcpp/sprite.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class LIBSCRATCHCPP_EXPORT Sprite
8181
void keepInFence(double newX, double newY, double *fencedX, double *fencedY) const;
8282

8383
bool touchingPoint(double x, double y) const override;
84-
bool touchingColor(const Value &color) const override;
85-
bool touchingColor(const Value &color, const Value &mask) const override;
84+
bool touchingColor(Rgb color) const override;
85+
bool touchingColor(Rgb color, Rgb mask) const override;
8686

8787
void setGraphicsEffectValue(IGraphicsEffect *effect, double value) override;
8888

include/scratchcpp/stage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class LIBSCRATCHCPP_EXPORT Stage : public Target
5555
Rect fastBoundingRect() const override;
5656

5757
bool touchingPoint(double x, double y) const override;
58-
bool touchingColor(const Value &color) const override;
59-
bool touchingColor(const Value &color, const Value &mask) const override;
58+
bool touchingColor(Rgb color) const override;
59+
bool touchingColor(Rgb color, Rgb mask) const override;
6060

6161
void setGraphicsEffectValue(IGraphicsEffect *effect, double value) override;
6262

include/scratchcpp/target.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma once
44

55
#include <vector>
6+
#include <scratchcpp/value_functions.h>
67

78
#include "drawable.h"
89
#include "rect.h"
@@ -12,7 +13,6 @@ namespace libscratchcpp
1213
{
1314

1415
class Variable;
15-
struct ValueData;
1616
class List;
1717
class Block;
1818
class Comment;
@@ -97,8 +97,8 @@ class LIBSCRATCHCPP_EXPORT Target : public Drawable
9797
bool touchingSprite(Sprite *sprite) const;
9898
virtual bool touchingPoint(double x, double y) const;
9999
bool touchingEdge() const;
100-
virtual bool touchingColor(const Value &color) const;
101-
virtual bool touchingColor(const Value &color, const Value &mask) const;
100+
virtual bool touchingColor(Rgb color) const;
101+
virtual bool touchingColor(Rgb color, Rgb mask) const;
102102

103103
double graphicsEffectValue(IGraphicsEffect *effect) const;
104104
virtual void setGraphicsEffectValue(IGraphicsEffect *effect, double value);

src/blocks/sensingblocks.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,13 @@ unsigned int SensingBlocks::touchingEdge(VirtualMachine *vm)
538538

539539
unsigned int SensingBlocks::touchingColor(VirtualMachine *vm)
540540
{
541-
vm->replaceReturnValue(vm->target()->touchingColor(*vm->getInput(0, 1)), 1);
541+
vm->replaceReturnValue(vm->target()->touchingColor(vm->getInput(0, 1)->toRgba()), 1);
542542
return 0;
543543
}
544544

545545
unsigned int SensingBlocks::colorIsTouchingColor(VirtualMachine *vm)
546546
{
547-
vm->replaceReturnValue(vm->target()->touchingColor(*vm->getInput(0, 2), *vm->getInput(1, 2)), 2);
547+
vm->replaceReturnValue(vm->target()->touchingColor(vm->getInput(0, 2)->toRgba(), vm->getInput(1, 2)->toRgba()), 2);
548548
return 1;
549549
}
550550

src/scratch/sprite.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ bool Sprite::touchingPoint(double x, double y) const
504504
}
505505

506506
/*! Overrides Target#touchingColor(). */
507-
bool Sprite::touchingColor(const Value &color) const
507+
bool Sprite::touchingColor(Rgb color) const
508508
{
509509
if (!impl->iface)
510510
return false;
@@ -513,7 +513,7 @@ bool Sprite::touchingColor(const Value &color) const
513513
}
514514

515515
/*! Overrides Target#touchingColor(). */
516-
bool Sprite::touchingColor(const Value &color, const Value &mask) const
516+
bool Sprite::touchingColor(Rgb color, Rgb mask) const
517517
{
518518
if (!impl->iface)
519519
return false;

src/scratch/stage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ bool Stage::touchingPoint(double x, double y) const
186186
}
187187

188188
/*! Overrides Target#touchingColor(). */
189-
bool Stage::touchingColor(const Value &color) const
189+
bool Stage::touchingColor(Rgb color) const
190190
{
191191
if (!impl->iface)
192192
return false;
@@ -195,7 +195,7 @@ bool Stage::touchingColor(const Value &color) const
195195
}
196196

197197
/*! Overrides Target#touchingColor(). */
198-
bool Stage::touchingColor(const Value &color, const Value &mask) const
198+
bool Stage::touchingColor(Rgb color, Rgb mask) const
199199
{
200200
if (!impl->iface)
201201
return false;

src/scratch/target.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,13 @@ bool Target::touchingEdge() const
588588
}
589589

590590
/*! Returns true if the Target is touching the given color (RGB triplet). */
591-
bool Target::touchingColor(const Value &color) const
591+
bool Target::touchingColor(Rgb color) const
592592
{
593593
return false;
594594
}
595595

596596
/*! Returns true if the mask part of the Target is touching the given color (RGB triplet). */
597-
bool Target::touchingColor(const Value &color, const Value &mask) const
597+
bool Target::touchingColor(Rgb color, Rgb mask) const
598598
{
599599
return false;
600600
}

test/blocks/sensing_blocks_test.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,29 +422,29 @@ TEST_F(SensingBlocksTest, TouchingColorImpl)
422422
vm.setFunctions(functions);
423423
vm.setConstValues(constValues);
424424

425-
EXPECT_CALL(target, touchingColor(constValues[0])).WillOnce(Return(false));
425+
EXPECT_CALL(target, touchingColor(constValues[0].toRgba())).WillOnce(Return(false));
426426
vm.setBytecode(bytecode1);
427427
vm.run();
428428

429429
ASSERT_EQ(vm.registerCount(), 1);
430430
ASSERT_FALSE(vm.getInput(0, 1)->toBool());
431431

432-
EXPECT_CALL(target, touchingColor(constValues[0])).WillOnce(Return(true));
432+
EXPECT_CALL(target, touchingColor(constValues[0].toRgba())).WillOnce(Return(true));
433433
vm.reset();
434434
vm.run();
435435

436436
ASSERT_EQ(vm.registerCount(), 1);
437437
ASSERT_TRUE(vm.getInput(0, 1)->toBool());
438438

439-
EXPECT_CALL(target, touchingColor(constValues[1])).WillOnce(Return(false));
439+
EXPECT_CALL(target, touchingColor(constValues[1].toRgba())).WillOnce(Return(false));
440440
vm.reset();
441441
vm.setBytecode(bytecode2);
442442
vm.run();
443443

444444
ASSERT_EQ(vm.registerCount(), 1);
445445
ASSERT_FALSE(vm.getInput(0, 1)->toBool());
446446

447-
EXPECT_CALL(target, touchingColor(constValues[1])).WillOnce(Return(true));
447+
EXPECT_CALL(target, touchingColor(constValues[1].toRgba())).WillOnce(Return(true));
448448
vm.reset();
449449
vm.run();
450450

@@ -495,29 +495,29 @@ TEST_F(SensingBlocksTest, ColorIsTouchingColorImpl)
495495
vm.setFunctions(functions);
496496
vm.setConstValues(constValues);
497497

498-
EXPECT_CALL(target, touchingColor(constValues[0], constValues[1])).WillOnce(Return(false));
498+
EXPECT_CALL(target, touchingColor(constValues[0].toRgba(), constValues[1].toRgba())).WillOnce(Return(false));
499499
vm.setBytecode(bytecode1);
500500
vm.run();
501501

502502
ASSERT_EQ(vm.registerCount(), 1);
503503
ASSERT_FALSE(vm.getInput(0, 1)->toBool());
504504

505-
EXPECT_CALL(target, touchingColor(constValues[0], constValues[1])).WillOnce(Return(true));
505+
EXPECT_CALL(target, touchingColor(constValues[0].toRgba(), constValues[1].toRgba())).WillOnce(Return(true));
506506
vm.reset();
507507
vm.run();
508508

509509
ASSERT_EQ(vm.registerCount(), 1);
510510
ASSERT_TRUE(vm.getInput(0, 1)->toBool());
511511

512-
EXPECT_CALL(target, touchingColor(constValues[2], constValues[3])).WillOnce(Return(false));
512+
EXPECT_CALL(target, touchingColor(constValues[2].toRgba(), constValues[3].toRgba())).WillOnce(Return(false));
513513
vm.reset();
514514
vm.setBytecode(bytecode2);
515515
vm.run();
516516

517517
ASSERT_EQ(vm.registerCount(), 1);
518518
ASSERT_FALSE(vm.getInput(0, 1)->toBool());
519519

520-
EXPECT_CALL(target, touchingColor(constValues[2], constValues[3])).WillOnce(Return(true));
520+
EXPECT_CALL(target, touchingColor(constValues[2].toRgba(), constValues[3].toRgba())).WillOnce(Return(true));
521521
vm.reset();
522522
vm.run();
523523

0 commit comments

Comments
 (0)