fix event func

This commit is contained in:
2025-03-15 12:33:59 +03:00
parent c555c47eb3
commit 3b64a8a337
7 changed files with 44 additions and 43 deletions

View File

@@ -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" );

View File

@@ -47,7 +47,6 @@ namespace sandbox
void opengl_panel::on_attach()
{
VE_CONNECT(opengl_panel);
hack::log()("on_attach");
}

View File

@@ -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();

View File

@@ -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<local_panel>();
lp->on_attach();
m_local_panel_hub.push_back(lp);
}
// for (int i = 0; i < 200; ++i)
// {
// auto lp = std::make_shared<local_panel>();
// lp->on_attach();
// m_local_panel_hub.push_back(lp);
// }
auto lp = std::make_shared<local_panel>();
lp->on_attach();
m_local_panel_hub.push_back(lp);
hack::log()("on_attach");
}

View File

@@ -66,4 +66,18 @@ namespace VE
}
}
};
template <typename T>
void CONNECT(T* obj)
{
VE::event_manager::instance().connect(obj, &T::on_event);
}
template <typename TYPE, typename DATA>
void EMIT(TYPE t, DATA d)
{
VE::event_manager::instance().emit(VE::event{ t, d });
}
inline void emit() {}
}

View File

@@ -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<double, std::milli> 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<float, float>{ static_cast<float>(xOffset), static_cast<float>(yOffset) } };
VE_EMIT(e);
auto data = std::pair<float, float>{ static_cast<float>(xOffset), static_cast<float>(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<float, float>{ static_cast<float>(xPos), static_cast<float>(yPos) } };
VE_EMIT(e);
auto data = std::pair<float, float>{ static_cast<float>(xPos), static_cast<float>(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<float, float>{ static_cast<float>(width), static_cast<float>(height) } };
VE_EMIT(e);
auto data = std::pair<float, float>{ static_cast<float>(width), static_cast<float>(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)
{

View File

@@ -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()