#include <msp/gl/font.h>
#include <msp/gl/texture.h>
-#include <msp/parser/loader.h>
+#include <msp/datafile/collection.h>
+#include <msp/datafile/directorysource.h>
+#include <msp/fs/path.h>
#include "graphic.h"
#include "style.h"
namespace Msp {
namespace GLtk {
-class Resources
+/**
+Stores resources such as styles and graphics. All widgets require a Resources
+instance in constructor.
+*/
+class Resources: public DataFile::Collection
{
public:
-
- class Loader: public Msp::Parser::Loader
+ class Loader: public Collection::Loader
{
- public:
- Loader(Resources &);
private:
Resources &res;
+ public:
+ Loader(Resources &);
+ private:
+ void default_font(const std::string &);
void font(const std::string &);
- void texture(const std::string &);
- void graphic(const std::string &);
- void style(const std::string &, const std::string &);
};
- Resources();
- ~Resources();
- const GL::Font &get_font(const std::string &) const;
- const GL::Font &get_default_font() const;
- const GL::Texture2D &get_texture(const std::string &) const;
- const Graphic &get_graphic(const std::string &) const;
- const Style &get_style(const std::string &, const std::string &) const;
private:
- struct StyleId
- {
- std::string widget;
- std::string name;
-
- StyleId(const std::string &w, const std::string &n): widget(w), name(n) { }
- bool operator<(const StyleId &) const;
- };
+ FS::Path path;
+ GL::Font *default_font;
+ DataFile::DirectorySource *dir_src;
- typedef std::map<std::string, GL::Font *> FontMap;
- typedef std::map<std::string, GL::Texture2D *> TextureMap;
- typedef std::map<std::string, Graphic> GraphicMap;
- typedef std::map<StyleId, Style> StyleMap;
+public:
+ Resources();
+ Resources(const FS::Path &);
+private:
+ void init();
+public:
+ ~Resources();
- FontMap fonts;
- GL::Font *default_font;
- TextureMap textures;
- GraphicMap graphics;
- StyleMap styles;
+ const GL::Font &get_default_font() const;
- Resources(const Resources &);
- Resources &operator=(const Resources &);
+private:
+ GL::Texture2D *create_texture(const std::string &);
};
} // namespace GLtk