MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
listbox.h
1 // © Copyright 2010 - 2014 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 _uilistbox_h
41 #define _uilistbox_h
42 
43 #include "colourvalue.h"
44 #include "UI/uienumerations.h"
45 #include "UI/widget.h"
46 
47 namespace Mezzanine
48 {
49  namespace UI
50  {
51  class VerticalScrollbar;
52  class VerticalContainer;
53  ///////////////////////////////////////////////////////////////////////////////
54  /// @brief This is a struct for the storage of parameters to be set on created ListBox list items.
55  /// @details
56  ///////////////////////////////////////
58  {
59  //UI::LinearAlignment HorizontalAlign;
60  //UI::LinearAlignment VerticalAlign;
61  //UI::RenderPriority Priority;
62  //Whole CursorOffset;
63  //Real TextScale;
64  //Vector2 Size;
65  //ColourValue TextColour;
66  //ColourValue BackgroundColour;
67  };
68 
69  ///////////////////////////////////////////////////////////////////////////////
70  /// @brief This is a widget for displaying a list of captions in a box.
71  /// @details
72  ///////////////////////////////////////
73  class MEZZ_LIB ListBox : public Widget
74  {
75  public:
76  /// @brief Convenience typedef for objects that will be used to represent list items in this ListBox.
77  typedef Widget ListItem;
78  /// @brief String containing the type name for this class: "ListBox".
79  static const String TypeName;
80  protected:
81  friend class ListBoxFactory;
82  /// @internal
83  /// @brief A pointer to the vertical scrollbar responsible for the visible list items.
85  /// @internal
86  /// @brief A pointer to the vertical container storing all the list items.
88  /// @internal
89  /// @brief Stores whether or not the scrollbar of this listbox should hide when there is 1 page or less of list items.
90  Boolean AutoHideScroll;
91  //public:
92  /// @brief Blank constructor.
93  /// @param Parent The parent Screen that created this widget.
94  ListBox(Screen* Parent);
95  /// @brief Standard initialization constructor.
96  /// @param RendName The name to be given to this renderable.
97  /// @param Parent The parent Screen that created this widget.
98  ListBox(const String& RendName, Screen* Parent);
99  /// @brief Rect constructor.
100  /// @param RendName The name to be given to this renderable.
101  /// @param RendRect The rect describing this widget's transform relative to it's parent.
102  /// @param Parent The parent screen that created this renderable.
103  ListBox(const String& RendName, const UnifiedRect& RendRect, Screen* Parent);
104  /// @brief XML constructor.
105  /// @param XMLNode The node of the xml document to construct from.
106  /// @param Parent The screen the created ListBox will belong to.
107  ListBox(const XML::Node& XMLNode, Screen* Parent);
108  /// @brief Class destructor.
109  virtual ~ListBox();
110  public:
111  ///////////////////////////////////////////////////////////////////////////////
112  // Utility Methods
113 
114  ///////////////////////////////////////////////////////////////////////////////
115  // ListBox Properties
116 
117  ///////////////////////////////////////////////////////////////////////////////
118  // ListBox Configuration
119 
120  ///////////////////////////////////////////////////////////////////////////////
121  // Serialization
122 
123  /// @copydoc Renderable::ProtoSerializeProperties(XML::Node&) const
124  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
125  /// @copydoc Renderable::ProtoDeSerializeProperties(const XML::Node&)
126  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
127 
128  /// @copydoc Renderable::GetSerializableName()
129  static String GetSerializableName();
130 
131  ///////////////////////////////////////////////////////////////////////////////
132  // Internal Event Methods
133 
134  ///////////////////////////////////////////////////////////////////////////////
135  // Internal Methods
136 
137  };//ListBox
138 
139 
140 
141  /*struct TemplateParams
142  {
143  UI::LinearAlignment HorizontalAlign;
144  UI::LinearAlignment VerticalAlign;
145  UI::RenderPriority Priority;
146  Whole GlyphIndex;
147  Whole CursorOffset;
148  Real TextScale;
149  Vector2 Size;
150  ColourValue TextColour;
151  ColourValue BackgroundColour;
152  };
153 
154  class MEZZ_LIB ListBox : public Widget
155  {
156  public:
157  TemplateParams Params;
158  protected:
159  friend class RenderableFactory;
160  Rectangle* BoxBack;
161  Scrollbar* VertScroll;
162  Caption* Selected;
163  Caption* HoveredCaption;
164  std::vector<Caption*> Selections;
165  std::vector<Caption*> VisibleSelections;
166  bool AutoHideScroll;
167  Real LastScrollValue;
168  Whole MaxDisplay;
169  Whole SelectionsAdded;
170  UI::TemplateParams SelectionTemplate;
171  /// @brief Checks to make sure the Scroller is the appropriate size.
172  virtual void ScrollerSizeCheck();
173  /// @brief Checks to see if the scrollbar should be hidden or not.
174  virtual void ScrollHideCheck();
175  /// @brief Checks to see if the current size of the selection needs adjusting.
176  virtual void SelectionSizeCheck(UI::Caption* Selection);
177  //public:
178  /// @brief Standard initialization constructor.
179  /// @param name The name of the List Box.
180  /// @param RendRect The Rect representing the position and size of the List Box.
181  /// The size portion of this rect would be in reference to the size of a single selection.
182  /// The actual size of this widget will be a result of how many selections are currently being displayed.
183  /// @param ScrollStyle The style of the scrollbar you want for this List Box. See Scrollbar
184  /// class for more information.
185  /// @param PScreen The parent screen this List Box belongs to.
186  ListBox(ConstString& name, const Rect& RendRect, const UI::ScrollbarStyle& ScrollStyle, Screen* PScreen);
187  /// @brief Standard destructor.
188  virtual ~ListBox();
189  public:
190  /// @brief Sets the size to be applied to all created Selections.
191  /// @param Size The size of the caption to make. Applied to all captions created by this class.
192  /// @param Relative Whether or not the size provided is in relative units(rather then pixels).
193  /// @return Returns a reference to this List Box.
194  virtual ListBox& SetTemplateSize(const Vector2& Size, bool Relative = true);
195  /// @brief Sets the glyph index to be applied to all created Selections.
196  /// @details This needs to be called prior to the creation of any selections(captions).
197  /// This defaults to 0, which may not be a valid font index in your mta file. In which case it will throw an exception.
198  /// @param Glyph The Glyph index to use for the text generated by all captions in this widget.
199  /// @return Returns a reference to this List Box.
200  virtual ListBox& SetTemplateGlyphIndex(const Whole& Glyph);
201  /// @brief Sets the text colour to be applied to all created Selections.
202  /// @details Optional parameter.
203  /// @param TextColour The Colour of the text. This defaults to black.
204  /// @return Returns a reference to this List Box.
205  virtual ListBox& SetTemplateTextColour(const ColourValue& TextColour);
206  /// @brief Sets the text scale to be applied to all created Selections.
207  /// @details Optional parameter.
208  /// @param Scale The scale you wish to apply to the text in all created selections.
209  /// @return Returns a reference to this List Box.
210  virtual ListBox& SetTemplateTextScale(const Real& Scale);
211  /// @brief Set the cursor offset to be applied to all created Selections.
212  /// @details Optional parameter.
213  /// @param Offset The offset in pixels to adjust where text starts appearing in the caption.
214  /// @return Returns a reference to this List Box.
215  virtual ListBox& SetTemplateCursorOffset(const Whole& Offset);
216  /// @brief Sets the background colour to be applied to all created Selections.
217  /// @details Optional parameter.
218  /// @param BackgroundColour The colour to set for the captions background. This defaults to white.
219  /// @return Returns a reference to this List Box.
220  virtual ListBox& SetTemplateBackgroundColour(const ColourValue& BackgroundColour);
221  /// @brief Sets the horizontal alignment to be applied to all created Selections.
222  /// @details Optional parameter.
223  /// @param HorAlign The horizontal text alignment. This defaults to UI::Middle.
224  /// @return Returns a reference to this List Box.
225  virtual ListBox& SetTemplateHorizontalAlign(const UI::LinearAlignment& HorAlign);
226  /// @brief Sets the vertical alignment to be applied to all created Selections.
227  /// @details Optional parameter.
228  /// @param VertAlign The Vertical text alignment. This defaults to UI::Center.
229  /// @return Returns a reference to this List Box.
230  virtual ListBox& SetTemplateVerticalAlign(const UI::LinearAlignment& VertAlign);
231  /// @brief Sets the render priority to be applied to all created Selections.
232  /// @details Optional parameter.
233  /// @param Priority The priority with which to render the image. This defaults to UI::RP_Medium.
234  /// @return Returns a reference to this List Box.
235  virtual ListBox& SetTemplateRenderPriority(const UI::RenderPriority& Priority);
236  /// @brief Gets the struct containing all the current template parameters used when creating a new selections.
237  /// @return Returns a const reference to the structure containing all the template parameters.
238  virtual const UI::TemplateParams& GetTemplateInfo();
239  /// @brief Adds a selectable caption to the list to be displayed.
240  /// @details If a colour other then white was set as the template and you try to set a background sprite, it will
241  /// attempt to blend the colour and sprite. Pure white colour will cause the sprite to look normal.
242  /// @param name A name for the selection.
243  /// @param Text The text to be displayed within the created caption.
244  /// @param BackgroundSprite Optional, name of the sprite to set as it's background. Ignored if the string is empty.
245  virtual Caption* AddSelection(ConstString& name, ConstString &Text, ConstString& BackgroundSprite = "");
246  /// @brief Gets a caption by name.
247  /// @param Name The name of the selectable caption you want to get.
248  /// @return Returns a pointer to the named caption.
249  virtual Caption* GetSelection(ConstString &Name);
250  /// @brief Destroys a selectable caption.
251  /// @param ToBeDestroyed A pointer to the caption you want destroyed and removed from this list.
252  virtual void DestroySelection(Caption* ToBeDestroyed);
253  };//LineList//*/
254  }//UI
255 }//Mezzanine
256 
257 #endif