From 184dc3f14feab183bcd84eca40f89c143ecbe41f Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 22 May 2019 01:44:59 +0300 Subject: [PATCH] Define UI text font and technique in Resources instead of hardcoding --- source/beatcounter.cpp | 4 ++-- source/beatcounter.h | 3 ++- source/launcher.h | 4 ++-- source/launchscreen.cpp | 6 +++--- source/launchscreen.h | 4 ++-- source/resources.cpp | 24 +++++++++++++++++++++++- source/resources.h | 9 +++++++++ 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/source/beatcounter.cpp b/source/beatcounter.cpp index cce1959..e984034 100644 --- a/source/beatcounter.cpp +++ b/source/beatcounter.cpp @@ -3,8 +3,8 @@ using namespace Msp; -BeatCounter::BeatCounter(DataFile::Collection &resources): - text(resources.get("ikarius-48.font"), &resources.get("basic_text.tech")), +BeatCounter::BeatCounter(Resources &resources): + text(resources.get_ui_font(), &resources.get_ui_text_technique()), instance(text) { text.set_alignment(GL::Text::CENTER); diff --git a/source/beatcounter.h b/source/beatcounter.h index 952ed6b..84e8dd1 100644 --- a/source/beatcounter.h +++ b/source/beatcounter.h @@ -5,6 +5,7 @@ #include #include #include +#include "resources.h" #include "action.h" class BeatCounter: public Msp::GL::Renderable, public Action @@ -14,7 +15,7 @@ private: Msp::GL::ObjectInstance instance; public: - BeatCounter(Msp::DataFile::Collection &); + BeatCounter(Resources &); virtual void beat(int); diff --git a/source/launcher.h b/source/launcher.h index f607c7b..c1dc33a 100644 --- a/source/launcher.h +++ b/source/launcher.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -12,6 +11,7 @@ #include #include #include +#include "resources.h" class Demo; class LaunchScreen; @@ -57,7 +57,7 @@ public: ~LauncherBase(); protected: - virtual Msp::DataFile::Collection &get_resources() = 0; + virtual Resources &get_resources() = 0; virtual Demo *create_demo() = 0; virtual void start(); virtual void tick(); diff --git a/source/launchscreen.cpp b/source/launchscreen.cpp index 4fd0883..972b311 100644 --- a/source/launchscreen.cpp +++ b/source/launchscreen.cpp @@ -6,9 +6,9 @@ using namespace Msp; -LaunchScreen::LaunchScreen(DataFile::Collection &resources): - font(resources.get("ikarius-48.font")), - tech(resources.get("basic_text.tech")), +LaunchScreen::LaunchScreen(Resources &resources): + font(resources.get_ui_font()), + tech(resources.get_ui_text_technique()), countdown(font, &tech), countdown_value(0), enter_prompt(font, &tech), diff --git a/source/launchscreen.h b/source/launchscreen.h index 7c4a923..e4c737f 100644 --- a/source/launchscreen.h +++ b/source/launchscreen.h @@ -1,11 +1,11 @@ #ifndef MSP_DEMOSCENE_LAUNCHSCREEN_H_ #define MSP_DEMOSCENE_LAUNCHSCREEN_H_ -#include #include #include #include #include +#include "resources.h" class LaunchScreen { @@ -19,7 +19,7 @@ private: Msp::GL::Camera camera; public: - LaunchScreen(Msp::DataFile::Collection &); + LaunchScreen(Resources &); void set_countdown(unsigned); diff --git a/source/resources.cpp b/source/resources.cpp index dac473a..cba8054 100644 --- a/source/resources.cpp +++ b/source/resources.cpp @@ -4,7 +4,9 @@ using namespace std; using namespace Msp; -Resources::Resources(const string &pack_name) +Resources::Resources(const string &pack_name): + ui_font(0), + ui_text_technique(0) { set_default_texture_anisotropy(8); set_srgb_conversion(true); @@ -20,3 +22,23 @@ Resources::Resources(const string &pack_name) add_source(pack_source); } } + +const GL::Font &Resources::get_ui_font() const +{ + if(!ui_font) + throw runtime_error("no ui font"); + return *ui_font; +} + +const GL::Technique &Resources::get_ui_text_technique() const +{ + if(!ui_text_technique) + throw runtime_error("no ui text technique"); + return *ui_text_technique; +} + +void Resources::set_ui_text_resources(const string &font, const string &tech) +{ + ui_font = &get(font); + ui_text_technique = &get(tech); +} diff --git a/source/resources.h b/source/resources.h index 3e0dbc9..63dee76 100644 --- a/source/resources.h +++ b/source/resources.h @@ -3,7 +3,9 @@ #include #include +#include #include +#include class Resources: public Msp::GL::Resources { @@ -11,8 +13,15 @@ private: Msp::DataFile::DirectorySource dir_source; Msp::DataFile::PackSource pack_source; + const Msp::GL::Font *ui_font; + const Msp::GL::Technique *ui_text_technique; + public: Resources(const std::string &); + + const Msp::GL::Font &get_ui_font() const; + const Msp::GL::Technique &get_ui_text_technique() const; + void set_ui_text_resources(const std::string &, const std::string &); }; #endif -- 2.45.2