diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-12-18 19:56:38 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-12-18 19:56:40 +0000 |
commit | 5cba33aedccdfa79f1c291bc1da8ff2223d5c70a (patch) | |
tree | 1aeb276c496edbd8beea180d9d032583d27cef49 | |
parent | Add sanity checking logic to GeoData (diff) | |
download | ilt-5cba33aedccdfa79f1c291bc1da8ff2223d5c70a.tar.bz2 ilt-5cba33aedccdfa79f1c291bc1da8ff2223d5c70a.tar.xz ilt-5cba33aedccdfa79f1c291bc1da8ff2223d5c70a.zip |
Give UI builders an interface that can be programmatically called
-rw-r--r-- | ui/builders/freeExtend.cpp | 16 | ||||
-rw-r--r-- | ui/builders/freeExtend.h | 6 | ||||
-rw-r--r-- | ui/builders/join.cpp | 4 | ||||
-rw-r--r-- | ui/builders/join.h | 3 | ||||
-rw-r--r-- | ui/builders/straight.cpp | 5 | ||||
-rw-r--r-- | ui/builders/straight.h | 5 |
6 files changed, 31 insertions, 8 deletions
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<GlobalPosition3D> & ray) override; void move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent & e, const Ray<GlobalPosition3D> & ray) override; +public: + Link::CCollection createJoin(Network * network, GlobalPosition3D, GlobalPosition3D) const; + Link::CCollection createExtend(Network * network, GlobalPosition3D, GlobalPosition3D) const; + +private: std::optional<GlobalPosition3D> 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<GlobalPosition3D> & ray) override; void move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent & e, const Ray<GlobalPosition3D> & 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 <game/geoData.h> 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<GlobalPosition3D> & ray) override; void move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent & e, const Ray<GlobalPosition3D> & 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<GlobalPosition3D> p1; }; |