summaryrefslogtreecommitdiff
path: root/ui/windowContent.cpp
blob: 91732a7cb7c53980bf32390c27d6a834e835938e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "windowContent.h"
#include "SDL_events.h"

WindowContent::WindowContent(size_t width, size_t height) : uiShader {width, height} { }

void
WindowContent::tick(TickDuration)
{
}

bool
WindowContent::handleInput(const SDL_Event & e)
{
	SDL_Event eAdjusted {e};
	const auto size = [&e] {
		glm::ivec2 size {};
		SDL_GetWindowSizeInPixels(SDL_GetWindowFromID(e.window.windowID), &size.x, &size.y);
		return size;
	}();
	switch (e.type) {
			//  SDL and OpenGL have coordinates that are vertically opposed.
		case SDL_MOUSEBUTTONDOWN:
		case SDL_MOUSEBUTTONUP:
			eAdjusted.button.y = size.y - e.button.y;
			break;
		case SDL_MOUSEMOTION:
			eAdjusted.motion.y = size.y - e.motion.y;
			break;
	}
	uiComponents.rapplyOne(&UIComponent::handleInput, eAdjusted, UIComponent::Position {{}, size});
	return true;
}