Spinning Topp Logo BlackTopp Studios
inc
widget.cpp
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 _uiwidget_cpp
41 #define _uiwidget_cpp
42 
43 #include "UI/widget.h"
44 #include "UI/screen.h"
45 #include "UI/renderlayergroup.h"
46 #include "UI/layoutstrategy.h"
47 
48 namespace Mezzanine
49 {
50  namespace UI
51  {
52  ///////////////////////////////////////////////////////////////////////////////
53  // Widget Static Members
54 
55  const String Widget::TypeName = "GenericWidget";
56  const String Widget::EventMouseEnter = "MouseEnter";
57  const String Widget::EventMouseExit = "MouseExit";
58  const String Widget::EventMouseDragStart = "MouseDragStart";
59  const String Widget::EventMouseDragEnd = "MouseDragEnd";
60  const String Widget::EventFocusGained = "FocusGained";
61  const String Widget::EventFocusLost = "FocusLost";
62  const String Widget::EventFocusLocked = "FocusLocked";
63  const String Widget::EventFocusUnlocked = "FocusUnlocked";
64  const String Widget::EventVisibilityShown = "VisibilityShown";
65  const String Widget::EventVisibilityHidden = "VisibilityHidden";
66 
67  ///////////////////////////////////////////////////////////////////////////////
68  // Widget Methods
69 
71  QuadRenderable(Parent),
72  HoveredSubWidget(NULL),
73  State(WS_Untouched)
74  { /* Do nothing to leave it blank */ }
75 
76  Widget::Widget(const String& RendName, Screen* Parent) :
77  QuadRenderable(RendName,Parent),
78  HoveredSubWidget(NULL),
79  State(WS_Untouched)
80  { this->ConstructWidget(); }
81 
82  Widget::Widget(const String& RendName, const UnifiedRect& RendRect, Screen* Parent) :
83  QuadRenderable(RendName,RendRect,Parent),
84  HoveredSubWidget(NULL),
85  State(WS_Untouched)
86  { this->ConstructWidget(); }
87 
88  Widget::Widget(const XML::Node& XMLNode, Screen* Parent) :
89  QuadRenderable(Parent),
90  HoveredSubWidget(NULL),
91  State(WS_Untouched)
92  { this->ProtoDeSerialize(XMLNode); }
93 
95  { }
96 
97  void Widget::ProtoSerializeImpl(XML::Node& SelfRoot) const
98  {
99  this->QuadRenderable::ProtoSerializeImpl(SelfRoot);
100  this->ProtoSerializeStateGroupBindings(SelfRoot);
101  this->ProtoSerializeEvents(SelfRoot);
102  /// @todo Seriailze subscribed events? Scripts at least.
103  }
104 
106  {
107  this->QuadRenderable::ProtoDeSerializeImpl(SelfRoot);
108  this->ProtoDeSerializeStateGroupBindings(SelfRoot);
109  this->ProtoDeSerializeEvents(SelfRoot);
110  }
111 
113  {
114  return false;
115  }
116 
117  void Widget::HandleChildStateChangeImpl(Widget* Child, const UInt32& OldState, const UInt32& NewState)
118  {
119  // Default to nothing
120  }
121 
123  {
124  // Create our events.
125  this->AddEvent(Widget::EventMouseEnter);
126  this->AddEvent(Widget::EventMouseExit);
127  this->AddEvent(Widget::EventMouseDragStart);
128  this->AddEvent(Widget::EventMouseDragEnd);
129  this->AddEvent(Widget::EventFocusGained);
130  this->AddEvent(Widget::EventFocusLost);
131  this->AddEvent(Widget::EventFocusLocked);
132  this->AddEvent(Widget::EventFocusUnlocked);
133  this->AddEvent(Widget::EventVisibilityShown);
134  this->AddEvent(Widget::EventVisibilityHidden);
135 
136  // Create our render groups and bind them
137  RenderLayerGroup* NormalGroup = this->CreateRenderLayerGroup(Widget::WG_Normal);
138  RenderLayerGroup* HoveredGroup = this->CreateRenderLayerGroup(Widget::WG_Hovered);
139 
140  this->BindGroupToState( WS_Untouched, NormalGroup);
141  this->BindGroupToState( WS_Hovered, HoveredGroup);
142  this->BindGroupToState( WS_Focused, NormalGroup);
143  this->BindGroupToState( WS_Dragged, NormalGroup);
144  this->BindGroupToState( WS_Hovered | WS_Focused, HoveredGroup);
145  this->BindGroupToState( WS_Hovered | WS_Dragged, HoveredGroup);
146  this->BindGroupToState( WS_Focused | WS_Dragged, NormalGroup);
147  this->BindGroupToState( WS_Hovered | WS_Focused | WS_Dragged, HoveredGroup);
148  }
149 
150  ///////////////////////////////////////////////////////////////////////////////
151  // Utility Methods
152 
154  { return Renderable::RT_Widget; }
155 
157  { return Widget::TypeName; }
158 
160  { return (this->State & WS_Hovered); }
161 
163  { return (this->State & WS_Focused); }
164 
166  { return (this->State & WS_Dragged); }
167 
168  void Widget::ForceState(const UInt32 NewState)
169  {
170  if( this->State != NewState ) {
171  UInt32 OldState = this->State;
172  this->State = NewState;
173  this->SetGroupFromState(this->State);
174 
175  if( this->ParentQuad && this->ParentQuad->IsWidget() ) {
176  static_cast<UI::Widget*>(this->ParentQuad)->_NotifyChildStateChange(this,OldState,NewState);
177  }
178  }
179  }
180 
182  {
183  return this->State;
184  }
185 
186  ///////////////////////////////////////////////////////////////////////////////
187  // State-LayerGroup Binding Methods
188 
189  void Widget::BindGroupToState(const UInt32 BindState, RenderLayerGroup* ToBind)
190  {
191  this->StateGroupBindings[BindState] = ToBind;
192  }
193 
195  {
196  ConstStateLayerGroupIterator It = this->StateGroupBindings.find(BindState);
197  if( It != this->StateGroupBindings.end() ) return (*It).second;
198  else return NULL;
199  }
200 
202  {
203  StateLayerGroupIterator It = this->StateGroupBindings.find(BindState);
204  if( It != this->StateGroupBindings.end() )
205  {
206  this->SetActiveGroup( (*It).second );
207  return true;
208  }
209  else return false;
210  }
211 
212  ///////////////////////////////////////////////////////////////////////////////
213  // Fetch Methods
214 
216  {
217  return this->HoveredSubWidget;
218  }
219 
221  {
223  else return this;
224  }
225 
226  ///////////////////////////////////////////////////////////////////////////////
227  // Visibility and Priority Methods
228 
230  {
231  if( this->Visible != CanSee ) {
232  if(CanSee) {
233  this->_OnVisibilityShown();
234  }else{
235  this->_OnVisibilityHidden();
236  }
237 
238  for( ChildIterator It = this->ChildWidgets.begin() ; It != this->ChildWidgets.end() ; ++It )
239  { (*It)->SetVisible(CanSee); }
240  }
241  }
242 
244  {
245  return this->Visible;
246  }
247 
249  {
250  if( this->ParentQuad ) {
251  return this->Visible && this->ParentQuad->IsVisible();
252  }else{
253  return this->Visible;
254  }
255  }
256 
258  {
259  if( this->Visible == false ) {
260  this->_OnVisibilityShown();
261  for( ChildIterator It = this->ChildWidgets.begin() ; It != this->ChildWidgets.end() ; ++It )
262  { (*It)->Show(); }
263  }
264  }
265 
267  {
268  if( this->Visible == true ) {
269  this->_OnVisibilityHidden();
270  for( ChildIterator It = this->ChildWidgets.begin() ; It != this->ChildWidgets.end() ; ++It )
271  { (*It)->Hide(); }
272  }
273  }
274 
275  ///////////////////////////////////////////////////////////////////////////////
276  // Serialization
277 
279  {
281  XML::Node PropertiesNode = SelfRoot.AppendChild( Widget::GetSerializableName() + "Properties" );
282 
283  if( PropertiesNode.AppendAttribute("Version").SetValue("1") &&
284  PropertiesNode.AppendAttribute("State").SetValue( this->State ) )
285  {
286  return;
287  }else{
288  SerializeError("Create XML Attribute Values",Widget::GetSerializableName() + "Properties",true);
289  }
290  }
291 
293  {
294  XML::Node BindingsNode = SelfRoot.AppendChild( "StateGroupBindings" );
295 
296  if( BindingsNode.AppendAttribute("Version").SetValue("1") ) {
297  for( ConstStateLayerGroupIterator BindingIt = this->StateGroupBindings.begin() ; BindingIt != this->StateGroupBindings.end() ; ++BindingIt )
298  {
299  XML::Node BindingNode = BindingsNode.AppendChild( "StateGroupBinding" );
300 
301  if( BindingNode.AppendAttribute("Version").SetValue("1") &&
302  BindingNode.AppendAttribute("StateID").SetValue( (*BindingIt).first ) &&
303  BindingNode.AppendAttribute("LayerGroupID").SetValue( (*BindingIt).second->GetGroupID() ) )
304  {
305  continue;
306  }else{
307  SerializeError("Create XML Version Attribute","StateGroupBinding",true);
308  }
309  }
310  }else{
311  SerializeError("Create XML Version Attribute","StateGroupBindings",true);
312  }
313  }
314 
316  {
317  XML::Node EventsNode = SelfRoot.AppendChild( "Events" );
318 
319  if( EventsNode.AppendAttribute("Version").SetValue("1") ) {
320  for( ConstEventIterator EvIt = this->Events.begin() ; EvIt != this->Events.end() ; ++EvIt )
321  {
322  XML::Node BindingNode = EventsNode.AppendChild( "Event" );
323 
324  if( BindingNode.AppendAttribute("Version").SetValue("1") &&
325  BindingNode.AppendAttribute("Name").SetValue( (*EvIt).first ) )
326  {
327  continue;
328  }else{
329  SerializeError("Create XML Version Attribute","Event",true);
330  }
331  }
332  }else{
333  SerializeError("Create XML Version Attribute","Events",true);
334  }
335  }
336 
338  {
340 
341  XML::Attribute CurrAttrib;
342  XML::Node PropertiesNode = SelfRoot.GetChild( Widget::GetSerializableName() + "Properties" );
343 
344  if( !PropertiesNode.Empty() ) {
345  if(PropertiesNode.GetAttribute("Version").AsInt() == 1) {
346  CurrAttrib = PropertiesNode.GetAttribute("State");
347  if( !CurrAttrib.Empty() )
348  this->State = CurrAttrib.AsUint();
349  }else{
350  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + (Widget::GetSerializableName() + "Properties") + ": Not Version 1.");
351  }
352  }else{
353  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,Widget::GetSerializableName() + "Properties" + " was not found in the provided XML node, which was expected.");
354  }
355  }
356 
358  {
359  this->StateGroupBindings.clear();
360 
361  XML::Attribute CurrAttrib;
362  XML::Node BindingsNode = SelfRoot.GetChild( "StateGroupBindings" );
363 
364  if( !BindingsNode.Empty() ) {
365  if( BindingsNode.GetAttribute("Version").AsInt() == 1 ) {
366  for( XML::NodeIterator BindingNodeIt = BindingsNode.begin() ; BindingNodeIt != BindingsNode.end() ; ++BindingNodeIt )
367  {
368  if( (*BindingNodeIt).GetAttribute("Version").AsInt() == 1 ) {
369  UInt32 StateID = 0;
370 
371  CurrAttrib = (*BindingNodeIt).GetAttribute("StateID");
372  if( !CurrAttrib.Empty() )
373  StateID = CurrAttrib.AsUint();
374 
375  CurrAttrib = (*BindingNodeIt).GetAttribute("LayerGroupID");
376  if( !CurrAttrib.Empty() ) {
377  UInt16 LayerGroupID = CurrAttrib.AsUint();
378  RenderLayerGroup* NamedGroup = this->GetRenderLayerGroup( LayerGroupID );
379  if( NamedGroup != NULL ) {
380  this->StateGroupBindings.insert( std::pair<UInt32,RenderLayerGroup*>(StateID,NamedGroup) );
381  }else{
382  StringStream ExceptionStream;
383  ExceptionStream << "Named RenderLayerGroup \"" << LayerGroupID << "\" not found when deserializing Widget named \"" << this->GetName() << "\".";
385  }
386  }
387  }else{
388  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + String("StateGroupBindings") + ": Not Version 1.");
389  }
390  }
391  }else{
392  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + String("StateGroupBindings") + ": Not Version 1.");
393  }
394  }
395  }
396 
398  {
399  this->RemoveAllEvents();
400 
401  XML::Attribute CurrAttrib;
402  XML::Node EventsNode = SelfRoot.GetChild( "Events" );
403 
404  if( !EventsNode.Empty() ) {
405  if( EventsNode.GetAttribute("Version").AsInt() == 1 ) {
406  for( XML::NodeIterator EvNodeIt = EventsNode.begin() ; EvNodeIt != EventsNode.end() ; ++EvNodeIt )
407  {
408  if( (*EvNodeIt).GetAttribute("Version").AsInt() == 1 ) {
409  String EvName;
410 
411  CurrAttrib = (*EvNodeIt).GetAttribute("Name");
412  if( !CurrAttrib.Empty() )
413  EvName = CurrAttrib.AsString();
414 
415  if( !EvName.empty() ) {
416  this->AddEvent(EvName);
417  }
418  }else{
419  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + String("Events") + ": Not Version 1.");
420  }
421  }
422  }else{
423  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + String("Events") + ": Not Version 1.");
424  }
425  }
426  }
427 
429  {
430  return this->GetTypeName();
431  }
432 
434  {
435  return Widget::TypeName;
436  }
437 
438  ///////////////////////////////////////////////////////////////////////////////
439  // Internal Event Methods
440 
442  {
443  if( !this->IsHovered() ) {
444  UInt32 NewState = this->State | WS_Hovered;
445  this->ForceState(NewState);
446 
447  WidgetEventArgumentsPtr Args( new WidgetEventArguments(Widget::EventMouseEnter,this->Name) );
448  this->FireEvent(Args);
449  }
450  }
451 
453  {
454  if( this->IsHovered() ) {
455  UInt32 NewState = this->State & ~WS_Hovered;
456  this->ForceState(NewState);
457 
458  WidgetEventArgumentsPtr Args( new WidgetEventArguments(Widget::EventMouseExit,this->Name) );
459  this->FireEvent(Args);
460  }
461  }
462 
464  {
465  if( !this->IsDragged() ) {
466  UInt32 NewState = this->State | WS_Dragged;
467  this->ForceState(NewState);
468 
469  WidgetEventArgumentsPtr Args( new WidgetEventArguments(Widget::EventMouseDragStart,this->Name) );
470  this->FireEvent(Args);
471  }
472  }
473 
475  {
476  if( this->IsDragged() ) {
477  UInt32 NewState = this->State & ~WS_Dragged;
478  this->ForceState(NewState);
479 
480  WidgetEventArgumentsPtr Args( new WidgetEventArguments(Widget::EventMouseDragEnd,this->Name) );
481  this->FireEvent(Args);
482  }
483  }
484 
486  {
487  if( !this->HasFocus() ) {
488  UInt32 NewState = this->State | WS_Focused;
489  this->ForceState(NewState);
490 
491  WidgetEventArgumentsPtr Args( new WidgetEventArguments(Widget::EventFocusGained,this->Name) );
492  this->FireEvent(Args);
493  }
494  }
495 
497  {
498  if( this->HasFocus() ) {
499  UInt32 NewState = this->State & ~WS_Focused;
500  this->ForceState(NewState);
501 
502  WidgetEventArgumentsPtr Args( new WidgetEventArguments(Widget::EventFocusLost,this->Name) );
503  this->FireEvent(Args);
504  }
505  }
506 
508  {
509  WidgetEventArgumentsPtr Args( new WidgetEventArguments(Widget::EventFocusLocked,this->Name) );
510  this->FireEvent(Args);
511  }
512 
514  {
515  WidgetEventArgumentsPtr Args( new WidgetEventArguments(Widget::EventFocusUnlocked,this->Name) );
516  this->FireEvent(Args);
517  }
518 
520  {
521  this->Visible = true;
522  this->_MarkDirty();
523 
524  WidgetEventArgumentsPtr Args( new WidgetEventArguments(Widget::EventVisibilityShown,this->Name) );
525  this->FireEvent(Args);
526  }
527 
529  {
530  this->Visible = false;
531  this->_MarkDirty();
532 
533  WidgetEventArgumentsPtr Args( new WidgetEventArguments(Widget::EventVisibilityHidden,this->Name) );
534  this->FireEvent(Args);
535  }
536 
537  ///////////////////////////////////////////////////////////////////////////////
538  // Internal Methods
539 
541  {
542  if( this->HandleInputImpl(Code) ) {
543  return true;
544  }else{
545  if( this->ParentQuad && this->ParentQuad->IsWidget() )
546  return static_cast<Widget*>(this->ParentQuad)->_HandleInput(Code);
547  else return false;
548  }
549  }
550 
551  void Widget::_NotifyChildStateChange(Widget* Child, const UInt32& OldState, const UInt32& NewState)
552  {
553  this->HandleChildStateChangeImpl(Child,OldState,NewState);
554  if( this->ParentQuad && this->ParentQuad->IsWidget() )
555  static_cast<Widget*>(this->ParentQuad)->_NotifyChildStateChange(Child,OldState,NewState);
556  }
557 
559  {
560  // Default to doing nothing, must be overridden to add logic if a widget needs it
561  }
562 
563  ///////////////////////////////////////////////////////////////////////////////
564  // ButtonFactory Methods
565 
567  { return Widget::TypeName; }
568 
570  {
571  Widget* Ret = new Widget(RendName,Parent);
572  Ret->_SetLayoutStrat( new LayoutStrategy() );
573  return Ret;
574  }
575 
576  Widget* GenericWidgetFactory::CreateWidget(const String& RendName, const UnifiedRect& RendRect, Screen* Parent)
577  {
578  Widget* Ret = new Widget(RendName,RendRect,Parent);
579  Ret->_SetLayoutStrat( new LayoutStrategy() );
580  return Ret;
581  }
582 
584  {
585  Widget* Ret = new Widget(Parent);
586  Ret->_SetLayoutStrat( new LayoutStrategy() );
587  return Ret;
588  }
589 
590  Widget* GenericWidgetFactory::CreateWidget(const String& RendName, const NameValuePairMap& Params, Screen* Parent)
591  { return this->CreateWidget(RendName,Parent); }
592 
593  Widget* GenericWidgetFactory::CreateWidget(const String& RendName, const UnifiedRect& RendRect, const NameValuePairMap& Params, Screen* Parent)
594  { return this->CreateWidget(RendName,RendRect,Parent); }
595 
597  {
598  Widget* Ret = new Widget(XMLNode,Parent);
599  Ret->_SetLayoutStrat( new LayoutStrategy() );
600  return Ret;
601  }
602 
604  { delete ToBeDestroyed; }
605  }//UI
606 }//Mezzanine
607 
608 #endif
virtual Boole IsVisible() const
Gets whether or not this renderable is being drawn.
Definition: widget.cpp:248
static const String EventFocusUnlocked
Event name fow when the system removes the focus lock from this widget.
Definition: widget.h:190
Widget * GetBottomMostHoveredWidget()
Gets a pointer to the Widget at the bottom of the hovered SubWidget chain.
Definition: widget.cpp:220
static const String EventMouseDragEnd
Event name for when the mouse stops dragging this widget.
Definition: widget.h:182
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
const String & GetName() const
Gets the name of this renderable.
Definition: renderable.cpp:77
virtual void ProtoDeSerializeEvents(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the Events of this object with it.
Definition: widget.cpp:397
A light-weight handle for manipulating attributes in DOM tree.
Definition: attribute.h:74
static const String TypeName
String containing the type name for this class: "GenericWidget".
Definition: widget.h:174
virtual Widget * CreateWidget(const String &RendName, Screen *Parent)
Creates a new Widget.
Definition: widget.cpp:569
virtual void Show()
Forces this renderable to be shown.
Definition: widget.cpp:257
This is a base class for the algorithms used by QuadRenderables to determine how they should update t...
virtual void _OnFocusLost()
Self logic to be executed when focus is removed from this widget.
Definition: widget.cpp:496
virtual Boole _HandleInput(const Input::MetaCode &Code)
Handles input passed to this widget.
Definition: widget.cpp:540
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
StateLayerGroupMap::iterator StateLayerGroupIterator
Iterator type for RenderLayerGroup instances stored in relation to widget states. ...
Definition: widget.h:169
virtual String GetDerivedSerializableName() const
Gets the most derived serializable name of this Renderable.
Definition: widget.cpp:428
EventContainer Events
A container storing all the Events published by this class by name.
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
Widget * HoveredSubWidget
The child widget of this widget the mouse is over, if any.
Definition: widget.h:201
static const String EventFocusGained
Event name for when this widget gains focus.
Definition: widget.h:184
UInt32 State
UInt32 describing the current state of this widget.
Definition: widget.h:204
virtual void _OnVisibilityShown()
Self logic to be executed when this widget becomes visible.
Definition: widget.cpp:519
virtual const String & GetTypeName() const
Gets the type of widget this is.
Definition: widget.cpp:156
Thrown when the requested identity could not be found.
Definition: exception.h:94
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
A simple reference counting pointer.
Definition: countedptr.h:70
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
Definition: widget.cpp:278
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Definition: exception.h:112
virtual void ProtoSerializeEvents(XML::Node &SelfRoot) const
Convert the Events of this class to an XML::Node ready for serialization.
Definition: widget.cpp:315
virtual void BindGroupToState(const UInt32 BindState, RenderLayerGroup *ToBind)
Binds a RenderLayerGroup to a WidgetState.
Definition: widget.cpp:189
const Char8 * AsString(const Char8 *def="") const
Attempts to convert the value of the attribute to a String and returns the results.
virtual void ProtoDeSerializeImpl(const XML::Node &SelfRoot)
Implementation method for deseriailizing additional sets of data.
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
Boole Visible
Stores whether this Renderable is to be rendered (also dependent on parent visibility).
Definition: renderable.h:75
static String GetSerializableName()
Get the name of the the XML tag the Renderable class will leave behind as its instances are serialize...
Definition: widget.cpp:433
EventContainer::const_iterator ConstEventIterator
Const Iterator type for Event instances stored by this class.
virtual void DestroyWidget(Widget *ToBeDestroyed)
Destroys a Widget created by this factory.
Definition: widget.cpp:603
virtual Boole IsHovered() const
Gets the result of the last mouse hover check.
Definition: widget.cpp:159
RenderLayerGroup * CreateRenderLayerGroup(const UInt16 GroupID)
Creates a new RenderLayerGroup that can have. function will throw an exception if a group already exi...
void ConstructWidget()
Contains all the common necessary startup initializations for this class.
Definition: widget.cpp:122
virtual void ProtoSerializeImpl(XML::Node &SelfRoot) const
Implementation method for serializing additional sets of data.
bool Empty() const
Is this storing anything at all?
static const String EventMouseExit
Event name for when the mouse leaves this widget.
Definition: widget.h:178
std::stringstream StringStream
A Datatype used for streaming operations with strings.
Definition: datatypes.h:176
ChildContainer ChildWidgets
This is a container storing all the children that belong to this Quad.
virtual void ProtoSerializeStateGroupBindings(XML::Node &SelfRoot) const
Convert the state-group bindings of this class to an XML::Node ready for serialization.
Definition: widget.cpp:292
virtual void HandleChildStateChangeImpl(Widget *Child, const UInt32 &OldState, const UInt32 &NewState)
Handles the logic to execute when a child of this widget has it's state updated.
Definition: widget.cpp:117
virtual Boole SetGroupFromState(const UInt32 BindState)
Sets the group bound to the specified WidgetState as active.
Definition: widget.cpp:201
virtual RenderLayerGroup * GetGroupBoundToState(const UInt32 BindState) const
Gets the current RenderLayerGroup bound to a specified WidgetState.
Definition: widget.cpp:194
bool SetValue(const Char8 *rhs)
Set the value of this.
virtual String GetWidgetTypeName() const
Gets the name of the Widget that is created by this factory.
Definition: widget.cpp:566
void RemoveAllEvents()
Removes all events in this Publisher.
This class represents a 2D rect which can express the size and position of a renderable on screen...
Definition: unifieddim.h:661
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
static const String EventVisibilityShown
Event name for when this widget is switched from being hidden to being shown.
Definition: widget.h:192
static const String EventFocusLocked
Event name for when the system locks focus on this widget.
Definition: widget.h:188
StateLayerGroupMap::const_iterator ConstStateLayerGroupIterator
Const Iterator type for RenderLayerGroup instances stored in relation to widget states.
Definition: widget.h:171
Child node iterator (a bidirectional iterator over a collection of Node)
Definition: nodeiterator.h:77
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
iterator begin() const
Get a Child node iterator that references the first child Node.
unsigned int AsUint(unsigned int def=0) const
Attempts to convert the value of the attribute to an unsigned int and returns the results...
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
virtual ~Widget()
Standard destructor.
Definition: widget.cpp:94
iterator end() const
Get a Child node iterator that references one past the last child Node.
bool Empty() const
Is this storing anything at all?
virtual void _OnFocusGained()
Self logic to be executed when focus is given to this widget.
Definition: widget.cpp:485
This is the base class for all widgets.
Definition: widget.h:126
StateLayerGroupMap StateGroupBindings
Map containing all the RenderLayerGroups bound to specific widget states.
Definition: widget.h:198
Event * AddEvent(const String &EventName)
Creates a new event this Publisher can fire.
virtual RenderableType GetRenderableType() const
Gets the type of renderable this is.
Definition: widget.cpp:153
virtual void _NotifyEvent(EventArgumentsPtr Args)
Notifies this subscriber of an event being fired.
Definition: widget.cpp:558
virtual void ProtoDeSerializeImpl(const XML::Node &SelfRoot)
Implementation method for deseriailizing additional sets of data.
Definition: widget.cpp:105
String Name
The unique name of this Renderable.
Definition: renderable.h:81
void FireEvent(EventArgumentsPtr Args)
Fires an event.
static const String EventMouseEnter
Event name for when the mouse enters this widget.
Definition: widget.h:176
virtual void _OnMouseEnter()
Self logic to be executed when the mouse cursor enters the bounds of this widget. ...
Definition: widget.cpp:441
Thrown when parameters are checked at runtime and found invalid.
Definition: exception.h:108
virtual void _SetLayoutStrat(LayoutStrategy *ToSet)
Sets a new LayoutStrategy for this quad to use.
This Determines the kind of user input.
Definition: metacode.h:93
This class stores a group of render layers that can be set to be rendered.
static const String EventMouseDragStart
Event name for when the mouse starts dragging this widget.
Definition: widget.h:180
virtual void Hide()
Forces this renderable to hide.
Definition: widget.cpp:266
static const String EventVisibilityHidden
Event name for when this widget is switched from being shown to being hidden.
Definition: widget.h:194
virtual Boole HandleInputImpl(const Input::MetaCode &Code)
Consumes input for this widget's use.
Definition: widget.cpp:112
Widget(Screen *Parent)
Blank constructor.
Definition: widget.cpp:70
virtual void _OnFocusLocked()
Self logic to be executed when focus is locked to this widget.
Definition: widget.cpp:507
static const String EventFocusLost
Event name for when this widget loses focus.
Definition: widget.h:186
virtual void ProtoSerializeImpl(XML::Node &SelfRoot) const
Implementation method for serializing additional sets of data.
Definition: widget.cpp:97
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
ChildContainer::iterator ChildIterator
Iterator type for Widget instances stored by this class.
virtual void SetVisible(Boole CanSee)
Sets the visibility of this renderable.
Definition: widget.cpp:229
virtual void ProtoDeSerializeStateGroupBindings(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the state-group bindings of this object with it...
Definition: widget.cpp:357
virtual void ForceState(const UInt32 NewState)
Forces a new state of this Widget.
Definition: widget.cpp:168
virtual void _NotifyChildStateChange(Widget *Child, const UInt32 &OldState, const UInt32 &NewState)
Notifies this widget that a child (or grandchild) has had it's state updated.
Definition: widget.cpp:551
Boole IsWidget() const
Gets whether or not this renderable is a Widget.
Definition: renderable.cpp:83
virtual void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
virtual Boole GetVisible() const
Gets the visibility setting of this renderable.
Definition: widget.cpp:243
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
Definition: widget.cpp:337
virtual Boole HasFocus() const
Gets whether or not this widget currently has focus.
Definition: widget.cpp:162
virtual Boole IsDragged() const
Gets whether or not the system mouse is being dragged over this widget.
Definition: widget.cpp:165
virtual void _OnMouseDragStart()
Self logic to be executed when the mouse cursor starts dragging across the bounds of this widget...
Definition: widget.cpp:463
This represents a nestable quad for an object in a GUI layout.
Widget * GetHoveredSubWidget() const
Gets the hovered sub-widget within this widget, if any.
Definition: widget.cpp:215
virtual void _MarkDirty()
Marks this renderable as dirty, and informs other renderables if needed.
virtual void _OnFocusUnlocked()
Self logic to be executed when focus is no longer locked to this widget.
Definition: widget.cpp:513
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
RenderLayerGroup * GetRenderLayerGroup(const UInt16 GroupID) const
Gets a RenderLayerGroup by ID.
virtual void _OnMouseExit()
Self logic to be executed when the mouse cursor leaves the bounds of thiw widget. ...
Definition: widget.cpp:452
virtual void _OnVisibilityHidden()
Self logic to be executed when this widget becomes invisible.
Definition: widget.cpp:528
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
virtual Boole IsVisible() const =0
Gets whether or not this renderable is being drawn.
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
virtual void _OnMouseDragEnd()
Self logic to be executed when the mouse cursor stops dragging across the bounds of this widget...
Definition: widget.cpp:474
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
RenderableType
A small enum to describe the type of renderable this is.
Definition: renderable.h:62
QuadRenderable * ParentQuad
This is a pointer to the Quad that owns this Quad and is responsible for transform updates applied to...
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.
virtual UInt32 GetState() const
Gets the current state of this Widget.
Definition: widget.cpp:181
This is the base class for widget specific event arguments.
Definition: widget.h:60
void SetActiveGroup(const UInt16 GroupID)
Sets the RenderLayerGroup that will be used to render this renderable.