From 03b3b8ae80559745f98ef94569b421adddeb441f Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Mar 2019 23:46:59 +0800 Subject: *misc --- source/3rd-party/Luax/luax_class.hpp | 65 +++-- source/3rd-party/Luax/luax_class.inl | 30 ++- source/3rd-party/Luax/luax_ref.h | 2 +- source/3rd-party/Luax/luax_state.cpp | 5 + source/3rd-party/Luax/luax_state.h | 7 +- source/3rd-party/Luax/luax_state.inl | 14 +- 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 - source/libs/asura-lib-core/application.h | 4 +- .../asura-lib-core/graphics/binding/_canvas.cpp | 0 .../asura-lib-core/graphics/binding/_color.cpp | 0 .../libs/asura-lib-core/graphics/binding/_gif.cpp | 0 .../asura-lib-core/graphics/binding/_image.cpp | 0 .../graphics/binding/_image_data.cpp | 62 +++++ .../asura-lib-core/graphics/binding/_mesh2d.cpp | 0 .../graphics/binding/_mesh2d_data.cpp | 9 + .../asura-lib-core/graphics/binding/_shader.cpp | 114 ++++++++ .../graphics/binding/_sprite_batch.cpp | 0 .../asura-lib-core/graphics/binding/_window.cpp | 11 + .../graphics/binding/canvas.binding.cpp | 0 .../graphics/binding/color.binding.cpp | 0 .../graphics/binding/gif.binding.cpp | 0 .../graphics/binding/image.binding.cpp | 0 .../graphics/binding/image_data.binding.cpp | 62 ----- .../graphics/binding/mesh2d.binding.cpp | 0 .../graphics/binding/mesh2d_data.binding.cpp | 9 - .../graphics/binding/shader.binding.cpp | 114 -------- .../graphics/binding/sprite_batch.binding.cpp | 0 .../graphics/binding/window.binding.cpp | 11 - source/libs/asura-lib-core/graphics/image.h | 4 +- .../libs/asura-lib-core/graphics/stb_decoder.cpp | 4 +- source/libs/asura-lib-core/input/cursor.h | 23 +- source/libs/asura-lib-core/input/event.h | 45 ++++ source/libs/asura-lib-core/input/input_device.hpp | 9 +- source/libs/asura-lib-core/input/joypad.h | 0 source/libs/asura-lib-core/input/mouse.defs | 7 + source/libs/asura-lib-core/manager.hpp | 14 - source/libs/asura-lib-core/singleton.hpp | 59 ----- source/libs/asura-lib-core/stringmap.cpp | 0 source/libs/asura-lib-core/stringmap.hpp | 29 --- .../threading/binding/_coroutine.cpp | 0 .../asura-lib-core/threading/binding/_thread.cpp | 0 source/libs/asura-lib-core/threading/coroutine.cpp | 0 source/libs/asura-lib-core/threading/coroutine.h | 27 ++ source/libs/asura-lib-core/threading/thread.cpp | 0 source/libs/asura-lib-core/threading/thread.h | 0 .../libs/asura-lib-framework/scripts/component.lua | 6 +- source/libs/asura-lib-framework/scripts/entity.lua | 114 ++++++++ .../scripts/filesystem/entity_loader.lua | 2 +- .../asura-lib-framework/scripts/gameobject.lua | 115 --------- .../scripts/graphics/animator.lua | 6 +- .../scripts/graphics/particle_system.lua | 4 +- source/libs/asura-lib-framework/scripts/scene.lua | 2 +- .../filesystem/binding/data_buffer.binding.cpp | 110 -------- .../asura-lib-utils/filesystem/data_buffer.cpp | 67 ----- .../libs/asura-lib-utils/filesystem/data_buffer.h | 55 ---- .../asura-lib-utils/filesystem/decoded_data.cpp | 20 -- .../libs/asura-lib-utils/filesystem/decoded_data.h | 42 --- .../libs/asura-lib-utils/filesystem/reloadable.h | 27 -- .../filesystem/resource_manager.cpp | 0 .../asura-lib-utils/filesystem/resource_manager.h | 48 ---- .../asura-lib-utils/io/binding/_compressor.cpp | 0 .../asura-lib-utils/io/binding/_data_buffer.cpp | 110 ++++++++ source/libs/asura-lib-utils/io/binding/_file.cpp | 186 ++++++++++++++ .../libs/asura-lib-utils/io/binding/_file_data.cpp | 64 +++++ .../asura-lib-utils/io/binding/_file_system.cpp | 267 +++++++++++++++++++ source/libs/asura-lib-utils/io/compressor.cpp | 11 + source/libs/asura-lib-utils/io/compressor.h | 30 +++ source/libs/asura-lib-utils/io/data_buffer.cpp | 77 ++++++ source/libs/asura-lib-utils/io/data_buffer.h | 54 ++++ source/libs/asura-lib-utils/io/decoded_data.cpp | 20 ++ source/libs/asura-lib-utils/io/decoded_data.h | 42 +++ source/libs/asura-lib-utils/io/file.cpp | 286 +++++++++++++++++++++ source/libs/asura-lib-utils/io/file.h | 132 ++++++++++ source/libs/asura-lib-utils/io/file_data.cpp | 57 ++++ source/libs/asura-lib-utils/io/file_data.h | 68 +++++ source/libs/asura-lib-utils/io/file_system.cpp | 198 ++++++++++++++ source/libs/asura-lib-utils/io/file_system.h | 110 ++++++++ source/libs/asura-lib-utils/io/reloadable.h | 27 ++ source/libs/asura-lib-utils/manager.hpp | 14 + source/libs/asura-lib-utils/math/rect.hpp | 19 +- source/libs/asura-lib-utils/scripting/portable.hpp | 7 + source/libs/asura-lib-utils/singleton.hpp | 59 +++++ source/libs/asura-lib-utils/stringmap.cpp | 0 source/libs/asura-lib-utils/stringmap.hpp | 29 +++ source/libs/asura-lib-utils/type.h | 14 + source/libs/asura-lib-utils/utils_config.h | 0 source/tests/02-luax/main.cpp | 67 ++++- source/tests/05-physfs/ok.txt | 0 104 files changed, 2737 insertions(+), 932 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 create mode 100644 source/libs/asura-lib-core/graphics/binding/_canvas.cpp create mode 100644 source/libs/asura-lib-core/graphics/binding/_color.cpp create mode 100644 source/libs/asura-lib-core/graphics/binding/_gif.cpp create mode 100644 source/libs/asura-lib-core/graphics/binding/_image.cpp create mode 100644 source/libs/asura-lib-core/graphics/binding/_image_data.cpp create mode 100644 source/libs/asura-lib-core/graphics/binding/_mesh2d.cpp create mode 100644 source/libs/asura-lib-core/graphics/binding/_mesh2d_data.cpp create mode 100644 source/libs/asura-lib-core/graphics/binding/_shader.cpp create mode 100644 source/libs/asura-lib-core/graphics/binding/_sprite_batch.cpp create mode 100644 source/libs/asura-lib-core/graphics/binding/_window.cpp delete mode 100644 source/libs/asura-lib-core/graphics/binding/canvas.binding.cpp delete mode 100644 source/libs/asura-lib-core/graphics/binding/color.binding.cpp delete mode 100644 source/libs/asura-lib-core/graphics/binding/gif.binding.cpp delete mode 100644 source/libs/asura-lib-core/graphics/binding/image.binding.cpp delete mode 100644 source/libs/asura-lib-core/graphics/binding/image_data.binding.cpp delete mode 100644 source/libs/asura-lib-core/graphics/binding/mesh2d.binding.cpp delete mode 100644 source/libs/asura-lib-core/graphics/binding/mesh2d_data.binding.cpp delete mode 100644 source/libs/asura-lib-core/graphics/binding/shader.binding.cpp delete mode 100644 source/libs/asura-lib-core/graphics/binding/sprite_batch.binding.cpp delete mode 100644 source/libs/asura-lib-core/graphics/binding/window.binding.cpp create mode 100644 source/libs/asura-lib-core/input/event.h create mode 100644 source/libs/asura-lib-core/input/joypad.h create mode 100644 source/libs/asura-lib-core/input/mouse.defs delete mode 100644 source/libs/asura-lib-core/manager.hpp delete mode 100644 source/libs/asura-lib-core/singleton.hpp delete mode 100644 source/libs/asura-lib-core/stringmap.cpp delete mode 100644 source/libs/asura-lib-core/stringmap.hpp create mode 100644 source/libs/asura-lib-core/threading/binding/_coroutine.cpp create mode 100644 source/libs/asura-lib-core/threading/binding/_thread.cpp create mode 100644 source/libs/asura-lib-core/threading/coroutine.cpp create mode 100644 source/libs/asura-lib-core/threading/coroutine.h create mode 100644 source/libs/asura-lib-core/threading/thread.cpp create mode 100644 source/libs/asura-lib-core/threading/thread.h create mode 100644 source/libs/asura-lib-framework/scripts/entity.lua delete mode 100644 source/libs/asura-lib-framework/scripts/gameobject.lua delete mode 100644 source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp delete mode 100644 source/libs/asura-lib-utils/filesystem/data_buffer.cpp delete mode 100644 source/libs/asura-lib-utils/filesystem/data_buffer.h delete mode 100644 source/libs/asura-lib-utils/filesystem/decoded_data.cpp delete mode 100644 source/libs/asura-lib-utils/filesystem/decoded_data.h delete mode 100644 source/libs/asura-lib-utils/filesystem/reloadable.h delete mode 100644 source/libs/asura-lib-utils/filesystem/resource_manager.cpp delete mode 100644 source/libs/asura-lib-utils/filesystem/resource_manager.h create mode 100644 source/libs/asura-lib-utils/io/binding/_compressor.cpp create mode 100644 source/libs/asura-lib-utils/io/binding/_data_buffer.cpp create mode 100644 source/libs/asura-lib-utils/io/binding/_file.cpp create mode 100644 source/libs/asura-lib-utils/io/binding/_file_data.cpp create mode 100644 source/libs/asura-lib-utils/io/binding/_file_system.cpp create mode 100644 source/libs/asura-lib-utils/io/compressor.cpp create mode 100644 source/libs/asura-lib-utils/io/compressor.h create mode 100644 source/libs/asura-lib-utils/io/data_buffer.cpp create mode 100644 source/libs/asura-lib-utils/io/data_buffer.h create mode 100644 source/libs/asura-lib-utils/io/decoded_data.cpp create mode 100644 source/libs/asura-lib-utils/io/decoded_data.h create mode 100644 source/libs/asura-lib-utils/io/file.cpp create mode 100644 source/libs/asura-lib-utils/io/file.h create mode 100644 source/libs/asura-lib-utils/io/file_data.cpp create mode 100644 source/libs/asura-lib-utils/io/file_data.h create mode 100644 source/libs/asura-lib-utils/io/file_system.cpp create mode 100644 source/libs/asura-lib-utils/io/file_system.h create mode 100644 source/libs/asura-lib-utils/io/reloadable.h create mode 100644 source/libs/asura-lib-utils/manager.hpp create mode 100644 source/libs/asura-lib-utils/singleton.hpp create mode 100644 source/libs/asura-lib-utils/stringmap.cpp create mode 100644 source/libs/asura-lib-utils/stringmap.hpp create mode 100644 source/libs/asura-lib-utils/utils_config.h create mode 100644 source/tests/05-physfs/ok.txt (limited to 'source') diff --git a/source/3rd-party/Luax/luax_class.hpp b/source/3rd-party/Luax/luax_class.hpp index 539ff1a..3d7ede6 100644 --- a/source/3rd-party/Luax/luax_class.hpp +++ b/source/3rd-party/Luax/luax_class.hpp @@ -62,28 +62,47 @@ namespace Luax state.RegisterEnum(name, __e); \ }while(0) +#define LUAX_PREPARE(L, T) \ + LUAX_STATE(L); \ + T* self = state.GetUserdata(1); + + /// + /// 虚基类,为了实现多态。需要访问下面这些接口的外部基类需要虚继承此类,之后再派生链中就会调用对应实体的方法。注意继承此 + /// 类时不能实现下面的方法,实现在LuaxNativeClass中,实现会导致二义性。 + /// + class ILuaxNativeAccessor + { + public: + + /// + /// 成员引用管理,在实例的ref table里。设置、取、清除 + /// + virtual bool PushLuaxMemberRef(LuaxState& state, int refID) { assert(false); return false; }; + + }; + /// /// 需要暴露给lua的native class需要继承此类。通过lua管理的实例要确保引用计数的正确性,在多个线程中需要确定不会误释放。 /// template - class LuaxNativeClass + class LuaxNativeClass : public virtual ILuaxNativeAccessor { public: + static bool IsTypeOf(ILuaxNativeAccessor); + /// - /// 将userdata作为key,在ref table里对userdata添加一个引用,以维持userdata的生命周期。 + /// 将userdata作为key,在ref table里对userdata添加一个引用,以维持userdata的生命周期。相比较member ref,这个用在 + /// 实体会被多次被不同其他实体引用的情况,并频繁销毁这些实体,避免lua频繁的调用gc检测。 /// - template void LuaRetain(LuaxState& state, U* userdata); + template void LuaxRetain(LuaxState& state, U* userdata); /// /// 对userdata减少一个引用在ref table里,以尝试回收userdata。 /// - template void LuaRelease(LuaxState& state, U* userdata); + template void LuaxRelease(LuaxState& state, U* userdata); - protected: - - LuaxNativeClass(); - virtual ~LuaxNativeClass(); + bool PushLuaxMemberRef(LuaxState& state, int refID) override; /// /// 将userdata push到栈顶,如果没有初始化mUserdata,初始化设置好元表并把初始化好的userdata留在栈顶。并添加一个引用。 @@ -92,12 +111,17 @@ namespace Luax bool PushLuaxMemberTable(LuaxState& state); bool PushLuaxRefTable(LuaxState& state); + protected: + /// /// 成员引用管理,在实例的ref table里。设置、取、清除 /// - void SetMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx); - bool PushMemberRef(LuaxState& state, LuaxMemberRef& memRef); - void ClearMemberRef(LuaxState& state, LuaxMemberRef& memRef); + void SetLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx); + bool PushLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef); + void ClearLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef); + + LuaxNativeClass(); + virtual ~LuaxNativeClass(); private: @@ -122,14 +146,16 @@ namespace Luax /// void BindToLua(LuaxState& state); - //------------------------------------------------------------------------------------------------------------ - /// - /// 所有LuaxNativeClass类型的实例共享的内容 + /// class table,工厂和单例都有。 + /// + static LuaxStrongRef mClassTable; /// - static LuaxStrongRef mClassTable; // class table,工厂和单例都有 - static LuaxStrongRef mSingletonRefTable; // 如果类是单例,这个用来保存singleton的成员,以保证不会被回收类似普通类的 - // ref table。单例的成员是全生命周期的,所以直接在_LUAX_STRONGREF_TABLE + /// 如果类是单例,这个用来保存singleton的引用关系,以保证不会被回收类似普通类的ref table。单例的成员是全生命周期的, + /// 所以直接在_LUAX_STRONGREF_TABLE。单例对userdata进行LuaxRetain\LuaxRelease和member ref操作时和工厂实例不同, + /// 是存在下面这个ref table里的,这个table在_LUAX_STRONGREF_TABLE里。 + /// + static LuaxStrongRef mSingletonRefTable; /// /// 通过userdata可以拿到: @@ -141,16 +167,12 @@ namespace Luax public: - //------------------------------------------------------------------------------------------------------------ // 公共内容 - LUAX_DECL_METHOD( l___tostring ); LUAX_DECL_METHOD( l_GetClass ); LUAX_DECL_METHOD( l_GetClassName ); - //------------------------------------------------------------------------------------------------------------ // 工厂类相关 - LUAX_DECL_METHOD( l___gc ); #if LUAX_ENABLE_NATIVE_EXTEND LUAX_DECL_METHOD( l_ExtendFactory ); @@ -158,7 +180,6 @@ namespace Luax LUAX_DECL_METHOD( l_GetRefTable ); LUAX_DECL_METHOD( l_New ); - //------------------------------------------------------------------------------------------------------------ // 单例类相关 #if LUAX_ENABLE_NATIVE_EXTEND LUAX_DECL_METHOD( l_ExtendSingleton ); diff --git a/source/3rd-party/Luax/luax_class.inl b/source/3rd-party/Luax/luax_class.inl index 7a24896..e2b8de8 100644 --- a/source/3rd-party/Luax/luax_class.inl +++ b/source/3rd-party/Luax/luax_class.inl @@ -87,7 +87,7 @@ namespace Luax template template - void LuaxNativeClass::LuaRetain(LuaxState& state, U* userdata) + void LuaxNativeClass::LuaxRetain(LuaxState& state, U* userdata) { if (PushLuaxRefTable(state)) { @@ -105,7 +105,7 @@ namespace Luax template template - void LuaxNativeClass::LuaRelease(LuaxState& state, U* userdata) + void LuaxNativeClass::LuaxRelease(LuaxState& state, U* userdata) { if (PushLuaxRefTable(state)) { @@ -157,7 +157,7 @@ namespace Luax } } } - state.SetTop(top); + lua_settop(state, top); lua_pushnil(state); return false; } @@ -250,9 +250,9 @@ namespace Luax /// 成员引用管理 /// template - void LuaxNativeClass::SetMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx) + void LuaxNativeClass::SetLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx) { - ClearMemberRef(state, memRef); + ClearLuaxMemberRef(state, memRef); if (!lua_isnil(state, idx)) { idx = state.AbsIndex(idx); @@ -266,7 +266,7 @@ namespace Luax } template - bool LuaxNativeClass::PushMemberRef(LuaxState& state, LuaxMemberRef& memRef) + bool LuaxNativeClass::PushLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef) { if (memRef) { @@ -285,8 +285,24 @@ namespace Luax return false; } + template + bool LuaxNativeClass::PushLuaxMemberRef(LuaxState& state, int refID) + { + if (PushLuaxRefTable(state)) + { + lua_rawgeti(state, -1, refID); + lua_replace(state, -2); // ref table + if (lua_isnil(state, -1)) + goto failed; + return true; + } + lua_pushnil(state); + failed: + return false; + } + template - void LuaxNativeClass::ClearMemberRef(LuaxState& state, LuaxMemberRef& memRef) + void LuaxNativeClass::ClearLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef) { if (memRef) { diff --git a/source/3rd-party/Luax/luax_ref.h b/source/3rd-party/Luax/luax_ref.h index b7aabe5..d0001f2 100644 --- a/source/3rd-party/Luax/luax_ref.h +++ b/source/3rd-party/Luax/luax_ref.h @@ -14,7 +14,7 @@ namespace Luax { public: - enum + enum RefMode { STRONG_REF, WEAK_REF diff --git a/source/3rd-party/Luax/luax_state.cpp b/source/3rd-party/Luax/luax_state.cpp index 622f352..8c30c00 100644 --- a/source/3rd-party/Luax/luax_state.cpp +++ b/source/3rd-party/Luax/luax_state.cpp @@ -171,6 +171,11 @@ namespace Luax lua_pushlightuserdata(mState, (void*)value); } + void LuaxState::Push(std::string value) + { + Push(value.c_str()); + } + void LuaxState::PushValues(int idx, int n) { idx = AbsIndex(idx); diff --git a/source/3rd-party/Luax/luax_state.h b/source/3rd-party/Luax/luax_state.h index 564eba3..d675c7c 100644 --- a/source/3rd-party/Luax/luax_state.h +++ b/source/3rd-party/Luax/luax_state.h @@ -98,6 +98,7 @@ namespace Luax void Push(lua_CFunction value); void Push(void* data, size_t size); void Push(const void* value); + void Push(std::string value); /// /// 将idx开始的n个push到栈顶,idx会被取正,n向上生长。 @@ -210,7 +211,7 @@ namespace Luax }; //-------------------------------------------------------------------------------------------------------------- - // GetValue()模板实例化 + // GetValue()模板特化 template <> bool LuaxState::GetValue < bool >(int idx, const bool value); template <> cc8* LuaxState::GetValue < cc8* >(int idx, const cc8* value); @@ -228,7 +229,7 @@ namespace Luax template <> const void* LuaxState::GetValue < const void* >(int idx, const void* value); //-------------------------------------------------------------------------------------------------------------- - // CheckParam模板实例化 + // CheckParam模板特化 template <> bool LuaxState::CheckParam < bool >(int idx); template <> cc8* LuaxState::CheckParam < cc8* >(int idx); @@ -254,7 +255,7 @@ namespace Luax if(!state.CheckParams(1, params)) return 0 #define LUAX_STATE(L) \ - LuaxState& state = LuaxRuntime::Get().GetLuaxState(L) + Luax::LuaxState& state = Luax::LuaxRuntime::Get().GetLuaxState(L) } diff --git a/source/3rd-party/Luax/luax_state.inl b/source/3rd-party/Luax/luax_state.inl index 4af45a2..20d132c 100644 --- a/source/3rd-party/Luax/luax_state.inl +++ b/source/3rd-party/Luax/luax_state.inl @@ -25,8 +25,7 @@ namespace Luax assert(IsType(-1, LUA_TFUNCTION)); \ Pop(); - _assertmethod(-1, "New"); - //_assertmethod(-1, "__gc"); + //_assertmethod(-1, "New"); #undef _assertmethod @@ -104,6 +103,17 @@ namespace Luax } } + template + void LuaxState::SetFieldByIndex(int idx, int key, T value) + { + if (IsTableOrUserdata(idx)) + { + idx = AbsIndex(idx); + this->Push(value); + lua_rawseti(mState, idx, key); + } + } + template T LuaxState::GetField(int idx, cc8* key, T value) { 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