Spinning Topp Logo BlackTopp Studios
inc
editbox.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 _uieditbox_h
42 #define _uieditbox_h
43 
44 #include "UI/widget.h"
45 
46 namespace Mezzanine
47 {
48  namespace UI
49  {
50  class TextLayer;
51  class FontData;
52  ///////////////////////////////////////////////////////////////////////////////
53  /// @brief Widget for handling the input and manipulation of text.
54  /// @details This class does not use a LayoutStrategy.
55  /// @remarks The auto-created text layer used for editing will be given a ZOrder of 5 on all auto-created
56  /// RenderLayerGroups. When the layer is to be edited, the EditBox will attempt to get the layer at ZOrder
57  /// 5 in the active group. If there is no active group, or no layer at ZOrder 5 in the active group, or the
58  /// layer at ZOrder 5 isn't a text layer, then the edit will be blocked and not occur.
59  ///////////////////////////////////////
60  class MEZZ_LIB EditBox : public Widget
61  {
62  public:
63  /// @brief String containing the type name for this class: "EditBox".
64  static const String TypeName;
65  /// @brief Event name for when the text in this widget has been updated.
66  static const String EventTextUpdated;
67  /// @brief Callback type for input filtering.
68  typedef Boole (FilterCallback)(const Int32 Glyph);
69  protected:
70  /// @internal
71  /// @brief Stores the screen position where the mouse is located during editing. Used to find the end index for highlighting.
73  /// @internal
74  /// @brief A pointer to the method that will filter any input before adding it as text to this EditBox.
75  FilterCallback* InputFilter;
76  /// @internal
77  /// @brief Stores the index of the character initially highlighted while editing.
79  /// @internal
80  /// @brief Stores whether or not inputs into this widget will alter it's underlying text.
82 
83  /// @copydoc Widget::HandleInputImpl(const Input::MetaCode& Code)
84  virtual Boole HandleInputImpl(const Input::MetaCode& Code);
85  /// @internal
86  /// @brief Contains all the common necessary startup initializations for this class.
87  /// @param EditLayerType The type of text layer to be auto-created for editing.
88  /// @param EditFont A pointer to the font to be used by the edit layer.
89  virtual void ConstructEditBox(const RenderLayerType EditLayerType, FontData* EditFont);
90  /// @internal
91  /// @brief Convenience method that will check the configuration of this EditBox to determine if inputs will be consumed by this EditBox.
92  virtual void UpdateEditMode();
93  public:
94  /// @brief Blank constructor.
95  /// @param Parent The parent Screen that created this widget.
96  EditBox(Screen* Parent);
97  /// @brief Standard initialization constructor.
98  /// @param RendName The name to be given to this renderable.
99  /// @param EditLayerType The type of text layer to be auto-created for editing.
100  /// @param EditFont A pointer to the font to be used by the edit layer.
101  /// @param Parent The parent Screen that created this widget.
102  EditBox(const String& RendName, const RenderLayerType EditLayerType, FontData* EditFont, Screen* Parent);
103  /// @brief Standard initialization constructor.
104  /// @param RendName The name to be given to this renderable.
105  /// @param EditLayerType The type of text layer to be auto-created for editing.
106  /// @param EditFontName The name of the font to be used by the edit layer.
107  /// @param Parent The parent Screen that created this widget.
108  EditBox(const String& RendName, const RenderLayerType EditLayerType, const String& EditFontName, Screen* Parent);
109  /// @brief Rect constructor.
110  /// @param RendName The name to be given to this renderable.
111  /// @param RendRect The rect describing this widget's transform relative to it's parent.
112  /// @param EditLayerType The type of text layer to be auto-created for editing.
113  /// @param EditFont A pointer to the font to be used by the edit layer.
114  /// @param Parent The parent screen that created this renderable.
115  EditBox(const String& RendName, const UnifiedRect& RendRect, const RenderLayerType EditLayerType, FontData* EditFont, Screen* Parent);
116  /// @brief Rect constructor.
117  /// @param RendName The name to be given to this renderable.
118  /// @param RendRect The rect describing this widget's transform relative to it's parent.
119  /// @param EditLayerType The type of text layer to be auto-created for editing.
120  /// @param EditFontName The name of the font to be used by the edit layer.
121  /// @param Parent The parent screen that created this renderable.
122  EditBox(const String& RendName, const UnifiedRect& RendRect, const RenderLayerType EditLayerType, const String& EditFontName, Screen* Parent);
123  /// @brief XML constructor.
124  /// @param XMLNode The node of the xml document to construct from.
125  /// @param Parent The screen the created EditBox will belong to.
126  EditBox(const XML::Node& XMLNode, Screen* Parent);
127  /// @brief Class destructor.
128  virtual ~EditBox();
129  //public:
130  ///////////////////////////////////////////////////////////////////////////////
131  // Utility Methods
132 
133  /// @copydoc Widget::GetTypeName() const
134  virtual const String& GetTypeName() const;
135  /// @brief Checks to see if this EditBox is currently Editing.
136  /// @note Editing in the context means that Editing has been set to enabled, this EditBox currently has the focus,
137  /// and the cursor is enabled (which is handled automatically). If these criteria are met then this EditBox will consume
138  /// the appropriate inputs to display text.
139  /// @return Returns true if this EditBox is currently editing and ready for inputs, false otherwise.
140  virtual Boole IsCurrentlyEditing() const;
141 
142  /// @brief Sets the text in the edit layer of this EditBox.
143  /// @param Text A string containing the text the edit layer of this EditBox is to display.
144  virtual void SetText(const String& Text);
145  /// @brief Gets the text in the edit layer of this EditBox.
146  /// @return Returns a string containing the text in the text layer being edited by this EditBox.
147  virtual String GetText() const;
148 
149  ///////////////////////////////////////////////////////////////////////////////
150  // EditBox Properties
151 
152  /// @brief Sets wether or not this EditBox will consume inputs to generate text.
153  /// @param Enable True to consume inputs, false otherwise.
154  virtual void SetEditingEnabled(Boole Enable);
155  /// @brief Gets wether or not this EditBox will consume inputs to generate text.
156  /// @return Returns true if this EditBox is currently consuming inputs to generate text, false otherwise.
157  virtual Boole GetEditingEnabled() const;
158 
159  ///////////////////////////////////////////////////////////////////////////////
160  // EditBox Configuration
161 
162  /// @brief Sets the filter that will be used by this EditBox to determine if an input will be consumed.
163  /// @param Callback A pointer to the c-style method that will filter this EditBoxs inputs.
164  virtual void SetInputFilter(FilterCallback* Callback);
165  /// @brief Gets the filter that is being used by this EditBox to determine if an input will be consumed.
166  /// @return Returns a pointer to the currently set FilterCallback.
167  virtual FilterCallback* GetIntputFilter() const;
168 
169  /// @brief Gets the layer that consumed inputs will be inserted into.
170  /// @return Returns a pointer to the TextLayer that will be edited when this EditBox consumes inputs.
171  virtual TextLayer* GetEditLayer() const;
172 
173  ///////////////////////////////////////////////////////////////////////////////
174  // Serialization
175 
176  /// @copydoc Renderable::ProtoSerializeProperties(XML::Node&) const
177  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
178  /// @copydoc Renderable::ProtoDeSerializeProperties(const XML::Node&)
179  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
180 
181  /// @copydoc Renderable::GetSerializableName()
182  static String GetSerializableName();
183 
184  ///////////////////////////////////////////////////////////////////////////////
185  // Internal Event Methods
186 
187  /// @brief Self logic to be executed when this EditBox updates its text.
188  virtual void _OnTextUpdated();
189  /// @copydoc Widget::_OnMouseDragStart()
190  virtual void _OnMouseDragStart();
191  /// @copydoc Widget::_OnMouseDragEnd()
192  virtual void _OnMouseDragEnd();
193  /// @copydoc Widget::_OnFocusGained()
194  virtual void _OnFocusGained();
195  /// @copydoc Widget::_OnFocusLost()
196  virtual void _OnFocusLost();
197 
198  ///////////////////////////////////////////////////////////////////////////////
199  // Internal Methods
200 
201  };//EditBox
202 
203  ///////////////////////////////////////////////////////////////////////////////
204  /// @brief This is the factory implementation for EditBox widgets.
205  /// @details
206  ///////////////////////////////////////
208  {
209  public:
210  /// @brief Class constructor.
212  /// @brief Class destructor.
213  virtual ~EditBoxFactory() { }
214 
215  /// @copydoc WidgetFactory::GetWidgetTypeName() const
216  virtual String GetWidgetTypeName() const;
217 
218  /// @brief Creates a new EditBox.
219  /// @param RendName The name to be given to the created EditBox.
220  /// @param EditLayerType The type of text layer to be auto-created for editing.
221  /// @param EditFont A pointer to the font to be used by the edit layer.
222  /// @param Parent The screen the created EditBox will belong to.
223  /// @return Returns a pointer to the created EditBox.
224  virtual EditBox* CreateEditBox(const String& RendName, const RenderLayerType EditLayerType, FontData* EditFont, Screen* Parent);
225  /// @brief Creates a new EditBox.
226  /// @param RendName The name to be given to the created EditBox.
227  /// @param EditLayerType The type of text layer to be auto-created for editing.
228  /// @param EditFontName The name of the font to be used by the edit layer.
229  /// @param Parent The screen the created EditBox will belong to.
230  /// @return Returns a pointer to the created EditBox.
231  virtual EditBox* CreateEditBox(const String& RendName, const RenderLayerType EditLayerType, const String& EditFontName, Screen* Parent);
232  /// @brief Creates a new EditBox.
233  /// @param RendName The name to be given to the created EditBox.
234  /// @param RendRect The dimensions that will be assigned to the created EditBox.
235  /// @param EditLayerType The type of text layer to be auto-created for editing.
236  /// @param EditFont A pointer to the font to be used by the edit layer.
237  /// @param Parent The screen the created EditBox will belong to.
238  /// @return Returns a pointer to the created EditBox.
239  virtual EditBox* CreateEditBox(const String& RendName, const UnifiedRect& RendRect, const RenderLayerType EditLayerType, FontData* EditFont, Screen* Parent);
240  /// @brief Creates a new EditBox.
241  /// @param RendName The name to be given to the created EditBox.
242  /// @param RendRect The dimensions that will be assigned to the created EditBox.
243  /// @param EditLayerType The type of text layer to be auto-created for editing.
244  /// @param EditFontName The name of the font to be used by the edit layer.
245  /// @param Parent The screen the created EditBox will belong to.
246  /// @return Returns a pointer to the created EditBox.
247  virtual EditBox* CreateEditBox(const String& RendName, const UnifiedRect& RendRect, const RenderLayerType EditLayerType, const String& EditFontName, Screen* Parent);
248  /// @brief Creates a new EditBox.
249  /// @param XMLNode The node of the xml document to construct from.
250  /// @param Parent The screen the created EditBox will belong to.
251  /// @return Returns a pointer to the created EditBox.
252  virtual EditBox* CreateEditBox(const XML::Node& XMLNode, Screen* Parent);
253 
254  /// @copydoc WidgetFactory::CreateWidget(Screen*)
255  virtual Widget* CreateWidget(Screen* Parent);
256  /// @copydoc WidgetFactory::CreateWidget(const String&, const NameValuePairMap&, Screen*)
257  virtual Widget* CreateWidget(const String& RendName, const NameValuePairMap& Params, Screen* Parent);
258  /// @copydoc WidgetFactory::CreateWidget(const String&, const UnifiedRect&, const NameValuePairMap&, Screen*)
259  virtual Widget* CreateWidget(const String& RendName, const UnifiedRect& RendRect, const NameValuePairMap& Params, Screen* Parent);
260  /// @copydoc WidgetFactory::CreateWidget(const XML::Node&, Screen*)
261  virtual Widget* CreateWidget(const XML::Node& XMLNode, Screen* Parent);
262  /// @copydoc WidgetFactory::DestroyWidget(Widget*)
263  virtual void DestroyWidget(Widget* ToBeDestroyed);
264  };//EditBoxFactory
265  }//UI
266 }//Mezzanine
267 
268 #endif
int32_t Int32
An 32-bit integer.
Definition: datatypes.h:124
This class represents a collection of Glyphs in a common visual style.
Definition: font.h:55
Vector2 EditHighlightTarget
Stores the screen position where the mouse is located during editing. Used to find the end index for ...
Definition: editbox.h:72
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
EditBoxFactory()
Class constructor.
Definition: editbox.h:211
Class used to describe a single glyph or character available for text operations. ...
Definition: glyph.h:59
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
Integer EditHighlightOrigin
Stores the index of the character initially highlighted while editing.
Definition: editbox.h:78
This class represents a 2D rect which can express the size and position of a renderable on screen...
Definition: unifieddim.h:661
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
static const String TypeName
String containing the type name for this class: "EditBox".
Definition: editbox.h:64
This is the base class for all widgets.
Definition: widget.h:126
virtual ~EditBoxFactory()
Class destructor.
Definition: editbox.h:213
This Determines the kind of user input.
Definition: metacode.h:93
RenderLayerType
This enum describes the type of RenderLayer this is for use in casting.
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
FilterCallback * InputFilter
A pointer to the method that will filter any input before adding it as text to this EditBox...
Definition: editbox.h:75
static const String EventTextUpdated
Event name for when the text in this widget has been updated.
Definition: editbox.h:66
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
This is the factory implementation for EditBox widgets.
Definition: editbox.h:207
Boole EditingEnabled
Stores whether or not inputs into this widget will alter it's underlying text.
Definition: editbox.h:81
std::map< String, String > NameValuePairMap
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
Definition: datatypes.h:209
This class is a helper class for creating UI's. It is responsible for storing and keeping track of al...
Definition: screen.h:142
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
This is a base class for factories that construct the widgets available to the UI subsystem...
Definition: widgetfactory.h:61
Widget for handling the input and manipulation of text.
Definition: editbox.h:60