Sleeping Wombat GUI  0.100
swGUI
EventsSystem.h
Go to the documentation of this file.
1 #pragma once
2 
11 
12 #include "EventProxy.h"
13 #include "EventHandlers.h"
14 #include "IEventArgs.h"
15 #include "RegisteredEvent.h"
16 
17 
18 #include <mutex>
19 #include <set>
20 #include <string>
21 
22 
34 namespace sw {
35 namespace gui
36 {
37 
38 class UIElement;
39 
40 
41 template< typename ArgumentType >
42 using EventHandlerPointer = void ( UIElement::* )( UIElement*, ArgumentType* );
43 
44 
55 {
56 private:
57 
59 
60  std::mutex m_registerMutex;
61  std::set< RegisteredEvent > m_registeredEvents;
62 
63 protected:
64 public:
65  ~EventsSystem () = default;
66 
68  const RegisteredEvent* RegisterEvent ( const char* eventName, RoutingStrategy strategy, TypeID ownerType, TypeID eventTypeId );
69 
71  bool RaiseEvent ( const RegisteredEvent* eventInfo, UIElement* sender, IEventArgsOPtr&& arguments );
72 
80  bool RaiseForwardEvent ( const RegisteredEvent* eventInfo, UIElement* sender, IEventArgs* arguments );
81 
82  template< typename ArgumentType >
83  bool RaiseEvent ( const RegisteredEvent* eventInfo, UIElement* sender, ArgumentType* arguments, EventHandlerPointer< ArgumentType > handler );
84 
85 
86 private:
87 
88  template< typename ArgumentType >
89  bool RaiseDirectEvent ( const RegisteredEvent* eventInfo, UIElement* sender, ArgumentType* arguments, EventHandlerPointer< ArgumentType > handler );
90 
91  template< typename ArgumentType >
92  bool RaiseBubbleEvent ( const RegisteredEvent* eventInfo, UIElement* sender, ArgumentType* arguments, EventHandlerPointer< ArgumentType > handler );
93 
94  template< typename ArgumentType >
95  bool RaiseTunnelEvent ( const RegisteredEvent* eventInfo, UIElement* sender, ArgumentType* arguments, EventHandlerPointer< ArgumentType > handler );
96 
98  template< typename ArgumentType >
99  void RaiseTunnelEventForParents ( const RegisteredEvent* eventInfo, UIElement* sender, ArgumentType* arguments, UIElement* raiseForElement, EventHandlerPointer< ArgumentType > handler );
100 
101  template< typename ArgumentType >
102  bool RaiseEventImpl ( const RegisteredEvent* eventInfo, UIElement* sender, ArgumentType* arguments, EventHandlerPointer< ArgumentType > handler );
103 
104 public:
105  static EventsSystem& Get ();
106 
107 private:
108  explicit EventsSystem ();
109 };
110 
111 
112 
113 
114 
115 } // gui
116 } // sw
const RegisteredEvent * RegisterEvent(const char *eventName, RoutingStrategy strategy, TypeID ownerType, TypeID eventTypeId)
Registers new event and return idetifier used in DelegateContainers.
Definition: EventsSystem.cpp:50
Base class for events.
Definition: IEventArgs.h:27
Events management.
Definition: EventsSystem.h:54
RoutingStrategy
Describes how event behaves in visual tree.
Definition: RegisteredEvent.h:24
void RaiseTunnelEventForParents(const RegisteredEvent *eventInfo, UIElement *sender, ArgumentType *arguments, UIElement *raiseForElement, EventHandlerPointer< ArgumentType > handler)
Calls recursivly event for parents.
Definition: EventsSystem.inl:67
Definition: DirectInputModule.cpp:11
bool RaiseTunnelEvent(const RegisteredEvent *eventInfo, UIElement *sender, ArgumentType *arguments, EventHandlerPointer< ArgumentType > handler)
Definition: EventsSystem.inl:58
bool RaiseEvent(const RegisteredEvent *eventInfo, UIElement *sender, IEventArgsOPtr &&arguments)
Sends event to visual tree using RoutingStrategy specyfied in eventInfo.
Definition: EventsSystem.cpp:69
Interface for all controls in tree.
Definition: UIElement.h:57
bool RaiseForwardEvent(const RegisteredEvent *eventInfo, UIElement *sender, IEventArgs *arguments)
Sends event in response to other event. Use this function when you are in event handler and you want ...
Definition: EventsSystem.cpp:76
uint32 EventType
Event type identifier.
Definition: RegisteredEvent.h:19
Plik zawiera definicje podstawowych typów zmiennych.
void(UIElement::*)(UIElement *, ArgumentType *) EventHandlerPointer
Definition: EventsSystem.h:42
bool RaiseBubbleEvent(const RegisteredEvent *eventInfo, UIElement *sender, ArgumentType *arguments, EventHandlerPointer< ArgumentType > handler)
Definition: EventsSystem.inl:40
EventType m_counter
Definition: EventsSystem.h:58
rttr::type TypeID
Definition: RTTR.h:32
bool RaiseEventImpl(const RegisteredEvent *eventInfo, UIElement *sender, ArgumentType *arguments, EventHandlerPointer< ArgumentType > handler)
Definition: EventsSystem.inl:85
std::set< RegisteredEvent > m_registeredEvents
Definition: EventsSystem.h:61
bool RaiseDirectEvent(const RegisteredEvent *eventInfo, UIElement *sender, ArgumentType *arguments, EventHandlerPointer< ArgumentType > handler)
Definition: EventsSystem.inl:28
Structure describes event registered by controls.
Definition: RegisteredEvent.h:38
static EventsSystem & Get()
Definition: EventsSystem.cpp:83
std::mutex m_registerMutex
Definition: EventsSystem.h:60
EventsSystem()
Definition: EventsSystem.cpp:43