Spinning Topp Logo BlackTopp Studios
inc
textureatlas.cpp
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_cpp
41 #define _uitextureatlas_cpp
42 
43 #include "UI/textureatlas.h"
44 #include "UI/glyph.h"
45 #include "UI/sprite.h"
46 #include "stringtool.h"
47 
48 #include "entresol.h"
49 
50 #include <OgreTexture.h>
51 #include <OgreMaterial.h>
52 #include <OgreTechnique.h>
53 #include <OgrePass.h>
54 #include <OgreGpuProgram.h>
55 #include <OgreMaterialManager.h>
56 #include <OgreTextureManager.h>
57 #include <OgreRenderSystem.h>
58 #include <OgreRoot.h>
59 
60 namespace Mezzanine
61 {
62  namespace UI
63  {
64  ///////////////////////////////////////////////////////////
65  // TextureAtlasInternalData class and functions
66 
67  // Keeps this file form being documented by doxygen
68  /// @cond DontDocumentInternal
69 
70  ///////////////////////////////////////////////////////////////////////////////
71  /// @brief A struct storing all the internal render data for a UI::TextureAtlas.
72  /// @details
73  ///////////////////////////////////////
74  struct MEZZ_LIB TextureAtlasInternalData
75  {
76  /// @brief A shared pointer to the actual texture of this atlas.
77  Ogre::TexturePtr TATexture;
78  /// @brief A material used for 2D rendering of items on this atlas.
79  Ogre::MaterialPtr Mat2D;
80  /// @brief A material used for 3D rendering of items on this atlas.
81  Ogre::MaterialPtr Mat3D;
82  /// @brief A convenience pointer to the primary pass for 2D rendering of items.
83  Ogre::Pass* Pass2D;
84  /// @brief A convenience pointer to the primary pass for 3D rendering of items.
85  Ogre::Pass* Pass3D;
86 
87  /// @brief Class constructor.
88  TextureAtlasInternalData()
89  {
90  TATexture.setNull();
91  Mat2D.setNull();
92  Mat3D.setNull();
93  Pass2D = NULL;
94  Pass3D = NULL;
95  }
96  };//TextureAtlasInternalData
97 
98  /// @endcond
99 
100  ///////////////////////////////////////////////////////////
101  // TextureAtlas functions
102 
103  TextureAtlas::TextureAtlas(const String& Name, const UInt32& Width, const UInt32& Height) :
104  AtlasName(Name)
105  {
106  this->TAID = new TextureAtlasInternalData();
107  /// @todo This is just a starter code sample for proceadurally generated texture atlases. Not ready and needs to be completed.
108  String GroupName = "UI";
109  this->TAID->TATexture = Ogre::TextureManager::getSingletonPtr()->createManual(this->AtlasName+"Texture",GroupName,Ogre::TEX_TYPE_2D,Width,Height,0,Ogre::PF_R8G8B8A8,Ogre::TU_DEFAULT);
110  this->Create2DMaterial();
111  this->Create3DMaterial();
112  }
113 
115  {
116  this->TAID = new TextureAtlasInternalData();
117  // Parse and set the name
118  XML::Attribute NameAttrib = AtlasNode.GetAttribute("Name");
119  if( !NameAttrib.Empty() ) {
120  this->AtlasName = NameAttrib.AsString();
121  }else{
122  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_INVALID_EXCEPTION,"Empty string being used to set name of Texture Atlas being parsed from XML.");
123  }
124 
125  XML::Node TextureNode = AtlasNode.GetChild("Texture");
126  this->ParseTexture( TextureNode );
127  XML::Node FontsNode = AtlasNode.GetChild("Fonts");
128  this->ParseFonts( FontsNode );
129  XML::Node SpritesNode = AtlasNode.GetChild("Sprites");
130  this->ParseSprites( SpritesNode );
131 
132  this->Create2DMaterial();
133  this->Create3DMaterial();
134  }
135 
137  {
138  for( FontDataIterator FontIt = this->Fonts.begin() ; FontIt != this->Fonts.end() ; ++FontIt )
139  {
140  delete (*FontIt).second;
141  }
142  this->Fonts.clear();
143 
144  for( SpriteIterator SpriteIt = this->Sprites.begin() ; SpriteIt != this->Sprites.end() ; ++SpriteIt )
145  {
146  delete (*SpriteIt).second;
147  }
148  this->Sprites.clear();
149 
150  delete this->TAID;
151  }
152 
153  ///////////////////////////////////////////////////////////////////////////////
154  // Private & Setup Functions
155 
156  void TextureAtlas::ParseTexture(XML::Node& AtlasTextureNode)
157  {
158  XML::Attribute CurrAttrib;
159  String FileName;
160  String GroupName = "UI";
161 
162  // Get the filename
163  CurrAttrib = AtlasTextureNode.GetAttribute("TexFile");
164  if( !CurrAttrib.Empty() )
165  FileName = CurrAttrib.AsString();
166  else{ MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_INVALID_EXCEPTION,"Empty string parsed for texture file name when parsing Texture Atlas from XML."); }
167 
168  // Get the resource group
169  CurrAttrib = AtlasTextureNode.GetAttribute("TexFileGroup");
170  if( !CurrAttrib.Empty() )
171  GroupName = CurrAttrib.AsString();
172 
173  // Setup the texture
174  this->TAID->TATexture = Ogre::TextureManager::getSingletonPtr()->getByName(FileName,GroupName);
175  if(this->TAID->TATexture.isNull())
176  {
177  this->TAID->TATexture = Ogre::TextureManager::getSingletonPtr()->load(FileName,GroupName,Ogre::TEX_TYPE_2D,0);
178  }
179 
180  this->InverseTextureSize.X = 1.0 / this->TAID->TATexture->getWidth();
181  this->InverseTextureSize.Y = 1.0 / this->TAID->TATexture->getHeight();
182 
183  // Get the white pixel location
184  CurrAttrib = AtlasTextureNode.GetAttribute("WhitePixel");
185  if( !CurrAttrib.Empty() )
186  this->WhitePixel = StringTools::ConvertToVector2( CurrAttrib.AsString() );
187 
188  // Convert the white pixel location to relative
189  this->WhitePixel.X *= this->InverseTextureSize.X;
190  this->WhitePixel.Y *= this->InverseTextureSize.Y;
191  }
192 
193  void TextureAtlas::ParseFonts(XML::Node& AtlasFontsNode)
194  {
195  for( XML::NodeIterator FontNode = AtlasFontsNode.begin() ; FontNode != AtlasFontsNode.end() ; ++FontNode )
196  {
197  XML::Attribute CurrAttrib;
198  Vector2 Offset(0,0);
199  FontData* Data = new FontData(this);
200 
201  // Get the name
202  CurrAttrib = (*FontNode).GetAttribute("Name");
203  if( !CurrAttrib.Empty() )
204  Data->_SetName( CurrAttrib.AsString() );
205 
206  // Now that we have the name, quickly check if this is unique before we continue to parse
207  FontDataIterator FontIt = Fonts.find(Data->GetName());
208  if( FontIt == Fonts.end() ) { Fonts[Data->GetName()] = Data; }
209  else { MEZZ_EXCEPTION(ExceptionBase::II_DUPLICATE_IDENTITY_EXCEPTION,"Duplicate name of font:\"" + Data->GetName() + "\", found in atlas:\"" + AtlasName + "\"." ); }
210 
211  // Get the horizontal offset if there is any
212  CurrAttrib = (*FontNode).GetAttribute("OffsetX");
213  if( !CurrAttrib.Empty() )
214  Offset.X = CurrAttrib.AsReal();
215 
216  // Get the vertical offset if there is any
217  CurrAttrib = (*FontNode).GetAttribute("OffsetY");
218  if( !CurrAttrib.Empty() )
219  Offset.Y = CurrAttrib.AsReal();
220 
221  // Get the lineheight
222  CurrAttrib = (*FontNode).GetAttribute("LineHeight");
223  if( !CurrAttrib.Empty() )
224  Data->_SetLineHeight( CurrAttrib.AsReal() );
225 
226  // Get the spacelength
227  CurrAttrib = (*FontNode).GetAttribute("SpaceLength");
228  if( !CurrAttrib.Empty() )
229  Data->_SetSpaceLength( CurrAttrib.AsReal() );
230 
231  // Get the baseline
232  CurrAttrib = (*FontNode).GetAttribute("BaseLine");
233  if( !CurrAttrib.Empty() )
234  Data->_SetBaseLine( CurrAttrib.AsReal() );
235 
236  // Get the letterspacing
237  CurrAttrib = (*FontNode).GetAttribute("LetterSpacing");
238  if( !CurrAttrib.Empty() )
239  Data->_SetLetterSpacing( CurrAttrib.AsReal() );
240 
241  // Get the monowidth
242  /*CurrAttrib = (*FontNode).GetAttribute("MonoWidth");
243  if( !CurrAttrib.Empty() )
244  Data->_SetMonoWidth( CurrAttrib.AsReal() );// */
245 
246  // Get the start of the range
247  /*CurrAttrib = (*FontNode).GetAttribute("RangeBegin");
248  if( !CurrAttrib.Empty() )
249  Data->_SetRangeBegin( CurrAttrib.AsReal() );// */
250 
251  // Get the end of the range
252  /*CurrAttrib = (*FontNode).GetAttribute("RangeEnd");
253  if( !CurrAttrib.Empty() )
254  Data->_SetRangeEnd( CurrAttrib.AsReal() );// */
255 
256  // Generate the whitespaces
258  // Get the glyphs and parse them
259  XML::Node GlyphsNode = (*FontNode).GetChild("Glyphs");
260  this->ParseGlyphs( GlyphsNode, Offset, Data );
261  // Next parse the kernings for those glyphs
262  XML::Node KerningsNode = (*FontNode).GetChild("Kernings");
263  this->ParseKernings( KerningsNode, Data );
264  // Lastly parse the vertical offsets
265  XML::Node VerticalOffsetsNode = (*FontNode).GetChild("VerticalOffsets");
266  this->ParseVerticalOffsets( VerticalOffsetsNode, Data );
267  }
268  }
269 
270  void TextureAtlas::ParseGlyphs(XML::Node& GlyphsNode, const Vector2& Offset, FontData* FontD)
271  {
272  XML::Attribute CurrAttrib;
273  Ogre::RenderSystem* rs = Ogre::Root::getSingletonPtr()->getRenderSystem();
274 
275  Real TexelX = rs->getHorizontalTexelOffset();
276  Real TexelY = rs->getVerticalTexelOffset();
277 
278  UInt32 ParsedGlyphID = 0;
279  Real Left = 0, Top = 0, Right = 0, Bottom = 0;
280 
281  for( XML::NodeIterator GlyphIt = GlyphsNode.begin() ; GlyphIt != GlyphsNode.end() ; ++GlyphIt )
282  {
283  // Get the ID
284  CurrAttrib = (*GlyphIt).GetAttribute("ID");
285  if( !CurrAttrib.Empty() ) ParsedGlyphID = CurrAttrib.AsUint();
286  else continue;
287 
288  // Get the left position
289  CurrAttrib = (*GlyphIt).GetAttribute("PositionX");
290  if( !CurrAttrib.Empty() ) Left = (Offset.X + CurrAttrib.AsReal()) - TexelX;
291  else continue;
292 
293  // Get the top position
294  CurrAttrib = (*GlyphIt).GetAttribute("PositionY");
295  if( !CurrAttrib.Empty() ) Top = (Offset.Y + CurrAttrib.AsReal()) - TexelY;
296  else continue;
297 
298  // Get the width
299  CurrAttrib = (*GlyphIt).GetAttribute("SizeX");
300  if( !CurrAttrib.Empty() ) Right = (Left + CurrAttrib.AsReal()) - TexelX;
301  else continue;
302 
303  // Get the height
304  CurrAttrib = (*GlyphIt).GetAttribute("SizeY");
305  if( !CurrAttrib.Empty() ) Bottom = (Top + CurrAttrib.AsReal()) - TexelY;
306  else continue;
307 
308  // If we got this far, we have enough data for a valid glyph, create and insert it
309  Glyph* NewGlyph = new Glyph(FontD);
310  NewGlyph->GlyphID = ParsedGlyphID;
311  FontD->_AddGlyph(NewGlyph);
312 
313  // Convert the coordinates to relative
314  Left *= InverseTextureSize.X;
315  Top *= InverseTextureSize.Y;
316  Right *= InverseTextureSize.X;
317  Bottom *= InverseTextureSize.Y;
318 
319  // Assign the values to the glyph
320  NewGlyph->AtlasCoords[QC_TopLeft].SetValues(Left,Top);
321  NewGlyph->AtlasCoords[QC_TopRight].SetValues(Right,Top);
322  NewGlyph->AtlasCoords[QC_BottomRight].SetValues(Right,Bottom);
323  NewGlyph->AtlasCoords[QC_BottomLeft].SetValues(Left,Bottom);
324 
325  // Get or generate the glyph advance
326  CurrAttrib = (*GlyphIt).GetAttribute("Advance");
327  if( !CurrAttrib.Empty() ) NewGlyph->GlyphAdvance = CurrAttrib.AsReal();
328  else NewGlyph->GlyphAdvance = NewGlyph->GetWidth();
329  }
330  }
331 
332  void TextureAtlas::ParseKernings(XML::Node& KerningsNode, FontData* FontD)
333  {
334  XML::Attribute CurrAttrib;
335  UInt32 LeftID = 0;
336  UInt32 RightID = 0;
337  Real Kerning = 0;
338 
339  for( XML::NodeIterator KerningNode = KerningsNode.begin() ; KerningNode != KerningsNode.end() ; ++KerningNode )
340  {
341  // Get the left ID
342  CurrAttrib = (*KerningNode).GetAttribute("Left");
343  if( !CurrAttrib.Empty() ) LeftID = CurrAttrib.AsReal();
344  else continue;
345 
346  // Get the right ID
347  CurrAttrib = (*KerningNode).GetAttribute("Right");
348  if( !CurrAttrib.Empty() ) RightID = CurrAttrib.AsReal();
349  else continue;
350 
351  // Get the kerning adjustment
352  CurrAttrib = (*KerningNode).GetAttribute("Adjust");
353  if( !CurrAttrib.Empty() ) Kerning = CurrAttrib.AsReal();
354  else continue;
355 
356  FontD->GetGlyph(RightID)->Kernings.push_back(KerningInfo(LeftID,Kerning));
357  }
358  }
359 
360  void TextureAtlas::ParseVerticalOffsets(XML::Node& VerticalOffsetsNode, FontData* FontD)
361  {
362  XML::Attribute CurrAttrib;
363  UInt32 GlyphID = 0;
364  Real Offset = 0;
365 
366  for( XML::NodeIterator VerticalOffsetNode = VerticalOffsetsNode.begin() ; VerticalOffsetNode != VerticalOffsetsNode.end() ; ++VerticalOffsetNode )
367  {
368  // Get the glyph ID
369  CurrAttrib = (*VerticalOffsetNode).GetAttribute("GlyphID");
370  if( !CurrAttrib.Empty() ) GlyphID = CurrAttrib.AsUint();
371  else continue;
372 
373  // Get the offset
374  CurrAttrib = (*VerticalOffsetNode).GetAttribute("Offset");
375  if( !CurrAttrib.Empty() ) Offset = CurrAttrib.AsReal();
376  else continue;
377 
378  FontD->GetGlyph(GlyphID)->VerticalOffset = Offset;
379  }
380  }
381 
382  void TextureAtlas::ParseSprites(XML::Node& AtlasSpritesNode)
383  {
384  XML::Attribute CurrAttrib;
385  Ogre::RenderSystem* rs = Ogre::Root::getSingletonPtr()->getRenderSystem();
386 
387  Real TexelX = rs->getHorizontalTexelOffset();
388  Real TexelY = rs->getVerticalTexelOffset();
389 
390  String SpriteName;
391  Real Left = 0, Top = 0, Right = 0, Bottom = 0;
392 
393  for( XML::NodeIterator SpriteIt = AtlasSpritesNode.begin() ; SpriteIt != AtlasSpritesNode.end() ; ++SpriteIt )
394  {
395  // Get the name
396  CurrAttrib = (*SpriteIt).GetAttribute("Name");
397  if( !CurrAttrib.Empty() ) SpriteName = CurrAttrib.AsString();
398  else continue;
399 
400  // Get the left position
401  CurrAttrib = (*SpriteIt).GetAttribute("PositionX");
402  if( !CurrAttrib.Empty() ) Left = CurrAttrib.AsReal() - TexelX;
403  else continue;
404 
405  // Get the top position
406  CurrAttrib = (*SpriteIt).GetAttribute("PositionY");
407  if( !CurrAttrib.Empty() ) Top = CurrAttrib.AsReal() - TexelY;
408  else continue;
409 
410  // Get the width
411  CurrAttrib = (*SpriteIt).GetAttribute("SizeX");
412  if( !CurrAttrib.Empty() ) Right = (Left + CurrAttrib.AsReal()) - TexelX;
413  else continue;
414 
415  // Get the height
416  CurrAttrib = (*SpriteIt).GetAttribute("SizeY");
417  if( !CurrAttrib.Empty() ) Bottom = (Top + CurrAttrib.AsReal()) - TexelY;
418  else continue;
419 
420  // Convert the coordinates to relative
421  Left *= InverseTextureSize.X;
422  Top *= InverseTextureSize.Y;
423  Right *= InverseTextureSize.X;
424  Bottom *= InverseTextureSize.Y;
425 
426  // If we got this far, we have enough data for a valid sprite, create and insert it
427  Sprite* NewSprite = new Sprite(SpriteName,Top,Left,Bottom,Right,this);
428  SpriteIterator SpIt = this->Sprites.find(SpriteName);
429  if( SpIt == this->Sprites.end() ) {
430  this->Sprites.insert(std::pair<String,Sprite*>(SpriteName,NewSprite));
431  }else{
432  StringStream ExceptionStream;
433  ExceptionStream << "Sprite named \"" << SpriteName << "\" already exists in Atlas: \"" << this->AtlasName << "\".";
435  }
436  }
437  }
438 
440  {
441  String MatName = "Mezz2D." + this->TAID->TATexture->getName();
442  this->TAID->Mat2D = Ogre::MaterialManager::getSingletonPtr()->getByName(MatName);
443  if(!this->TAID->Mat2D.isNull())
444  {
445  return;
446  }
447 
448  this->TAID->Mat2D = GetOrCreate2DMasterMaterial()->clone(MatName);
449  this->TAID->Pass2D = this->TAID->Mat2D->getTechnique(0)->getPass(0);
450  this->TAID->Pass2D->getTextureUnitState(0)->setTextureName(this->TAID->TATexture->getName());
451  }
452 
454  {
455  String MatName = "Mezz3D." + this->TAID->TATexture->getName();
456  this->TAID->Mat3D = Ogre::MaterialManager::getSingletonPtr()->getByName(MatName);
457  if(!this->TAID->Mat3D.isNull())
458  {
459  return;
460  }
461 
462  this->TAID->Mat3D = GetOrCreate3DMasterMaterial()->clone(MatName);
463  this->TAID->Pass3D = this->TAID->Mat3D->getTechnique(0)->getPass(0);
464  this->TAID->Pass3D->getTextureUnitState(0)->setTextureName(this->TAID->TATexture->getName());
465  }
466 
468  {
469  Ogre::MaterialPtr Material2D = Ogre::MaterialManager::getSingletonPtr()->getByName("Mezz2D");
470  if(Material2D.isNull() == false)
471  {
472  Ogre::Pass* MatPass = Material2D->getTechnique(0)->getPass(0);
473 
474  if(MatPass->hasVertexProgram())
475  {
476  Ogre::GpuProgramPtr gpuPtr = MatPass->getVertexProgram();
477  gpuPtr->load();
478  }
479 
480  if(MatPass->hasFragmentProgram())
481  {
482  Ogre::GpuProgramPtr gpuPtr = MatPass->getFragmentProgram();
483  gpuPtr->load();
484  }
485 
486  return Material2D;
487  }
488 
489  Material2D = Ogre::MaterialManager::getSingletonPtr()->create("Mezz2D","UI");
490  Ogre::Pass* MatPass = Material2D->getTechnique(0)->getPass(0);
491  MatPass->setCullingMode(Ogre::CULL_NONE);
492  MatPass->setDepthCheckEnabled(false);
493  MatPass->setDepthWriteEnabled(false);
494  MatPass->setLightingEnabled(false);
495  MatPass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
496 
497  Ogre::TextureUnitState* TexUnit = MatPass->createTextureUnitState();
498  TexUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
499  TexUnit->setTextureFiltering(Ogre::FO_NONE, Ogre::FO_NONE, Ogre::FO_NONE);
500  return Material2D;
501  }
502 
504  {
505  Ogre::MaterialPtr Material3D = Ogre::MaterialManager::getSingletonPtr()->getByName("Mezz3D");
506  if(Material3D.isNull() == false)
507  {
508  Ogre::Pass* MatPass = Material3D->getTechnique(0)->getPass(0);
509 
510  if(MatPass->hasVertexProgram())
511  {
512  Ogre::GpuProgramPtr gpuPtr = MatPass->getVertexProgram();
513  gpuPtr->load();
514  }
515 
516  if(MatPass->hasFragmentProgram())
517  {
518  Ogre::GpuProgramPtr gpuPtr = MatPass->getFragmentProgram();
519  gpuPtr->load();
520  }
521 
522  return Material3D;
523  }
524 
525  Material3D = Ogre::MaterialManager::getSingletonPtr()->create("Mezz3D","UI");
526  Ogre::Pass* MatPass = Material3D->getTechnique(0)->getPass(0);
527  MatPass->setCullingMode(Ogre::CULL_NONE);
528  MatPass->setDepthCheckEnabled(false);
529  MatPass->setDepthWriteEnabled(false);
530  MatPass->setLightingEnabled(false);
531  MatPass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
532 
533  Ogre::TextureUnitState* TexUnit = MatPass->createTextureUnitState();
534  TexUnit->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
535  TexUnit->setTextureFiltering(Ogre::FO_ANISOTROPIC, Ogre::FO_ANISOTROPIC, Ogre::FO_ANISOTROPIC);
536  return Material3D;
537  }
538 
539  ///////////////////////////////////////////////////////////////////////////////
540  // Utility
541 
543  {
544  return AtlasName;
545  }
546 
547  ///////////////////////////////////////////////////////////////////////////////
548  // Information Gathering
549 
550  FontData* TextureAtlas::GetFont(const String& FontName) const
551  {
552  ConstFontDataIterator it = this->Fonts.find(FontName);
553  if( it == this->Fonts.end() )
554  return NULL;
555  return (*it).second;
556  }
557 
559  {
560  return this->Fonts;
561  }
562 
563  Sprite* TextureAtlas::GetSprite(const String& SpriteName) const
564  {
565  ConstSpriteIterator it = this->Sprites.find(SpriteName);
566  if( it == this->Sprites.end() )
567  return NULL;
568  return (*it).second;
569  }
570 
572  { return this->Sprites; }
573 
575  { return this->WhitePixel; }
576 
578  { return this->WhitePixel.X; }
579 
581  { return this->WhitePixel.Y; }
582 
584  { return Vector2( Real( this->TAID->TATexture->getWidth() ), Real( this->TAID->TATexture->getHeight() ) ); }
585 
587  { return 1.0 / Real(this->TAID->TATexture->getWidth()); }
588 
590  { return 1.0 / Real(this->TAID->TATexture->getHeight()); }
591 
592  ///////////////////////////////////////////////////////////////////////////////
593  // Internal Functions
594 
596  {
597  if(this->TAID->Mat2D.isNull()) {
599  }
600  return this->TAID->Mat2D;
601  }
602 
604  {
605  if(this->TAID->Mat3D.isNull()) {
607  }
608  return this->TAID->Mat3D;
609  }
610 
612  { return this->TAID->TATexture; }
613 
614  Ogre::Pass* TextureAtlas::_Get2DPass() const
615  { return this->TAID->Pass2D; }
616 
617  Ogre::Pass* TextureAtlas::_Get3DPass() const
618  { return this->TAID->Pass3D; }
619  }//UI
620 }//Mezzanine
621 
622 #endif
void _SetSpaceLength(const Real SL)
Sets the length of a space for this font.
Definition: font.cpp:110
Thrown when duplicates of teh same identity string exist.
Definition: exception.h:95
This class represents a collection of Glyphs in a common visual style.
Definition: font.h:55
Vector2 GetTextureSize() const
Gets the size of the TextureAtlas.
A light-weight handle for manipulating attributes in DOM tree.
Definition: attribute.h:74
const String & GetName() const
Gets the name of this Texture Atlas.
Class used to describe a single glyph or character available for text operations. ...
Definition: glyph.h:59
void _SetLetterSpacing(const Real LS)
Sets the LetterSpacing of this font.
Definition: font.cpp:119
void _GenerateWhitespaceGlyphs()
Generates Whitespace Glyphs from this font's data for this font.
Definition: font.cpp:137
Real GetInvTextureCoordsX() const
Gets the inverse size of the TextureAtlas on the X size.
Ogre::TexturePtr _GetTexture()
Gets the texture being used by this Atlas.
void ParseFonts(XML::Node &AtlasFontsNode)
Parses the data for a font.
KerningContainer Kernings
List of all the Kernings that apply to this glyph.
Definition: glyph.h:113
Real GetWidth() const
Gets the glyphs width on the Texture.
Definition: glyph.h:191
void _SetName(const String &Name)
Sets the name of this font.
Definition: font.cpp:122
TextureAtlas(const String &Name, const UInt32 &Width, const UInt32 &Height)
Proceadural constructor.
Ogre::MaterialPtr GetOrCreate2DMasterMaterial()
Gets or creates the 2D "template" or "master" material that is to be used to copy from for all Atlase...
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
Real GetWhitePixelY() const
Gets the Y coordinate for the WhitePixel.
SpriteContainer::const_iterator ConstSpriteIterator
Const Iterator type for images stored in this class.
Definition: textureatlas.h:85
void ParseKernings(XML::Node &KerningsNode, FontData *FontD)
Parses the kerning section of the Texture Atlas.
SpriteContainer & GetSprites()
Gets the full listing of all the Sprite's in this TextureAtlas.
const Char8 * AsString(const Char8 *def="") const
Attempts to convert the value of the attribute to a String and returns the results.
Ogre::MaterialPtr GetOrCreate3DMasterMaterial()
Gets or creates the 3D "template" or "master" material that is to be used to copy from for all Atlase...
~TextureAtlas()
Class destructor.
SpriteContainer::iterator SpriteIterator
Iterator type for images stored in this class.
Definition: textureatlas.h:83
std::stringstream StringStream
A Datatype used for streaming operations with strings.
Definition: datatypes.h:176
Vector2 WhitePixel
A known position on the atlas where the pixel is flat white. Surrounding pixels should also be white...
Definition: textureatlas.h:101
Real VerticalOffset
The amount of pixels the glyph is to be adjusted on the Y axis.
Definition: glyph.h:109
Real GlyphAdvance
The number of pixels to advance the cursor for the next glyph.
Definition: glyph.h:107
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
Real GetInvTextureCoordsY() const
Gets the inverse size of the TextureAtlas on the Y size.
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
Real Y
Coordinate on the Y vector.
Definition: vector2.h:69
Child node iterator (a bidirectional iterator over a collection of Node)
Definition: nodeiterator.h:77
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
iterator begin() const
Get a Child node iterator that references the first child Node.
Real X
Coordinate on the X vector.
Definition: vector2.h:67
unsigned int AsUint(unsigned int def=0) const
Attempts to convert the value of the attribute to an unsigned int and returns the results...
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
const String & GetName() const
Gets the name of this font.
Definition: font.cpp:91
iterator end() const
Get a Child node iterator that references one past the last child Node.
TextureAtlasInternalData * TAID
A pointer to internal rendering data that cannot be exposed here.
Definition: textureatlas.h:89
bool Empty() const
Is this storing anything at all?
Basic class used to describe Kerning for a given Glyph.
Definition: kerning.h:50
std::map< String, FontData * > FontDataContainer
Container type for storing fonts packed into this atlas.
Definition: textureatlas.h:75
void ParseTexture(XML::Node &AtlasTextureNode)
Parses the texture section of the Texture Atlas.
Real AsReal(Real def=0) const
Attempts to convert the value of the attribute to a Real and returns the results. ...
void _SetBaseLine(const Real BL)
Sets the height of the largest glyph in this font.
Definition: font.cpp:116
Vector2 AtlasCoords[4]
The 4 corner coordinates on the Texture.
Definition: glyph.h:111
void SetValues(const Real &x, const Real &y)
Sets the X and Y values of this vector2.
Definition: vector2.cpp:105
void Create3DMaterial()
Creates the material to be used by 3D interfaces with this Atlas.
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
Ogre::MaterialPtr _GetOrCreate3DMaterial()
Gets the 3D Material for this TextureAtlas, creating it also if neccessary.
Thrown when the identity string wasn't valid at all.
Definition: exception.h:93
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
Real GetWhitePixelX() const
Gets the X coordinate for the WhitePixel.
void _SetLineHeight(const Real LH)
Sets the height of a single line of text in this font.
Definition: font.cpp:113
FontDataContainer::iterator FontDataIterator
Iterator type for fonts stored in this class.
Definition: textureatlas.h:77
Sprite * GetSprite(const String &SpriteName) const
Gets a Sprite by name.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
void ParseSprites(XML::Node &AtlasSpritesNode)
Parses the sprites section of the Texture Atlas.
void ParseGlyphs(XML::Node &GlyphsNode, const Vector2 &Offset, FontData *GlyphD)
Parses the glyphs section of the Texture Atlas.
Ogre::Pass * _Get3DPass() const
Gets the 3D Material Pass for this TextureAtlas.
Vector2 GetWhitePixel() const
Gets the location of the WhitePixel on the TextureAtlas.
FontData * GetFont(const String &FontName) const
Gets the set of Glyphs of the specified name.
FontDataContainer & GetFonts()
Gets the full listing of all the FontData instances in this TextureAtlas.
void Create2DMaterial()
Creates the material to be used by 2D interfaces with this Atlas.
Ogre::Pass * _Get2DPass() const
Gets the 2D Material Pass for this TextureAtlas.
void ParseVerticalOffsets(XML::Node &VerticalOffsetsNode, FontData *FontD)
Parses the vertical offsets section of the Texture Atlas.
Vector2 ConvertToVector2(const String &ToConvert)
Convert two numbers in a string into a Vector2.
Definition: stringtool.cpp:281
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
Ogre::MaterialPtr _GetOrCreate2DMaterial()
Gets the 2D Material for this TextureAtlas, creating it also if neccessary.
void _AddGlyph(Glyph *NewGlyph)
Adds a new glyph to this Font. exception will be thrown if a glyph with the same ID is already taken...
Definition: font.cpp:125
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
UInt32 GlyphID
The Character this glyph information represents.
Definition: glyph.h:105
Glyph * GetGlyph(const UInt32 &GlyphID) const
Gets the glyph corresponding to the provided characters UTF-8 code.
Definition: font.cpp:100
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.