From 8e8c1c9c822cdeec4102451ccf491725d918e3a6 Mon Sep 17 00:00:00 2001 From: Matthew B Date: Tue, 25 Jun 2024 22:28:22 -0700 Subject: [PATCH] Support some C++11 features, like lambdas for callbacks Fix double mouse up on linux --- gwen/include/Gwen/Events.h | 3 +++ gwen/include/Gwen/Input/X11.h | 3 +++ gwen/src/events.cpp | 12 ++++++++++++ gwen/src/inputhandler.cpp | 1 - 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gwen/include/Gwen/Events.h b/gwen/include/Gwen/Events.h index 3efa6d73..baaf33b2 100644 --- a/gwen/include/Gwen/Events.h +++ b/gwen/include/Gwen/Events.h @@ -8,6 +8,7 @@ #ifndef GWEN_EVENTS_H #define GWEN_EVENTS_H +#include #include #include "Gwen/Exports.h" #include "Gwen/Structures.h" @@ -112,6 +113,7 @@ namespace Gwen template void Add( Event::Handler* ob, void ( T::*f )( Gwen::Event::Info ) ) { AddInternal( ob, static_cast( f ) ); } 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 ); 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 ) ); } @@ -152,6 +154,7 @@ namespace Gwen Handler::GlobalFunction fnGlobalFunction; Handler::GlobalFunctionWithInformation fnGlobalFunctionInfo; Handler::GlobalFunctionBlank fnGlobalFunctionBlank; + std::function fnFunctional; Event::Handler* pObject; void* Data; diff --git a/gwen/include/Gwen/Input/X11.h b/gwen/include/Gwen/Input/X11.h index df5495c6..c091deed 100644 --- a/gwen/include/Gwen/Input/X11.h +++ b/gwen/include/Gwen/Input/X11.h @@ -102,7 +102,10 @@ namespace Gwen case ButtonPress: { if (event.xbutton.button == 1) + { + if (!press && !Gwen::Input::IsLeftMouseDown()) return true; return Gwen::Input::OnMouseButton(0, press); + } if (event.xbutton.button == 2) return Gwen::Input::OnMouseButton(2, press); if (event.xbutton.button == 3) diff --git a/gwen/src/events.cpp b/gwen/src/events.cpp index 5d90c71e..b4ac9936 100644 --- a/gwen/src/events.cpp +++ b/gwen/src/events.cpp @@ -104,9 +104,21 @@ void Caller::Call( Controls::Base* pThis, Gwen::Event::Info information ) if ( h.fnGlobalFunctionBlank ) { ( *h.fnGlobalFunctionBlank )(); } + + if ( h.fnFunctional ) + { h.fnFunctional(); } } } +void Caller::Add( Event::Handler* pObject, const std::function fn ) +{ + handler h; + h.fnFunctional = fn; + h.pObject = pObject; + m_Handlers.push_back( h ); + pObject->RegisterCaller( this ); +} + void Caller::AddInternal( Event::Handler* pObject, Event::Handler::Function pFunction ) { handler h; diff --git a/gwen/src/inputhandler.cpp b/gwen/src/inputhandler.cpp index f963cf07..70be16c3 100644 --- a/gwen/src/inputhandler.cpp +++ b/gwen/src/inputhandler.cpp @@ -318,7 +318,6 @@ bool Gwen::Input::OnMouseButton( int iMouseButton, bool bDown ) else if ( iMouseButton == 1 ) { KeyData.RightMouseDown = bDown; } // Double click. - // Todo: Shouldn't double click if mouse has moved significantly bool bIsDoubleClick = false; if ( bDown &&