summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorDan Goodliffe <dan.goodliffe@octal.co.uk>2022-10-31 09:12:27 +0000
committerDan Goodliffe <dan.goodliffe@octal.co.uk>2022-10-31 09:12:27 +0000
commit377bb9207385bd29fc8084e4d2e51aba27c7f236 (patch)
tree81270b72b9d8915f0d59326d01dad1ae9b352bdf /ui
parentSetting texture unit when binding UI components (diff)
downloadilt-377bb9207385bd29fc8084e4d2e51aba27c7f236.tar.bz2
ilt-377bb9207385bd29fc8084e4d2e51aba27c7f236.tar.xz
ilt-377bb9207385bd29fc8084e4d2e51aba27c7f236.zip
Save window size as a member variable
Diffstat (limited to 'ui')
-rw-r--r--ui/window.cpp9
-rw-r--r--ui/window.h1
2 files changed, 5 insertions, 5 deletions
diff --git a/ui/window.cpp b/ui/window.cpp
index 73ed0c1..419abc3 100644
--- a/ui/window.cpp
+++ b/ui/window.cpp
@@ -26,8 +26,10 @@ using GL_Context = std::remove_pointer_t<SDL_GLContext>;
using SDL_GLContextPtr = wrapped_ptrt<GL_Context, SDL_GL_CreateContextAndGlewInit, SDL_GL_DeleteContext>;
Window::Window(size_t width, size_t height, const std::string & title) :
- m_window {title.c_str(), static_cast<int>(SDL_WINDOWPOS_CENTERED), static_cast<int>(SDL_WINDOWPOS_CENTERED),
- static_cast<int>(width), static_cast<int>(height), static_cast<Uint32>(SDL_WINDOW_OPENGL)},
+ size {static_cast<int>(width), static_cast<int>(height)}, m_window {title.c_str(),
+ static_cast<int>(SDL_WINDOWPOS_CENTERED),
+ static_cast<int>(SDL_WINDOWPOS_CENTERED), size.x,
+ size.y, static_cast<Uint32>(SDL_WINDOW_OPENGL)},
uiShader {[this](auto w) {
// must call glContent before creating the shader
std::ignore = glContext();
@@ -55,16 +57,13 @@ Window::handleInput(const SDL_Event & e)
{
if (SDL_GetWindowID(m_window) == e.window.windowID) {
SDL_Event eAdjusted {e};
- glm::ivec2 size {};
switch (e.type) {
// SDL and OpenGL have coordinates that are vertically opposed.
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
- SDL_GetWindowSize(m_window, &size.x, &size.y);
eAdjusted.button.y = size.y - e.button.y;
break;
case SDL_MOUSEMOTION:
- SDL_GetWindowSize(m_window, &size.x, &size.y);
eAdjusted.motion.y = size.y - e.motion.y;
break;
}
diff --git a/ui/window.h b/ui/window.h
index f808588..dc3c528 100644
--- a/ui/window.h
+++ b/ui/window.h
@@ -33,6 +33,7 @@ protected:
virtual const Shader & getShader() const = 0;
using SDL_WindowPtr = wrapped_ptrt<SDL_Window, SDL_CreateWindow, SDL_DestroyWindow>;
+ const glm::ivec2 size;
SDL_WindowPtr m_window;
Collection<UIComponent> uiComponents;
UIShader uiShader;