summaryrefslogtreecommitdiff
path: root/ui/builders
diff options
context:
space:
mode:
Diffstat (limited to 'ui/builders')
-rw-r--r--ui/builders/join.cpp43
-rw-r--r--ui/builders/join.h15
2 files changed, 58 insertions, 0 deletions
diff --git a/ui/builders/join.cpp b/ui/builders/join.cpp
new file mode 100644
index 0000000..90b1d61
--- /dev/null
+++ b/ui/builders/join.cpp
@@ -0,0 +1,43 @@
+#include "join.h"
+#include <game/geoData.h>
+
+void
+BuilderJoin::render(const Shader &) const
+{
+}
+
+std::string
+BuilderJoin::hint() const
+{
+ if (p1) {
+ return "Pick second node";
+ }
+ return "Pick first node";
+}
+
+void
+BuilderJoin::click(Network * network, const GeoData *, const SDL_MouseButtonEvent & e, const Ray & ray)
+{
+ switch (e.button) {
+ case SDL_BUTTON_LEFT:
+ if (const auto p = network->intersectRayNodes(ray)) {
+ if (p1) {
+ create(network, p1, p);
+ p1.reset();
+ }
+ else {
+ p1 = p;
+ }
+ }
+ return;
+ case SDL_BUTTON_MIDDLE:
+ p1.reset();
+ return;
+ }
+}
+
+void
+BuilderJoin::create(Network * network, const NodePtr & p1, const NodePtr & p2) const
+{
+ network->addJoins(p1->pos, p2->pos);
+}
diff --git a/ui/builders/join.h b/ui/builders/join.h
new file mode 100644
index 0000000..d4fb534
--- /dev/null
+++ b/ui/builders/join.h
@@ -0,0 +1,15 @@
+#pragma once
+#include "../editNetwork.h"
+
+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 create(Network * network, const NodePtr & p1, const NodePtr & p2) const;
+
+ NodePtr p1;
+};