1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ 2 3 #ifndef ICON_HANDLER_H 4 #define ICON_HANDLER_H 5 6 #include <map> 7 #include <string> 8 #include <vector> 9 10 #include "Icon.h" 11 #include "System/float3.h" 12 13 class CVertexArray; 14 15 namespace icon { 16 class CIconData { 17 public: 18 CIconData(); // for CIconHandler::safetyData 19 CIconData(const std::string& name, unsigned int texID, 20 float size, float distance, bool radiusAdjust, 21 bool ownTexture, int xsize, int ysize); 22 ~CIconData(); 23 24 void Ref(); 25 void UnRef(); 26 27 void CopyData(const CIconData* iconData); 28 29 void BindTexture() const; 30 void DrawArray(CVertexArray* va, float x0, float y0, float x1, float y1, const unsigned char* c) const; 31 void Draw(float x0, float y0, float x1, float y1) const; 32 void Draw(const float3& botLeft, const float3& botRight, 33 const float3& topLeft, const float3& topRight) const; 34 GetName()35 inline const std::string& GetName() const { return name; } GetSize()36 inline const float GetSize() const { return size; } GetDistance()37 inline const float GetDistance() const { return distance; } GetDistanceSqr()38 inline const float GetDistanceSqr() const { return distSqr; } GetRadiusAdjust()39 inline const bool GetRadiusAdjust() const { return radiusAdjust; } GetSizeX()40 inline const int GetSizeX() const { return xsize; } GetSizeY()41 inline const int GetSizeY() const { return ysize; } GetTextureID()42 inline const unsigned int GetTextureID() const { return texID; } 43 44 private: 45 bool ownTexture; 46 int refCount; 47 48 std::string name; 49 unsigned int texID; 50 int xsize; 51 int ysize; 52 float size; 53 float distance; 54 float distSqr; 55 bool radiusAdjust; 56 }; 57 58 59 class CIconHandler { 60 friend class CIcon; 61 62 public: 63 CIconHandler(); 64 ~CIconHandler(); 65 CIconHandler(const CIconHandler&) = delete; // no-copy 66 67 bool AddIcon(const std::string& iconName, 68 const std::string& textureName, 69 float size, float distance, 70 bool radiusAdjust); 71 72 bool FreeIcon(const std::string& iconName); 73 74 CIcon GetIcon(const std::string& iconName) const; 75 GetDefaultIcon()76 CIcon GetDefaultIcon() const { return CIcon(defIconData); } 77 GetDefaultIconData()78 const CIconData* GetDefaultIconData() const { return defIconData; } 79 80 private: 81 bool LoadIcons(const std::string& filename); 82 unsigned int GetDefaultTexture(); 83 84 private: 85 unsigned int defTexID; 86 CIconData* defIconData; 87 88 typedef std::map<std::string, CIcon> IconMap; 89 IconMap iconMap; 90 91 private: 92 static CIconData safetyData; 93 }; 94 95 extern CIconHandler* iconHandler; 96 } 97 98 #endif // ICON_HANDLER_H 99