]> git.localhorst.tv Git - blank.git/commitdiff
centralize fonts
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 11 Aug 2015 08:18:53 +0000 (10:18 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 11 Aug 2015 08:18:53 +0000 (10:18 +0200)
src/app/Assets.hpp
src/app/PreloadState.cpp
src/app/PreloadState.hpp
src/app/UnloadState.cpp
src/app/UnloadState.hpp
src/app/app.cpp
src/ui/Interface.hpp
src/ui/ui.cpp

index 6e1698a6fc94105d0893b2f1ee0259f80bf608dc..40623a21af6bdeb483e1f480eccdd3b3a3036a75 100644 (file)
@@ -1,13 +1,14 @@
 #ifndef BLANK_APP_ASSETS_HPP_
 #define BLANK_APP_ASSETS_HPP_
 
+#include "../graphics/Font.hpp"
+
 #include <string>
 
 
 namespace blank {
 
 class ArrayTexture;
-class Font;
 class Sound;
 class Texture;
 
@@ -26,6 +27,11 @@ private:
        std::string sounds;
        std::string textures;
 
+public:
+       // common assets shared by may states
+       Font large_ui_font;
+       Font small_ui_font;
+
 };
 
 }
index 389d331bd6034167e755edaad1470d908df17c17..aca2502eaeacc92e2417204fec3f618739c95eb7 100644 (file)
@@ -9,8 +9,7 @@ namespace blank {
 PreloadState::PreloadState(Environment &env, ChunkLoader &loader)
 : env(env)
 , loader(loader)
-, font(env.assets.LoadFont("DejaVuSans", 24))
-, progress(font)
+, progress(env.assets.large_ui_font)
 , total(loader.ToLoad())
 , per_update(64) {
        progress.Position(glm::vec3(0.0f), Gravity::CENTER);
index daf0a3792ae2b65fe5a2df52a301294a3cda1b71..010dde7648b5e8149b390e2991defdbe34b6431b 100644 (file)
@@ -4,7 +4,6 @@
 #include "State.hpp"
 
 #include "../ui/Progress.hpp"
-#include "../graphics/Font.hpp"
 
 #include <cstddef>
 
@@ -27,7 +26,6 @@ public:
 private:
        Environment &env;
        ChunkLoader &loader;
-       Font font;
        Progress progress;
        std::size_t total;
        std::size_t per_update;
index 9da6989d128b5403e018daa4a4e39136fc695d8f..dfe270ed61f39301032abd3a6a3121f8df017363 100644 (file)
@@ -10,8 +10,7 @@ namespace blank {
 UnloadState::UnloadState(Environment &env, ChunkLoader &loader)
 : env(env)
 , loader(loader)
-, font(env.assets.LoadFont("DejaVuSans", 24))
-, progress(font)
+, progress(env.assets.large_ui_font)
 , cur(loader.Loaded().begin())
 , end(loader.Loaded().end())
 , done(0)
index 6d5cea71ae2a89ecd3f417ad286a4ba7705e639b..877f8fb4d7f4030382fb2b47190c25a52b562c72 100644 (file)
@@ -4,7 +4,6 @@
 #include "State.hpp"
 
 #include "../ui/Progress.hpp"
-#include "../graphics/Font.hpp"
 
 #include <cstddef>
 #include <list>
@@ -31,7 +30,6 @@ public:
 private:
        Environment &env;
        ChunkLoader &loader;
-       Font font;
        Progress progress;
        std::list<Chunk>::iterator cur;
        std::list<Chunk>::iterator end;
index 880dc7118eaf2fcaa43e93b2a2e92c6ec91de5f1..8817d1f75bf821d48f58c5c1b6726f735bb60d53 100644 (file)
@@ -219,7 +219,9 @@ void StateControl::Commit(Application &app) {
 Assets::Assets(const string &base)
 : fonts(base + "fonts/")
 , sounds(base + "sounds/")
-, textures(base + "textures/") {
+, textures(base + "textures/")
+, large_ui_font(LoadFont("DejaVuSans", 24))
+, small_ui_font(LoadFont("DejaVuSans", 16)) {
 
 }
 
index 0d338bed9f3949a91c9854a254ac1c2fade51486..0cffd762cc29ea79af24b2204a94f0d4299c9e29 100644 (file)
@@ -7,13 +7,13 @@
 #include "../app/FPSController.hpp"
 #include "../app/IntervalTimer.hpp"
 #include "../audio/Sound.hpp"
-#include "../graphics/Font.hpp"
 #include "../model/geometry.hpp"
 #include "../model/OutlineModel.hpp"
 #include "../world/Block.hpp"
 
 #include <string>
 #include <glm/glm.hpp>
+#include <SDL.h>
 
 
 namespace blank {
@@ -87,7 +87,6 @@ private:
        Environment &env;
        World &world;
        FPSController ctrl;
-       Font font;
        HUD hud;
 
        Ray aim;
index 0c89a2f3a554ab6c0347ed669bdd71d801dea22a..be03c7e88f22fe7d202440a208b91b3eb2d7d4a9 100644 (file)
@@ -98,8 +98,7 @@ Interface::Interface(
 : env(env)
 , world(world)
 , ctrl(world.Player())
-, font(env.assets.LoadFont("DejaVuSans", 16))
-, hud(world.BlockTypes(), font)
+, hud(world.BlockTypes(), env.assets.small_ui_font)
 , aim{{ 0, 0, 0 }, { 0, 0, -1 }}
 , aim_chunk(nullptr)
 , aim_block(0)
@@ -107,7 +106,7 @@ Interface::Interface(
 , outline()
 , outline_transform(1.0f)
 , counter_text()
-, messages(font)
+, messages(env.assets.small_ui_font)
 , msg_timer(5000)
 , config(config)
 , place_timer(256)
@@ -123,7 +122,7 @@ Interface::Interface(
        counter_text.Foreground(glm::vec4(1.0f));
        counter_text.Background(glm::vec4(0.5f));
        position_text.Hide();
-       position_text.Position(glm::vec3(-25.0f, 25.0f + font.LineSkip(), 0.0f), Gravity::NORTH_EAST);
+       position_text.Position(glm::vec3(-25.0f, 25.0f + env.assets.small_ui_font.LineSkip(), 0.0f), Gravity::NORTH_EAST);
        position_text.Foreground(glm::vec4(1.0f));
        position_text.Background(glm::vec4(0.5f));
        messages.Position(glm::vec3(25.0f, -25.0f, 0.0f), Gravity::SOUTH_WEST);
@@ -355,13 +354,13 @@ void Interface::UpdateCounter() {
                "avg: " << env.counter.Average().running << "ms, "
                "peak: " << env.counter.Peak().running << "ms";
        std::string text = s.str();
-       counter_text.Set(font, text);
+       counter_text.Set(env.assets.small_ui_font, text);
 }
 
 void Interface::UpdatePosition() {
        std::stringstream s;
        s << std::setprecision(3) << "pos: " << ctrl.Controlled().AbsolutePosition();
-       position_text.Set(font, s.str());
+       position_text.Set(env.assets.small_ui_font, s.str());
 }