blob: 83fc7a537199799cdbb15dd0aff5c97a93a6647a [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; }
Dees_Troy51a0e822012-09-05 15:24:24 -040021
22private:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020023 std::string mName;
Dees_Troy51a0e822012-09-05 15:24:24 -040024
25protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020026 static int ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile);
Ethan Yonker63e414f2015-02-06 15:44:39 -060027 static void LoadImage(ZipArchive* pZip, std::string file, gr_surface* source);
28 static void CheckAndScaleImage(gr_surface source, gr_surface* destination, int retain_aspect);
Dees_Troy51a0e822012-09-05 15:24:24 -040029};
30
Dees_Troy51a0e822012-09-05 15:24:24 -040031class FontResource : public Resource
32{
33public:
Vojtech Bocek76ee9032014-09-07 15:01:56 +020034 enum Type
35 {
36 TYPE_TWRP,
37#ifndef TW_DISABLE_TTF
38 TYPE_TTF,
39#endif
40 };
41
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020042 FontResource(xml_node<>* node, ZipArchive* pZip);
43 virtual ~FontResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040044
45public:
thatf6ed8fc2015-02-14 20:23:16 +010046 void* GetResource() { return this ? mFont : NULL; }
47 int GetHeight() { return gr_getMaxFontHeight(this ? mFont : NULL); }
48
Dees_Troy51a0e822012-09-05 15:24:24 -040049protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020050 void* mFont;
Vojtech Bocek76ee9032014-09-07 15:01:56 +020051 Type m_type;
Dees_Troy51a0e822012-09-05 15:24:24 -040052};
53
54class ImageResource : public Resource
55{
56public:
Ethan Yonker63e414f2015-02-06 15:44:39 -060057 ImageResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020058 virtual ~ImageResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040059
60public:
thatf6ed8fc2015-02-14 20:23:16 +010061 gr_surface GetResource() { return this ? mSurface : NULL; }
62 int GetWidth() { return gr_get_width(this ? mSurface : NULL); }
63 int GetHeight() { return gr_get_height(this ? mSurface : NULL); }
64
Dees_Troy51a0e822012-09-05 15:24:24 -040065protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020066 gr_surface mSurface;
Dees_Troy51a0e822012-09-05 15:24:24 -040067};
68
69class AnimationResource : public Resource
70{
71public:
Ethan Yonker63e414f2015-02-06 15:44:39 -060072 AnimationResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020073 virtual ~AnimationResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040074
75public:
thatf6ed8fc2015-02-14 20:23:16 +010076 gr_surface GetResource() { return (!this || mSurfaces.empty()) ? NULL : mSurfaces.at(0); }
77 gr_surface GetResource(int entry) { return (!this || mSurfaces.empty()) ? NULL : mSurfaces.at(entry); }
78 int GetWidth() { return gr_get_width(this ? GetResource() : NULL); }
79 int GetHeight() { return gr_get_height(this ? GetResource() : NULL); }
80 int GetResourceCount() { return mSurfaces.size(); }
Dees_Troy51a0e822012-09-05 15:24:24 -040081
82protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020083 std::vector<gr_surface> mSurfaces;
Dees_Troy51a0e822012-09-05 15:24:24 -040084};
85
86class ResourceManager
87{
88public:
that74ac6062015-03-04 22:39:34 +010089 ResourceManager();
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020090 virtual ~ResourceManager();
Ethan Yonker780cd392014-07-21 15:24:39 -050091 void LoadResources(xml_node<>* resList, ZipArchive* pZip);
Dees_Troy51a0e822012-09-05 15:24:24 -040092
93public:
that74ac6062015-03-04 22:39:34 +010094 FontResource* FindFont(const std::string& name) const;
95 ImageResource* FindImage(const std::string& name) const;
96 AnimationResource* FindAnimation(const std::string& name) const;
Dees_Troy51a0e822012-09-05 15:24:24 -040097
98private:
that74ac6062015-03-04 22:39:34 +010099 std::vector<FontResource*> mFonts;
100 std::vector<ImageResource*> mImages;
101 std::vector<AnimationResource*> mAnimations;
Dees_Troy51a0e822012-09-05 15:24:24 -0400102};
103
104#endif // _RESOURCE_HEADER