fix event

This commit is contained in:
2025-02-26 15:09:30 +03:00
parent 121d4af325
commit 7e419c9b79
12 changed files with 29 additions and 85 deletions

View File

@@ -1,8 +1,6 @@
#include "glfw.hpp"
// #include "renderer/renderer.hpp"
// #include "event/system_event/category/key_event.hpp"
// #include "event/system_event/category/window_event.hpp"
#include "event/event.hpp"
namespace VE
{
@@ -111,16 +109,10 @@ namespace VE
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void glfw::set_event_fn(const event_fn<event>& fn)
{
m_win_data.execute = fn;
}
void glfw::set_key_callback()
{
glfwSetKeyCallback(m_win, [](GLFWwindow* w, int key, int scancode, int action, int mods)
{
auto d = static_cast<win_data*>(glfwGetWindowUserPointer(w));
event e{ event_target::VE, action, key };
// HERE
@@ -148,7 +140,7 @@ namespace VE
}
}
d->execute(e);
EMIT(e);
});
}
@@ -156,7 +148,6 @@ namespace VE
{
glfwSetMouseButtonCallback(m_win, [](GLFWwindow* w, int button, int action, int mods)
{
auto d = static_cast<win_data*>(glfwGetWindowUserPointer(w));
event e{ event_target::VE, action, button };
switch (action)
@@ -182,23 +173,15 @@ namespace VE
}
}
try
{
d->execute(e);
}
catch(std::exception& e)
{
hack::log()("VE_ERROR: ", e.what());
}
EMIT(e);
});
glfwSetScrollCallback(m_win, [](GLFWwindow* w, double xOffset, double yOffset)
{
auto d = static_cast<win_data*>(glfwGetWindowUserPointer(w));
try
{
event e{ event_target::VE, event_type::MOUSE_SCROLL, std::pair<float, float>{ static_cast<float>(xOffset), static_cast<float>(yOffset) } };
d->execute(e);
EMIT(e);
}
catch(std::exception& e)
{
@@ -208,11 +191,10 @@ namespace VE
glfwSetCursorPosCallback(m_win, [](GLFWwindow* w, double xPos, double yPos)
{
auto d = static_cast<win_data*>(glfwGetWindowUserPointer(w));
try
{
event e{ event_target::VE, event_type::MOUSE_CURSOR_POSITION, std::pair<float, float>{ static_cast<float>(xPos), static_cast<float>(yPos) } };
d->execute(e);
EMIT(e);
}
catch(std::exception& e)
{
@@ -234,7 +216,7 @@ namespace VE
try
{
event e{ event_target::VE, event_type::WINDOW_RESIZE, std::pair<float, float>{ static_cast<float>(width), static_cast<float>(height) } };
d->execute(e);
EMIT(e);
}
catch(std::exception& e)
{
@@ -244,11 +226,10 @@ namespace VE
glfwSetWindowCloseCallback(m_win, [](GLFWwindow* w)
{
auto d = static_cast<win_data*>(glfwGetWindowUserPointer(w));
try
{
event e{ event_target::VE, event_type::WINDOW_CLOSE, nullptr };
d->execute(e);
EMIT(e);
}
catch(std::exception& e)
{
@@ -258,11 +239,10 @@ namespace VE
glfwSetWindowFocusCallback(m_win, [](GLFWwindow* w, int focused)
{
auto d = static_cast<win_data*>(glfwGetWindowUserPointer(w));
try
{
event e{ event_target::VE, event_type::WINDOW_FOCUS, focused };
d->execute(e);
EMIT(e);
}
catch(std::exception& e)
{

View File

@@ -2,7 +2,6 @@
#include "utils/utils.hpp" // IWYU pragma: keep
#include "context/context.hpp"
#include "event/event.hpp"
namespace VE
{
@@ -27,7 +26,6 @@ namespace VE
{
std::string m_name;
int m_width, m_height;
event_fn<event&> execute; // в using.hpp
} m_win_data;
public:
@@ -40,8 +38,6 @@ namespace VE
void update();
void clear() const;
void set_event_fn(const event_fn<event>& fn);
private:
void set_hint();
void set_window();