Skip to content

Commit d151855

Browse files
committed
Engine: Add requestRedraw method
1 parent 9ee5bde commit d151855

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

include/scratchcpp/iengine.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,13 @@ class LIBSCRATCHCPP_EXPORT IEngine
159159
virtual bool broadcastByPtrRunning(Broadcast *broadcast, VirtualMachine *sourceScript) = 0;
160160

161161
/*!
162-
* Call this from a block implementation to force a "screen refresh".
162+
* Call this from a block implementation to force a redraw (screen refresh).
163+
* \note This has no effect in "run without screen refresh" custom blocks.
164+
*/
165+
virtual void requestRedraw() = 0;
166+
167+
/*!
168+
* Call this from a block implementation to break the execution of the current frame.
163169
* \note This has no effect in "run without screen refresh" custom blocks.
164170
*/
165171
virtual void breakFrame() = 0;

src/engine/internal/engine.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,11 @@ bool Engine::broadcastByPtrRunning(Broadcast *broadcast, VirtualMachine *sourceS
554554
return false;
555555
}
556556

557+
void Engine::requestRedraw()
558+
{
559+
m_redrawRequested = true;
560+
}
561+
557562
void Engine::breakFrame()
558563
{
559564
m_breakFrame = true;
@@ -950,6 +955,7 @@ void Engine::finalize()
950955
m_runningScripts.clear();
951956
m_scriptsToRemove.clear();
952957
m_running = false;
958+
m_redrawRequested = false;
953959
m_breakFrame = false;
954960
m_skipFrame = false;
955961
m_lockFrame = false;

src/engine/internal/engine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class Engine : public IEngine
7373
bool broadcastRunning(unsigned int index, VirtualMachine *sourceScript) override;
7474
bool broadcastByPtrRunning(Broadcast *broadcast, VirtualMachine *sourceScript) override;
7575

76+
void requestRedraw() override;
77+
7678
void breakFrame() override;
7779
bool breakingCurrentFrame() override;
7880

@@ -161,6 +163,7 @@ class Engine : public IEngine
161163
bool m_spriteFencingEnabled = true;
162164

163165
bool m_running = false;
166+
bool m_redrawRequested = false;
164167
bool m_breakFrame = false;
165168
bool m_skipFrame = false;
166169
bool m_lockFrame = false;

test/mocks/enginemock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class EngineMock : public IEngine
5959
MOCK_METHOD(bool, broadcastRunning, (unsigned int, VirtualMachine *), (override));
6060
MOCK_METHOD(bool, broadcastByPtrRunning, (Broadcast *, VirtualMachine *), (override));
6161

62+
MOCK_METHOD(void, requestRedraw, (), (override));
63+
6264
MOCK_METHOD(void, breakFrame, (), (override));
6365
MOCK_METHOD(bool, breakingCurrentFrame, (), (override));
6466

0 commit comments

Comments
 (0)