From 5cba33aedccdfa79f1c291bc1da8ff2223d5c70a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 18 Dec 2024 19:56:38 +0000 Subject: Give UI builders an interface that can be programmatically called --- ui/builders/freeExtend.cpp | 16 ++++++++++++++-- ui/builders/freeExtend.h | 6 ++++++ ui/builders/join.cpp | 4 ++-- ui/builders/join.h | 3 ++- ui/builders/straight.cpp | 5 +++-- ui/builders/straight.h | 5 ++++- 6 files changed, 31 insertions(+), 8 deletions(-) (limited to 'ui') diff --git a/ui/builders/freeExtend.cpp b/ui/builders/freeExtend.cpp index db127e6..904e144 100644 --- a/ui/builders/freeExtend.cpp +++ b/ui/builders/freeExtend.cpp @@ -38,11 +38,11 @@ BuilderFreeExtend::click( case SDL_BUTTON_LEFT: if (p1) { if (const auto p = network->intersectRayNodes(ray)) { - network->addJoins(*p1, p->pos); + createJoin(network, *p1, p->pos); p1 = p->pos; } else if (const auto p = geoData->intersectRay(ray)) { - network->addExtend(*p1, p->first); + createExtend(network, *p1, p->first); p1 = p->first; } } @@ -57,3 +57,15 @@ BuilderFreeExtend::click( return; } } + +Link::CCollection +BuilderFreeExtend::createJoin(Network * network, GlobalPosition3D p1, GlobalPosition3D p2) const +{ + return network->addJoins(p1, p2); +} + +Link::CCollection +BuilderFreeExtend::createExtend(Network * network, GlobalPosition3D p1, GlobalPosition3D p2) const +{ + return network->addExtend(p1, p2); +} diff --git a/ui/builders/freeExtend.h b/ui/builders/freeExtend.h index 0d5f327..8e30ef4 100644 --- a/ui/builders/freeExtend.h +++ b/ui/builders/freeExtend.h @@ -5,11 +5,17 @@ class Network; class GeoData; class BuilderFreeExtend : public EditNetwork::Builder { +private: 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; +public: + Link::CCollection createJoin(Network * network, GlobalPosition3D, GlobalPosition3D) const; + Link::CCollection createExtend(Network * network, GlobalPosition3D, GlobalPosition3D) const; + +private: std::optional p1; }; diff --git a/ui/builders/join.cpp b/ui/builders/join.cpp index 7474c5b..9fbbae9 100644 --- a/ui/builders/join.cpp +++ b/ui/builders/join.cpp @@ -46,8 +46,8 @@ BuilderJoin::click( } } -void +Link::CCollection BuilderJoin::create(Network * network, const Node::Ptr & p1, const Node::Ptr & p2) const { - network->addJoins(p1->pos, p2->pos); + return network->addJoins(p1->pos, p2->pos); } diff --git a/ui/builders/join.h b/ui/builders/join.h index dd57895..d92037c 100644 --- a/ui/builders/join.h +++ b/ui/builders/join.h @@ -5,13 +5,14 @@ class Network; class GeoData; class BuilderJoin : public EditNetwork::Builder { +private: 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; + Link::CCollection create(Network * network, const Node::Ptr & p1, const Node::Ptr & p2) const; Node::Ptr p1; }; diff --git a/ui/builders/straight.cpp b/ui/builders/straight.cpp index 43f5ec8..014eea5 100644 --- a/ui/builders/straight.cpp +++ b/ui/builders/straight.cpp @@ -1,4 +1,5 @@ #include "straight.h" +#include "stream_support.h" #include std::string @@ -48,8 +49,8 @@ BuilderStraight::click( } } -void +Link::CCollection BuilderStraight::create(Network * network, GlobalPosition3D p1, GlobalPosition3D p2) const { - network->addStraight(p1, p2); + return network->addStraight(p1, p2); } diff --git a/ui/builders/straight.h b/ui/builders/straight.h index 28eb66e..1717cad 100644 --- a/ui/builders/straight.h +++ b/ui/builders/straight.h @@ -5,13 +5,16 @@ class Network; class GeoData; class BuilderStraight : public EditNetwork::Builder { +private: 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, GlobalPosition3D p1, GlobalPosition3D p2) const; +public: + Link::CCollection create(Network * network, GlobalPosition3D p1, GlobalPosition3D p2) const; +private: std::optional p1; }; -- cgit v1.2.3