Spinning Topp Logo BlackTopp Studios
inc
textureatlas.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _uitextureatlas_h
41 #define _uitextureatlas_h
42 
43 #include "vector2.h"
44 #include "colourvalue.h"
45 #include "uienumerations.h"
46 #include "XML/xml.h"
47 
48 namespace Ogre
49 {
50  class Pass;
51  class Material;
52  class Texture;
53  template<typename T> class SharedPtr;
54  typedef SharedPtr<Material> MaterialPtr;
55  typedef SharedPtr<Texture> TexturePtr;
56 }
57 
58 namespace Mezzanine
59 {
60  namespace UI
61  {
62  struct TextureAtlasInternalData;
63  class FontData;
64  class Sprite;
65  class Glyph;
66 
67  ///////////////////////////////////////////////////////////////////////////////
68  /// @brief This is a collection of smaller textures packed into a larger texture, intended to increase UI performance.
69  /// @details
70  ///////////////////////////////////////
72  {
73  public:
74  /// @brief Container type for storing fonts packed into this atlas.
75  typedef std::map<String,FontData*> FontDataContainer;
76  /// @brief Iterator type for fonts stored in this class.
77  typedef FontDataContainer::iterator FontDataIterator;
78  /// @brief Const Iterator type for fonts stored in this class.
79  typedef FontDataContainer::const_iterator ConstFontDataIterator;
80  /// @brief Container type for storing images packed into this atlas.
81  typedef std::map<String,Sprite*> SpriteContainer;
82  /// @brief Iterator type for images stored in this class.
83  typedef SpriteContainer::iterator SpriteIterator;
84  /// @brief Const Iterator type for images stored in this class.
85  typedef SpriteContainer::const_iterator ConstSpriteIterator;
86  protected:
87  /// @internal
88  /// @brief A pointer to internal rendering data that cannot be exposed here.
89  TextureAtlasInternalData* TAID;
90  /// @internal
91  /// @brief A container of the fonts packed into this atlas.
92  FontDataContainer Fonts;
93  /// @internal
94  /// @brief A container of the images packed into this atlas.
95  SpriteContainer Sprites;
96  /// @internal
97  /// @brief The name of this atlas.
99  /// @internal
100  /// @brief A known position on the atlas where the pixel is flat white. Surrounding pixels should also be white.
102  /// @internal
103  /// @brief This is (Size / 1) on the X and Y. Useful for doing math.
105 
106  /// @brief Parses the texture section of the Texture Atlas.
107  void ParseTexture(XML::Node& AtlasTextureNode);
108  /// @brief Parses the data for a font.
109  void ParseFonts(XML::Node& AtlasFontsNode);
110  /// @brief Parses the glyphs section of the Texture Atlas.
111  void ParseGlyphs(XML::Node& GlyphsNode, const Vector2& Offset, FontData* GlyphD);
112  /// @brief Parses the kerning section of the Texture Atlas.
113  void ParseKernings(XML::Node& KerningsNode, FontData* FontD);
114  /// @brief Parses the vertical offsets section of the Texture Atlas.
115  void ParseVerticalOffsets(XML::Node& VerticalOffsetsNode, FontData* FontD);
116  /// @brief Parses the sprites section of the Texture Atlas.
117  void ParseSprites(XML::Node& AtlasSpritesNode);
118  /// @brief Creates the material to be used by 2D interfaces with this Atlas.
119  void Create2DMaterial();
120  /// @brief Creates the material to be used by 3D interfaces with this Atlas.
121  void Create3DMaterial();
122  /// @brief Gets or creates the 2D "template" or "master" material that is to be used to copy from for all Atlases.
123  Ogre::MaterialPtr GetOrCreate2DMasterMaterial();
124  /// @brief Gets or creates the 3D "template" or "master" material that is to be used to copy from for all Atlases.
125  Ogre::MaterialPtr GetOrCreate3DMasterMaterial();
126  public:
127  /// @brief Proceadural constructor.
128  /// @param Name The name to be given to this Texture Atlas.
129  /// @param Width The width of the desired texture to create for this atlas.
130  /// @param Height The height of the desired texture to create for this atlas.
131  TextureAtlas(const String& Name, const UInt32& Width, const UInt32& Height);
132  /// @brief XML constructor.
133  /// @param AtlasNode The XML node containing all the information to create and configure this texture atlas.
134  TextureAtlas(XML::Node& AtlasNode);
135  /// @brief Class destructor.
136  ~TextureAtlas();
137 
138  ///////////////////////////////////////////////////////////////////////////////
139  // Utility
140 
141  /// @brief Gets the name of this Texture Atlas.
142  /// @return Returns a string containing the name of this Texture Atlas
143  const String& GetName() const;
144 
145  ///////////////////////////////////////////////////////////////////////////////
146  // Information Gathering
147 
148  /// @brief Gets the set of Glyphs of the specified name.
149  /// @param FontName The name of the font as specified in the MTA file.
150  /// @return Returns a pointer to the GlyphData containing all the Glyphs.
151  FontData* GetFont(const String& FontName) const;
152  /// @brief Gets the full listing of all the FontData instances in this TextureAtlas.
153  /// @return Returns a reference to the map storing all the FontData instances loaded for this TextureAtlas.
154  FontDataContainer& GetFonts();
155  /// @brief Gets a Sprite by name.
156  /// @param SpriteName The name of the Sprite to get.
157  /// @return Returns a pointer to the named Sprite.
158  Sprite* GetSprite(const String& SpriteName) const;
159  /// @brief Gets the full listing of all the Sprite's in this TextureAtlas.
160  /// @return Returns a reference to the map storing all the Sprite's loaded for this TextureAtlas.
161  SpriteContainer& GetSprites();
162  /// @brief Gets the location of the WhitePixel on the TextureAtlas.
163  /// @return Returns a Vector2 with the location of the WhitePixel.
164  Vector2 GetWhitePixel() const;
165  /// @brief Gets the X coordinate for the WhitePixel.
166  /// @return Returns a Real containing the X coordinate of the WhitePixel.
167  Real GetWhitePixelX() const;
168  /// @brief Gets the Y coordinate for the WhitePixel.
169  /// @return Returns a Real containing the Y coordinate of the WhitePixel.
170  Real GetWhitePixelY() const;
171  /// @brief Gets the size of the TextureAtlas.
172  /// @return Returns a Vector2 with the size of this TextureAtlas.
173  Vector2 GetTextureSize() const;
174  /// @brief Gets the inverse size of the TextureAtlas on the X size.
175  /// @return Returns a Real containing the inverse width of the TextureAtlas.
176  Real GetInvTextureCoordsX() const;
177  /// @brief Gets the inverse size of the TextureAtlas on the Y size.
178  /// @return Returns a Real containing the inverse height of the TextureAtlas.
179  Real GetInvTextureCoordsY() const;
180 
181  ///////////////////////////////////////////////////////////////////////////////
182  // Internal Functions
183 
184  /// @internal
185  /// @brief Gets the 2D Material for this TextureAtlas, creating it also if neccessary.
186  /// @return Returns a shared pointer to the internal material for this Atlas.
187  Ogre::MaterialPtr _GetOrCreate2DMaterial();
188  /// @internal
189  /// @brief Gets the 3D Material for this TextureAtlas, creating it also if neccessary.
190  /// @return Returns a shared pointer to the internal material for this Atlas.
191  Ogre::MaterialPtr _GetOrCreate3DMaterial();
192  /// @internal
193  /// @brief Gets the texture being used by this Atlas.
194  /// @return Returns a shared pointer to the internal texture for this Atlas.
195  Ogre::TexturePtr _GetTexture();
196  /// @internal
197  /// @brief Gets the 2D Material Pass for this TextureAtlas.
198  /// @return Returns a pointer to the 2D Pass used for this TextureAtlas.
199  Ogre::Pass* _Get2DPass() const;
200  /// @internal
201  /// @brief Gets the 3D Material Pass for this TextureAtlas.
202  /// @return Returns a pointer to the 3D Pass used for this TextureAtlas.
203  Ogre::Pass* _Get3DPass() const;
204  };//TextureAtlas
205  }//UI
206 }//Mezzanine
207 
208 #endif
This class represents a collection of Glyphs in a common visual style.
Definition: font.h:55
SpriteContainer::const_iterator ConstSpriteIterator
Const Iterator type for images stored in this class.
Definition: textureatlas.h:85
This is a collection of smaller textures packed into a larger texture, intended to increase UI perfor...
Definition: textureatlas.h:71
SpriteContainer::iterator SpriteIterator
Iterator type for images stored in this class.
Definition: textureatlas.h:83
Vector2 WhitePixel
A known position on the atlas where the pixel is flat white. Surrounding pixels should also be white...
Definition: textureatlas.h:101
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
FontDataContainer Fonts
A container of the fonts packed into this atlas.
Definition: textureatlas.h:92
SpriteContainer Sprites
A container of the images packed into this atlas.
Definition: textureatlas.h:95
FontDataContainer::const_iterator ConstFontDataIterator
Const Iterator type for fonts stored in this class.
Definition: textureatlas.h:79
Vector2 InverseTextureSize
This is (Size / 1) on the X and Y. Useful for doing math.
Definition: textureatlas.h:104
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
TextureAtlasInternalData * TAID
A pointer to internal rendering data that cannot be exposed here.
Definition: textureatlas.h:89
std::map< String, FontData * > FontDataContainer
Container type for storing fonts packed into this atlas.
Definition: textureatlas.h:75
String AtlasName
The name of this atlas.
Definition: textureatlas.h:98
std::map< String, Sprite * > SpriteContainer
Container type for storing images packed into this atlas.
Definition: textureatlas.h:81
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
FontDataContainer::iterator FontDataIterator
Iterator type for fonts stored in this class.
Definition: textureatlas.h:77
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
Basic class used to describe a portion of a texture to be applied to a Quad.
Definition: sprite.h:55
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159