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 | |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 6 | #include <string> |
| 7 | #include <vector> |
| 8 | #include <map> |
| 9 | |
| 10 | struct ZipArchive; |
Dees Troy | b7ae098 | 2013-09-10 20:47:35 +0000 | [diff] [blame] | 11 | |
that | f37aec2 | 2015-02-01 13:38:35 +0100 | [diff] [blame] | 12 | extern "C" { |
| 13 | #include "../minuitwrp/minui.h" |
| 14 | } |
| 15 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 16 | // Base Objects |
| 17 | class Resource |
| 18 | { |
| 19 | public: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 20 | Resource(xml_node<>* node, ZipArchive* pZip); |
| 21 | virtual ~Resource() {} |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 22 | |
| 23 | public: |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 24 | std::string GetName() { return mName; } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 25 | |
| 26 | private: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 27 | std::string mName; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 28 | |
| 29 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 30 | 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] | 31 | static void LoadImage(ZipArchive* pZip, std::string file, gr_surface* source); |
| 32 | static void CheckAndScaleImage(gr_surface source, gr_surface* destination, int retain_aspect); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 33 | }; |
| 34 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 35 | class FontResource : public Resource |
| 36 | { |
| 37 | public: |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 38 | enum Type |
| 39 | { |
| 40 | TYPE_TWRP, |
| 41 | #ifndef TW_DISABLE_TTF |
| 42 | TYPE_TTF, |
| 43 | #endif |
| 44 | }; |
| 45 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 46 | FontResource(xml_node<>* node, ZipArchive* pZip); |
| 47 | virtual ~FontResource(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 48 | |
| 49 | public: |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 50 | void* GetResource() { return this ? mFont : NULL; } |
| 51 | int GetHeight() { return gr_getMaxFontHeight(this ? mFont : NULL); } |
| 52 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 53 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 54 | void* mFont; |
Vojtech Bocek | 76ee903 | 2014-09-07 15:01:56 +0200 | [diff] [blame] | 55 | Type m_type; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | class ImageResource : public Resource |
| 59 | { |
| 60 | public: |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 61 | ImageResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 62 | virtual ~ImageResource(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 63 | |
| 64 | public: |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 65 | gr_surface GetResource() { return this ? mSurface : NULL; } |
| 66 | int GetWidth() { return gr_get_width(this ? mSurface : NULL); } |
| 67 | int GetHeight() { return gr_get_height(this ? mSurface : NULL); } |
| 68 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 69 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 70 | gr_surface mSurface; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | class AnimationResource : public Resource |
| 74 | { |
| 75 | public: |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 76 | AnimationResource(xml_node<>* node, ZipArchive* pZip, int retain_aspect); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 77 | virtual ~AnimationResource(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 78 | |
| 79 | public: |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame] | 80 | gr_surface GetResource() { return (!this || mSurfaces.empty()) ? NULL : mSurfaces.at(0); } |
| 81 | gr_surface GetResource(int entry) { return (!this || mSurfaces.empty()) ? NULL : mSurfaces.at(entry); } |
| 82 | int GetWidth() { return gr_get_width(this ? GetResource() : NULL); } |
| 83 | int GetHeight() { return gr_get_height(this ? GetResource() : NULL); } |
| 84 | int GetResourceCount() { return mSurfaces.size(); } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 85 | |
| 86 | protected: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 87 | std::vector<gr_surface> mSurfaces; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | class ResourceManager |
| 91 | { |
| 92 | public: |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 93 | ResourceManager(); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 94 | virtual ~ResourceManager(); |
Ethan Yonker | 780cd39 | 2014-07-21 15:24:39 -0500 | [diff] [blame] | 95 | void LoadResources(xml_node<>* resList, ZipArchive* pZip); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 96 | |
| 97 | public: |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 98 | FontResource* FindFont(const std::string& name) const; |
| 99 | ImageResource* FindImage(const std::string& name) const; |
| 100 | AnimationResource* FindAnimation(const std::string& name) const; |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 101 | std::string FindString(const std::string& name) const; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 102 | |
| 103 | private: |
that | 74ac606 | 2015-03-04 22:39:34 +0100 | [diff] [blame] | 104 | std::vector<FontResource*> mFonts; |
| 105 | std::vector<ImageResource*> mImages; |
| 106 | std::vector<AnimationResource*> mAnimations; |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 107 | std::map<std::string, std::string> mStrings; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | #endif // _RESOURCE_HEADER |