Skip to content

Commit 43e6f0b

Browse files
authored
Merge pull request #519 from scratchcpp/signals_slots
Use a library for signals/slots
2 parents 597c4a0 + 049fc34 commit 43e6f0b

26 files changed

+1970
-161
lines changed

include/scratchcpp/iengine.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <functional>
99

1010
#include "global.h"
11+
#include "signal.h"
1112

1213
namespace libscratchcpp
1314
{
@@ -109,8 +110,11 @@ class LIBSCRATCHCPP_EXPORT IEngine
109110
/*! Stops the event loop which is running in another thread. */
110111
virtual void stopEventLoop() = 0;
111112

112-
/*! Sets the function which is called on every frame. */
113-
virtual void setRedrawHandler(const std::function<void()> &handler) = 0;
113+
/*! Emits when rendering should occur. */
114+
virtual sigslot::signal<> &aboutToRender() = 0;
115+
116+
/*! Emits when a script is about to stop. */
117+
virtual sigslot::signal<VirtualMachine *> &threadAboutToStop() = 0;
114118

115119
/*! Returns true if the project is currently running. */
116120
virtual bool isRunning() const = 0;
@@ -345,23 +349,17 @@ class LIBSCRATCHCPP_EXPORT IEngine
345349
/*! Sets the list of monitors. */
346350
virtual void setMonitors(const std::vector<std::shared_ptr<Monitor>> &newMonitors) = 0;
347351

348-
/*! Sets the function which is called when a monitor is added. */
349-
virtual void setAddMonitorHandler(const std::function<void(Monitor *)> &handler) = 0;
350-
351-
/*! Sets the function which is called when a monitor is removed. */
352-
virtual void setRemoveMonitorHandler(const std::function<void(Monitor *, IMonitorHandler *)> &handler) = 0;
353-
354-
/*! Returns the function which is called when a question is asked, for example using the 'ask and wait' block. */
355-
virtual const std::function<void(const std::string &)> &questionAsked() const = 0;
352+
/*! Emits when a monitor is added. */
353+
virtual sigslot::signal<Monitor *> &monitorAdded() = 0;
356354

357-
/*! Sets the function which is called when a question is asked, for example using the 'ask and wait' block. */
358-
virtual void setQuestionAsked(const std::function<void(const std::string &)> &f) = 0;
355+
/*! Emits when a monitor is removed. */
356+
virtual sigslot::signal<Monitor *, IMonitorHandler *> &monitorRemoved() = 0;
359357

360-
/*! Returns the function which should be called when a question is answered. */
361-
virtual const std::function<void(const std::string &)> &questionAnswered() const = 0;
358+
/*! Emits when a question is asked, for example using the 'ask and wait' block. */
359+
virtual sigslot::signal<const std::string &> &questionAsked() = 0;
362360

363-
/*! Sets the function which should be called when a question is answered. */
364-
virtual void setQuestionAnswered(const std::function<void(const std::string &)> &f) = 0;
361+
/*! Emits when a question is answered. */
362+
virtual sigslot::signal<const std::string &> &questionAnswered() = 0;
365363

366364
/*! Returns the list of extension names. */
367365
virtual const std::vector<std::string> &extensions() const = 0;

include/scratchcpp/project.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "spimpl.h"
88

99
#include "global.h"
10+
#include "signal.h"
1011

1112
namespace libscratchcpp
1213
{
@@ -42,7 +43,7 @@ class LIBSCRATCHCPP_EXPORT Project
4243

4344
std::shared_ptr<IEngine> engine() const;
4445

45-
void setDownloadProgressCallback(const std::function<void(unsigned int, unsigned int)> &&f);
46+
sigslot::signal<unsigned int, unsigned int> &downloadProgressChanged();
4647

4748
private:
4849
spimpl::unique_impl_ptr<ProjectPrivate> impl;

0 commit comments

Comments
 (0)