Spinning Topp Logo BlackTopp Studios
inc
textcursor.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 _uitextcursor_h
41 #define _uitextcursor_h
42 
43 #include "colourvalue.h"
44 #include "timer.h"
45 #include "UI/rect.h"
46 #include "UI/textlayer.h"
47 
48 namespace Mezzanine
49 {
50  namespace UI
51  {
52  class TextLayer;
53  class Glyph;
54  class Sprite;
55  ///////////////////////////////////////////////////////////////////////////////
56  /// @brief Class for encapsulating the functionality of the text cursor/carat navigation in text layers.
57  /// @details
58  ///////////////////////////////////////
59  class TextCursor
60  {
61  protected:
62  /// @internal
63  /// @brief The colour to be given to the TextCursor.
65  /*/// @internal
66  /// @brief The timer used for cursor flickering.
67  Timer FlickerTimer;// */
68  /// @internal
69  /// @brief The index of the character this TextCursor is to the left of.
71  /// @internal
72  /// @brief The layer this TextCursor belongs to.
74  /// @internal
75  /// @brief Stores the cursors current visibility state.
77  public:
78  /// @brief Class constructor.
79  /// @param Creator The layer that this TextCursor belongs to.
80  TextCursor(TextLayer* Creator);
81  /// @brief Class destructor.
82  virtual ~TextCursor();
83 
84  ///////////////////////////////////////////////////////////////////////////////
85  // Utility Methods
86 
87  /// @brief Sets the visibility of this cursor.
88  /// @param Visible True to enable rendering of this cursor, false otherwise.
89  virtual void SetVisible(Boole Visible);
90  /// @brief Gets the visibility of this cursor.
91  /// @return Returns true if this cursor is being rendered along with it's parent TextLayer, false otherwise.
92  virtual Boole GetVisible() const;
93 
94  /*/// @brief Sets whether or not this cursor will flicker while being rendered.
95  /// @note The flicker will occur in half second intervals.
96  /// @param Flicker True to enable cursor flickering, false otherwise.
97  virtual void SetFlicker(Boole Flicker);
98  /// @brief Gets whether or not this cursor will flicker while being rendered.
99  /// @return Returns true if this cursor is currently set to flicker every half second.
100  virtual Boole GetFlicker() const;// */
101 
102  /// @brief Sets the index position of this cursor.
103  /// @param Index The index indicating the position of this cursor among the characters in the parent layer.
104  virtual void SetCursorIndex(const Integer& Index);
105  /// @brief Gets the index position of this cursor.
106  /// @return Returns an Integer representing the index position of this cursor.
107  virtual Integer GetCursorIndex() const;
108 
109  /// @brief Sets the offset position of this cursor to the nearest appropriate point.
110  /// @param Offset The position from the top left corner of the parent layer where the bottom left corner of this cursor is to be placed.
111  virtual void SetOffsetPosition(const Vector2& Offset);
112  /// @brief Gets the current offset position of this cursor.
113  /// @return Returns a Vector2 containing the position of this cursor relative to the parent layer.
115  /// @brief Gets a rect representing this cursors dimentions.
116  /// @return Returns a Rect containing the position and size of this TextCursor.
117  virtual Rect GetCursorRect() const;
118 
119  /// @brief Sets the colour that the Text Cursor should be rendered as.
120  /// @param Colour The colour to use when rendering the Text Cursor.
121  virtual void SetColour(const ColourValue& Colour);
122  /// @brief Gets the colour that the Text Cursor will be rendered as.
123  /// @return Returns a const ColourValue reference of the Text Cursors colour.
124  virtual const ColourValue& GetColour() const;
125 
126  ///////////////////////////////////////////////////////////////////////////////
127  // Left and Right Methods
128 
129  /// @brief Decrements this cursors index position, moving it to the left.
130  virtual void MoveCursorLeft();
131  /// @brief Increments this cursors index position, moving it to the right.
132  virtual void MoveCursorRight();
133 
134  /// @brief Creates a character from a Glyph ID and inserts it at the cursor position.
135  /// @param GlyphID The ID of the Glyph to be inserted.
136  virtual void InsertCharacterAtCursor(const UInt32 GlyphID);
137  /// @brief Creates a series of characters from a UTF-8 encoded string to be inserted at the cursor position.
138  /// @param Characters An array of Char8's encoded in UTF-8 to be inserted.
139  /// @param BufSize The size of the array of Char8's passed in.
140  virtual void InsertCharactersAtCursor(const Char8* Characters, const UInt32 BufSize);
141  /// @brief Creates a series of characters from a UTF-32 encoded string to be inserted at the cursor position.
142  /// @param Characters An array of UInt32's encoded in UTF-32 to be inserted.
143  /// @param BufSize The size of the array of Char8's passed in.
144  virtual void InsertCharactersAtCursor(const UInt32* Characters, const UInt32 BufSize);
145  /// @brief Removes the character to the left (and decrements the index position) of this cursor.
146  virtual void RemoveLeftCharacter();
147  /// @brief Removes the character to the right of this cursor.
148  virtual void RemoveRightCharacter();
149 
150  ///////////////////////////////////////////////////////////////////////////////
151  // Serialization
152 
153  /// @brief Convert this class to an XML::Node ready for serialization.
154  /// @param ParentNode The point in the XML hierarchy that this renderable should be appended to.
155  virtual void ProtoSerialize(XML::Node& ParentNode) const;
156  /// @brief Take the data stored in an XML Node and overwrite this object with it.
157  /// @param SelfRoot An XML::Node containing the data to populate this class with.
158  virtual void ProtoDeSerialize(const XML::Node& SelfRoot);
159 
160  /// @brief Get the name of the the XML tag the Renderable class will leave behind as its instances are serialized.
161  /// @return A string containing the name of this class.
162  static String GetSerializableName();
163  };//TextCursor
164  }//UI
165 }//Mezzanine
166 
167 #endif
std::pair< Boole, Vector2 > CharOffsetPair
An std::pair type used as a return for index-offset conversions.
Definition: textlayer.h:88
Boole Visibility
Stores the cursors current visibility state.
Definition: textcursor.h:76
Integer IndexPosition
The index of the character this TextCursor is to the left of.
Definition: textcursor.h:70
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
virtual ~TextCursor()
Class destructor.
Definition: textcursor.cpp:61
virtual void InsertCharacterAtCursor(const UInt32 GlyphID)
Creates a character from a Glyph ID and inserts it at the cursor position.
Definition: textcursor.cpp:186
virtual void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
Definition: textcursor.cpp:237
virtual void MoveCursorLeft()
Decrements this cursors index position, moving it to the left.
Definition: textcursor.cpp:165
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
virtual void MoveCursorRight()
Increments this cursors index position, moving it to the right.
Definition: textcursor.cpp:177
This class represents a box shaped area on the screen.
Definition: rect.h:55
This is a simple class for holding 4 reals representing the colour any give object or lightsource can...
Definition: colourvalue.h:64
ColourValue CursorColour
The colour to be given to the TextCursor.
Definition: textcursor.h:64
TextCursor(TextLayer *Creator)
Class constructor.
Definition: textcursor.cpp:55
char Char8
A datatype to represent one character.
Definition: datatypes.h:169
virtual void SetColour(const ColourValue &Colour)
Sets the colour that the Text Cursor should be rendered as.
Definition: textcursor.cpp:149
virtual Rect GetCursorRect() const
Gets a rect representing this cursors dimentions.
Definition: textcursor.cpp:107
virtual void RemoveLeftCharacter()
Removes the character to the left (and decrements the index position) of this cursor.
Definition: textcursor.cpp:210
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
virtual Integer GetCursorIndex() const
Gets the index position of this cursor.
Definition: textcursor.cpp:91
Class for encapsulating the functionality of the text cursor/carat navigation in text layers...
Definition: textcursor.h:59
virtual Boole GetVisible() const
Gets the visibility of this cursor.
Definition: textcursor.cpp:70
virtual void SetOffsetPosition(const Vector2 &Offset)
Sets the offset position of this cursor to the nearest appropriate point.
Definition: textcursor.cpp:96
virtual void InsertCharactersAtCursor(const Char8 *Characters, const UInt32 BufSize)
Creates a series of characters from a UTF-8 encoded string to be inserted at the cursor position...
Definition: textcursor.cpp:194
virtual TextLayer::CharOffsetPair GetOffsetPosition() const
Gets the current offset position of this cursor.
Definition: textcursor.cpp:104
virtual void RemoveRightCharacter()
Removes the character to the right of this cursor.
Definition: textcursor.cpp:222
virtual void SetCursorIndex(const Integer &Index)
Sets the index position of this cursor.
Definition: textcursor.cpp:83
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
virtual void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
Definition: textcursor.cpp:254
static String GetSerializableName()
Get the name of the the XML tag the Renderable class will leave behind as its instances are serialize...
Definition: textcursor.cpp:279
TextLayer * Layer
The layer this TextCursor belongs to.
Definition: textcursor.h:73
virtual const ColourValue & GetColour() const
Gets the colour that the Text Cursor will be rendered as.
Definition: textcursor.cpp:157
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
virtual void SetVisible(Boole Visible)
Sets the visibility of this cursor.
Definition: textcursor.cpp:67
This is a base class for render layers that render text.
Definition: textlayer.h:64