MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
character.h
1 //© Copyright 2010 - 2012 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 
41 #ifndef _uicharacter_h
42 #define _uicharacter_h
43 
44 #include "UI/glyph.h"
45 #include "UI/sprite.h"
46 #include "UI/charactertraits.h"
47 #include "UI/uienumerations.h"
48 
49 namespace Mezzanine
50 {
51  namespace UI
52  {
53  class TextLayer;
54  class TextureAtlas;
55  ///////////////////////////////////////////////////////////////////////////////
56  /// @brief This class creates and encapsultes a character that can be used in text renders.
57  /// @details
58  ///////////////////////////////////////
60  {
61  protected:
62  /// @internal
63  /// @brief The rendering traits of this character.
65  /// @internal
66  /// @brief The forced size of this character, if it is set.
68  /// @internal
69  /// @brief A pointer to the layer this character is being rendered by.
71  /// @internal
72  /// @brief A pointer to the Glyph this character is being rendered as, or NULL if it is a Sprite.
74  /// @internal
75  /// @brief A pointer to the Sprite this character is being rendered as, or NULL if it is a Glyph.
77  /// @internal
78  /// @brief The X-axis offset from the left side where this character is being rendered relative to the TextLine position.
80  /// @internal
81  /// @brief Stores whether or not this character is being highlighted.
82  Boolean Highlighted;
83  public:
84  /// @brief GlyphID Constructor.
85  /// @param GlyphID The ID of the glyph to be used when creating this character.
86  /// @param Traits The sharable metadata to be given to this Character.
87  /// @param Creator The TextLayer that created this Character.
88  Character(const UInt32& GlyphID, const CharacterTraits& Traits, TextLayer* Creator);
89  /// @brief Glyph Constructor.
90  /// @param CharacterGlyph The glyph used when rendering this Character.
91  /// @param Creator The TextLayer that created this Character.
92  Character(Glyph* CharacterGlyph, TextLayer* Creator);
93  /// @brief Styled Glyph Constructor.
94  /// @param CharacterGlyph The glyph used when rendering this Character.
95  /// @param Traits The sharable metadata to be given to this Character.
96  /// @param Creator The TextLayer that created this Character.
97  Character(Glyph* CharacterGlyph, const CharacterTraits& Traits, TextLayer* Creator);
98  /// @brief Sprite Constructor.
99  /// @param CharacterSprite The sprite used when rendering this character.
100  /// @param Creator The TextLayer that created this Character.
101  Character(Sprite* CharacterSprite, TextLayer* Creator);
102  /// @brief Styled Sprite Constructor.
103  /// @param CharacterSprite The sprite used when rendering this character.
104  /// @param Traits The sharable metadata to be given to this Character.
105  /// @param Creator The TextLayer that created this Character.
106  Character(Sprite* CharacterSprite, const CharacterTraits& Traits, TextLayer* Creator);
107 
108  ///////////////////////////////////////////////////////////////////////////////
109  // Utility
110 
111  /// @brief Gets the amount of pixels to advance the cursor after placing this character.
112  /// @param Prev The glyph prior to this one in the parent TextLine. Needed for kerning information.
113  /// @return Returns a Real representing the number of pixels to advance.
114  Real GetCharacterAdvance(Glyph* Prev) const;
115  /// @brief Gets the amount of pixels to advance the cursor after placing this character without scaling applied.
116  /// @param Prev The glyph prior to this one in the parent TextLine. Needed for kerning information.
117  /// @return Returns a Real representing the number of pixels to advance.
118  Real GetUnscaledCharacterAdvance(Glyph* Prev) const;
119  /// @brief Gets the height a line needs to be to support rendering this character.
120  /// @return Returns a Real representing how tall a TextLine needs to be to support this character in pixels.
121  Real GetLineHeight() const;
122  /// @brief Gets the height a line needs to be to support rendering this character without scaling applied.
123  /// @return Returns a Real representing how tall a TextLine needs to be to support this character in pixels before scaling.
124  Real GetUnscaledLineHeight() const;
125  /// @brief Gets the vertical adjustment for this character.
126  /// @return Returns a Real representing the position adjustment on the Y axis in pixels.
127  Real GetVerticalOffset() const;
128  /// @brief Gets the vertical adjustment for this character without scaling applied.
129  /// @return Returns a Real representing the position adjustment on the Y axis in pixels before scaling.
130  Real GetUnscaledVerticalOffset() const;
131 
132  /// @brief Gets the atlas this character is using for rendering.
133  /// @return Returns a pointer to this characters atlas.
134  TextureAtlas* GetAtlas() const;
135  /// @brief Gets the name of the atlas this character is using for rendering.
136  /// @return Returns a const String reference containing the name of this characters atlas.
137  const String& GetAtlasName() const;
138  /// @brief Gets the coordinates to the white pixel on the atlas this character belongs to.
139  /// @return Returns a Vector2 containing the relative coordinates of the atlas whitepixel.
140  Vector2 GetAtlasWhitePixel() const;
141  /// @brief Gets the atlas coordinates of a quad corner.
142  /// @param Corner The corner to get the atlas coordinates for.
143  /// @return Returns a Vector2 containing the Atlas pixel position of the requested corner.
144  Vector2 GetAtlasCoords(const UI::QuadCorner Corner) const;
145  /// @brief Gets the relative atlas coordinates of a quad corner.
146  /// @param Corner The corner to retrieve the coordinates for.
147  /// @return Returns a Vector2 containing the Atlas relative(0 to 1) position of the requested corner.
148  Vector2 GetRelativeAtlasCoords(const UI::QuadCorner Corner) const;
149 
150  /// @brief Sets the fill colour for this character.
151  /// @note With most text/glyphs this will simply set the colour of the letters. In the case of
152  /// sprites or special coloured text this will blend with the rendered colour giving a third result.
153  /// @param Colour The colour to render this character with.
154  void SetCharacterColour(const ColourValue& Colour);
155  /// @brief Gets the fill colour of this character.
156  /// @return Returns a const colourvalue reference containing the fill colour of this character.
157  const ColourValue& GetCharacterColour() const;
158 
159  /// @brief Sets whether or not this character should be highlighted.
160  /// @param Highlight True to highlight this character, false to remove a highlight on it.
161  void SetHighlighted(Boolean Highlight);
162  /// @brief Gets if this character is being highlighted.
163  /// @return Returns true if this character is being highlighted, false otherwise.
164  Boolean GetHighlighted() const;
165 
166  /// @brief Sets this Characters sharable traits.
167  /// @param Traits The traits to be given to this Character.
168  void SetTraits(const CharacterTraits& Traits);
169  /// @brief Gets this Characters sharable traits.
170  /// @return Returns a const reference to the sharable traits belonging to this Character.
171  const CharacterTraits& GetTraits() const;
172 
173  /// @brief Gets whether or not this character is a glyph.
174  /// @return Returns true if this character is a glyph, false otherwise.
175  Boolean IsGlyph() const;
176  /// @brief Gets whether or not this character is a sprite.
177  /// @return Returns true if this character is a sprite, false otherwise.
178  Boolean IsSprite() const;
179 
180  /// @brief Gets if this character contains valid data for rendering.
181  /// @return Returns true if this character can be rendered, false otherwise.
182  Boolean IsRenderable() const;
183  /// @brief Gets if this character can be highlighted.
184  /// @return Returns true if this character can be highlighted, false otherwise.
185  Boolean IsHighlightable() const;
186  /// @brief Gets if this character is a whitespace glyph.
187  /// @return Returns true if this character is a whitespace, false otherwise.
188  Boolean IsWhiteSpace() const;
189  /// @brief Gets if this character is a line break character.
190  /// @return Returns true if this character indicates a new line, false otherwise.
191  Boolean IsNewLine() const;
192 
193  ///////////////////////////////////////////////////////////////////////////////
194  // Transform Related Methods
195 
196  /// @brief Sets the offset from the position of the parent TextLine.
197  /// @warning Adjusting this value manually can create visual artifacts. Only call this manually if you know what you are doing.
198  /// @param Offset The placement offset from the parent's origin in pixels.
199  void SetLengthOffset(const Real& Offset);
200  /// @brief Gets the length offset of this Character.
201  /// @return Returns a real representing the number of pixels to offset this from it's parent.
202  Real GetLengthOffset() const;
203  /// @brief Sets the custom size this character is to be resized to.
204  /// @remarks The size set here is still subject to scaling from it's parent, and thus is not final. @n @n
205  /// The default for this value is (-1,-1), and this can be set at any time to revert to using the characters default size.
206  /// @param Size The custom size to apply to this character in pixels.
207  void SetCustomSize(const Vector2& Size);
208  /// @brief Whether or not the custom size has been set.
209  /// @return Returns true if a custom size has been provided for this character, false if it is using it's default size.
210  Boolean IsCustomSizeSet() const;
211  /// @brief Gets the rendered size of this character.
212  /// @return Returns a Vector2 containing the size this character is to be rendered at after scaling.
213  Vector2 GetCharacterSize() const;
214  /// @brief Gets the rendered size of this character without any scaling applied.
215  /// @return Returns a Vector2 containing the size this character is to be rendered at before scaling.
216  Vector2 GetUnscaledCharacterSize() const;
217 
218  ///////////////////////////////////////////////////////////////////////////////
219  // Fetch Methods
220 
221  /// @brief Gets the glyph being rendered by this character.
222  /// @return Returns a pointer to the glyph this character is representing, or NULL if this character is a Sprite.
223  Glyph* GetCharGlyph() const;
224  /// @brief Gets the sprite being rendered by this character.
225  /// @return Returns a pointer to the sprite this character is representing, or NULL if this character is a Glyph.
226  Sprite* GetCharSprite() const;
227  };//Character
228  }//UI
229 }//Mezzanine
230 
231 #endif