summaryrefslogtreecommitdiff
path: root/ui/window.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-12-22 12:16:38 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-12-22 12:16:38 +0000
commite806d41c8703ddc4bcaf2186d0c1701bd1e1ada3 (patch)
tree1612baf22456c0b5a1bef82980177afb34b2756c /ui/window.cpp
parentWindow handles UIComponent rendering (diff)
downloadilt-e806d41c8703ddc4bcaf2186d0c1701bd1e1ada3.tar.bz2
ilt-e806d41c8703ddc4bcaf2186d0c1701bd1e1ada3.tar.xz
ilt-e806d41c8703ddc4bcaf2186d0c1701bd1e1ada3.zip
Initial commit with some basic UI
Diffstat (limited to 'ui/window.cpp')
-rw-r--r--ui/window.cpp21
1 files changed, 16 insertions, 5 deletions
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 <GL/glew.h>
-#include <optional>
+#include <glm/glm.hpp>
#include <stdexcept>
+#include <tuple>
+#include <type_traits>
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<int>(width), static_cast<int>(height), static_cast<Uint32>(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>(&UIComponent::render, uiShader);
+ uiComponents.apply(&UIComponent::render, uiShader, UIComponent::Position {});
}