blob: 1a86d544d5970e2fdf2211b6be2189462d1d281c [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001// resources.hpp - Base classes for resource management of GUI
2
3#ifndef _RESOURCE_HEADER
4#define _RESOURCE_HEADER
5
Dees Troyb7ae0982013-09-10 20:47:35 +00006#include "../minzip/Zip.h"
Dees Troyb7ae0982013-09-10 20:47:35 +00007
Dees_Troy51a0e822012-09-05 15:24:24 -04008// Base Objects
9class Resource
10{
11public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020012 Resource(xml_node<>* node, ZipArchive* pZip);
13 virtual ~Resource() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040014
15public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020016 virtual void* GetResource(void) = 0;
17 std::string GetName(void) { return mName; }
Dees_Troy51a0e822012-09-05 15:24:24 -040018
19private:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020020 std::string mName;
Dees_Troy51a0e822012-09-05 15:24:24 -040021
22protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020023 static int ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile);
Dees_Troy51a0e822012-09-05 15:24:24 -040024};
25
Dees_Troy51a0e822012-09-05 15:24:24 -040026class FontResource : public Resource
27{
28public:
Vojtech Bocek76ee9032014-09-07 15:01:56 +020029 enum Type
30 {
31 TYPE_TWRP,
32#ifndef TW_DISABLE_TTF
33 TYPE_TTF,
34#endif
35 };
36
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020037 FontResource(xml_node<>* node, ZipArchive* pZip);
38 virtual ~FontResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040039
40public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020041 virtual void* GetResource(void) { return mFont; }
Dees_Troy51a0e822012-09-05 15:24:24 -040042
43protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020044 void* mFont;
Vojtech Bocek76ee9032014-09-07 15:01:56 +020045 Type m_type;
Dees_Troy51a0e822012-09-05 15:24:24 -040046};
47
48class ImageResource : public Resource
49{
50public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020051 ImageResource(xml_node<>* node, ZipArchive* pZip);
52 virtual ~ImageResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040053
54public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020055 virtual void* GetResource(void) { return mSurface; }
Dees_Troy51a0e822012-09-05 15:24:24 -040056
57protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020058 gr_surface mSurface;
Dees_Troy51a0e822012-09-05 15:24:24 -040059};
60
61class AnimationResource : public Resource
62{
63public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020064 AnimationResource(xml_node<>* node, ZipArchive* pZip);
65 virtual ~AnimationResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040066
67public:
bigbiff85939e52014-11-15 21:03:52 -050068 virtual void* GetResource(void) { return mSurfaces.empty() ? NULL : mSurfaces.at(0); }
69 virtual void* GetResource(int entry) { return mSurfaces.empty() ? NULL : mSurfaces.at(entry); }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020070 virtual int GetResourceCount(void) { return mSurfaces.size(); }
Dees_Troy51a0e822012-09-05 15:24:24 -040071
72protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020073 std::vector<gr_surface> mSurfaces;
Dees_Troy51a0e822012-09-05 15:24:24 -040074};
75
76class ResourceManager
77{
78public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020079 ResourceManager(xml_node<>* resList, ZipArchive* pZip);
80 virtual ~ResourceManager();
Ethan Yonker780cd392014-07-21 15:24:39 -050081 void LoadResources(xml_node<>* resList, ZipArchive* pZip);
Dees_Troy51a0e822012-09-05 15:24:24 -040082
83public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020084 Resource* FindResource(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -040085
86private:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020087 std::vector<Resource*> mResources;
Dees_Troy51a0e822012-09-05 15:24:24 -040088};
89
90#endif // _RESOURCE_HEADER