summaryrefslogtreecommitdiff
path: root/ui/editNetwork.cpp
blob: ac2d93d800d5ffe57a1468abba35198e9931a26c (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "editNetwork.h"
#include "builders/freeExtend.h"
#include "builders/join.h"
#include "builders/straight.h"
#include "text.h"
#include <game/gamestate.h>
#include <game/geoData.h>
#include <gfx/gl/sceneShader.h>
#include <gfx/models/texture.h>

const std::filesystem::path fontpath {"/usr/share/fonts/hack/Hack-Regular.ttf"};
constexpr const glm::u8vec4 TRANSPARENT_BLUE {30, 50, 255, 200};

EditNetwork::EditNetwork(Network * n) :
	network {n},
	builderToolbar {
			{"ui/icon/network.png", mode.toggle<BuilderStraight>()},
			{"ui/icon/network.png", mode.toggle<BuilderJoin>()},
			{"ui/icon/network.png", mode.toggle<BuilderFreeExtend>()},
	},
	blue {1, 1, &TRANSPARENT_BLUE}, font {fontpath, 15}
{
}

bool
EditNetwork::click(const SDL_MouseButtonEvent & e, const Ray<GlobalPosition3D> & ray)
{
	if (builder && (e.button == SDL_BUTTON_LEFT || e.button == SDL_BUTTON_MIDDLE)) {
		builder->click(network, gameState->geoData.get(), e, ray);
		return true;
	}
	return false;
}

bool
EditNetwork::move(const SDL_MouseMotionEvent & e, const Ray<GlobalPosition3D> & ray)
{
	if (builder) {
		builder->move(network, gameState->geoData.get(), e, ray);
	}
	return false;
}

bool
EditNetwork::handleInput(const SDL_Event & e, const UIComponent::Position & parentPos)
{
	return builderToolbar.handleInput(e, parentPos);
}

void
EditNetwork::render(const SceneShader & shader) const
{
	if (builder) {
		blue.bind();
		shader.absolute.use();
		builder->render(shader);
	}
}

void
EditNetwork::Builder::render(const SceneShader & shader) const
{
	candidateLinks.apply<const Renderable>(&Renderable::render, shader);
}

void
EditNetwork::render(const UIShader & shader, const UIComponent::Position & parentPos) const
{
	if (builder) {
		Text {builder->hint(), font, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos);
	}
	builderToolbar.render(shader, parentPos);
}