Skip to content

Commit 24ca4f8

Browse files
committed
Add X and Y changed methods to IMonitorHandler
1 parent f7b6f13 commit 24ca4f8

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

include/scratchcpp/imonitorhandler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class LIBSCRATCHCPP_EXPORT IMonitorHandler
1818
virtual void init(Monitor *monitor) = 0;
1919

2020
virtual void onValueChanged(const VirtualMachine *vm) = 0;
21+
virtual void onXChanged(int x) = 0;
22+
virtual void onYChanged(int y) = 0;
2123
virtual void onVisibleChanged(bool visible) = 0;
2224
};
2325

src/scratch/monitor.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ int Monitor::x() const
180180
void Monitor::setX(int x)
181181
{
182182
impl->x = x;
183+
184+
if (impl->iface)
185+
impl->iface->onXChanged(x);
183186
}
184187

185188
/*! Returns the monitor's y-coordinate. */
@@ -192,6 +195,9 @@ int Monitor::y() const
192195
void Monitor::setY(int y)
193196
{
194197
impl->y = y;
198+
199+
if (impl->iface)
200+
impl->iface->onYChanged(y);
195201
}
196202

197203
/*! Returns true if the monitor is visible. */

test/mocks/monitorhandlermock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ class MonitorHandlerMock : public IMonitorHandler
1111
MOCK_METHOD(void, init, (Monitor *), (override));
1212

1313
MOCK_METHOD(void, onValueChanged, (const VirtualMachine *), (override));
14+
MOCK_METHOD(void, onXChanged, (int), (override));
15+
MOCK_METHOD(void, onYChanged, (int), (override));
1416
MOCK_METHOD(void, onVisibleChanged, (bool), (override));
1517
};

test/scratch_classes/monitor_test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ TEST(MonitorTest, X)
182182
Monitor monitor("", "");
183183
ASSERT_EQ(monitor.x(), 0);
184184

185+
MonitorHandlerMock handler;
186+
EXPECT_CALL(handler, init);
187+
monitor.setInterface(&handler);
188+
189+
EXPECT_CALL(handler, onXChanged(-78));
185190
monitor.setX(-78);
186191
ASSERT_EQ(monitor.x(), -78);
187192
}
@@ -191,6 +196,11 @@ TEST(MonitorTest, Y)
191196
Monitor monitor("", "");
192197
ASSERT_EQ(monitor.y(), 0);
193198

199+
MonitorHandlerMock handler;
200+
EXPECT_CALL(handler, init);
201+
monitor.setInterface(&handler);
202+
203+
EXPECT_CALL(handler, onYChanged(150));
194204
monitor.setY(150);
195205
ASSERT_EQ(monitor.y(), 150);
196206
}

0 commit comments

Comments
 (0)