summaryrefslogtreecommitdiff
path: root/source/Asura.Editor/core
diff options
context:
space:
mode:
Diffstat (limited to 'source/Asura.Editor/core')
-rw-r--r--source/Asura.Editor/core/signal.h52
-rw-r--r--source/Asura.Editor/core/slot.h43
2 files changed, 95 insertions, 0 deletions
diff --git a/source/Asura.Editor/core/signal.h b/source/Asura.Editor/core/signal.h
new file mode 100644
index 0000000..f1ab9b4
--- /dev/null
+++ b/source/Asura.Editor/core/signal.h
@@ -0,0 +1,52 @@
+#ifndef __ASRUA_EDTIRO_SIGNAL_H__
+#define __ASRUA_EDTIRO_SIGNAL_H__
+
+#include <vector>
+
+#include <asura-lib-utils/scripting/portable.hpp>
+
+#include "../widgets/widget.h"
+#include "slot.h"
+
+namespace AsuraEditor
+{
+
+ ///
+ /// ؼ¼
+ ///
+ class Signal
+ {
+ public:
+ Signal();
+
+ ///
+ /// Fire¼connectļߣãconnectĺ
+ ///
+ void operator()(void* userdata)
+ {
+ for (auto callback : mCallbacks)
+ callback();
+ }
+
+ ///
+ /// עص
+ ///
+ void Connect(const Slot& callback)
+ {
+ mCallbacks.push_back(callback);
+ }
+
+ ///
+ ///
+ ///
+ void Disconnect();
+
+ private:
+
+ std::vector<Slot> mCallbacks; //
+
+ };
+
+}
+
+#endif \ No newline at end of file
diff --git a/source/Asura.Editor/core/slot.h b/source/Asura.Editor/core/slot.h
new file mode 100644
index 0000000..ff565cf
--- /dev/null
+++ b/source/Asura.Editor/core/slot.h
@@ -0,0 +1,43 @@
+#ifndef __ASURA_EDITOR_SLOT_H__
+#define __ASURA_EDITOR_SLOT_H__
+
+#include <asura-lib-utils/scripting/portable.hpp>
+#include <asura-lib-core/input/event.h>
+
+#include "../widgets/widget.h"
+
+namespace AsuraEditor
+{
+
+ ///
+ /// Ӧsignalıհ
+ ///
+ class Slot
+ {
+ public:
+ Slot(Luax::LuaxState& state, Widget& widget, int refID)
+ : mState(state)
+ , mRefID(refID)
+ , mWidget(widget)
+ {
+ }
+
+ void operator()()
+ {
+ mWidget.PushLuaxMemberRef(mState, mRefID);
+ if (lua_isfunction(mState, -1)) // callback
+ {
+ mState.Call(0, 0);
+ }
+ }
+
+ private:
+ Luax::LuaxState& mState;
+ Widget& mWidget;
+ int mRefID;
+
+ };
+
+}
+
+#endif \ No newline at end of file