From 0d59b73de4e51a3a5b3c680f3dca97c2b942cc09 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Oct 2022 18:15:53 +0100 Subject: Builders manage a collection of candidate links rendered by the base builder --- ui/builders/join.cpp | 19 ++++++++++++++----- ui/builders/join.h | 2 +- ui/builders/straight.cpp | 20 +++++++++++++++----- ui/builders/straight.h | 2 +- 4 files changed, 31 insertions(+), 12 deletions(-) (limited to 'ui/builders') diff --git a/ui/builders/join.cpp b/ui/builders/join.cpp index cc2ca2d..caa635f 100644 --- a/ui/builders/join.cpp +++ b/ui/builders/join.cpp @@ -1,11 +1,6 @@ #include "join.h" #include -void -BuilderJoin::render(const Shader &) const -{ -} - std::string BuilderJoin::hint() const { @@ -15,6 +10,19 @@ BuilderJoin::hint() const return "Pick first node"; } +void +BuilderJoin::move(Network * network, const GeoData *, const SDL_MouseMotionEvent &, const Ray & ray) +{ + if (p1) { + if (const auto p = network->intersectRayNodes(ray)) { + candidateLinks.objects = network->candidateJoins(p1->pos, p->pos); + } + else { + candidateLinks.removeAll(); + } + } +} + void BuilderJoin::click(Network * network, const GeoData *, const SDL_MouseButtonEvent & e, const Ray & ray) { @@ -24,6 +32,7 @@ BuilderJoin::click(Network * network, const GeoData *, const SDL_MouseButtonEven if (p1) { create(network, p1, p); p1.reset(); + candidateLinks.removeAll(); } else { p1 = p; diff --git a/ui/builders/join.h b/ui/builders/join.h index 30d39cd..bb0bd4c 100644 --- a/ui/builders/join.h +++ b/ui/builders/join.h @@ -5,9 +5,9 @@ class Network; class GeoData; class BuilderJoin : 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 move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent & e, const Ray & ray) override; void create(Network * network, const Node::Ptr & p1, const Node::Ptr & p2) const; diff --git a/ui/builders/straight.cpp b/ui/builders/straight.cpp index 7024746..477b40d 100644 --- a/ui/builders/straight.cpp +++ b/ui/builders/straight.cpp @@ -1,11 +1,6 @@ #include "straight.h" #include -void -BuilderStraight::render(const Shader &) const -{ -} - std::string BuilderStraight::hint() const { @@ -15,6 +10,19 @@ BuilderStraight::hint() const return "Pick straight start point"; } +void +BuilderStraight::move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent &, const Ray & ray) +{ + if (p1) { + if (const auto p = geoData->intersectRay(ray)) { + candidateLinks.objects = network->candidateStraight(*p1, *p); + } + else { + candidateLinks.removeAll(); + } + } +} + void BuilderStraight::click(Network * network, const GeoData * geoData, const SDL_MouseButtonEvent & e, const Ray & ray) { @@ -23,12 +31,14 @@ BuilderStraight::click(Network * network, const GeoData * geoData, const SDL_Mou if (const auto p = geoData->intersectRay(ray)) { if (p1) { create(network, *p1, *p); + candidateLinks.removeAll(); } p1 = *p; } return; case SDL_BUTTON_MIDDLE: p1.reset(); + candidateLinks.removeAll(); return; } } diff --git a/ui/builders/straight.h b/ui/builders/straight.h index 77847dd..1cde2b0 100644 --- a/ui/builders/straight.h +++ b/ui/builders/straight.h @@ -5,9 +5,9 @@ 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 move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent & e, const Ray & ray) override; void create(Network * network, glm::vec3 p1, glm::vec3 p2) const; -- cgit v1.2.3