Spinning Topp Logo BlackTopp Studios
inc
character.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 
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.
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 String containing the name of this characters atlas, or an empty string if this isn't properly initialized.
137  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(Boole Highlight);
162  /// @brief Gets if this character is being highlighted.
163  /// @return Returns true if this character is being highlighted, false otherwise.
164  Boole 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  Boole 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  Boole 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  Boole IsRenderable() const;
183  /// @brief Gets if this character can be highlighted.
184  /// @return Returns true if this character can be highlighted, false otherwise.
185  Boole 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  Boole 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  Boole 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 from it's parent TextLine.
201  /// @return Returns a Real representing the number of pixels to offset this from it's parents left edge.
202  Real GetLengthOffset() const;
203  /// @brief Gets the length offset of this Characters right side from its parent TextLine.
204  /// @return Returns a Real representing the pixel distance from this characters right side from the parent TextLines left edge.
205  Real GetRightEdgeLengthOffset() const;
206  /// @brief Sets the custom size this character is to be resized to.
207  /// @remarks The size set here is still subject to scaling from it's parent, and thus is not final. @n @n
208  /// The default for this value is (-1,-1), and this can be set at any time to revert to using the characters default size.
209  /// @param Size The custom size to apply to this character in pixels.
210  void SetCustomSize(const Vector2& Size);
211  /// @brief Whether or not the custom size has been set.
212  /// @return Returns true if a custom size has been provided for this character, false if it is using it's default size.
213  Boole IsCustomSizeSet() const;
214  /// @brief Gets the rendered size of this character.
215  /// @return Returns a Vector2 containing the size this character is to be rendered at after scaling.
216  Vector2 GetCharacterSize() const;
217  /// @brief Gets the rendered size of this character without any scaling applied.
218  /// @return Returns a Vector2 containing the size this character is to be rendered at before scaling.
219  Vector2 GetUnscaledCharacterSize() const;
220 
221  ///////////////////////////////////////////////////////////////////////////////
222  // Fetch Methods
223 
224  /// @brief Gets the glyph being rendered by this character.
225  /// @return Returns a pointer to the glyph this character is representing, or NULL if this character is a Sprite.
226  Glyph* GetCharGlyph() const;
227  /// @brief Gets the sprite being rendered by this character.
228  /// @return Returns a pointer to the sprite this character is representing, or NULL if this character is a Glyph.
229  Sprite* GetCharSprite() const;
230  };//Character
231  }//UI
232 }//Mezzanine
233 
234 #endif
Boole Highlighted
Stores whether or not this character is being highlighted.
Definition: character.h:82
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Real LengthOffset
The X-axis offset from the left side where this character is being rendered relative to the TextLine ...
Definition: character.h:79
Class used to describe a single glyph or character available for text operations. ...
Definition: glyph.h:59
QuadCorner
Used by Sprites and Glyphs for tracking their placement on a TextureAtlas.
This is a collection of smaller textures packed into a larger texture, intended to increase UI perfor...
Definition: textureatlas.h:71
Glyph * CharGlyph
A pointer to the Glyph this character is being rendered as, or NULL if it is a Sprite.
Definition: character.h:73
This is a simple class for holding 4 reals representing the colour any give object or lightsource can...
Definition: colourvalue.h:64
This class stores common data for determining the look of a Character.
Sprite * CharSprite
A pointer to the Sprite this character is being rendered as, or NULL if it is a Glyph.
Definition: character.h:76
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
This class creates and encapsultes a character that can be used in text renders.
Definition: character.h:59
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
Vector2 CustomSize
The forced size of this character, if it is set.
Definition: character.h:67
TextLayer * Layer
A pointer to the layer this character is being rendered by.
Definition: character.h:70
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
CharacterTraits CharTraits
The rendering traits of this character.
Definition: character.h:64
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
This is a base class for render layers that render text.
Definition: textlayer.h:64