blob: 3cb528176acb13672728e2c559655cdf77763e8d [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#ifdef HAVE_SELINUX
7#include "../minzip/Zip.h"
8#else
9#include "../minzipold/Zip.h"
10#endif
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
30typedef enum {
Matt Mowerfb1c4ff2014-04-16 13:43:36 -050031 TOUCH_START = 0,
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020032 TOUCH_DRAG = 1,
33 TOUCH_RELEASE = 2,
Dees_Troy51a0e822012-09-05 15:24:24 -040034 TOUCH_HOLD = 3,
35 TOUCH_REPEAT = 4
36} TOUCH_STATE;
37
38class FontResource : public Resource
39{
40public:
Vojtech Bocek76ee9032014-09-07 15:01:56 +020041 enum Type
42 {
43 TYPE_TWRP,
44#ifndef TW_DISABLE_TTF
45 TYPE_TTF,
46#endif
47 };
48
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020049 FontResource(xml_node<>* node, ZipArchive* pZip);
50 virtual ~FontResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040051
52public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020053 virtual void* GetResource(void) { return mFont; }
Dees_Troy51a0e822012-09-05 15:24:24 -040054
55protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020056 void* mFont;
Vojtech Bocek76ee9032014-09-07 15:01:56 +020057 Type m_type;
Dees_Troy51a0e822012-09-05 15:24:24 -040058};
59
60class ImageResource : public Resource
61{
62public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020063 ImageResource(xml_node<>* node, ZipArchive* pZip);
64 virtual ~ImageResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040065
66public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020067 virtual void* GetResource(void) { return mSurface; }
Dees_Troy51a0e822012-09-05 15:24:24 -040068
69protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020070 gr_surface mSurface;
Dees_Troy51a0e822012-09-05 15:24:24 -040071};
72
73class AnimationResource : public Resource
74{
75public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020076 AnimationResource(xml_node<>* node, ZipArchive* pZip);
77 virtual ~AnimationResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040078
79public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020080 virtual void* GetResource(void) { return mSurfaces.at(0); }
81 virtual void* GetResource(int entry) { return mSurfaces.at(entry); }
82 virtual int GetResourceCount(void) { return mSurfaces.size(); }
Dees_Troy51a0e822012-09-05 15:24:24 -040083
84protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020085 std::vector<gr_surface> mSurfaces;
Dees_Troy51a0e822012-09-05 15:24:24 -040086};
87
88class ResourceManager
89{
90public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020091 ResourceManager(xml_node<>* resList, ZipArchive* pZip);
92 virtual ~ResourceManager();
Ethan Yonker780cd392014-07-21 15:24:39 -050093 void LoadResources(xml_node<>* resList, ZipArchive* pZip);
Dees_Troy51a0e822012-09-05 15:24:24 -040094
95public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020096 Resource* FindResource(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -040097
98private:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020099 std::vector<Resource*> mResources;
Dees_Troy51a0e822012-09-05 15:24:24 -0400100};
101
102#endif // _RESOURCE_HEADER