From e806d41c8703ddc4bcaf2186d0c1701bd1e1ada3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 22 Dec 2021 12:16:38 +0000 Subject: Initial commit with some basic UI --- ui/window.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'ui/window.cpp') diff --git a/ui/window.cpp b/ui/window.cpp index cd4a202..13c7d95 100644 --- a/ui/window.cpp +++ b/ui/window.cpp @@ -1,9 +1,10 @@ #include "window.h" -#include "inputHandler.h" #include "uiComponent.h" #include -#include +#include #include +#include +#include static SDL_GLContext SDL_GL_CreateContextAndGlewInit(SDL_Window * w) @@ -27,7 +28,7 @@ Window::Window(size_t width, size_t height, const std::string & title) : static_cast(width), static_cast(height), static_cast(SDL_WINDOW_OPENGL)}, uiShader {[this](auto w) { // must call glContent before creating the shader - glContext(); + std::ignore = glContext(); return w; }(width), height} @@ -51,7 +52,17 @@ bool Window::handleInput(const SDL_Event & e) { if (SDL_GetWindowID(m_window) == e.window.windowID) { - inputStack.applyOne(&InputHandler::handleInput, e); + 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; + } + uiComponents.applyOne(&UIComponent::handleInput, eAdjusted, UIComponent::Position {{}, size}); return true; } return false; @@ -80,5 +91,5 @@ Window::render(const GameState *) const { uiShader.use(); glDisable(GL_DEPTH_TEST); - inputStack.apply(&UIComponent::render, uiShader); + uiComponents.apply(&UIComponent::render, uiShader, UIComponent::Position {}); } -- cgit v1.2.3