summaryrefslogtreecommitdiff
path: root/ui/toolbar.cpp
blob: 31d87dc31253c1c60baca129ef889f02a59aaa06 (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
33
34
35
#include "toolbar.h"
#include "gfx/gl/uiShader.h"
#include "ui/iconButton.h"
#include "ui/uiComponent.h"
#include "uiComponentPlacer.h"
#include <SDL2/SDL.h>
#include <glm/glm.hpp>

Toolbar::Toolbar(const std::initializer_list<InitInfo> & initInfo) : UIComponent {{{}, {}}}
{
	UIComponentPlacer placer {{10, 10}, 5, 1};
	for (const auto & ii : initInfo) {
		icons.create(ii.first, placer.next(ICON_SIZE), ii.second);
	}
	this->position.size = placer.getLimit();
}

void
Toolbar::render(const UIShader & uiShader, const Position & parentPos) const
{
	uiShader.icon.use();
	const auto absPos = this->position + parentPos;
	icons.apply(&UIComponent::render, uiShader, absPos);
}

bool
Toolbar::handleInput(const SDL_Event & e, const Position & parentPos)
{
	const auto absPos = this->position + parentPos;
	if (absPos & e.button) {
		icons.applyOne(&UIComponent::handleInput, e, absPos);
		return true;
	}
	return false;
}