Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | // resources.hpp - Base classes for resource management of GUI |
| 2 | |
| 3 | #ifndef _RESOURCE_HEADER |
| 4 | #define _RESOURCE_HEADER |
| 5 | |
Dees Troy | b7ae098 | 2013-09-10 20:47:35 +0000 | [diff] [blame] | 6 | #include "../minzip/Zip.h" |
Dees Troy | b7ae098 | 2013-09-10 20:47:35 +0000 | [diff] [blame] | 7 | |
that | f37aec2 | 2015-02-01 13:38:35 +0100 | [diff] [blame] | 8 | extern "C" { |
| 9 | #include "../minuitwrp/minui.h" |
| 10 | } |
| 11 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 12 | // Base Objects |
| 13 | class Resource |
| 14 | { |
| 15 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 16 | Resource(xml_node<>* node, ZipArchive* pZip); |
| 17 | virtual ~Resource() {} |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 18 | |
| 19 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 20 | virtual void* GetResource(void) = 0; |
| 21 | std::string GetName(void) { return mName; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 22 | |
| 23 | private: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 24 | std::string mName; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 25 | |
| 26 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 27 | static int ExtractResource(ZipArchive* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile); |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 28 | 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_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 30 | }; |
| 31 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 32 | class FontResource : public Resource |
| 33 | { |
| 34 | public: |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 35 | enum Type |
| 36 | { |
| 37 | TYPE_TWRP, |
| 38 | #ifndef TW_DISABLE_TTF |
| 39 | TYPE_TTF, |
| 40 | #endif |
| 41 | }; |
| 42 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 43 | FontResource(xml_node<>* node, ZipArchive* pZip); |
| 44 | virtual ~FontResource(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 45 | |
| 46 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 47 | virtual void* GetResource(void) { return mFont; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 48 | |
| 49 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 50 | void* mFont; |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 51 | Type m_type; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | class ImageResource : public Resource |
| 55 | { |
| 56 | public: |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 57 | ImageResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 58 | virtual ~ImageResource(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 59 | |
| 60 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 61 | virtual void* GetResource(void) { return mSurface; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 62 | |
| 63 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 64 | gr_surface mSurface; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | class AnimationResource : public Resource |
| 68 | { |
| 69 | public: |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 70 | AnimationResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 71 | virtual ~AnimationResource(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 72 | |
| 73 | public: |
bigbiff | 85939e5 | 2014-11-15 21:03:52 -0500 | [diff] [blame] | 74 | virtual void* GetResource(void) { return mSurfaces.empty() ? NULL : mSurfaces.at(0); } |
| 75 | virtual void* GetResource(int entry) { return mSurfaces.empty() ? NULL : mSurfaces.at(entry); } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 76 | virtual int GetResourceCount(void) { return mSurfaces.size(); } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 77 | |
| 78 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 79 | std::vector<gr_surface> mSurfaces; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | class ResourceManager |
| 83 | { |
| 84 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 85 | ResourceManager(xml_node<>* resList, ZipArchive* pZip); |
| 86 | virtual ~ResourceManager(); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 87 | void LoadResources(xml_node<>* resList, ZipArchive* pZip); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 88 | |
| 89 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 90 | Resource* FindResource(std::string name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 91 | |
| 92 | private: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 93 | std::vector<Resource*> mResources; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | #endif // _RESOURCE_HEADER |