summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/builders/freeExtend.h2
-rw-r--r--ui/builders/straight.cpp2
-rw-r--r--ui/builders/straight.h4
-rw-r--r--ui/editNetwork.h2
-rw-r--r--ui/font.cpp1
-rw-r--r--ui/font.h1
-rw-r--r--ui/gameMainSelector.cpp12
-rw-r--r--ui/gameMainSelector.h3
-rw-r--r--ui/gameMainWindow.cpp8
-rw-r--r--ui/iconButton.h1
-rw-r--r--ui/manualCameraController.cpp4
-rw-r--r--ui/manualCameraController.h6
-rw-r--r--ui/modeHelper.h1
-rw-r--r--ui/text.cpp1
-rw-r--r--ui/text.h1
-rw-r--r--ui/uiComponent.cpp1
-rw-r--r--ui/uiComponent.h1
-rw-r--r--ui/uiComponentPlacer.cpp1
-rw-r--r--ui/window.h3
19 files changed, 36 insertions, 19 deletions
diff --git a/ui/builders/freeExtend.h b/ui/builders/freeExtend.h
index 55fe7ff..b276426 100644
--- a/ui/builders/freeExtend.h
+++ b/ui/builders/freeExtend.h
@@ -9,5 +9,5 @@ class BuilderFreeExtend : public EditNetwork::Builder {
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;
- std::optional<glm::vec3> p1;
+ std::optional<Position3D> p1;
};
diff --git a/ui/builders/straight.cpp b/ui/builders/straight.cpp
index 4fa9585..9b262bb 100644
--- a/ui/builders/straight.cpp
+++ b/ui/builders/straight.cpp
@@ -47,7 +47,7 @@ BuilderStraight::click(Network * network, const GeoData * geoData, const SDL_Mou
}
void
-BuilderStraight::create(Network * network, glm::vec3 p1, glm::vec3 p2) const
+BuilderStraight::create(Network * network, Position3D p1, Position3D p2) const
{
network->addStraight(p1, p2);
}
diff --git a/ui/builders/straight.h b/ui/builders/straight.h
index 1cde2b0..cf99a1d 100644
--- a/ui/builders/straight.h
+++ b/ui/builders/straight.h
@@ -9,7 +9,7 @@ class BuilderStraight : public EditNetwork::Builder {
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;
+ void create(Network * network, Position3D p1, Position3D p2) const;
- std::optional<glm::vec3> p1;
+ std::optional<Position3D> p1;
};
diff --git a/ui/editNetwork.h b/ui/editNetwork.h
index eb1677e..e1aaa61 100644
--- a/ui/editNetwork.h
+++ b/ui/editNetwork.h
@@ -21,7 +21,7 @@ public:
void render(const SceneShader &) const override;
void render(const UIShader & shader, const UIComponent::Position & pos) const override;
- using NetworkClickPos = std::variant<glm::vec3, Node::Ptr>;
+ using NetworkClickPos = std::variant<Position3D, Node::Ptr>;
class Builder {
public:
diff --git a/ui/font.cpp b/ui/font.cpp
index 108f905..ebd856d 100644
--- a/ui/font.cpp
+++ b/ui/font.cpp
@@ -14,6 +14,7 @@
#include <unicode.h>
#include <util.h>
#include <utility>
+
// IWYU pragma: no_forward_declare FT_LibraryRec_
std::string
diff --git a/ui/font.h b/ui/font.h
index 6c86e18..2f3337f 100644
--- a/ui/font.h
+++ b/ui/font.h
@@ -31,6 +31,7 @@ public:
glm::ivec2 bearing;
long advance;
};
+
struct FontTexture {
glTexture texture;
unsigned int used;
diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp
index 081718d..a451ee1 100644
--- a/ui/gameMainSelector.cpp
+++ b/ui/gameMainSelector.cpp
@@ -8,14 +8,16 @@
#include <game/selectable.h>
#include <game/worldobject.h> // IWYU pragma: keep
#include <gfx/gl/camera.h>
+#include <math.h>
#include <optional>
#include <span>
#include <stream_support.h>
#include <typeinfo>
#include <vector>
-GameMainSelector::GameMainSelector(const Camera * c, glm::vec2 size) : UIComponent {{{}, size}}, camera {c} { }
-constexpr glm::vec2 TargetPos {5, 45};
+GameMainSelector::GameMainSelector(const Camera * c, ScreenAbsCoord size) : UIComponent {{{}, size}}, camera {c} { }
+
+constexpr ScreenAbsCoord TargetPos {5, 45};
void
GameMainSelector::render(const UIShader & shader, const Position & parentPos) const
@@ -40,7 +42,7 @@ bool
GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos)
{
const auto getRay = [this](const auto & e) {
- const auto mouse = glm::vec2 {e.x, e.y} / position.size;
+ const auto mouse = ScreenRelCoord {e.x, e.y} / position.size;
return camera->unProject(mouse);
};
if (target) {
@@ -71,8 +73,8 @@ GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos)
void
GameMainSelector::defaultClick(const Ray & ray)
{
- glm::vec2 baryPos {};
- float distance;
+ Position2D baryPos {};
+ float distance {};
if (const auto selected
= gameState->world.applyOne<Selectable>(&Selectable::intersectRay, ray, &baryPos, &distance);
diff --git a/ui/gameMainSelector.h b/ui/gameMainSelector.h
index 98cdf53..88db34b 100644
--- a/ui/gameMainSelector.h
+++ b/ui/gameMainSelector.h
@@ -1,6 +1,7 @@
#pragma once
#include "SDL_events.h"
+#include "config/types.h"
#include "special_members.h"
#include "uiComponent.h"
#include "worldOverlay.h"
@@ -26,7 +27,7 @@ public:
virtual void render(const SceneShader &) const;
};
- GameMainSelector(const Camera * c, glm::vec2 size);
+ GameMainSelector(const Camera * c, ScreenAbsCoord size);
void render(const UIShader & shader, const Position & pos) const override;
void render(const SceneShader & shader) const override;
diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp
index 6981c54..d71c74a 100644
--- a/ui/gameMainWindow.cpp
+++ b/ui/gameMainWindow.cpp
@@ -31,8 +31,8 @@ public:
GameMainWindow::GameMainWindow(size_t w, size_t h) :
Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {Window::size, 0}
{
- uiComponents.create<ManualCameraController>(glm::vec2 {315000, 495000});
- auto gms = uiComponents.create<GameMainSelector>(&camera, glm::vec2 {w, h});
+ uiComponents.create<ManualCameraController>(glm::vec2 {315'000'000, 495'000'000});
+ auto gms = uiComponents.create<GameMainSelector>(&camera, ScreenAbsCoord {w, h});
uiComponents.create<GameMainToolbar>(gms.get());
}
@@ -48,6 +48,7 @@ GameMainWindow::render() const
SceneRenderer::render(*this);
Window::render();
}
+
void
GameMainWindow::content(const SceneShader & shader) const
{
@@ -59,17 +60,20 @@ GameMainWindow::content(const SceneShader & shader) const
gameState->world.apply<Renderable>(&Renderable::render, shader);
uiComponents.apply<WorldOverlay>(&WorldOverlay::render, shader);
}
+
void
GameMainWindow::environment(const SceneShader & s, const SceneRenderer & r) const
{
// default for now
SceneProvider::environment(s, r);
}
+
void
GameMainWindow::lights(const SceneShader & shader) const
{
gameState->world.apply<Renderable>(&Renderable::lights, shader);
}
+
void
GameMainWindow::shadows(const ShadowMapper & shadowMapper) const
{
diff --git a/ui/iconButton.h b/ui/iconButton.h
index 6ac9317..0afe92d 100644
--- a/ui/iconButton.h
+++ b/ui/iconButton.h
@@ -10,6 +10,7 @@ class UIShader;
union SDL_Event;
static const constexpr glm::vec2 ICON_SIZE {32.F, 32.F};
+
class IconButton : public UIComponent {
public:
IconButton(const std::string & icon, glm::vec2 position, UIEvent click);
diff --git a/ui/manualCameraController.cpp b/ui/manualCameraController.cpp
index 8e52b0e..f6993a8 100644
--- a/ui/manualCameraController.cpp
+++ b/ui/manualCameraController.cpp
@@ -59,12 +59,12 @@ ManualCameraController::handleInput(const SDL_Event & e, const Position &)
pitch = std::clamp(pitch - 0.01F * static_cast<float>(e.motion.yrel), 0.1F, half_pi);
}
else {
- focus += rotate_flat(-direction) * glm::vec2 {-e.motion.xrel, e.motion.yrel};
+ focus += rotate_flat(-direction) * (Position2D {-e.motion.xrel, e.motion.yrel} * dist / 2.0F);
}
}
return true;
case SDL_MOUSEWHEEL:
- dist = std::clamp(dist - static_cast<float>(e.wheel.y) * 4.F, 5.F, 200.F);
+ dist = std::clamp(dist - static_cast<float>(e.wheel.y) * 400.F, 5.F, 200000.F);
break;
}
return false;
diff --git a/ui/manualCameraController.h b/ui/manualCameraController.h
index d15fa76..1efaee1 100644
--- a/ui/manualCameraController.h
+++ b/ui/manualCameraController.h
@@ -11,7 +11,7 @@ class Camera;
class ManualCameraController : public CameraController, public UIComponent {
public:
- explicit ManualCameraController(glm::vec2 f) : UIComponent {{}}, focus {f} { }
+ explicit ManualCameraController(Position2D f) : UIComponent {{}}, focus {f} { }
bool handleInput(const SDL_Event & e, const Position &) override;
void render(const UIShader &, const Position & parentPos) const override;
@@ -20,7 +20,7 @@ public:
private:
bool ctrl {false}, mrb {false};
- glm::vec2 focus;
+ Position2D focus;
float direction {quarter_pi};
- float dist {40}, pitch {quarter_pi};
+ float dist {4000}, pitch {quarter_pi};
};
diff --git a/ui/modeHelper.h b/ui/modeHelper.h
index 77707f2..d20f2db 100644
--- a/ui/modeHelper.h
+++ b/ui/modeHelper.h
@@ -4,6 +4,7 @@
union SDL_Event;
enum ModeSecondClick { Unset, Reset, NoAction };
+
template<typename Target, ModeSecondClick msc = ModeSecondClick::Unset> class Mode {
public:
explicit Mode(Target & t) : target {t} { }
diff --git a/ui/text.cpp b/ui/text.cpp
index d24c268..b776b90 100644
--- a/ui/text.cpp
+++ b/ui/text.cpp
@@ -12,6 +12,7 @@
#include <utility>
const std::filesystem::path font {"/usr/share/fonts/hack/Hack-Regular.ttf"};
+
Text::Text(std::string_view s, Position pos, glm::vec3 c) : UIComponent {pos}, colour {c}
{
for (const auto & textureQuads :
diff --git a/ui/text.h b/ui/text.h
index 9fe87d1..de2fe2e 100644
--- a/ui/text.h
+++ b/ui/text.h
@@ -25,6 +25,7 @@ private:
glVertexArray vao;
glBuffer vbo;
};
+
std::vector<Model> models;
glm::vec3 colour;
};
diff --git a/ui/uiComponent.cpp b/ui/uiComponent.cpp
index e480fbc..aa4838d 100644
--- a/ui/uiComponent.cpp
+++ b/ui/uiComponent.cpp
@@ -20,6 +20,7 @@ UIComponent::Position::operator&(const glm::vec2 & pos) const
{
return (pos.x >= origin.x && pos.y >= origin.y && pos.x < origin.x + size.x && pos.y < origin.y + size.y);
}
+
bool
UIComponent::Position::operator&(const SDL_MouseButtonEvent & pos) const
{
diff --git a/ui/uiComponent.h b/ui/uiComponent.h
index 75c2284..71d2659 100644
--- a/ui/uiComponent.h
+++ b/ui/uiComponent.h
@@ -18,6 +18,7 @@ public:
bool operator&(const SDL_MouseButtonEvent &) const;
bool operator&(const glm::vec2 &) const;
};
+
explicit UIComponent(Position);
virtual ~UIComponent() = default;
diff --git a/ui/uiComponentPlacer.cpp b/ui/uiComponentPlacer.cpp
index 368e772..5e645d8 100644
--- a/ui/uiComponentPlacer.cpp
+++ b/ui/uiComponentPlacer.cpp
@@ -16,6 +16,7 @@ UIComponentPlacer::next(glm::vec2 size)
max = std::max(max, size[1 - axis]);
return n;
}
+
glm::vec2
UIComponentPlacer::getLimit() const
{
diff --git a/ui/window.h b/ui/window.h
index 369228a..8f2b70b 100644
--- a/ui/window.h
+++ b/ui/window.h
@@ -31,11 +31,12 @@ public:
protected:
virtual void render() const;
+
struct GLInitHelper {
GLInitHelper();
};
- const glm::ivec2 size;
+ const ScreenAbsCoord size;
SDL_WindowPtr m_window;
SDL_GLContextPtr glContext;
GLInitHelper glInithelper;