From 03b3b8ae80559745f98ef94569b421adddeb441f Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Mar 2019 23:46:59 +0800 Subject: *misc --- source/Asura.Editor/core/signal.h | 52 +++++++++++++++++++++ source/Asura.Editor/core/slot.h | 43 ++++++++++++++++++ source/Asura.Editor/dui_module.cpp | 8 ++++ source/Asura.Editor/dui_module.h | 18 ++++++++ source/Asura.Editor/editor.h | 17 ++++++- source/Asura.Editor/events/events.h | 24 ---------- source/Asura.Editor/graphics/shader.cpp | 0 source/Asura.Editor/graphics/shader.h | 21 --------- source/Asura.Editor/scripts/asset_view.lua | 0 source/Asura.Editor/scripts/main.lua | 3 +- source/Asura.Editor/scripts/scene_view.lua | 1 - source/Asura.Editor/widgets/binding/_button.cpp | 60 +++++++++++++++++++++++++ source/Asura.Editor/widgets/button.cpp | 10 +++++ source/Asura.Editor/widgets/button.h | 54 +++++++++++++++++++--- source/Asura.Editor/widgets/label.h | 11 ++++- source/Asura.Editor/widgets/widget.h | 27 +++++++++-- source/Asura.Editor/window/window.h | 14 ------ 17 files changed, 287 insertions(+), 76 deletions(-) create mode 100644 source/Asura.Editor/core/signal.h create mode 100644 source/Asura.Editor/core/slot.h delete mode 100644 source/Asura.Editor/events/events.h delete mode 100644 source/Asura.Editor/graphics/shader.cpp delete mode 100644 source/Asura.Editor/graphics/shader.h create mode 100644 source/Asura.Editor/scripts/asset_view.lua create mode 100644 source/Asura.Editor/widgets/binding/_button.cpp delete mode 100644 source/Asura.Editor/window/window.h (limited to 'source/Asura.Editor') 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 + +#include + +#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 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 +#include + +#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 diff --git a/source/Asura.Editor/dui_module.cpp b/source/Asura.Editor/dui_module.cpp index e69de29..63b7361 100644 --- a/source/Asura.Editor/dui_module.cpp +++ b/source/Asura.Editor/dui_module.cpp @@ -0,0 +1,8 @@ +#include "dui_module.h" + +namespace AsuraEditor +{ + + + +} diff --git a/source/Asura.Editor/dui_module.h b/source/Asura.Editor/dui_module.h index abcaca5..48c341f 100644 --- a/source/Asura.Editor/dui_module.h +++ b/source/Asura.Editor/dui_module.h @@ -1,6 +1,24 @@ #ifndef __ASRUA_EDITOR_DIRECTUI_MODULE_H__ #define __ASRUA_EDITOR_DIRECTUI_MODULE_H__ +#include +namespace AsuraEditor +{ + + /// + /// Direct UI module. + /// + class DUIModule : public AsuraEngine::Module + { + public: + + void Initialize(Luax::LuaxState& state) override; + + void Finalize(Luax::LuaxState& state) override; + + }; + +} #endif \ No newline at end of file diff --git a/source/Asura.Editor/editor.h b/source/Asura.Editor/editor.h index 6555c81..b56852f 100644 --- a/source/Asura.Editor/editor.h +++ b/source/Asura.Editor/editor.h @@ -1,14 +1,29 @@ #ifndef __ASURA_EDITOR_H__ #define __ASURA_EDITOR_H__ +#include + namespace AsuraEditor { /// - /// + /// 编辑器实例。 /// class Editor { + public: + + /// + /// 获得界面的lua State + /// + Luax::LuaxState& GetLuaxState(); + + private: + + /// + /// 界面和逻辑运行的state。 + /// + lua_State* mMainState; }; diff --git a/source/Asura.Editor/events/events.h b/source/Asura.Editor/events/events.h deleted file mode 100644 index bbe5cc3..0000000 --- a/source/Asura.Editor/events/events.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __ASUSRA_EDITOR_EVENT_H__ -#define __ASUSRA_EDITOR_EVENT_H__ - -namespace AsuraEditor -{ - namespace Events - { - - enum EventType - { - GRAPHIC_EVENT, - KEYBOARD_EVENT, - MOUSE_EVENT - }; - - enum GraphicEvent - { - EVENT_PAINT, - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/Asura.Editor/graphics/shader.cpp b/source/Asura.Editor/graphics/shader.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/graphics/shader.h b/source/Asura.Editor/graphics/shader.h deleted file mode 100644 index 7511e1c..0000000 --- a/source/Asura.Editor/graphics/shader.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __ASURA_EDITOR_SHADER_H__ -#define __ASURA_EDITOR_SHADER_H__ - -#include - -namespace AsuraEditor -{ - - /// - /// 编辑器中使用的shader,不会有lua接口。 - /// - class Shader : public AEGraphics::Shader - { - public: - - - }; - -} - -#endif \ No newline at end of file diff --git a/source/Asura.Editor/scripts/asset_view.lua b/source/Asura.Editor/scripts/asset_view.lua new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/scripts/main.lua b/source/Asura.Editor/scripts/main.lua index a513f87..76fab7a 100644 --- a/source/Asura.Editor/scripts/main.lua +++ b/source/Asura.Editor/scripts/main.lua @@ -1,5 +1,4 @@ -local Editor = require("Asura.Editor") --编辑器入口 ---编辑器真正的内容在Asura.Editor/Scripts下面实现 +--编辑器真正的内容在Asura.Editor/scripts下面实现 diff --git a/source/Asura.Editor/scripts/scene_view.lua b/source/Asura.Editor/scripts/scene_view.lua index ff96b2c..db4790f 100644 --- a/source/Asura.Editor/scripts/scene_view.lua +++ b/source/Asura.Editor/scripts/scene_view.lua @@ -1,2 +1 @@ -- 鍦烘櫙绐楀彛 - diff --git a/source/Asura.Editor/widgets/binding/_button.cpp b/source/Asura.Editor/widgets/binding/_button.cpp new file mode 100644 index 0000000..463aef6 --- /dev/null +++ b/source/Asura.Editor/widgets/binding/_button.cpp @@ -0,0 +1,60 @@ +#include "../button.h" + +using namespace Luax; + +namespace AsuraEditor +{ + + LUAX_REGISTRY(Button) + { + + // Button.EStatus.xxx + LUAX_REGISTER_ENUM(state, "EStatus", + { "NORMAL", BUTTON_STATUS_NORMAL }, + { "PUSHED", BUTTON_STATUS_PUSHED }, + { "HOVER", BUTTON_STATUS_HOVER }, + { "DISABLED", BUTTON_STATUS_DISABLED }, + { "FOCUSED", BUTTON_STATUS_FOCUSED } + ); + + // Button.EMsg.xxx + LUAX_REGISTER_ENUM(state, "EMessage", + { "CLICK", BUTTON_MSG_CLICK }, + { "HOVER", BUTTON_MSG_HOVER }, + { "FOCUS", BUTTON_MSG_KILLFOCUS } + ); + + } + + LUAX_POSTPROCESS(Button) + { + + } + + // button:Connect(msg, callback) + LUAX_IMPL_METHOD(Button, _Connect) + { + LUAX_STATE(L); + + Button* self = state.GetUserdata