blob: f359c55ddd9ceadbbcf789571b55cab6c4f6739e [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
26typedef enum {
Matt Mowerfb1c4ff2014-04-16 13:43:36 -050027 TOUCH_START = 0,
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020028 TOUCH_DRAG = 1,
29 TOUCH_RELEASE = 2,
Dees_Troy51a0e822012-09-05 15:24:24 -040030 TOUCH_HOLD = 3,
31 TOUCH_REPEAT = 4
32} TOUCH_STATE;
33
34class FontResource : public Resource
35{
36public:
Vojtech Bocek76ee9032014-09-07 15:01:56 +020037 enum Type
38 {
39 TYPE_TWRP,
40#ifndef TW_DISABLE_TTF
41 TYPE_TTF,
42#endif
43 };
44
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020045 FontResource(xml_node<>* node, ZipArchive* pZip);
46 virtual ~FontResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040047
48public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020049 virtual void* GetResource(void) { return mFont; }
Dees_Troy51a0e822012-09-05 15:24:24 -040050
51protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020052 void* mFont;
Vojtech Bocek76ee9032014-09-07 15:01:56 +020053 Type m_type;
Dees_Troy51a0e822012-09-05 15:24:24 -040054};
55
56class ImageResource : public Resource
57{
58public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020059 ImageResource(xml_node<>* node, ZipArchive* pZip);
60 virtual ~ImageResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040061
62public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020063 virtual void* GetResource(void) { return mSurface; }
Dees_Troy51a0e822012-09-05 15:24:24 -040064
65protected:
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:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020072 AnimationResource(xml_node<>* node, ZipArchive* pZip);
73 virtual ~AnimationResource();
Dees_Troy51a0e822012-09-05 15:24:24 -040074
75public:
bigbiff85939e52014-11-15 21:03:52 -050076 virtual void* GetResource(void) { return mSurfaces.empty() ? NULL : mSurfaces.at(0); }
77 virtual void* GetResource(int entry) { return mSurfaces.empty() ? NULL : mSurfaces.at(entry); }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020078 virtual int GetResourceCount(void) { return mSurfaces.size(); }
Dees_Troy51a0e822012-09-05 15:24:24 -040079
80protected:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020081 std::vector<gr_surface> mSurfaces;
Dees_Troy51a0e822012-09-05 15:24:24 -040082};
83
84class ResourceManager
85{
86public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020087 ResourceManager(xml_node<>* resList, ZipArchive* pZip);
88 virtual ~ResourceManager();
Ethan Yonker780cd392014-07-21 15:24:39 -050089 void LoadResources(xml_node<>* resList, ZipArchive* pZip);
Dees_Troy51a0e822012-09-05 15:24:24 -040090
91public:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020092 Resource* FindResource(std::string name);
Dees_Troy51a0e822012-09-05 15:24:24 -040093
94private:
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020095 std::vector<Resource*> mResources;
Dees_Troy51a0e822012-09-05 15:24:24 -040096};
97
98#endif // _RESOURCE_HEADER