From f6890e8077133b5dd2cc0a92270d2a328d6c5ab9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 8 Oct 2022 17:04:40 +0100 Subject: Initial commit of a basic working network editor --- ui/builders/straight.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ ui/builders/straight.h | 15 +++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 ui/builders/straight.cpp create mode 100644 ui/builders/straight.h (limited to 'ui/builders') diff --git a/ui/builders/straight.cpp b/ui/builders/straight.cpp new file mode 100644 index 0000000..7024746 --- /dev/null +++ b/ui/builders/straight.cpp @@ -0,0 +1,40 @@ +#include "straight.h" +#include + +void +BuilderStraight::render(const Shader &) const +{ +} + +std::string +BuilderStraight::hint() const +{ + if (p1) { + return "Pick straight end point"; + } + return "Pick straight start point"; +} + +void +BuilderStraight::click(Network * network, const GeoData * geoData, const SDL_MouseButtonEvent & e, const Ray & ray) +{ + switch (e.button) { + case SDL_BUTTON_LEFT: + if (const auto p = geoData->intersectRay(ray)) { + if (p1) { + create(network, *p1, *p); + } + p1 = *p; + } + return; + case SDL_BUTTON_MIDDLE: + p1.reset(); + return; + } +} + +void +BuilderStraight::create(Network * network, glm::vec3 p1, glm::vec3 p2) const +{ + network->addStraight(p1, p2); +} diff --git a/ui/builders/straight.h b/ui/builders/straight.h new file mode 100644 index 0000000..77847dd --- /dev/null +++ b/ui/builders/straight.h @@ -0,0 +1,15 @@ +#pragma once +#include "../editNetwork.h" + +class Network; +class GeoData; + +class BuilderStraight : public EditNetwork::Builder { + void render(const Shader &) const override; + std::string hint() const override; + void click(Network * network, const GeoData * geoData, const SDL_MouseButtonEvent & e, const Ray & ray) override; + + void create(Network * network, glm::vec3 p1, glm::vec3 p2) const; + + std::optional p1; +}; -- cgit v1.2.3