diff --git a/bin/layers/local_panel/local_panel.cpp b/bin/layers/local_panel/local_panel.cpp index 30a8e69..5c2a638 100755 --- a/bin/layers/local_panel/local_panel.cpp +++ b/bin/layers/local_panel/local_panel.cpp @@ -5,7 +5,7 @@ namespace sandbox { void local_panel::on_attach() { - VE_CONNECT(local_panel); + VE::CONNECT(this); } void local_panel::render() @@ -15,8 +15,7 @@ namespace sandbox { auto f = []() { - VE::event e { test_event::TEST_EVEN , std::string("test event message from thread") }; - VE_EMIT(e); + VE::EMIT(test_event::TEST_EVEN, std::string("test event message from thread")); }; std::thread th(f); th.detach(); @@ -26,8 +25,7 @@ namespace sandbox if (ImGui::Button(VE::style::icon::ICON_STOP, ImVec2(28, 30))) { - VE::event e { test_event::TEST_EVEN , std::string("test icon button") }; - VE_EMIT(e); + VE::EMIT(test_event::TEST_EVEN, std::string("test icon button")); } ImGui::Text(VE::style::icon::ICON_PAINT_BRUSH, " Paint" ); diff --git a/bin/layers/opengl_panel/opengl_panel.cpp b/bin/layers/opengl_panel/opengl_panel.cpp index 361e21e..6aaa58e 100755 --- a/bin/layers/opengl_panel/opengl_panel.cpp +++ b/bin/layers/opengl_panel/opengl_panel.cpp @@ -47,7 +47,6 @@ namespace sandbox void opengl_panel::on_attach() { - VE_CONNECT(opengl_panel); hack::log()("on_attach"); } diff --git a/bin/layers/test_panel/test_panel.cpp b/bin/layers/test_panel/test_panel.cpp index e7e894b..65cd612 100755 --- a/bin/layers/test_panel/test_panel.cpp +++ b/bin/layers/test_panel/test_panel.cpp @@ -5,7 +5,7 @@ namespace sandbox { void test_panel::on_attach() { - VE_CONNECT(test_panel); + VE::CONNECT(this); hack::log()("on_attach", VE::application::get()->get_glfw()->width()); } @@ -18,8 +18,7 @@ namespace sandbox if (ImGui::Button("RUN test_panel_1", ImVec2(128, 130))) { - VE::event e { test_event::TEST_EVEN , std::string("test event message tp 1") }; - VE_EMIT(e); + VE::EMIT(test_event::TEST_EVEN, std::string("test event message tp 1")); } ImGui::End(); diff --git a/bin/layers/test_panel_2/test_panel_2.cpp b/bin/layers/test_panel_2/test_panel_2.cpp index 7a9a19d..b124d9c 100755 --- a/bin/layers/test_panel_2/test_panel_2.cpp +++ b/bin/layers/test_panel_2/test_panel_2.cpp @@ -5,17 +5,21 @@ namespace sandbox { void test_panel_2::on_attach() { - VE_CONNECT(test_panel_2); + VE::CONNECT(this); // ATTENTION: активировать сигнальную систему в детях-компонентах m_local_panel.on_attach(); - for (int i = 0; i < 200; ++i) - { - auto lp = std::make_shared(); - lp->on_attach(); - m_local_panel_hub.push_back(lp); - } + // for (int i = 0; i < 200; ++i) + // { + // auto lp = std::make_shared(); + // lp->on_attach(); + // m_local_panel_hub.push_back(lp); + // } + + auto lp = std::make_shared(); + lp->on_attach(); + m_local_panel_hub.push_back(lp); hack::log()("on_attach"); } diff --git a/src/event/event.hpp b/src/event/event.hpp index 2cd4cf4..eb14eeb 100755 --- a/src/event/event.hpp +++ b/src/event/event.hpp @@ -66,4 +66,18 @@ namespace VE } } }; + + template + void CONNECT(T* obj) + { + VE::event_manager::instance().connect(obj, &T::on_event); + } + + template + void EMIT(TYPE t, DATA d) + { + VE::event_manager::instance().emit(VE::event{ t, d }); + } + + inline void emit() {} } diff --git a/src/glfw/glfw.cpp b/src/glfw/glfw.cpp index 1c67801..b474fbc 100755 --- a/src/glfw/glfw.cpp +++ b/src/glfw/glfw.cpp @@ -113,8 +113,6 @@ namespace VE { glfwSetKeyCallback(m_win, [](GLFWwindow* w, int key, int scancode, int action, int mods) { - event e{ action, key }; - // HERE // тут одноврекменно срабатывает только один сигнал // т.е. если нажада клавиша и удерживается сигнал о повторе идет @@ -125,22 +123,21 @@ namespace VE { case GLFW_PRESS: { - e.m_type = event_type::KEY_PRESSED; + VE::EMIT(event_type::KEY_PRESSED, key); break; } case GLFW_RELEASE: { - e.m_type = event_type::KEY_RELEASED; + VE::EMIT(event_type::KEY_RELEASED, key); break; } case GLFW_REPEAT: { - e.m_type = event_type::KEY_REPEATE; + VE::EMIT(event_type::KEY_REPEATE, key); break; } } - VE_EMIT(e); }); } @@ -148,8 +145,6 @@ namespace VE { glfwSetMouseButtonCallback(m_win, [](GLFWwindow* w, int button, int action, int mods) { - event e{ action, button }; - switch (action) { case GLFW_PRESS: @@ -159,29 +154,27 @@ namespace VE std::chrono::duration duration = local - time; if (duration.count() > 10 && duration.count() < 200) - e.m_type = event_type::MOUSE_BUTTON_DOUBLE_PRESSED; + VE::EMIT(event_type::MOUSE_BUTTON_DOUBLE_PRESSED, button); else - e.m_type = event_type::MOUSE_BUTTON_PRESSED; + VE::EMIT(event_type::MOUSE_BUTTON_PRESSED, button); time = local; break; } case GLFW_RELEASE: { - e.m_type = event_type::MOUSE_BUTTON_RELEASED; + VE::EMIT(event_type::MOUSE_BUTTON_RELEASED, button); break; } } - - VE_EMIT(e); }); glfwSetScrollCallback(m_win, [](GLFWwindow* w, double xOffset, double yOffset) { try { - event e{ event_type::MOUSE_SCROLL, std::pair{ static_cast(xOffset), static_cast(yOffset) } }; - VE_EMIT(e); + auto data = std::pair{ static_cast(xOffset), static_cast(yOffset) }; + VE::EMIT(event_type::MOUSE_SCROLL, data); } catch(std::exception& e) { @@ -193,8 +186,8 @@ namespace VE { try { - event e{ event_type::MOUSE_CURSOR_POSITION, std::pair{ static_cast(xPos), static_cast(yPos) } }; - VE_EMIT(e); + auto data = std::pair{ static_cast(xPos), static_cast(yPos) }; + VE::EMIT(event_type::MOUSE_CURSOR_POSITION, data); } catch(std::exception& e) { @@ -215,8 +208,8 @@ namespace VE try { - event e{ event_type::WINDOW_RESIZE, std::pair{ static_cast(width), static_cast(height) } }; - VE_EMIT(e); + auto data = std::pair{ static_cast(width), static_cast(height) }; + VE::EMIT(event_type::WINDOW_RESIZE, data); } catch(std::exception& e) { @@ -228,8 +221,7 @@ namespace VE { try { - event e{ event_type::WINDOW_CLOSE, nullptr }; - VE_EMIT(e); + VE::EMIT(event_type::WINDOW_CLOSE, nullptr); } catch(std::exception& e) { @@ -241,8 +233,7 @@ namespace VE { try { - event e{ event_type::WINDOW_FOCUS, focused }; - VE_EMIT(e); + VE::EMIT(event_type::WINDOW_FOCUS, focused); } catch(std::exception& e) { diff --git a/src/utils/define.hpp b/src/utils/define.hpp index ae19edb..576dfb4 100755 --- a/src/utils/define.hpp +++ b/src/utils/define.hpp @@ -10,10 +10,6 @@ void update() override;\ void on_event(VE::event e) override -#define VE_CONNECT(DEF_CLASS) VE::event_manager::instance().connect(this, &DEF_CLASS::on_event); - -#define VE_EMIT(e) VE::event_manager::instance().emit(e) - #define VE_PUSH_FONT(def_font, def_size)\ ImGui::PushFont(VE::style::fonts::get_font(VE::style::fonts::font_type::def_font, def_size)) #define VE_POP_FONT() ImGui::PopFont()