From 5cd73a8f2b40e59ec13aa2a6af33bc8e2a6b9a6c Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Tue, 11 Aug 2015 10:18:53 +0200 Subject: [PATCH] centralize fonts --- src/app/Assets.hpp | 8 +++++++- src/app/PreloadState.cpp | 3 +-- src/app/PreloadState.hpp | 2 -- src/app/UnloadState.cpp | 3 +-- src/app/UnloadState.hpp | 2 -- src/app/app.cpp | 4 +++- src/ui/Interface.hpp | 3 +-- src/ui/ui.cpp | 11 +++++------ 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/app/Assets.hpp b/src/app/Assets.hpp index 6e1698a..40623a2 100644 --- a/src/app/Assets.hpp +++ b/src/app/Assets.hpp @@ -1,13 +1,14 @@ #ifndef BLANK_APP_ASSETS_HPP_ #define BLANK_APP_ASSETS_HPP_ +#include "../graphics/Font.hpp" + #include 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; + }; } diff --git a/src/app/PreloadState.cpp b/src/app/PreloadState.cpp index 389d331..aca2502 100644 --- a/src/app/PreloadState.cpp +++ b/src/app/PreloadState.cpp @@ -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); diff --git a/src/app/PreloadState.hpp b/src/app/PreloadState.hpp index daf0a37..010dde7 100644 --- a/src/app/PreloadState.hpp +++ b/src/app/PreloadState.hpp @@ -4,7 +4,6 @@ #include "State.hpp" #include "../ui/Progress.hpp" -#include "../graphics/Font.hpp" #include @@ -27,7 +26,6 @@ public: private: Environment &env; ChunkLoader &loader; - Font font; Progress progress; std::size_t total; std::size_t per_update; diff --git a/src/app/UnloadState.cpp b/src/app/UnloadState.cpp index 9da6989..dfe270e 100644 --- a/src/app/UnloadState.cpp +++ b/src/app/UnloadState.cpp @@ -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) diff --git a/src/app/UnloadState.hpp b/src/app/UnloadState.hpp index 6d5cea7..877f8fb 100644 --- a/src/app/UnloadState.hpp +++ b/src/app/UnloadState.hpp @@ -4,7 +4,6 @@ #include "State.hpp" #include "../ui/Progress.hpp" -#include "../graphics/Font.hpp" #include #include @@ -31,7 +30,6 @@ public: private: Environment &env; ChunkLoader &loader; - Font font; Progress progress; std::list::iterator cur; std::list::iterator end; diff --git a/src/app/app.cpp b/src/app/app.cpp index 880dc71..8817d1f 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -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)) { } diff --git a/src/ui/Interface.hpp b/src/ui/Interface.hpp index 0d338be..0cffd76 100644 --- a/src/ui/Interface.hpp +++ b/src/ui/Interface.hpp @@ -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 #include +#include namespace blank { @@ -87,7 +87,6 @@ private: Environment &env; World &world; FPSController ctrl; - Font font; HUD hud; Ray aim; diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index 0c89a2f..be03c7e 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -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()); } -- 2.39.2