#include "editNetwork.h" #include "builders/freeExtend.h" #include "builders/join.h" #include "builders/straight.h" #include "text.h" #include #include #include #include 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()}, {"ui/icon/network.png", mode.toggle()}, {"ui/icon/network.png", mode.toggle()}, }, blue {1, 1, &TRANSPARENT_BLUE}, font {fontpath, 15} { } bool EditNetwork::click(const SDL_MouseButtonEvent & e, const Ray & 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 & 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(&Renderable::render, shader); } void EditNetwork::Builder::setHeightsFor(Network * network, const Link::CCollection & links, GeoData::SetHeightsOpts opts) { opts.surface = network->getBaseSurface(); const auto width = network->getBaseWidth(); for (const auto & link : links) { gameState->geoData->setHeights(link->getBase(width), opts); } } 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); }