Sleeping Wombat GUI  0.100
swGUI
UIElement.h
Go to the documentation of this file.
1 #pragma once
2 
13 
14 // Include events arguments
19 
20 
21 
28 namespace sw {
29 namespace gui
30 {
31 
32 class UIElement;
33 DEFINE_OPTR_TYPE( UIElement );
34 
35 struct IEventArgs;
36 struct InputEventArgs;
37 struct MouseEventArgs;
38 struct MouseButtonEventArgs;
39 struct MouseWheelEventArgs;
40 struct KeyEventArgs;
41 
42 
43 
57 class UIElement : public Visual
58 {
61 
62  friend class UIElementTester;
63 private:
64 protected:
65 
67 
68  bool m_isVisible : 1;
69  bool m_isEnabled : 1;
70  bool m_isMouseOver : 1;
71  bool m_isFocused : 1;
72  bool m_isKeyboardFocus : 1;
74  bool m_isMouseCaptured : 1;
76  bool m_isFocusable : 1;
77 
80 
81 public:
82  explicit UIElement () = default;
83  virtual ~UIElement () = default;
84 
85 
88 
89  virtual Size2D Measure ( Size2D availableSize ) = 0;
91  virtual void Arrange ( Rect& finalRect ) = 0;
93 
94 
97 
98  virtual Size GetNumChildren () = 0;
99 
101  virtual UIElement* GetUIChild ( Size idx ) = 0;
102 
106  virtual bool AddChild ( UIElementOPtr&& child ) = 0;
107 
110  virtual void SetParent ( UIElement* parent );
111 
113  virtual UIElement* GetParent () { return m_parent; }
114 
116 
117 public:
118 
121  virtual void InvokeEventDelegates ( EventType eventID, UIElement* sender, IEventArgs* e, AccessKey );
122 
124 
125 
129  virtual void OnLoaded ( UIElement* sender, IEventArgs* e ) { }
130  virtual void OnUnloaded ( UIElement* sender, IEventArgs* e ) { }
131 
132  virtual void OnGotFocus ( UIElement* sender, IEventArgs* e ) { }
133  virtual void OnLostFocus ( UIElement* sender, IEventArgs* e ) { }
134 
135  // Mouse
136  virtual void OnMouseEnter ( UIElement* sender, MouseEventArgs* e ) { }
137  virtual void OnMouseLeave ( UIElement* sender, MouseEventArgs* e ) { }
138  virtual void OnMouseMove ( UIElement* sender, MouseMoveEventArgs* e ) { }
139  virtual void OnMouseWheel ( UIElement* sender, MouseWheelEventArgs* e ) { }
140 
141  virtual void OnMouseDown ( UIElement* sender, MouseButtonEventArgs* e ) { }
142  virtual void OnMouseUp ( UIElement* sender, MouseButtonEventArgs* e ) { }
143 
144  virtual void OnMouseRightButtonDown ( UIElement* sender, MouseButtonEventArgs* e ) { }
145  virtual void OnMouseRightButtonUp ( UIElement* sender, MouseButtonEventArgs* e ) { }
146 
147  virtual void OnMouseLeftButtonDown ( UIElement* sender, MouseButtonEventArgs* e ) { }
148  virtual void OnMouseLeftButtonUp ( UIElement* sender, MouseButtonEventArgs* e ) { }
149 
150 
151  virtual void OnPreviewMouseMove ( UIElement* sender, MouseMoveEventArgs* e ) { }
152  virtual void OnPreviewMouseWheel ( UIElement* sender, MouseWheelEventArgs* e ) { }
153 
154  virtual void OnPreviewMouseDown ( UIElement* sender, MouseButtonEventArgs* e ) { }
155  virtual void OnPreviewMouseUp ( UIElement* sender, MouseButtonEventArgs* e ) { }
156 
159 
162 
163  //Keyboard
164  virtual void OnKeyDown ( UIElement* sender, KeyEventArgs* e ) { }
165  virtual void OnKeyUp ( UIElement* sender, KeyEventArgs* e ) { }
166 
167  virtual void OnPreviewKeyDown ( UIElement* sender, KeyEventArgs* e ) { }
168  virtual void OnPreviewKeyUp ( UIElement* sender, KeyEventArgs* e ) { }
170 
171 
172 public:
173 
174  //
177 
182 
185 
188 
189  //
192 
197 
200 
203 
204  //
207 };
208 
209 
210 
211 } // gui
212 } // sw
213 
Base class for events.
Definition: IEventArgs.h:27
virtual void OnLostFocus(UIElement *sender, IEventArgs *e)
Definition: UIElement.h:133
virtual void OnMouseLeave(UIElement *sender, MouseEventArgs *e)
Definition: UIElement.h:137
bool m_isEnabled
Definition: UIElement.h:69
virtual void OnMouseRightButtonDown(UIElement *sender, MouseButtonEventArgs *e)
Definition: UIElement.h:144
virtual void OnMouseMove(UIElement *sender, MouseMoveEventArgs *e)
Definition: UIElement.h:138
virtual Size GetNumChildren()=0
Get number of children in visual tree.
bool m_isMouseCapturedWithin
Element or it's children have captured mouse.
Definition: UIElement.h:75
virtual UIElement * GetUIChild(Size idx)=0
Gets child in visual tree.
virtual void SetParent(UIElement *parent)
Set control parent. Internal use.
Definition: UIElement.cpp:64
EventHandlers m_eventHandlers
Managing delegates.
Definition: UIElement.h:79
virtual void OnPreviewMouseDown(UIElement *sender, MouseButtonEventArgs *e)
Definition: UIElement.h:154
Mouse button clicked event.
Definition: MouseButtonEventArgs.h:22
Definition: DirectInputModule.cpp:11
virtual UIElement * GetParent()
Returns control parent.
Definition: UIElement.h:113
Key state changed event.
Definition: KeyEventArgs.h:21
Interface for all controls in tree.
Definition: UIElement.h:57
Rectangle structure.
Definition: CommonTypes.h:32
uint32 EventType
Event type identifier.
Definition: RegisteredEvent.h:19
virtual void OnMouseRightButtonUp(UIElement *sender, MouseButtonEventArgs *e)
Definition: UIElement.h:145
virtual void OnPreviewMouseRightButtonDown(UIElement *sender, MouseButtonEventArgs *e)
Definition: UIElement.h:157
Base class for mouse input events.
Definition: MouseEventArgs.h:22
DirectX::XMFLOAT2 Size2D
Definition: CommonTypes.h:28
Class Restincts access to some functions only for chosen classes.
Definition: AccessKey.h:14
virtual ~UIElement()=default
virtual void OnPreviewKeyUp(UIElement *sender, KeyEventArgs *e)
Definition: UIElement.h:168
bool m_isFocused
This is logical focus.
Definition: UIElement.h:71
virtual void OnPreviewMouseLeftButtonUp(UIElement *sender, MouseButtonEventArgs *e)
Definition: UIElement.h:161
Mouse wheel changed position.
Definition: MouseWheelEventArgs.h:19
virtual void OnMouseDown(UIElement *sender, MouseButtonEventArgs *e)
Definition: UIElement.h:141
virtual void OnPreviewMouseMove(UIElement *sender, MouseMoveEventArgs *e)
Definition: UIElement.h:151
virtual Size2D Measure(Size2D availableSize)=0
Meassure pass. Check documentation in WPF.
size_t Size
Definition: TypesDefinitions.h:35
virtual void InvokeEventDelegates(EventType eventID, UIElement *sender, IEventArgs *e, AccessKey)
Definition: UIElement.cpp:71
bool m_isVisible
Definition: UIElement.h:68
bool m_isFocusable
Definition: UIElement.h:76
Size2D m_desiredSize
Desired size after Messure pass.
Definition: UIElement.h:78
RTTR_REGISTRATION_FRIEND
Definition: UIElement.h:60
virtual void OnMouseWheel(UIElement *sender, MouseWheelEventArgs *e)
Definition: UIElement.h:139
virtual void Arrange(Rect &finalRect)=0
Arragement pass. Check WPF documentation.
virtual void OnMouseLeftButtonUp(UIElement *sender, MouseButtonEventArgs *e)
Definition: UIElement.h:148
virtual void OnKeyDown(UIElement *sender, KeyEventArgs *e)
Definition: UIElement.h:164
friend class UIElementTester
Definition: UIElement.h:62
bool m_isMouseCaptured
Check if element have captured mouse.
Definition: UIElement.h:74
virtual bool AddChild(UIElementOPtr &&child)=0
Add child. This function should set child parent to this pointer.
virtual void OnKeyUp(UIElement *sender, KeyEventArgs *e)
Definition: UIElement.h:165
DEFINE_OPTR_TYPE(UIElement)
virtual void OnPreviewMouseWheel(UIElement *sender, MouseWheelEventArgs *e)
Definition: UIElement.h:152
virtual void OnPreviewMouseLeftButtonDown(UIElement *sender, MouseButtonEventArgs *e)
Definition: UIElement.h:160
virtual void OnLoaded(UIElement *sender, IEventArgs *e)
Definition: UIElement.h:129
virtual void OnPreviewMouseUp(UIElement *sender, MouseButtonEventArgs *e)
Definition: UIElement.h:155
bool m_isMouseOver
Definition: UIElement.h:70
Mouse moved event.
Definition: MouseMoveEventArgs.h:22
Container class for delegates.
Definition: EventHandlers.h:24
virtual void OnMouseLeftButtonDown(UIElement *sender, MouseButtonEventArgs *e)
Definition: UIElement.h:147
virtual void OnMouseEnter(UIElement *sender, MouseEventArgs *e)
Definition: UIElement.h:136
Provide interface for visual controls which can be rendered.
Definition: Visual.h:30
UIElement * m_parent
Parent in controls visual tree.
Definition: UIElement.h:66
bool m_isKeyboardFocusWithin
This element or it's children have keyboard focus.
Definition: UIElement.h:73
virtual void OnMouseUp(UIElement *sender, MouseButtonEventArgs *e)
Definition: UIElement.h:142
virtual void OnGotFocus(UIElement *sender, IEventArgs *e)
Definition: UIElement.h:132
REGISTER_EVENT_DECLARATION(PreviewMouseUp, RoutingStrategy::Tunnel, UIElement, MouseButtonEventArgs)
virtual void OnPreviewKeyDown(UIElement *sender, KeyEventArgs *e)
Definition: UIElement.h:167
bool m_isKeyboardFocus
This element has keyboard focus and will receive keyboard events.
Definition: UIElement.h:72
virtual void OnUnloaded(UIElement *sender, IEventArgs *e)
Definition: UIElement.h:130
virtual void OnPreviewMouseRightButtonUp(UIElement *sender, MouseButtonEventArgs *e)
Definition: UIElement.h:158