blob: 69d24279f988b19112b3a4dfdbb6a95f2e666bfb [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:
thatf6ed8fc2015-02-14 20:23:16 +010020 std::string GetName() { return mName; }
21 virtual bool loadedOK() = 0;
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);
Ethan Yonker63e414f2015-02-06 15:44:39 -060028 static void LoadImage(ZipArchive* pZip, std::string file, gr_surface* source);
29 static void CheckAndScaleImage(gr_surface source, gr_surface* destination, int retain_aspect);
Dees_Troy51a0e822012-09-05 15:24:24 -040030};
31
Dees_Troy51a0e822012-09-05 15:24:24 -040032class FontResource : public Resource
33{
34public:
Vojtech Bocek76ee9032014-09-07 15:01:56 +020035 enum Type
36 {
37 TYPE_TWRP,
38#ifndef TW_DISABLE_TTF
39 TYPE_TTF,
40#endif
41 };
42
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020043 FontResource(xml_node<>* node, ZipArchive* pZip);
44 virtual ~FontResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040045
46public:
thatf6ed8fc2015-02-14 20:23:16 +010047 void* GetResource() { return this ? mFont : NULL; }
48 int GetHeight() { return gr_getMaxFontHeight(this ? mFont : NULL); }
49
50 virtual bool loadedOK() { return mFont != NULL; }
Dees_Troy51a0e822012-09-05 15:24:24 -040051
52protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020053 void* mFont;
Vojtech Bocek76ee9032014-09-07 15:01:56 +020054 Type m_type;
Dees_Troy51a0e822012-09-05 15:24:24 -040055};
56
57class ImageResource : public Resource
58{
59public:
Ethan Yonker63e414f2015-02-06 15:44:39 -060060 ImageResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020061 virtual ~ImageResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040062
63public:
thatf6ed8fc2015-02-14 20:23:16 +010064 gr_surface GetResource() { return this ? mSurface : NULL; }
65 int GetWidth() { return gr_get_width(this ? mSurface : NULL); }
66 int GetHeight() { return gr_get_height(this ? mSurface : NULL); }
67
68 virtual bool loadedOK() { return mSurface != NULL; }
Dees_Troy51a0e822012-09-05 15:24:24 -040069
70protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020071 gr_surface mSurface;
Dees_Troy51a0e822012-09-05 15:24:24 -040072};
73
74class AnimationResource : public Resource
75{
76public:
Ethan Yonker63e414f2015-02-06 15:44:39 -060077 AnimationResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020078 virtual ~AnimationResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040079
80public:
thatf6ed8fc2015-02-14 20:23:16 +010081 gr_surface GetResource() { return (!this || mSurfaces.empty()) ? NULL : mSurfaces.at(0); }
82 gr_surface GetResource(int entry) { return (!this || mSurfaces.empty()) ? NULL : mSurfaces.at(entry); }
83 int GetWidth() { return gr_get_width(this ? GetResource() : NULL); }
84 int GetHeight() { return gr_get_height(this ? GetResource() : NULL); }
85 int GetResourceCount() { return mSurfaces.size(); }
86 virtual bool loadedOK() { return !mSurfaces.empty(); }
Dees_Troy51a0e822012-09-05 15:24:24 -040087
88protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020089 std::vector<gr_surface> mSurfaces;
Dees_Troy51a0e822012-09-05 15:24:24 -040090};
91
92class ResourceManager
93{
94public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020095 ResourceManager(xml_node<>* resList, ZipArchive* pZip);
96 virtual ~ResourceManager();
Ethan Yonker780cd392014-07-21 15:24:39 -050097 void LoadResources(xml_node<>* resList, ZipArchive* pZip);
Dees_Troy51a0e822012-09-05 15:24:24 -040098
99public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200100 Resource* FindResource(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400101
102private:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200103 std::vector<Resource*> mResources;
Dees_Troy51a0e822012-09-05 15:24:24 -0400104};
105
106#endif // _RESOURCE_HEADER