mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-09-03 01:20:00 +02:00
Fixed an annoying bug where the application would freeze when resizing the window This pull request made it so the SDL window's resizing event now broadcasts a new event specifically asking the swapchain to recreate itself, which will in turn broadcast the original event when done. It also removed the Event enum specific values, as they were irrelevant.
55 lines
1.1 KiB
C++
55 lines
1.1 KiB
C++
#include <PreCompiled.h>
|
|
|
|
#include <Platform/Inputs.h>
|
|
#include <Core/SDLManager.h>
|
|
#include <Core/EventBus.h>
|
|
|
|
namespace mlx
|
|
{
|
|
namespace Internal
|
|
{
|
|
struct SwapchainResizeEventBroadcast : public EventBase
|
|
{
|
|
Event What() const override { return Event::SwapchainResizeEventCode; }
|
|
};
|
|
}
|
|
|
|
void Inputs::FetchInputs()
|
|
{
|
|
SDLManager::Get().InputsFetcher([this](mlx_event_type event, int window_id, int code)
|
|
{
|
|
if(!m_windows.contains(window_id))
|
|
return;
|
|
if(!m_events_hooks.contains(window_id) || m_events_hooks[window_id][event].empty())
|
|
return;
|
|
if(event == MLX_WINDOW_EVENT && code == 8)
|
|
EventBus::SendBroadcast(Internal::SwapchainResizeEventBroadcast{});
|
|
for(const auto& hook : m_events_hooks[window_id][event])
|
|
{
|
|
if(hook.fn)
|
|
hook.fn(code, hook.param);
|
|
}
|
|
});
|
|
}
|
|
|
|
std::int32_t Inputs::GetX() const noexcept
|
|
{
|
|
return SDLManager::Get().GetX();
|
|
}
|
|
|
|
std::int32_t Inputs::GetY() const noexcept
|
|
{
|
|
return SDLManager::Get().GetY();
|
|
}
|
|
|
|
std::int32_t Inputs::GetXRel() const noexcept
|
|
{
|
|
return SDLManager::Get().GetXRel();
|
|
}
|
|
|
|
std::int32_t Inputs::GetYRel() const noexcept
|
|
{
|
|
return SDLManager::Get().GetYRel();
|
|
}
|
|
}
|