feat(gx): handle SDL window resize event

This commit is contained in:
superp00t 2023-11-26 14:42:47 -05:00
parent dbac391d9e
commit 21dcc7d8ae
2 changed files with 21 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include "event/Types.hpp"
#include "event/Input.hpp"
#include "event/Event.hpp"
#include "gx/Window.hpp"
#include <bc/Debug.hpp>
#include <storm/Unicode.hpp>
@ -287,6 +288,9 @@ void GLSDLWindow::DispatchSDLEvent(const SDL_Event& event) {
case SDL_EVENT_TEXT_INPUT:
this->DispatchSDLTextInputEvent(event);
break;
case SDL_EVENT_WINDOW_RESIZED:
this->DispatchSDLWindowResizedEvent(event);
break;
case SDL_EVENT_QUIT:
EventPostClose();
break;
@ -363,3 +367,19 @@ void GLSDLWindow::DispatchSDLTextInputEvent(const SDL_Event& event) {
text += charactersize;
}
}
void GLSDLWindow::DispatchSDLWindowResizedEvent(const SDL_Event& event) {
auto width = static_cast<int32_t>(event.window.data1);
auto height = static_cast<int32_t>(event.window.data2);
OsQueuePut(OS_INPUT_SIZE, width, height, 0, 0);
auto bounds = GetSavedWindowBounds();
Rect newBounds = {
bounds->top,
bounds->left,
static_cast<int16_t>(bounds->top + height),
static_cast<int16_t>(bounds->left + width)
};
SetSavedWindowBounds(newBounds);
}

View File

@ -35,6 +35,7 @@ class GLSDLWindow {
void DispatchSDLMouseMotionEvent(const SDL_Event& event);
void DispatchSDLMouseButtonEvent(const SDL_Event& event);
void DispatchSDLTextInputEvent(const SDL_Event& event);
void DispatchSDLWindowResizedEvent(const SDL_Event& event);
void Resize(const GLSDLWindowRect& rect);
GLSDLWindowRect GetRect();