MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
textureatlas.h
1 // © Copyright 2010 - 2014 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 MaterialPtr;
52  class TexturePtr;
53 }
54 
55 namespace Mezzanine
56 {
57  namespace UI
58  {
59  struct TextureAtlasInternalData;
60  class FontData;
61  class Sprite;
62  class Glyph;
63  /// @class TextureAtlas
64  /// @headerfile uitextureatlas.h
65  /// @brief
66  /// @details
68  {
69  public:
70  typedef std::map<String,FontData*> FontDataContainer;
71  typedef FontDataContainer::iterator FontDataIterator;
72  typedef FontDataContainer::const_iterator ConstFontDataIterator;
73  typedef std::map<String,Sprite*> SpriteContainer;
74  typedef SpriteContainer::iterator SpriteIterator;
75  typedef SpriteContainer::const_iterator ConstSpriteIterator;
76  protected:
78  FontDataContainer Fonts;
79  SpriteContainer Sprites;
80  Vector2 WhitePixel;
81  Vector2 InverseTextureSize;
82  String AtlasName;
83 
84  /// @brief Parses the texture section of the Texture Atlas.
85  void ParseTexture(XML::Node& AtlasTextureNode);
86  /// @brief Parses the data for a font.
87  void ParseFonts(XML::Node& AtlasFontsNode);
88  /// @brief Parses the glyphs section of the Texture Atlas.
89  void ParseGlyphs(XML::Node& GlyphsNode, const Vector2& Offset, FontData* GlyphD);
90  /// @brief Parses the kerning section of the Texture Atlas.
91  void ParseKernings(XML::Node& KerningsNode, FontData* FontD);
92  /// @brief Parses the vertical offsets section of the Texture Atlas.
93  void ParseVerticalOffsets(XML::Node& VerticalOffsetsNode, FontData* FontD);
94  /// @brief Parses the sprites section of the Texture Atlas.
95  void ParseSprites(XML::Node& AtlasSpritesNode);
96  /// @brief Creates the material to be used by 2D interfaces with this Atlas.
97  void Create2DMaterial();
98  /// @brief Creates the material to be used by 3D interfaces with this Atlas.
99  void Create3DMaterial();
100  /// @brief Gets or creates the 2D "template" or "master" material that is to be used to copy from for all Atlases.
101  Ogre::MaterialPtr GetOrCreate2DMasterMaterial();
102  /// @brief Gets or creates the 3D "template" or "master" material that is to be used to copy from for all Atlases.
103  Ogre::MaterialPtr GetOrCreate3DMasterMaterial();
104  public:
105  /// @brief Proceadural constructor.
106  /// @param Name The name to be given to this Texture Atlas.
107  /// @param Width The width of the desired texture to create for this atlas.
108  /// @param Height The height of the desired texture to create for this atlas.
109  TextureAtlas(const String& Name, const UInt32& Width, const UInt32& Height);
110  /// @brief XML constructor.
111  /// @param AtlasNode The XML node containing all the information to create and configure this texture atlas.
112  TextureAtlas(XML::Node& AtlasNode);
113  /// @brief Class destructor.
114  ~TextureAtlas();
115 
116  ///////////////////////////////////////////////////////////////////////////////
117  // Utility
118 
119  /// @brief Gets the name of this Texture Atlas.
120  /// @return Returns a string containing the name of this Texture Atlas
121  const String& GetName() const;
122 
123  ///////////////////////////////////////////////////////////////////////////////
124  // Information Gathering
125 
126  /// @brief Gets the set of Glyphs of the specified name.
127  /// @param Name The name of the font as specified in the MTA file.
128  /// @return Returns a pointer to the GlyphData containing all the Glyphs.
129  FontData* GetFont(const String& FontName) const;
130  /// @brief Gets the full listing of all the FontData instances in this TextureAtlas.
131  /// @return Returns a reference to the map storing all the FontData instances loaded for this TextureAtlas.
132  FontDataContainer& GetFonts();
133  /// @brief Gets a Sprite by name.
134  /// @param Name The name of the Sprite to get.
135  /// @return Returns a pointer to the named Sprite.
136  Sprite* GetSprite(const String& Name) const;
137  /// @brief Gets the full listing of all the Sprite's in this TextureAtlas.
138  /// @return Returns a reference to the map storing all the Sprite's loaded for this TextureAtlas.
139  SpriteContainer& GetSprites();
140  /// @brief Gets the location of the WhitePixel on the TextureAtlas.
141  /// @return Returns a Vector2 with the location of the WhitePixel.
142  Vector2 GetWhitePixel() const;
143  /// @brief Gets the X coordinate for the WhitePixel.
144  /// @return Returns a Real containing the X coordinate of the WhitePixel.
145  Real GetWhitePixelX() const;
146  /// @brief Gets the Y coordinate for the WhitePixel.
147  /// @return Returns a Real containing the Y coordinate of the WhitePixel.
148  Real GetWhitePixelY() const;
149  /// @brief Gets the size of the TextureAtlas.
150  /// @return Returns a Vector2 with the size of this TextureAtlas.
151  Vector2 GetTextureSize() const;
152  /// @brief Gets the inverse size of the TextureAtlas on the X size.
153  /// @return Returns a Real containing the inverse width of the TextureAtlas.
154  Real GetInvTextureCoordsX() const;
155  /// @brief Gets the inverse size of the TextureAtlas on the Y size.
156  /// @return Returns a Real containing the inverse height of the TextureAtlas.
157  Real GetInvTextureCoordsY() const;
158 
159  ///////////////////////////////////////////////////////////////////////////////
160  // Internal Functions
161 
162  /// @internal
163  /// @brief Gets the 2D Material for this TextureAtlas, creating it also if neccessary.
164  /// @return Returns a shared pointer to the internal material for this Atlas.
165  Ogre::MaterialPtr _GetOrCreate2DMaterial();
166  /// @internal
167  /// @brief Gets the 3D Material for this TextureAtlas, creating it also if neccessary.
168  /// @return Returns a shared pointer to the internal material for this Atlas.
169  Ogre::MaterialPtr _GetOrCreate3DMaterial();
170  /// @internal
171  /// @brief Gets the texture being used by this Atlas.
172  /// @return Returns a shared pointer to the internal texture for this Atlas.
173  Ogre::TexturePtr _GetTexture();
174  /// @internal
175  /// @brief Gets the 2D Material Pass for this TextureAtlas.
176  /// @return Returns a pointer to the 2D Pass used for this TextureAtlas.
177  Ogre::Pass* _Get2DPass() const;
178  /// @internal
179  /// @brief Gets the 3D Material Pass for this TextureAtlas.
180  /// @return Returns a pointer to the 3D Pass used for this TextureAtlas.
181  Ogre::Pass* _Get3DPass() const;
182  };//TextureAtlas
183  }//UI
184 }//Mezzanine
185 
186 #endif