From 377bb9207385bd29fc8084e4d2e51aba27c7f236 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 31 Oct 2022 09:12:27 +0000 Subject: Save window size as a member variable --- ui/window.cpp | 9 ++++----- ui/window.h | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'ui') 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; using SDL_GLContextPtr = wrapped_ptrt; Window::Window(size_t width, size_t height, const std::string & title) : - m_window {title.c_str(), static_cast(SDL_WINDOWPOS_CENTERED), static_cast(SDL_WINDOWPOS_CENTERED), - static_cast(width), static_cast(height), static_cast(SDL_WINDOW_OPENGL)}, + size {static_cast(width), static_cast(height)}, m_window {title.c_str(), + static_cast(SDL_WINDOWPOS_CENTERED), + static_cast(SDL_WINDOWPOS_CENTERED), size.x, + size.y, static_cast(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; + const glm::ivec2 size; SDL_WindowPtr m_window; Collection uiComponents; UIShader uiShader; -- cgit v1.2.3