summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/editNetwork.cpp5
-rw-r--r--ui/editNetwork.h2
-rw-r--r--ui/font.cpp2
-rw-r--r--ui/font.h5
-rw-r--r--ui/gameMainSelector.cpp12
-rw-r--r--ui/gameMainSelector.h3
-rw-r--r--ui/text.cpp10
-rw-r--r--ui/text.h3
8 files changed, 17 insertions, 25 deletions
diff --git a/ui/editNetwork.cpp b/ui/editNetwork.cpp
index 7fbde32..ac2d93d 100644
--- a/ui/editNetwork.cpp
+++ b/ui/editNetwork.cpp
@@ -8,6 +8,7 @@
#include <gfx/gl/sceneShader.h>
#include <gfx/models/texture.h>
+const std::filesystem::path fontpath {"/usr/share/fonts/hack/Hack-Regular.ttf"};
constexpr const glm::u8vec4 TRANSPARENT_BLUE {30, 50, 255, 200};
EditNetwork::EditNetwork(Network * n) :
@@ -17,7 +18,7 @@ EditNetwork::EditNetwork(Network * n) :
{"ui/icon/network.png", mode.toggle<BuilderJoin>()},
{"ui/icon/network.png", mode.toggle<BuilderFreeExtend>()},
},
- blue {1, 1, &TRANSPARENT_BLUE}
+ blue {1, 1, &TRANSPARENT_BLUE}, font {fontpath, 15}
{
}
@@ -66,7 +67,7 @@ void
EditNetwork::render(const UIShader & shader, const UIComponent::Position & parentPos) const
{
if (builder) {
- Text {builder->hint(), {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos);
+ Text {builder->hint(), font, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos);
}
builderToolbar.render(shader, parentPos);
}
diff --git a/ui/editNetwork.h b/ui/editNetwork.h
index 23dcf43..ec06fa7 100644
--- a/ui/editNetwork.h
+++ b/ui/editNetwork.h
@@ -7,7 +7,6 @@
#include <game/gamestate.h>
#include <game/network/network.h>
#include <gfx/models/texture.h>
-#include <optional>
template<typename> class Ray;
@@ -43,6 +42,7 @@ private:
Mode<Builder::Ptr, ModeSecondClick::NoAction> mode {builder};
Toolbar builderToolbar;
Texture blue;
+ const Font font;
};
template<typename T> class EditNetworkOf : public EditNetwork {
diff --git a/ui/font.cpp b/ui/font.cpp
index f610a1b..237c22d 100644
--- a/ui/font.cpp
+++ b/ui/font.cpp
@@ -60,8 +60,6 @@ using Face = glRef<FT_Face,
},
FT_Done_Face>;
-Cache<Font, std::filesystem::path, unsigned int> Font::cachedFontRenderings;
-
Font::Font(std::filesystem::path p, unsigned s) : path {std::move(p)}, size {getTextureSize(s)}
{
generateChars(BASIC_CHARS);
diff --git a/ui/font.h b/ui/font.h
index 2f3337f..3254f80 100644
--- a/ui/font.h
+++ b/ui/font.h
@@ -1,22 +1,17 @@
#pragma once
#include <array>
-#include <cache.h>
#include <cstddef>
-#include <cstdint>
#include <filesystem>
#include <glArrays.h>
#include <glad/gl.h>
#include <glm/glm.hpp>
#include <map>
-#include <string_view>
#include <unicode.h>
#include <vector>
class Font {
public:
- static Cache<Font, std::filesystem::path, unsigned int> cachedFontRenderings;
-
Font(std::filesystem::path path, unsigned int height);
using Quad = std::array<glm::vec4, 4>;
diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp
index a577838..5bef48d 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, ScreenAbsCoord size) : UIComponent {{{}, size}}, camera {c} { }
+const std::filesystem::path fontpath {"/usr/share/fonts/hack/Hack-Regular.ttf"};
+
+GameMainSelector::GameMainSelector(const Camera * c, ScreenAbsCoord size) :
+ UIComponent {{{}, size}}, camera {c}, font {fontpath, 15}
+{
+}
constexpr ScreenAbsCoord TargetPos {5, 45};
@@ -26,7 +28,7 @@ GameMainSelector::render(const UIShader & shader, const Position & parentPos) co
target->render(shader, parentPos + position + TargetPos);
}
if (!clicked.empty()) {
- Text {clicked, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos);
+ Text {clicked, font, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos);
}
}
diff --git a/ui/gameMainSelector.h b/ui/gameMainSelector.h
index cc30707..ccf0fa0 100644
--- a/ui/gameMainSelector.h
+++ b/ui/gameMainSelector.h
@@ -2,7 +2,7 @@
#include "SDL_events.h"
#include "config/types.h"
-#include "special_members.h"
+#include "font.h"
#include "uiComponent.h"
#include "worldOverlay.h"
#include <glm/glm.hpp>
@@ -40,5 +40,6 @@ public:
private:
const Camera * camera;
+ const Font font;
std::string clicked;
};
diff --git a/ui/text.cpp b/ui/text.cpp
index b776b90..7cb7d30 100644
--- a/ui/text.cpp
+++ b/ui/text.cpp
@@ -4,19 +4,13 @@
#include "uiComponent.h"
#include <array>
#include <cache.h>
-#include <filesystem>
#include <glArrays.h>
#include <glm/gtc/type_ptr.hpp>
-#include <map>
-#include <memory>
#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}
+Text::Text(std::string_view s, const Font & font, Position pos, glm::vec3 c) : UIComponent {pos}, colour {c}
{
- for (const auto & textureQuads :
- Font::cachedFontRenderings.get(font, static_cast<unsigned int>(pos.size.y))->render(s)) {
+ for (const auto & textureQuads : font.render(s)) {
auto & rendering
= models.emplace_back(textureQuads.first, static_cast<GLsizei>(6 * textureQuads.second.size()));
glBindVertexArray(rendering.vao);
diff --git a/ui/text.h b/ui/text.h
index de2fe2e..5217050 100644
--- a/ui/text.h
+++ b/ui/text.h
@@ -1,5 +1,6 @@
#pragma once
+#include "font.h"
#include "uiComponent.h"
#include <glArrays.h>
#include <glad/gl.h>
@@ -12,7 +13,7 @@ union SDL_Event;
class Text : public UIComponent {
public:
- Text(std::string_view s, Position, glm::vec3 colour);
+ Text(std::string_view s, const Font &, Position, glm::vec3 colour);
void render(const UIShader &, const Position & parentPos) const override;
bool handleInput(const SDL_Event &, const Position & parentPos) override;