]> git.tdb.fi Git - libs/demoscene.git/commitdiff
Define UI text font and technique in Resources instead of hardcoding
authorMikko Rasa <tdb@tdb.fi>
Tue, 21 May 2019 22:44:59 +0000 (01:44 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 21 May 2019 22:44:59 +0000 (01:44 +0300)
source/beatcounter.cpp
source/beatcounter.h
source/launcher.h
source/launchscreen.cpp
source/launchscreen.h
source/resources.cpp
source/resources.h

index cce19596ddc2796ea47ea312238095be91aae471..e984034966b000158593ed9bc2407667ecb65966 100644 (file)
@@ -3,8 +3,8 @@
 
 using namespace Msp;
 
-BeatCounter::BeatCounter(DataFile::Collection &resources):
-       text(resources.get<GL::Font>("ikarius-48.font"), &resources.get<GL::Technique>("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);
index 952ed6b0460869dd2af309257fb7336501e65cb7..84e8dd1bac34f3cf9bf6d2b18118a8e631a78c57 100644 (file)
@@ -5,6 +5,7 @@
 #include <msp/gl/objectinstance.h>
 #include <msp/gl/renderable.h>
 #include <msp/gl/text.h>
+#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);
 
index f607c7bc64ead5fffa8a63eda6ac138a7be7ccff..c1dc33a8db8e1be88393082e97e1099a46ea095e 100644 (file)
@@ -4,7 +4,6 @@
 #include <msp/al/context.h>
 #include <msp/al/device.h>
 #include <msp/core/application.h>
-#include <msp/datafile/collection.h>
 #include <msp/graphics/display.h>
 #include <msp/graphics/glcontext.h>
 #include <msp/graphics/window.h>
@@ -12,6 +11,7 @@
 #include <msp/io/base.h>
 #include <msp/time/timedelta.h>
 #include <msp/time/timestamp.h>
+#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();
index 4fd08836d4b8dc7448376f628cf8a4c6dd67ae93..972b311188a576ffbda6f741e23dd6e84342c50f 100644 (file)
@@ -6,9 +6,9 @@
 
 using namespace Msp;
 
-LaunchScreen::LaunchScreen(DataFile::Collection &resources):
-       font(resources.get<GL::Font>("ikarius-48.font")),
-       tech(resources.get<GL::Technique>("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),
index 7c4a923ddd2363c6af3d573e45ab1ef89c265bc3..e4c737f4a3c9ac020ab848ff790af2fe1d43e23c 100644 (file)
@@ -1,11 +1,11 @@
 #ifndef MSP_DEMOSCENE_LAUNCHSCREEN_H_
 #define MSP_DEMOSCENE_LAUNCHSCREEN_H_
 
-#include <msp/datafile/collection.h>
 #include <msp/gl/camera.h>
 #include <msp/gl/font.h>
 #include <msp/gl/technique.h>
 #include <msp/gl/text.h>
+#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);
 
index dac473ab2c11f1ff5438065f30c2d96d6039d371..cba8054cf4b9f3636b02a0630fde7fa585a03d32 100644 (file)
@@ -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<GL::Font>(font);
+       ui_text_technique = &get<GL::Technique>(tech);
+}
index 3e0dbc9ef72afe36e0ece4657ff075d6dc366ed4..63dee766967164a36ae676c20fbbf54be9665bea 100644 (file)
@@ -3,7 +3,9 @@
 
 #include <msp/datafile/directorysource.h>
 #include <msp/datafile/packsource.h>
+#include <msp/gl/font.h>
 #include <msp/gl/resources.h>
+#include <msp/gl/technique.h>
 
 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