From 54c406a71f68ab14cf292ce38c4142d224e899d3 Mon Sep 17 00:00:00 2001 From: Matthew B Date: Tue, 17 Sep 2024 21:00:19 -0700 Subject: [PATCH] Add lambda callback option with no objection --- gwen/include/Gwen/Events.h | 1 + gwen/src/events.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/gwen/include/Gwen/Events.h b/gwen/include/Gwen/Events.h index baaf33b..483b4c6 100644 --- a/gwen/include/Gwen/Events.h +++ b/gwen/include/Gwen/Events.h @@ -114,6 +114,7 @@ namespace Gwen template void Add( Event::Handler* ob, void ( T::*f )( Gwen::Event::Info ), void* data ) { AddInternal( ob, static_cast( f ), data ); } template void Add( Event::Handler* ob, void ( T::*f )() ) { AddInternal( ob, static_cast( f ) ); } void Add( Event::Handler* pObject, const std::function fn ); + void Add( const std::function fn ); template void GlobalAdd( Event::Handler* ob, T f ) { AddInternal( ob, static_cast( f ) ); } void GlobalAdd( Event::Handler* ob, void ( *f )( Gwen::Event::Info ) ) { AddInternal( ob, static_cast( f ) ); } diff --git a/gwen/src/events.cpp b/gwen/src/events.cpp index b4ac993..40615d9 100644 --- a/gwen/src/events.cpp +++ b/gwen/src/events.cpp @@ -119,6 +119,14 @@ void Caller::Add( Event::Handler* pObject, const std::function fn ) pObject->RegisterCaller( this ); } +void Caller::Add( const std::function fn ) +{ + handler h; + h.fnFunctional = fn; + h.pObject = 0; + m_Handlers.push_back( h ); +} + void Caller::AddInternal( Event::Handler* pObject, Event::Handler::Function pFunction ) { handler h;