Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Muto::EventDispatcher Class Reference

Stack-based templated event dispatcher. More...

#include <Event.h>

Public Member Functions

template<typename T >
bool Dispatch (EventFn< T > func)
 Dispatch the event to the appropriate handler if the types match.
 
 EventDispatcher (Event &event)
 Construct an EventDispatcher for a specific event.
 

Private Types

template<typename T >
using EventFn = std::function< bool(T &)>
 Type alias for event handling functions.
 

Private Attributes

Event & m_Event
 The event to be dispatched.
 

Detailed Description

Stack-based templated event dispatcher.

Member Typedef Documentation

◆ EventFn

template<typename T >
using Muto::EventDispatcher::EventFn = std::function<bool(T&)>
private

Type alias for event handling functions.

Constructor & Destructor Documentation

◆ EventDispatcher()

Muto::EventDispatcher::EventDispatcher ( Event &  event)
inline

Construct an EventDispatcher for a specific event.

Parameters
eventThe event to dispatch.
77 : m_Event(event)
78 {
79 }
Event & m_Event
The event to be dispatched.
Definition Event.h:98
constexpr Scope< T > CreateScope(Args &&... args)
Creates a Scope (unique_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:51

References m_Event.

Referenced by Muto::Application::OnEvent(), Muto::EditorCamera::OnEvent(), Muto::OrthographicCameraController::OnEvent(), and Muto::EditorLayer::OnEvent().

Member Function Documentation

◆ Dispatch()

template<typename T >
bool Muto::EventDispatcher::Dispatch ( EventFn< T >  func)
inline

Dispatch the event to the appropriate handler if the types match.

Template Parameters
TThe type of the event to dispatch.
Parameters
funcThe function to handle the event.
Returns
True if the event was handled, false otherwise.
88 {
89 if (m_Event.GetEventType() == T::GetStaticType())
90 {
91 m_Event.Handled = func(*(T*)&m_Event);
92 return true;
93 }
94 return false;
95 }
bool Handled
Indicates whether the event has been handled.
Definition Event.h:60
virtual EventType GetEventType() const =0
Get the type of the event.

References Muto::Event::GetEventType(), Muto::Event::Handled, and m_Event.

Member Data Documentation

◆ m_Event

Event& Muto::EventDispatcher::m_Event
private

The event to be dispatched.

Referenced by Dispatch(), and EventDispatcher().


The documentation for this class was generated from the following file: