Skip to content

Commit 3c20340

Browse files
committed
Add stage height properties to Engine
1 parent 8eadadf commit 3c20340

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

include/scratchcpp/iengine.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ class LIBSCRATCHCPP_EXPORT IEngine
103103
/*! Sets the Y coordinate of the mouse pointer. */
104104
virtual void setMouseY(double y) = 0;
105105

106+
/*! Returns the stage width. */
107+
virtual unsigned int stageWidth() const = 0;
108+
109+
/*! Sets the stage width. */
110+
virtual void setStageWidth(unsigned int width) = 0;
111+
112+
/*! Returns the stage height. */
113+
virtual unsigned int stageHeight() const = 0;
114+
115+
/*! Sets the stage height. */
116+
virtual void setStageHeight(unsigned int height) = 0;
117+
106118
/*! Returns true if there are any running script of the broadcast with the given index. */
107119
virtual bool broadcastRunning(unsigned int index, VirtualMachine *sourceScript) = 0;
108120

src/engine/internal/engine.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,26 @@ void Engine::setMouseY(double y)
383383
m_mouseY = y;
384384
}
385385

386+
unsigned int Engine::stageWidth() const
387+
{
388+
return m_stageWidth;
389+
}
390+
391+
void Engine::setStageWidth(unsigned int width)
392+
{
393+
m_stageWidth = width;
394+
}
395+
396+
unsigned int Engine::stageHeight() const
397+
{
398+
return m_stageHeight;
399+
}
400+
401+
void Engine::setStageHeight(unsigned int height)
402+
{
403+
m_stageHeight = height;
404+
}
405+
386406
bool Engine::broadcastRunning(unsigned int index, VirtualMachine *sourceScript)
387407
{
388408
const auto &scripts = m_runningBroadcastMap[index];

src/engine/internal/engine.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ class Engine : public IEngine
4545
double mouseY() const override;
4646
void setMouseY(double y) override;
4747

48+
unsigned int stageWidth() const override;
49+
void setStageWidth(unsigned int width) override;
50+
51+
unsigned int stageHeight() const override;
52+
void setStageHeight(unsigned int height) override;
53+
4854
bool broadcastRunning(unsigned int index, VirtualMachine *sourceScript) override;
4955

5056
void breakFrame() override;
@@ -122,6 +128,8 @@ class Engine : public IEngine
122128
std::chrono::milliseconds m_frameDuration; // will be computed in run()
123129
double m_mouseX = 0;
124130
double m_mouseY = 0;
131+
unsigned int m_stageWidth = 480;
132+
unsigned int m_stageHeight = 360;
125133

126134
bool m_running = false;
127135
bool m_breakFrame = false;

test/engine/engine_test.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ TEST(EngineTest, MouseY)
6161
ASSERT_EQ(engine.mouseY(), 179.9258);
6262
}
6363

64+
TEST(EngineTest, StageWidth)
65+
{
66+
Engine engine;
67+
ASSERT_EQ(engine.stageWidth(), 480);
68+
69+
engine.setStageWidth(640);
70+
ASSERT_EQ(engine.stageWidth(), 640);
71+
}
72+
73+
TEST(EngineTest, StageHeight)
74+
{
75+
Engine engine;
76+
ASSERT_EQ(engine.stageHeight(), 360);
77+
78+
engine.setStageHeight(515);
79+
ASSERT_EQ(engine.stageHeight(), 515);
80+
}
81+
6482
TEST(EngineTest, BreakFrame)
6583
{
6684
Engine engine;

test/mocks/enginemock.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class EngineMock : public IEngine
3333
MOCK_METHOD(double, mouseY, (), (const, override));
3434
MOCK_METHOD(void, setMouseY, (double y), (override));
3535

36+
MOCK_METHOD(unsigned int, stageWidth, (), (const, override));
37+
MOCK_METHOD(void, setStageWidth, (unsigned int), (override));
38+
39+
MOCK_METHOD(unsigned int, stageHeight, (), (const, override));
40+
MOCK_METHOD(void, setStageHeight, (unsigned int), (override));
41+
3642
MOCK_METHOD(bool, broadcastRunning, (unsigned int, VirtualMachine *), (override));
3743

3844
MOCK_METHOD(void, breakFrame, (), (override));

0 commit comments

Comments
 (0)