Skip to content

Commit

Permalink
Support some C++11 features, like lambdas for callbacks
Browse files Browse the repository at this point in the history
Fix double mouse up on linux
  • Loading branch information
matt-attack committed Jun 26, 2024
1 parent cd20a54 commit 8e8c1c9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions gwen/include/Gwen/Events.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef GWEN_EVENTS_H
#define GWEN_EVENTS_H

#include <functional>
#include <list>
#include "Gwen/Exports.h"
#include "Gwen/Structures.h"
Expand Down Expand Up @@ -112,6 +113,7 @@ namespace Gwen
template <typename T> void Add( Event::Handler* ob, void ( T::*f )( Gwen::Event::Info ) ) { AddInternal( ob, static_cast<Handler::FunctionWithInformation>( f ) ); }
template <typename T> void Add( Event::Handler* ob, void ( T::*f )( Gwen::Event::Info ), void* data ) { AddInternal( ob, static_cast<Handler::FunctionWithInformation>( f ), data ); }
template <typename T> void Add( Event::Handler* ob, void ( T::*f )() ) { AddInternal( ob, static_cast<Handler::FunctionBlank>( f ) ); }
void Add( Event::Handler* pObject, const std::function<void()> fn );

template <typename T> void GlobalAdd( Event::Handler* ob, T f ) { AddInternal( ob, static_cast<Handler::GlobalFunction>( f ) ); }
void GlobalAdd( Event::Handler* ob, void ( *f )( Gwen::Event::Info ) ) { AddInternal( ob, static_cast<Handler::GlobalFunctionWithInformation>( f ) ); }
Expand Down Expand Up @@ -152,6 +154,7 @@ namespace Gwen
Handler::GlobalFunction fnGlobalFunction;
Handler::GlobalFunctionWithInformation fnGlobalFunctionInfo;
Handler::GlobalFunctionBlank fnGlobalFunctionBlank;
std::function<void()> fnFunctional;

Event::Handler* pObject;
void* Data;
Expand Down
3 changes: 3 additions & 0 deletions gwen/include/Gwen/Input/X11.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions gwen/src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void()> 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;
Expand Down
1 change: 0 additions & 1 deletion gwen/src/inputhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit 8e8c1c9

Please sign in to comment.