blob: 603b1c9588d1a54b219468689b0dafd204cc5186 [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
thatf37aec22015-02-01 13:38:35 +01008extern "C" {
9#include "../minuitwrp/minui.h"
10}
11
Dees_Troy51a0e822012-09-05 15:24:24 -040012// Base Objects
13class Resource
14{
15public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020016 Resource(xml_node<>* node, ZipArchive* pZip);
17 virtual ~Resource() {}
Dees_Troy51a0e822012-09-05 15:24:24 -040018
19public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020020 virtual void* GetResource(void) = 0;
21 std::string GetName(void) { return mName; }
Dees_Troy51a0e822012-09-05 15:24:24 -040022
23private:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020024 std::string mName;
Dees_Troy51a0e822012-09-05 15:24:24 -040025
26protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020027 static int ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile);
Dees_Troy51a0e822012-09-05 15:24:24 -040028};
29
Dees_Troy51a0e822012-09-05 15:24:24 -040030class FontResource : public Resource
31{
32public:
Vojtech Bocek76ee9032014-09-07 15:01:56 +020033 enum Type
34 {
35 TYPE_TWRP,
36#ifndef TW_DISABLE_TTF
37 TYPE_TTF,
38#endif
39 };
40
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020041 FontResource(xml_node<>* node, ZipArchive* pZip);
42 virtual ~FontResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040043
44public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020045 virtual void* GetResource(void) { return mFont; }
Dees_Troy51a0e822012-09-05 15:24:24 -040046
47protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020048 void* mFont;
Vojtech Bocek76ee9032014-09-07 15:01:56 +020049 Type m_type;
Dees_Troy51a0e822012-09-05 15:24:24 -040050};
51
52class ImageResource : public Resource
53{
54public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020055 ImageResource(xml_node<>* node, ZipArchive* pZip);
56 virtual ~ImageResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040057
58public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020059 virtual void* GetResource(void) { return mSurface; }
Dees_Troy51a0e822012-09-05 15:24:24 -040060
61protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020062 gr_surface mSurface;
Dees_Troy51a0e822012-09-05 15:24:24 -040063};
64
65class AnimationResource : public Resource
66{
67public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020068 AnimationResource(xml_node<>* node, ZipArchive* pZip);
69 virtual ~AnimationResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040070
71public:
bigbiff85939e52014-11-15 21:03:52 -050072 virtual void* GetResource(void) { return mSurfaces.empty() ? NULL : mSurfaces.at(0); }
73 virtual void* GetResource(int entry) { return mSurfaces.empty() ? NULL : mSurfaces.at(entry); }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020074 virtual int GetResourceCount(void) { return mSurfaces.size(); }
Dees_Troy51a0e822012-09-05 15:24:24 -040075
76protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020077 std::vector<gr_surface> mSurfaces;
Dees_Troy51a0e822012-09-05 15:24:24 -040078};
79
80class ResourceManager
81{
82public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020083 ResourceManager(xml_node<>* resList, ZipArchive* pZip);
84 virtual ~ResourceManager();
Ethan Yonker780cd392014-07-21 15:24:39 -050085 void LoadResources(xml_node<>* resList, ZipArchive* pZip);
Dees_Troy51a0e822012-09-05 15:24:24 -040086
87public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020088 Resource* FindResource(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -040089
90private:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020091 std::vector<Resource*> mResources;
Dees_Troy51a0e822012-09-05 15:24:24 -040092};
93
94#endif // _RESOURCE_HEADER