diff --git a/include/eepp/core.hpp b/include/eepp/core.hpp index b1dd9a003..a36d44d2e 100644 --- a/include/eepp/core.hpp +++ b/include/eepp/core.hpp @@ -3,8 +3,6 @@ #include -#include - #include #include diff --git a/include/eepp/core/core.hpp b/include/eepp/core/core.hpp index 629a83dde..ceeced8ca 100644 --- a/include/eepp/core/core.hpp +++ b/include/eepp/core/core.hpp @@ -5,6 +5,5 @@ #include #include #include -#include #endif diff --git a/include/eepp/graphics/particlesystem.hpp b/include/eepp/graphics/particlesystem.hpp index 8ae22f780..4d14f1e0e 100644 --- a/include/eepp/graphics/particlesystem.hpp +++ b/include/eepp/graphics/particlesystem.hpp @@ -40,7 +40,7 @@ enum class ParticleEffect : Uint32 { /** @brief Basic but powerfull Particle System */ class EE_API ParticleSystem { public: - typedef cb::Callback2 ParticleCallback; + typedef std::function ParticleCallback; ParticleSystem(); diff --git a/include/eepp/thirdparty/PlusCallback/callback.hpp b/include/eepp/thirdparty/PlusCallback/callback.hpp deleted file mode 100644 index 0ac84483b..000000000 --- a/include/eepp/thirdparty/PlusCallback/callback.hpp +++ /dev/null @@ -1,1981 +0,0 @@ -/* - * PlusCallback 1.7 - * Copyright (c) 2009-2010 Lewis Van Winkle - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - */ - -#ifndef __CALLBACK_HPP__ -#define __CALLBACK_HPP__ - -#include -#include - -#if !defined( __ANDROID__ ) && !defined( ANDROID ) -#define EXCEPTIONS_SUPPORTED -#endif - -#ifdef EXCEPTIONS_SUPPORTED -#include - -#define THROW_RUNTIME_ERROR( R ) throw std::runtime_error( unset_call_error ); -#else -#include - -#define THROW_RUNTIME_ERROR( R ) \ - printf( "throw std::runtime_error(unset_call_error)" ); \ - return (R)NULL; -#endif - -// PlusCallback 1.7 -// This library was built on 12.10.2010 to support -// functions with a maximum of 9 parameters. -#define CALLBACK_VERSION 1.7 - -namespace cb { - -static const std::string unset_call_error( "Attempting to invoke null callback." ); - -/// Stores a callback for a function taking 0 parameters. -///\tparam R Callback function return type. -template class Callback0 { - public: - /// Constructs the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - Callback0( C* object, R ( C::*function )() ) : - mCallback( new ( &mMem ) ChildMethod( object, function ) ) {} - - /// Constructs the callback to a free function or static member function. - ///\param function Free function address to call. - Callback0( R ( *function )() ) : mCallback( new ( &mMem ) ChildFree( function ) ) {} - - /// Constructs a callback that can later be set. - Callback0() : mCallback( 0 ) {} - - Callback0( const Callback0& c ) : mCallback( c.mCallback ) { - if ( mCallback ) { - memcpy( mMem, c.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - } - - Callback0& operator=( const Callback0& rhs ) { - mCallback = rhs.mCallback; - if ( mCallback ) { - memcpy( mMem, rhs.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - - return *this; - } - - ~Callback0() {} - - /// Sets the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template void Reset( C* object, R ( C::*function )() ) { - mCallback = new ( &mMem ) ChildMethod( object, function ); - } - - /// Sets the callback to a free function or static member function. - ///\param function Free function address to call. - void Reset( R ( *function )() ) { mCallback = new ( &mMem ) ChildFree( function ); } - - /// Resests to callback to nothing. - void Reset() { mCallback = 0; } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator==( const Callback0& rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) == ( *( rhs.mCallback ) ); - else - return mCallback == rhs.mCallback; - } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator!=( const Callback0& rhs ) const { return !( *this == rhs ); } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator<( const Callback0 rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) < ( *( rhs.mCallback ) ); - else - return mCallback < rhs.mCallback; - } - - /// Returns true if the callback has been set, or false if the callback is not set and is - /// invalid. - bool IsSet() const { return 0 != mCallback; } - - /// Invokes the callback. - R operator()() const { - if ( mCallback ) - return ( *mCallback )(); - else - THROW_RUNTIME_ERROR( R ) - } - - /// Invokes the callback. This function can sometimes be more convenient than the operator(), - /// which does the same thing. - R Call() const { - if ( mCallback ) - return ( *mCallback )(); - else - THROW_RUNTIME_ERROR( R ) - } - - private: - class Base { - public: - Base() {} - virtual R operator()() = 0; - virtual bool operator==( const Base& rhs ) const = 0; - virtual bool operator<( const Base& rhs ) const = 0; - virtual void* Comp() const = 0; // Returns a pointer used in comparisons. - }; - - class ChildFree : public Base { - public: - ChildFree( R ( *function )() ) : mFunc( function ) {} - - virtual R operator()() { return mFunc(); } - - virtual bool operator==( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return mFunc < r->mFunc; - else - return true; // Free functions will always be less than methods (because comp - // returns 0). - } - - virtual void* Comp() const { return 0; } - - private: - R ( *const mFunc )(); - }; - - template class ChildMethod : public Base { - public: - ChildMethod( C* object, R ( C::*function )() ) : mObj( object ), mFunc( function ) {} - - virtual R operator()() { return ( mObj->*mFunc )(); } - - virtual bool operator==( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) - return ( mObj == r->mObj ) && ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) { - if ( mObj != r->mObj ) - return mObj < r->mObj; - else - return 0 > memcmp( (void*)&mFunc, (void*)&( r->mFunc ), sizeof( mFunc ) ); - } else - return mObj < rhs.Comp(); - } - - virtual void* Comp() const { return mObj; } - - private: - C* const mObj; - R ( C::*const mFunc )(); - }; - - /// This class is only to find the worst case method pointer size. - class unknown; - - char mMem[sizeof( ChildMethod )]; // Reserve memory for creating useful objects later. - Base* mCallback; -}; - -/// Helper function to construct a callback without bothering to specify template parameters. -template Callback0 Make0( C* object, R ( C::*function )() ) { - return Callback0( object, function ); -} - -/// Helper function to construct a callback without bothering to specify template parameters. -template Callback0 Make0( R ( *function )() ) { - return Callback0( function ); -} - -/// Stores a callback for a function taking 1 parameters. -///\tparam R Callback function return type. -template class Callback1 { - public: - /// Constructs the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - Callback1( C* object, R ( C::*function )( T0 t0 ) ) : - mCallback( new ( &mMem ) ChildMethod( object, function ) ) {} - - /// Constructs the callback to a free function or static member function. - ///\param function Free function address to call. - Callback1( R ( *function )( T0 t0 ) ) : mCallback( new ( &mMem ) ChildFree( function ) ) {} - - /// Constructs a callback that can later be set. - Callback1() : mCallback( 0 ) {} - - Callback1( const Callback1& c ) : mCallback( c.mCallback ) { - if ( mCallback ) { - memcpy( mMem, c.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - } - - Callback1& operator=( const Callback1& rhs ) { - mCallback = rhs.mCallback; - if ( mCallback ) { - memcpy( mMem, rhs.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - - return *this; - } - - ~Callback1() {} - - /// Sets the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template void Reset( C* object, R ( C::*function )( T0 t0 ) ) { - mCallback = new ( &mMem ) ChildMethod( object, function ); - } - - /// Sets the callback to a free function or static member function. - ///\param function Free function address to call. - void Reset( R ( *function )( T0 t0 ) ) { mCallback = new ( &mMem ) ChildFree( function ); } - - /// Resests to callback to nothing. - void Reset() { mCallback = 0; } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator==( const Callback1& rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) == ( *( rhs.mCallback ) ); - else - return mCallback == rhs.mCallback; - } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator!=( const Callback1& rhs ) const { return !( *this == rhs ); } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator<( const Callback1 rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) < ( *( rhs.mCallback ) ); - else - return mCallback < rhs.mCallback; - } - - /// Returns true if the callback has been set, or false if the callback is not set and is - /// invalid. - bool IsSet() const { return 0 != mCallback; } - - /// Invokes the callback. - R operator()( T0 t0 ) const { - if ( mCallback ) - return ( *mCallback )( t0 ); - else - THROW_RUNTIME_ERROR( R ) - } - - /// Invokes the callback. This function can sometimes be more convenient than the operator(), - /// which does the same thing. - R Call( T0 t0 ) const { - if ( mCallback ) - return ( *mCallback )( t0 ); - else - THROW_RUNTIME_ERROR( R ) - } - - private: - class Base { - public: - Base() {} - virtual R operator()( T0 t0 ) = 0; - virtual bool operator==( const Base& rhs ) const = 0; - virtual bool operator<( const Base& rhs ) const = 0; - virtual void* Comp() const = 0; // Returns a pointer used in comparisons. - }; - - class ChildFree : public Base { - public: - ChildFree( R ( *function )( T0 t0 ) ) : mFunc( function ) {} - - virtual R operator()( T0 t0 ) { return mFunc( t0 ); } - - virtual bool operator==( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return mFunc < r->mFunc; - else - return true; // Free functions will always be less than methods (because comp - // returns 0). - } - - virtual void* Comp() const { return 0; } - - private: - R ( *const mFunc )( T0 t0 ); - }; - - template class ChildMethod : public Base { - public: - ChildMethod( C* object, R ( C::*function )( T0 t0 ) ) : mObj( object ), mFunc( function ) {} - - virtual R operator()( T0 t0 ) { return ( mObj->*mFunc )( t0 ); } - - virtual bool operator==( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) - return ( mObj == r->mObj ) && ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) { - if ( mObj != r->mObj ) - return mObj < r->mObj; - else - return 0 > memcmp( (void*)&mFunc, (void*)&( r->mFunc ), sizeof( mFunc ) ); - } else - return mObj < rhs.Comp(); - } - - virtual void* Comp() const { return mObj; } - - private: - C* const mObj; - R ( C::*const mFunc )( T0 t0 ); - }; - - /// This class is only to find the worst case method pointer size. - class unknown; - - char mMem[sizeof( ChildMethod )]; // Reserve memory for creating useful objects later. - Base* mCallback; -}; - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback1 Make1( C* object, R ( C::*function )( T0 t0 ) ) { - return Callback1( object, function ); -} - -/// Helper function to construct a callback without bothering to specify template parameters. -template Callback1 Make1( R ( *function )( T0 t0 ) ) { - return Callback1( function ); -} - -/// Stores a callback for a function taking 2 parameters. -///\tparam R Callback function return type. -template class Callback2 { - public: - /// Constructs the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - Callback2( C* object, R ( C::*function )( T0 t0, T1 t1 ) ) : - mCallback( new ( &mMem ) ChildMethod( object, function ) ) {} - - /// Constructs the callback to a free function or static member function. - ///\param function Free function address to call. - Callback2( R ( *function )( T0 t0, T1 t1 ) ) : - mCallback( new ( &mMem ) ChildFree( function ) ) {} - - /// Constructs a callback that can later be set. - Callback2() : mCallback( 0 ) {} - - Callback2( const Callback2& c ) : mCallback( c.mCallback ) { - if ( mCallback ) { - memcpy( mMem, c.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - } - - Callback2& operator=( const Callback2& rhs ) { - mCallback = rhs.mCallback; - if ( mCallback ) { - memcpy( mMem, rhs.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - - return *this; - } - - ~Callback2() {} - - /// Sets the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template void Reset( C* object, R ( C::*function )( T0 t0, T1 t1 ) ) { - mCallback = new ( &mMem ) ChildMethod( object, function ); - } - - /// Sets the callback to a free function or static member function. - ///\param function Free function address to call. - void Reset( R ( *function )( T0 t0, T1 t1 ) ) { - mCallback = new ( &mMem ) ChildFree( function ); - } - - /// Resests to callback to nothing. - void Reset() { mCallback = 0; } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator==( const Callback2& rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) == ( *( rhs.mCallback ) ); - else - return mCallback == rhs.mCallback; - } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator!=( const Callback2& rhs ) const { return !( *this == rhs ); } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator<( const Callback2 rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) < ( *( rhs.mCallback ) ); - else - return mCallback < rhs.mCallback; - } - - /// Returns true if the callback has been set, or false if the callback is not set and is - /// invalid. - bool IsSet() const { return 0 != mCallback; } - - /// Invokes the callback. - R operator()( T0 t0, T1 t1 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1 ); - else - THROW_RUNTIME_ERROR( R ) - } - - /// Invokes the callback. This function can sometimes be more convenient than the operator(), - /// which does the same thing. - R Call( T0 t0, T1 t1 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1 ); - else - THROW_RUNTIME_ERROR( R ) - } - - private: - class Base { - public: - Base() {} - virtual R operator()( T0 t0, T1 t1 ) = 0; - virtual bool operator==( const Base& rhs ) const = 0; - virtual bool operator<( const Base& rhs ) const = 0; - virtual void* Comp() const = 0; // Returns a pointer used in comparisons. - }; - - class ChildFree : public Base { - public: - ChildFree( R ( *function )( T0 t0, T1 t1 ) ) : mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1 ) { return mFunc( t0, t1 ); } - - virtual bool operator==( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return mFunc < r->mFunc; - else - return true; // Free functions will always be less than methods (because comp - // returns 0). - } - - virtual void* Comp() const { return 0; } - - private: - R ( *const mFunc )( T0 t0, T1 t1 ); - }; - - template class ChildMethod : public Base { - public: - ChildMethod( C* object, R ( C::*function )( T0 t0, T1 t1 ) ) : - mObj( object ), mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1 ) { return ( mObj->*mFunc )( t0, t1 ); } - - virtual bool operator==( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) - return ( mObj == r->mObj ) && ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) { - if ( mObj != r->mObj ) - return mObj < r->mObj; - else - return 0 > memcmp( (void*)&mFunc, (void*)&( r->mFunc ), sizeof( mFunc ) ); - } else - return mObj < rhs.Comp(); - } - - virtual void* Comp() const { return mObj; } - - private: - C* const mObj; - R ( C::*const mFunc )( T0 t0, T1 t1 ); - }; - - /// This class is only to find the worst case method pointer size. - class unknown; - - char mMem[sizeof( ChildMethod )]; // Reserve memory for creating useful objects later. - Base* mCallback; -}; - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback2 Make2( C* object, R ( C::*function )( T0 t0, T1 t1 ) ) { - return Callback2( object, function ); -} - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback2 Make2( R ( *function )( T0 t0, T1 t1 ) ) { - return Callback2( function ); -} - -/// Stores a callback for a function taking 3 parameters. -///\tparam R Callback function return type. -template class Callback3 { - public: - /// Constructs the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - Callback3( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2 ) ) : - mCallback( new ( &mMem ) ChildMethod( object, function ) ) {} - - /// Constructs the callback to a free function or static member function. - ///\param function Free function address to call. - Callback3( R ( *function )( T0 t0, T1 t1, T2 t2 ) ) : - mCallback( new ( &mMem ) ChildFree( function ) ) {} - - /// Constructs a callback that can later be set. - Callback3() : mCallback( 0 ) {} - - Callback3( const Callback3& c ) : mCallback( c.mCallback ) { - if ( mCallback ) { - memcpy( mMem, c.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - } - - Callback3& operator=( const Callback3& rhs ) { - mCallback = rhs.mCallback; - if ( mCallback ) { - memcpy( mMem, rhs.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - - return *this; - } - - ~Callback3() {} - - /// Sets the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template void Reset( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2 ) ) { - mCallback = new ( &mMem ) ChildMethod( object, function ); - } - - /// Sets the callback to a free function or static member function. - ///\param function Free function address to call. - void Reset( R ( *function )( T0 t0, T1 t1, T2 t2 ) ) { - mCallback = new ( &mMem ) ChildFree( function ); - } - - /// Resests to callback to nothing. - void Reset() { mCallback = 0; } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator==( const Callback3& rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) == ( *( rhs.mCallback ) ); - else - return mCallback == rhs.mCallback; - } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator!=( const Callback3& rhs ) const { return !( *this == rhs ); } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator<( const Callback3 rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) < ( *( rhs.mCallback ) ); - else - return mCallback < rhs.mCallback; - } - - /// Returns true if the callback has been set, or false if the callback is not set and is - /// invalid. - bool IsSet() const { return 0 != mCallback; } - - /// Invokes the callback. - R operator()( T0 t0, T1 t1, T2 t2 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2 ); - else - THROW_RUNTIME_ERROR( R ) - } - - /// Invokes the callback. This function can sometimes be more convenient than the operator(), - /// which does the same thing. - R Call( T0 t0, T1 t1, T2 t2 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2 ); - else - THROW_RUNTIME_ERROR( R ) - } - - private: - class Base { - public: - Base() {} - virtual R operator()( T0 t0, T1 t1, T2 t2 ) = 0; - virtual bool operator==( const Base& rhs ) const = 0; - virtual bool operator<( const Base& rhs ) const = 0; - virtual void* Comp() const = 0; // Returns a pointer used in comparisons. - }; - - class ChildFree : public Base { - public: - ChildFree( R ( *function )( T0 t0, T1 t1, T2 t2 ) ) : mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2 ) { return mFunc( t0, t1, t2 ); } - - virtual bool operator==( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return mFunc < r->mFunc; - else - return true; // Free functions will always be less than methods (because comp - // returns 0). - } - - virtual void* Comp() const { return 0; } - - private: - R ( *const mFunc )( T0 t0, T1 t1, T2 t2 ); - }; - - template class ChildMethod : public Base { - public: - ChildMethod( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2 ) ) : - mObj( object ), mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2 ) { return ( mObj->*mFunc )( t0, t1, t2 ); } - - virtual bool operator==( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) - return ( mObj == r->mObj ) && ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) { - if ( mObj != r->mObj ) - return mObj < r->mObj; - else - return 0 > memcmp( (void*)&mFunc, (void*)&( r->mFunc ), sizeof( mFunc ) ); - } else - return mObj < rhs.Comp(); - } - - virtual void* Comp() const { return mObj; } - - private: - C* const mObj; - R ( C::*const mFunc )( T0 t0, T1 t1, T2 t2 ); - }; - - /// This class is only to find the worst case method pointer size. - class unknown; - - char mMem[sizeof( ChildMethod )]; // Reserve memory for creating useful objects later. - Base* mCallback; -}; - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback3 Make3( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2 ) ) { - return Callback3( object, function ); -} - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback3 Make3( R ( *function )( T0 t0, T1 t1, T2 t2 ) ) { - return Callback3( function ); -} - -/// Stores a callback for a function taking 4 parameters. -///\tparam R Callback function return type. -template class Callback4 { - public: - /// Constructs the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - Callback4( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3 ) ) : - mCallback( new ( &mMem ) ChildMethod( object, function ) ) {} - - /// Constructs the callback to a free function or static member function. - ///\param function Free function address to call. - Callback4( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3 ) ) : - mCallback( new ( &mMem ) ChildFree( function ) ) {} - - /// Constructs a callback that can later be set. - Callback4() : mCallback( 0 ) {} - - Callback4( const Callback4& c ) : mCallback( c.mCallback ) { - if ( mCallback ) { - memcpy( mMem, c.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - } - - Callback4& operator=( const Callback4& rhs ) { - mCallback = rhs.mCallback; - if ( mCallback ) { - memcpy( mMem, rhs.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - - return *this; - } - - ~Callback4() {} - - /// Sets the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - void Reset( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3 ) ) { - mCallback = new ( &mMem ) ChildMethod( object, function ); - } - - /// Sets the callback to a free function or static member function. - ///\param function Free function address to call. - void Reset( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3 ) ) { - mCallback = new ( &mMem ) ChildFree( function ); - } - - /// Resests to callback to nothing. - void Reset() { mCallback = 0; } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator==( const Callback4& rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) == ( *( rhs.mCallback ) ); - else - return mCallback == rhs.mCallback; - } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator!=( const Callback4& rhs ) const { return !( *this == rhs ); } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator<( const Callback4 rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) < ( *( rhs.mCallback ) ); - else - return mCallback < rhs.mCallback; - } - - /// Returns true if the callback has been set, or false if the callback is not set and is - /// invalid. - bool IsSet() const { return 0 != mCallback; } - - /// Invokes the callback. - R operator()( T0 t0, T1 t1, T2 t2, T3 t3 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2, t3 ); - else - THROW_RUNTIME_ERROR( R ) - } - - /// Invokes the callback. This function can sometimes be more convenient than the operator(), - /// which does the same thing. - R Call( T0 t0, T1 t1, T2 t2, T3 t3 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2, t3 ); - else - THROW_RUNTIME_ERROR( R ) - } - - private: - class Base { - public: - Base() {} - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3 ) = 0; - virtual bool operator==( const Base& rhs ) const = 0; - virtual bool operator<( const Base& rhs ) const = 0; - virtual void* Comp() const = 0; // Returns a pointer used in comparisons. - }; - - class ChildFree : public Base { - public: - ChildFree( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3 ) ) : mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3 ) { return mFunc( t0, t1, t2, t3 ); } - - virtual bool operator==( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return mFunc < r->mFunc; - else - return true; // Free functions will always be less than methods (because comp - // returns 0). - } - - virtual void* Comp() const { return 0; } - - private: - R ( *const mFunc )( T0 t0, T1 t1, T2 t2, T3 t3 ); - }; - - template class ChildMethod : public Base { - public: - ChildMethod( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3 ) ) : - mObj( object ), mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3 ) { - return ( mObj->*mFunc )( t0, t1, t2, t3 ); - } - - virtual bool operator==( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) - return ( mObj == r->mObj ) && ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) { - if ( mObj != r->mObj ) - return mObj < r->mObj; - else - return 0 > memcmp( (void*)&mFunc, (void*)&( r->mFunc ), sizeof( mFunc ) ); - } else - return mObj < rhs.Comp(); - } - - virtual void* Comp() const { return mObj; } - - private: - C* const mObj; - R ( C::*const mFunc )( T0 t0, T1 t1, T2 t2, T3 t3 ); - }; - - /// This class is only to find the worst case method pointer size. - class unknown; - - char mMem[sizeof( ChildMethod )]; // Reserve memory for creating useful objects later. - Base* mCallback; -}; - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback4 Make4( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3 ) ) { - return Callback4( object, function ); -} - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback4 Make4( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3 ) ) { - return Callback4( function ); -} - -/// Stores a callback for a function taking 5 parameters. -///\tparam R Callback function return type. -template -class Callback5 { - public: - /// Constructs the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - Callback5( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ) ) : - mCallback( new ( &mMem ) ChildMethod( object, function ) ) {} - - /// Constructs the callback to a free function or static member function. - ///\param function Free function address to call. - Callback5( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ) ) : - mCallback( new ( &mMem ) ChildFree( function ) ) {} - - /// Constructs a callback that can later be set. - Callback5() : mCallback( 0 ) {} - - Callback5( const Callback5& c ) : mCallback( c.mCallback ) { - if ( mCallback ) { - memcpy( mMem, c.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - } - - Callback5& operator=( const Callback5& rhs ) { - mCallback = rhs.mCallback; - if ( mCallback ) { - memcpy( mMem, rhs.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - - return *this; - } - - ~Callback5() {} - - /// Sets the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - void Reset( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ) ) { - mCallback = new ( &mMem ) ChildMethod( object, function ); - } - - /// Sets the callback to a free function or static member function. - ///\param function Free function address to call. - void Reset( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ) ) { - mCallback = new ( &mMem ) ChildFree( function ); - } - - /// Resests to callback to nothing. - void Reset() { mCallback = 0; } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator==( const Callback5& rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) == ( *( rhs.mCallback ) ); - else - return mCallback == rhs.mCallback; - } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator!=( const Callback5& rhs ) const { return !( *this == rhs ); } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator<( const Callback5 rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) < ( *( rhs.mCallback ) ); - else - return mCallback < rhs.mCallback; - } - - /// Returns true if the callback has been set, or false if the callback is not set and is - /// invalid. - bool IsSet() const { return 0 != mCallback; } - - /// Invokes the callback. - R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2, t3, t4 ); - else - THROW_RUNTIME_ERROR( R ) - } - - /// Invokes the callback. This function can sometimes be more convenient than the operator(), - /// which does the same thing. - R Call( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2, t3, t4 ); - else - THROW_RUNTIME_ERROR( R ) - } - - private: - class Base { - public: - Base() {} - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ) = 0; - virtual bool operator==( const Base& rhs ) const = 0; - virtual bool operator<( const Base& rhs ) const = 0; - virtual void* Comp() const = 0; // Returns a pointer used in comparisons. - }; - - class ChildFree : public Base { - public: - ChildFree( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ) ) : mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ) { - return mFunc( t0, t1, t2, t3, t4 ); - } - - virtual bool operator==( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return mFunc < r->mFunc; - else - return true; // Free functions will always be less than methods (because comp - // returns 0). - } - - virtual void* Comp() const { return 0; } - - private: - R ( *const mFunc )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ); - }; - - template class ChildMethod : public Base { - public: - ChildMethod( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ) ) : - mObj( object ), mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ) { - return ( mObj->*mFunc )( t0, t1, t2, t3, t4 ); - } - - virtual bool operator==( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) - return ( mObj == r->mObj ) && ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) { - if ( mObj != r->mObj ) - return mObj < r->mObj; - else - return 0 > memcmp( (void*)&mFunc, (void*)&( r->mFunc ), sizeof( mFunc ) ); - } else - return mObj < rhs.Comp(); - } - - virtual void* Comp() const { return mObj; } - - private: - C* const mObj; - R ( C::*const mFunc )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ); - }; - - /// This class is only to find the worst case method pointer size. - class unknown; - - char mMem[sizeof( ChildMethod )]; // Reserve memory for creating useful objects later. - Base* mCallback; -}; - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback5 Make5( C* object, - R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ) ) { - return Callback5( object, function ); -} - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback5 Make5( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4 ) ) { - return Callback5( function ); -} - -/// Stores a callback for a function taking 6 parameters. -///\tparam R Callback function return type. -template -class Callback6 { - public: - /// Constructs the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - Callback6( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5 ) ) : - mCallback( new ( &mMem ) ChildMethod( object, function ) ) {} - - /// Constructs the callback to a free function or static member function. - ///\param function Free function address to call. - Callback6( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5 ) ) : - mCallback( new ( &mMem ) ChildFree( function ) ) {} - - /// Constructs a callback that can later be set. - Callback6() : mCallback( 0 ) {} - - Callback6( const Callback6& c ) : mCallback( c.mCallback ) { - if ( mCallback ) { - memcpy( mMem, c.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - } - - Callback6& operator=( const Callback6& rhs ) { - mCallback = rhs.mCallback; - if ( mCallback ) { - memcpy( mMem, rhs.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - - return *this; - } - - ~Callback6() {} - - /// Sets the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - void Reset( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5 ) ) { - mCallback = new ( &mMem ) ChildMethod( object, function ); - } - - /// Sets the callback to a free function or static member function. - ///\param function Free function address to call. - void Reset( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5 ) ) { - mCallback = new ( &mMem ) ChildFree( function ); - } - - /// Resests to callback to nothing. - void Reset() { mCallback = 0; } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator==( const Callback6& rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) == ( *( rhs.mCallback ) ); - else - return mCallback == rhs.mCallback; - } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator!=( const Callback6& rhs ) const { return !( *this == rhs ); } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator<( const Callback6 rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) < ( *( rhs.mCallback ) ); - else - return mCallback < rhs.mCallback; - } - - /// Returns true if the callback has been set, or false if the callback is not set and is - /// invalid. - bool IsSet() const { return 0 != mCallback; } - - /// Invokes the callback. - R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2, t3, t4, t5 ); - else - THROW_RUNTIME_ERROR( R ) - } - - /// Invokes the callback. This function can sometimes be more convenient than the operator(), - /// which does the same thing. - R Call( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2, t3, t4, t5 ); - else - THROW_RUNTIME_ERROR( R ) - } - - private: - class Base { - public: - Base() {} - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5 ) = 0; - virtual bool operator==( const Base& rhs ) const = 0; - virtual bool operator<( const Base& rhs ) const = 0; - virtual void* Comp() const = 0; // Returns a pointer used in comparisons. - }; - - class ChildFree : public Base { - public: - ChildFree( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5 ) ) : - mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5 ) { - return mFunc( t0, t1, t2, t3, t4, t5 ); - } - - virtual bool operator==( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return mFunc < r->mFunc; - else - return true; // Free functions will always be less than methods (because comp - // returns 0). - } - - virtual void* Comp() const { return 0; } - - private: - R ( *const mFunc )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5 ); - }; - - template class ChildMethod : public Base { - public: - ChildMethod( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5 ) ) : - mObj( object ), mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5 ) { - return ( mObj->*mFunc )( t0, t1, t2, t3, t4, t5 ); - } - - virtual bool operator==( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) - return ( mObj == r->mObj ) && ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) { - if ( mObj != r->mObj ) - return mObj < r->mObj; - else - return 0 > memcmp( (void*)&mFunc, (void*)&( r->mFunc ), sizeof( mFunc ) ); - } else - return mObj < rhs.Comp(); - } - - virtual void* Comp() const { return mObj; } - - private: - C* const mObj; - R ( C::*const mFunc )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5 ); - }; - - /// This class is only to find the worst case method pointer size. - class unknown; - - char mMem[sizeof( ChildMethod )]; // Reserve memory for creating useful objects later. - Base* mCallback; -}; - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback6 Make6( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, - T3 t3, T4 t4, T5 t5 ) ) { - return Callback6( object, function ); -} - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback6 Make6( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, - T5 t5 ) ) { - return Callback6( function ); -} - -/// Stores a callback for a function taking 7 parameters. -///\tparam R Callback function return type. -template -class Callback7 { - public: - /// Constructs the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - Callback7( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ) ) : - mCallback( new ( &mMem ) ChildMethod( object, function ) ) {} - - /// Constructs the callback to a free function or static member function. - ///\param function Free function address to call. - Callback7( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ) ) : - mCallback( new ( &mMem ) ChildFree( function ) ) {} - - /// Constructs a callback that can later be set. - Callback7() : mCallback( 0 ) {} - - Callback7( const Callback7& c ) : mCallback( c.mCallback ) { - if ( mCallback ) { - memcpy( mMem, c.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - } - - Callback7& operator=( const Callback7& rhs ) { - mCallback = rhs.mCallback; - if ( mCallback ) { - memcpy( mMem, rhs.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - - return *this; - } - - ~Callback7() {} - - /// Sets the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - void Reset( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ) ) { - mCallback = new ( &mMem ) ChildMethod( object, function ); - } - - /// Sets the callback to a free function or static member function. - ///\param function Free function address to call. - void Reset( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ) ) { - mCallback = new ( &mMem ) ChildFree( function ); - } - - /// Resests to callback to nothing. - void Reset() { mCallback = 0; } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator==( const Callback7& rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) == ( *( rhs.mCallback ) ); - else - return mCallback == rhs.mCallback; - } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator!=( const Callback7& rhs ) const { return !( *this == rhs ); } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator<( const Callback7 rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) < ( *( rhs.mCallback ) ); - else - return mCallback < rhs.mCallback; - } - - /// Returns true if the callback has been set, or false if the callback is not set and is - /// invalid. - bool IsSet() const { return 0 != mCallback; } - - /// Invokes the callback. - R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2, t3, t4, t5, t6 ); - else - THROW_RUNTIME_ERROR( R ) - } - - /// Invokes the callback. This function can sometimes be more convenient than the operator(), - /// which does the same thing. - R Call( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2, t3, t4, t5, t6 ); - else - THROW_RUNTIME_ERROR( R ) - } - - private: - class Base { - public: - Base() {} - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ) = 0; - virtual bool operator==( const Base& rhs ) const = 0; - virtual bool operator<( const Base& rhs ) const = 0; - virtual void* Comp() const = 0; // Returns a pointer used in comparisons. - }; - - class ChildFree : public Base { - public: - ChildFree( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ) ) : - mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ) { - return mFunc( t0, t1, t2, t3, t4, t5, t6 ); - } - - virtual bool operator==( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return mFunc < r->mFunc; - else - return true; // Free functions will always be less than methods (because comp - // returns 0). - } - - virtual void* Comp() const { return 0; } - - private: - R ( *const mFunc )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ); - }; - - template class ChildMethod : public Base { - public: - ChildMethod( C* object, - R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ) ) : - mObj( object ), mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ) { - return ( mObj->*mFunc )( t0, t1, t2, t3, t4, t5, t6 ); - } - - virtual bool operator==( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) - return ( mObj == r->mObj ) && ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) { - if ( mObj != r->mObj ) - return mObj < r->mObj; - else - return 0 > memcmp( (void*)&mFunc, (void*)&( r->mFunc ), sizeof( mFunc ) ); - } else - return mObj < rhs.Comp(); - } - - virtual void* Comp() const { return mObj; } - - private: - C* const mObj; - R ( C::*const mFunc )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ); - }; - - /// This class is only to find the worst case method pointer size. - class unknown; - - char mMem[sizeof( ChildMethod )]; // Reserve memory for creating useful objects later. - Base* mCallback; -}; - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback7 -Make7( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6 ) ) { - return Callback7( object, function ); -} - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback7 Make7( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, - T5 t5, T6 t6 ) ) { - return Callback7( function ); -} - -/// Stores a callback for a function taking 8 parameters. -///\tparam R Callback function return type. -template -class Callback8 { - public: - /// Constructs the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - Callback8( C* object, - R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ) ) : - mCallback( new ( &mMem ) ChildMethod( object, function ) ) {} - - /// Constructs the callback to a free function or static member function. - ///\param function Free function address to call. - Callback8( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ) ) : - mCallback( new ( &mMem ) ChildFree( function ) ) {} - - /// Constructs a callback that can later be set. - Callback8() : mCallback( 0 ) {} - - Callback8( const Callback8& c ) : mCallback( c.mCallback ) { - if ( mCallback ) { - memcpy( mMem, c.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - } - - Callback8& operator=( const Callback8& rhs ) { - mCallback = rhs.mCallback; - if ( mCallback ) { - memcpy( mMem, rhs.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - - return *this; - } - - ~Callback8() {} - - /// Sets the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - void Reset( C* object, - R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ) ) { - mCallback = new ( &mMem ) ChildMethod( object, function ); - } - - /// Sets the callback to a free function or static member function. - ///\param function Free function address to call. - void Reset( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ) ) { - mCallback = new ( &mMem ) ChildFree( function ); - } - - /// Resests to callback to nothing. - void Reset() { mCallback = 0; } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator==( const Callback8& rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) == ( *( rhs.mCallback ) ); - else - return mCallback == rhs.mCallback; - } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator!=( const Callback8& rhs ) const { return !( *this == rhs ); } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator<( const Callback8 rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) < ( *( rhs.mCallback ) ); - else - return mCallback < rhs.mCallback; - } - - /// Returns true if the callback has been set, or false if the callback is not set and is - /// invalid. - bool IsSet() const { return 0 != mCallback; } - - /// Invokes the callback. - R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2, t3, t4, t5, t6, t7 ); - else - THROW_RUNTIME_ERROR( R ) - } - - /// Invokes the callback. This function can sometimes be more convenient than the operator(), - /// which does the same thing. - R Call( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2, t3, t4, t5, t6, t7 ); - else - THROW_RUNTIME_ERROR( R ) - } - - private: - class Base { - public: - Base() {} - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ) = 0; - virtual bool operator==( const Base& rhs ) const = 0; - virtual bool operator<( const Base& rhs ) const = 0; - virtual void* Comp() const = 0; // Returns a pointer used in comparisons. - }; - - class ChildFree : public Base { - public: - ChildFree( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ) ) : - mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ) { - return mFunc( t0, t1, t2, t3, t4, t5, t6, t7 ); - } - - virtual bool operator==( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return mFunc < r->mFunc; - else - return true; // Free functions will always be less than methods (because comp - // returns 0). - } - - virtual void* Comp() const { return 0; } - - private: - R ( *const mFunc )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ); - }; - - template class ChildMethod : public Base { - public: - ChildMethod( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, - T7 t7 ) ) : - mObj( object ), mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ) { - return ( mObj->*mFunc )( t0, t1, t2, t3, t4, t5, t6, t7 ); - } - - virtual bool operator==( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) - return ( mObj == r->mObj ) && ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) { - if ( mObj != r->mObj ) - return mObj < r->mObj; - else - return 0 > memcmp( (void*)&mFunc, (void*)&( r->mFunc ), sizeof( mFunc ) ); - } else - return mObj < rhs.Comp(); - } - - virtual void* Comp() const { return mObj; } - - private: - C* const mObj; - R ( C::*const mFunc )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ); - }; - - /// This class is only to find the worst case method pointer size. - class unknown; - - char mMem[sizeof( ChildMethod )]; // Reserve memory for creating useful objects later. - Base* mCallback; -}; - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback8 -Make8( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ) ) { - return Callback8( object, function ); -} - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback8 -Make8( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7 ) ) { - return Callback8( function ); -} - -/// Stores a callback for a function taking 9 parameters. -///\tparam R Callback function return type. -template -class Callback9 { - public: - /// Constructs the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - Callback9( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, - T7 t7, T8 t8 ) ) : - mCallback( new ( &mMem ) ChildMethod( object, function ) ) {} - - /// Constructs the callback to a free function or static member function. - ///\param function Free function address to call. - Callback9( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8 ) ) : - mCallback( new ( &mMem ) ChildFree( function ) ) {} - - /// Constructs a callback that can later be set. - Callback9() : mCallback( 0 ) {} - - Callback9( const Callback9& c ) : mCallback( c.mCallback ) { - if ( mCallback ) { - memcpy( mMem, c.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - } - - Callback9& operator=( const Callback9& rhs ) { - mCallback = rhs.mCallback; - if ( mCallback ) { - memcpy( mMem, rhs.mMem, sizeof( mMem ) ); - mCallback = reinterpret_cast( &mMem ); - } - - return *this; - } - - ~Callback9() {} - - /// Sets the callback to a specific object and member function. - ///\param object Pointer to the object to call upon. Care should be taken that this object - /// remains valid as long as the callback may be invoked. \param function Member function - /// address to call. - template - void Reset( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, - T7 t7, T8 t8 ) ) { - mCallback = new ( &mMem ) ChildMethod( object, function ); - } - - /// Sets the callback to a free function or static member function. - ///\param function Free function address to call. - void Reset( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8 ) ) { - mCallback = new ( &mMem ) ChildFree( function ); - } - - /// Resests to callback to nothing. - void Reset() { mCallback = 0; } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator==( const Callback9& rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) == ( *( rhs.mCallback ) ); - else - return mCallback == rhs.mCallback; - } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator!=( const Callback9& rhs ) const { return !( *this == rhs ); } - - /// Note that comparison operators may not work with virtual function callbacks. - bool operator<( const Callback9 rhs ) const { - if ( mCallback && rhs.mCallback ) - return ( *mCallback ) < ( *( rhs.mCallback ) ); - else - return mCallback < rhs.mCallback; - } - - /// Returns true if the callback has been set, or false if the callback is not set and is - /// invalid. - bool IsSet() const { return 0 != mCallback; } - - /// Invokes the callback. - R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2, t3, t4, t5, t6, t7, t8 ); - else - THROW_RUNTIME_ERROR( R ) - } - - /// Invokes the callback. This function can sometimes be more convenient than the operator(), - /// which does the same thing. - R Call( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8 ) const { - if ( mCallback ) - return ( *mCallback )( t0, t1, t2, t3, t4, t5, t6, t7, t8 ); - else - THROW_RUNTIME_ERROR( R ) - } - - private: - class Base { - public: - Base() {} - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8 ) = 0; - virtual bool operator==( const Base& rhs ) const = 0; - virtual bool operator<( const Base& rhs ) const = 0; - virtual void* Comp() const = 0; // Returns a pointer used in comparisons. - }; - - class ChildFree : public Base { - public: - ChildFree( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, - T8 t8 ) ) : - mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8 ) { - return mFunc( t0, t1, t2, t3, t4, t5, t6, t7, t8 ); - } - - virtual bool operator==( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildFree* const r = dynamic_cast( &rhs ); - if ( r ) - return mFunc < r->mFunc; - else - return true; // Free functions will always be less than methods (because comp - // returns 0). - } - - virtual void* Comp() const { return 0; } - - private: - R ( *const mFunc )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8 ); - }; - - template class ChildMethod : public Base { - public: - ChildMethod( C* object, R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, - T7 t7, T8 t8 ) ) : - mObj( object ), mFunc( function ) {} - - virtual R operator()( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8 ) { - return ( mObj->*mFunc )( t0, t1, t2, t3, t4, t5, t6, t7, t8 ); - } - - virtual bool operator==( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) - return ( mObj == r->mObj ) && ( mFunc == r->mFunc ); - else - return false; - } - - virtual bool operator<( const Base& rhs ) const { - const ChildMethod* const r = dynamic_cast*>( &rhs ); - if ( r ) { - if ( mObj != r->mObj ) - return mObj < r->mObj; - else - return 0 > memcmp( (void*)&mFunc, (void*)&( r->mFunc ), sizeof( mFunc ) ); - } else - return mObj < rhs.Comp(); - } - - virtual void* Comp() const { return mObj; } - - private: - C* const mObj; - R ( C::*const mFunc )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8 ); - }; - - /// This class is only to find the worst case method pointer size. - class unknown; - - char mMem[sizeof( ChildMethod )]; // Reserve memory for creating useful objects later. - Base* mCallback; -}; - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback9 -Make9( C* object, - R ( C::*function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8 ) ) { - return Callback9( object, function ); -} - -/// Helper function to construct a callback without bothering to specify template parameters. -template -Callback9 -Make9( R ( *function )( T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8 ) ) { - return Callback9( function ); -} - -} // namespace cb -#endif /*__CALLBACK_HPP__*/ diff --git a/include/eepp/ui/tools/textureatlaseditor.hpp b/include/eepp/ui/tools/textureatlaseditor.hpp index ce36f73cc..4b151abbc 100644 --- a/include/eepp/ui/tools/textureatlaseditor.hpp +++ b/include/eepp/ui/tools/textureatlaseditor.hpp @@ -94,7 +94,7 @@ class EE_API TextureAtlasEditor { void update(); - UIWidget* createTextureAtlasTextureRegionEditor( std::string name ); + UIWidget* createTextureAtlasTextureRegionEditor(); }; }}} // namespace EE::UI::Tools diff --git a/premake4.lua b/premake4.lua index f71bd58c6..8a720e4d3 100644 --- a/premake4.lua +++ b/premake4.lua @@ -165,6 +165,7 @@ newoption { trigger = "with-mold-linker", description = "Tries to use the mold l newoption { trigger = "with-debug-symbols", description = "Release builds are built with debug symbols." } newoption { trigger = "thread-sanitizer", description ="Compile with ThreadSanitizer." } newoption { trigger = "address-sanitizer", description = "Compile with AddressSanitizer." } +newoption { trigger = "time-trace", description = "Compile with time trace." } newoption { trigger = "with-backend", description = "Select the backend to use for window and input handling.\n\t\t\tIf no backend is selected or if the selected is not installed the script will search for a backend present in the system, and will use it.", @@ -712,6 +713,10 @@ function parse_args() links { "asan" } end end + + if _OPTIONS["time-trace"] then + buildoptions { "-ftime-trace" } + end end function add_static_links() diff --git a/premake5.lua b/premake5.lua index 8d7763c56..451e00a88 100644 --- a/premake5.lua +++ b/premake5.lua @@ -13,6 +13,7 @@ newoption { trigger = "with-mold-linker", description = "Tries to use the mold l newoption { trigger = "with-debug-symbols", description = "Release builds are built with debug symbols." } newoption { trigger = "thread-sanitizer", description = "Compile with ThreadSanitizer." } newoption { trigger = "address-sanitizer", description = "Compile with AddressSanitizer." } +newoption { trigger = "time-trace", description = "Compile with time tracing." } newoption { trigger = "with-backend", description = "Select the backend to use for window and input handling.\n\t\t\tIf no backend is selected or if the selected is not installed the script will search for a backend present in the system, and will use it.", @@ -454,6 +455,10 @@ function parse_args() links { "asan" } end end + + if _OPTIONS["time-trace"] then + buildoptions { "-ftime-trace" } + end end function add_static_links() diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index eceab5180..b6fac7308 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -1173,7 +1173,6 @@ ProjectExplorer.CustomExecutableRunConfiguration true - --css=/root/.config/ecode/style.css --language=de 0 false 1 diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 7135e3940..7eac524e5 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -301,7 +301,6 @@ ../../include/eepp/thirdparty/chipmunk/cpSpace.h ../../include/eepp/thirdparty/chipmunk/cpSpatialIndex.h ../../include/eepp/thirdparty/chipmunk/cpVect.h -../../include/eepp/thirdparty/PlusCallback/callback.hpp ../../include/eepp/ui/models/model.hpp ../../include/eepp/ui/abstract/uiabstracttableview.hpp ../../include/eepp/ui/abstract/uiabstractview.hpp diff --git a/src/eepp/graphics/particlesystem.cpp b/src/eepp/graphics/particlesystem.cpp index 599673269..4dcd6a79d 100644 --- a/src/eepp/graphics/particlesystem.cpp +++ b/src/eepp/graphics/particlesystem.cpp @@ -307,7 +307,7 @@ void ParticleSystem::reset( Particle* P ) { break; } case ParticleEffect::Callback: { - if ( mPC.IsSet() ) { + if ( mPC ) { mPC( P, this ); } diff --git a/src/eepp/ui/tools/textureatlaseditor.cpp b/src/eepp/ui/tools/textureatlaseditor.cpp index 94935b823..a742ed5f0 100644 --- a/src/eepp/ui/tools/textureatlaseditor.cpp +++ b/src/eepp/ui/tools/textureatlaseditor.cpp @@ -15,7 +15,7 @@ namespace EE { namespace UI { namespace Tools { -UIWidget* TextureAtlasEditor::createTextureAtlasTextureRegionEditor( std::string ) { +UIWidget* TextureAtlasEditor::createTextureAtlasTextureRegionEditor() { mTextureRegionEditor = TextureAtlasTextureRegionEditor::New( this ); return mTextureRegionEditor; } @@ -113,9 +113,9 @@ TextureAtlasEditor::TextureAtlasEditor( UIWindow* attachTo, const TGEditorCloseC )xml"; - UIWidgetCreator::addCustomWidgetCallback( - "TextureAtlasTextureRegionEditor", - cb::Make1( this, &TextureAtlasEditor::createTextureAtlasTextureRegionEditor ) ); + UIWidgetCreator::addCustomWidgetCallback( "TextureAtlasTextureRegionEditor", [this]( auto ) { + return createTextureAtlasTextureRegionEditor(); + } ); if ( NULL != mUIContainer->getSceneNode()->asType()->getUIThemeManager() ) mUIContainer->getSceneNode()->asType()->loadLayoutFromString( layout, @@ -125,56 +125,53 @@ TextureAtlasEditor::TextureAtlasEditor( UIWindow* attachTo, const TGEditorCloseC mUIContainer->bind( "TextureRegionList", mTextureRegionList ); mTextureRegionList->addEventListener( - Event::OnItemSelected, cb::Make1( this, &TextureAtlasEditor::onTextureRegionChange ) ); + Event::OnItemSelected, [this]( auto event ) { onTextureRegionChange( event ); } ); mUIContainer->bind( "gridlayout", mTextureRegionGrid ); mUIContainer->bind( "offX", mSpinOffX ); mSpinOffX->addEventListener( Event::OnValueChange, - cb::Make1( this, &TextureAtlasEditor::onOffXChange ) ); + [this]( auto event ) { onOffXChange( event ); } ); mUIContainer->bind( "offY", mSpinOffY ); mSpinOffY->addEventListener( Event::OnValueChange, - cb::Make1( this, &TextureAtlasEditor::onOffYChange ) ); + [this]( auto event ) { onOffYChange( event ); } ); mUIContainer->bind( "destW", mSpinDestW ); mSpinDestW->addEventListener( Event::OnValueChange, - cb::Make1( this, &TextureAtlasEditor::onDestWChange ) ); + [this]( auto event ) { onDestWChange( event ); } ); mUIContainer->bind( "destH", mSpinDestH ); mSpinDestH->addEventListener( Event::OnValueChange, - cb::Make1( this, &TextureAtlasEditor::onDestHChange ) ); + [this]( auto event ) { onDestHChange( event ); } ); mUIContainer->bind( "textureFilter", mTextureFilterList ); mTextureFilterList->addEventListener( - Event::OnItemSelected, cb::Make1( this, &TextureAtlasEditor::onTextureFilterChange ) ); + Event::OnItemSelected, [this]( auto event ) { onTextureFilterChange( event ); } ); mUIContainer->find( "resetDest" ) - ->addEventListener( Event::MouseClick, - cb::Make1( this, &TextureAtlasEditor::onResetDestSize ) ); + ->addEventListener( Event::MouseClick, [this]( auto event ) { onResetDestSize( event ); } ); mUIContainer->find( "resetOff" ) - ->addEventListener( Event::MouseClick, - cb::Make1( this, &TextureAtlasEditor::onResetOffset ) ); + ->addEventListener( Event::MouseClick, [this]( auto event ) { onResetOffset( event ); } ); mUIContainer->find( "centerOff" ) - ->addEventListener( Event::MouseClick, - cb::Make1( this, &TextureAtlasEditor::onCenterOffset ) ); + ->addEventListener( Event::MouseClick, [this]( auto event ) { onCenterOffset( event ); } ); mUIContainer->find( "hbotOff" ) - ->addEventListener( Event::MouseClick, cb::Make1( this, &TextureAtlasEditor::onHBOffset ) ); + ->addEventListener( Event::MouseClick, [this]( auto event ) { onHBOffset( event ); } ); mUIContainer->find( "fileMenu" ) ->addEventListener( Event::OnItemClicked, - cb::Make1( this, &TextureAtlasEditor::fileMenuClick ) ); + [this]( auto event ) { fileMenuClick( event ); } ); if ( NULL != mUIWindow ) { mUIWindow->setTitle( "Texture Atlas Editor" ); mUIWindow->addEventListener( Event::OnWindowClose, - cb::Make1( this, &TextureAtlasEditor::windowClose ) ); + [this]( auto event ) { windowClose( event ); } ); } else { mUIContainer->addEventListener( Event::OnClose, - cb::Make1( this, &TextureAtlasEditor::windowClose ) ); + [this]( auto event ) { windowClose( event ); } ); mUIContainer->find( "texture_atlas_editor_root" ) ->setThemeSkin( mUIContainer->getSceneNode() ->asType() @@ -291,14 +288,14 @@ void TextureAtlasEditor::fileMenuClick( const Event* Event ) { const String& txt = Event->getNode()->asType()->getText(); if ( "New..." == txt ) { - eeNew( TextureAtlasNew, ( cb::Make1( this, &TextureAtlasEditor::onTextureAtlasCreate ) ) ); + eeNew( TextureAtlasNew, ( [this]( auto event ) { onTextureAtlasCreate( event ); } ) ); } else if ( "Open..." == txt ) { UIFileDialog* TGDialog = UIFileDialog::New( UIFileDialog::DefaultFlags, std::string( "*" ) + EE_TEXTURE_ATLAS_EXTENSION ); TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Open Texture Atlas" ); TGDialog->addEventListener( Event::OpenFile, - cb::Make1( this, &TextureAtlasEditor::openTextureAtlas ) ); + [this]( auto event ) { openTextureAtlas( event ); } ); TGDialog->center(); TGDialog->show(); } else if ( "Save" == txt ) { @@ -311,7 +308,7 @@ void TextureAtlasEditor::fileMenuClick( const Event* Event ) { "Do you really want to close the current " "texture atlas?\nAll changes will be lost." ); MsgBox->addEventListener( Event::OnConfirm, - cb::Make1( this, &TextureAtlasEditor::onTextureAtlasClose ) ); + [this]( auto event ) { onTextureAtlasClose( event ); } ); MsgBox->setTitle( "Close Texture Atlas?" ); MsgBox->center(); MsgBox->show(); @@ -350,7 +347,7 @@ void TextureAtlasEditor::onTextureAtlasCreate( TexturePacker* TexPacker ) { mTextureAtlasLoader = TextureAtlasLoader::New( FPath, Engine::instance()->isThreaded(), - cb::Make1( this, &TextureAtlasEditor::onTextureAtlasLoaded ) ); + [this]( auto event ) { onTextureAtlasLoaded( event ); } ); } void TextureAtlasEditor::updateWidgets() { @@ -400,7 +397,7 @@ void TextureAtlasEditor::fillTextureRegionList() { ->setGravity( UI_HALIGN_CENTER | UI_VALIGN_CENTER ) ->setParent( mTextureRegionGrid ) ->addEventListener( Event::MouseClick, - cb::Make1( this, &TextureAtlasEditor::onTextureRegionChange ) ); + [this]( auto event ) { onTextureRegionChange( event ); } ); ; } } @@ -449,7 +446,7 @@ void TextureAtlasEditor::openTextureAtlas( const Event* Event ) { mTextureAtlasLoader = TextureAtlasLoader::New( Event->getNode()->asType()->getFullPath(), Engine::instance()->isThreaded(), - cb::Make1( this, &TextureAtlasEditor::onTextureAtlasLoaded ) ); + [this]( auto event ) { onTextureAtlasLoaded( event ); } ); } void TextureAtlasEditor::onTextureAtlasLoaded( TextureAtlasLoader* textureAtlasLoader ) { diff --git a/src/eepp/ui/tools/textureatlasnew.cpp b/src/eepp/ui/tools/textureatlasnew.cpp index f78d431ec..1e0dd1240 100644 --- a/src/eepp/ui/tools/textureatlasnew.cpp +++ b/src/eepp/ui/tools/textureatlasnew.cpp @@ -16,7 +16,7 @@ TextureAtlasNew::TextureAtlasNew( TGCreateCb NewTGCb ) : mUIWindow( NULL ), mNew UI_WIN_MODAL ); mUIWindow->addEventListener( Event::OnWindowClose, - cb::Make1( this, &TextureAtlasNew::windowClose ) ); + [this] ( auto event ) { windowClose( event ); } ); mUIWindow->setTitle( "New Texture Atlas" ); static const auto layout = R"xml( @@ -105,11 +105,11 @@ TextureAtlasNew::TextureAtlasNew( TGCreateCb NewTGCb ) : mUIWindow( NULL ), mNew mComboHeight->getListBox()->setSelected( "2048" ); mSetPathButton->addEventListener( Event::MouseClick, - cb::Make1( this, &TextureAtlasNew::onDialogFolderSelect ) ); + [this] ( auto event ) { onDialogFolderSelect( event ); } ); mUIWindow->find( "okButton" ) - ->addEventListener( Event::MouseClick, cb::Make1( this, &TextureAtlasNew::okClick ) ); + ->addEventListener( Event::MouseClick, [this] ( auto event ) { okClick( event ); } ); mUIWindow->find( "cancelButton" ) - ->addEventListener( Event::MouseClick, cb::Make1( this, &TextureAtlasNew::cancelClick ) ); + ->addEventListener( Event::MouseClick, [this] ( auto event ) { cancelClick( event ); } ); container->addEventListener( Event::OnLayoutUpdate, [this]( const Event* event ) { mUIWindow->setMinWindowSize( event->getNode()->getSize() ); @@ -133,7 +133,7 @@ void TextureAtlasNew::okClick( const Event* event ) { TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Save Texture Atlas" ); TGDialog->addEventListener( Event::SaveFile, - cb::Make1( this, &TextureAtlasNew::textureAtlasSave ) ); + [this] ( auto event ) { textureAtlasSave( event ); } ); TGDialog->center(); TGDialog->show(); } @@ -212,7 +212,7 @@ void TextureAtlasNew::onDialogFolderSelect( const Event* event ) { TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Create Texture Atlas ( Select Folder Containing Textures )" ); TGDialog->addEventListener( Event::OpenFile, - cb::Make1( this, &TextureAtlasNew::onSelectFolder ) ); + [this] ( auto event ) { onSelectFolder( event ); } ); TGDialog->center(); TGDialog->show(); } diff --git a/src/eepp/ui/tools/uicolorpicker.cpp b/src/eepp/ui/tools/uicolorpicker.cpp index f3805146b..6b4f98fde 100644 --- a/src/eepp/ui/tools/uicolorpicker.cpp +++ b/src/eepp/ui/tools/uicolorpicker.cpp @@ -248,10 +248,10 @@ UIColorPicker::UIColorPicker( UIWindow* attachTo, const UIColorPicker::ColorPick if ( NULL != mUIWindow ) { mUIWindow->setTitle( "Color Picker" ); mUIWindow->addEventListener( Event::OnWindowClose, - cb::Make1( this, &UIColorPicker::windowClose ) ); + [this] ( auto event ) { windowClose( event ); } ); } else { mUIContainer->addEventListener( Event::OnClose, - cb::Make1( this, &UIColorPicker::windowClose ) ); + [this] ( auto event ) { windowClose( event ); } ); } if ( NULL != mUIWindow && mUIWindow->isModal() ) { diff --git a/src/eepp/ui/uidropdownlist.cpp b/src/eepp/ui/uidropdownlist.cpp index 010fd8d6c..6dbec8c03 100644 --- a/src/eepp/ui/uidropdownlist.cpp +++ b/src/eepp/ui/uidropdownlist.cpp @@ -38,15 +38,15 @@ UIDropDownList::UIDropDownList( const std::string& tag ) : mListBox->setParent( this ); mListBox->addEventListener( Event::OnWidgetFocusLoss, - cb::Make1( this, &UIDropDownList::onListBoxFocusLoss ) ); + [this] ( auto event ) { onListBoxFocusLoss( event ); } ); mListBox->addEventListener( Event::OnItemSelected, - cb::Make1( this, &UIDropDownList::onItemSelected ) ); + [this] ( auto event ) { onItemSelected( event ); } ); mListBox->addEventListener( Event::OnItemClicked, - cb::Make1( this, &UIDropDownList::onItemClicked ) ); + [this] ( auto event ) { onItemClicked( event ); } ); mListBox->addEventListener( Event::OnItemKeyDown, - cb::Make1( this, &UIDropDownList::onItemKeyDown ) ); - mListBox->addEventListener( Event::KeyDown, cb::Make1( this, &UIDropDownList::onItemKeyDown ) ); - mListBox->addEventListener( Event::OnClear, cb::Make1( this, &UIDropDownList::onWidgetClear ) ); + [this] ( auto event ) { onItemKeyDown( event ); } ); + mListBox->addEventListener( Event::KeyDown, [this] ( auto event ) { onItemKeyDown( event ); } ); + mListBox->addEventListener( Event::OnClear, [this] ( auto event ) { onWidgetClear( event ); } ); mListBox->addEventListener( Event::OnClose, [this]( const Event* ) { mListBox = nullptr; } ); mListBox->addEventListener( Event::OnSelectionChanged, [this]( auto ) { if ( !mListBox->hasSelection() ) diff --git a/src/eepp/ui/uifiledialog.cpp b/src/eepp/ui/uifiledialog.cpp index 6b7d130cb..b7d1a95a1 100644 --- a/src/eepp/ui/uifiledialog.cpp +++ b/src/eepp/ui/uifiledialog.cpp @@ -80,7 +80,7 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, const std::string& defaultFilePa ->setLayoutSizePolicy( SizePolicy::WrapContent, SizePolicy::WrapContent ) ->setLayoutWeight( 1 ) ->setParent( hLayout ); - mPath->addEventListener( Event::OnPressEnter, cb::Make1( this, &UIFileDialog::onPressEnter ) ); + mPath->addEventListener( Event::OnPressEnter, [this] ( auto event ) { onPressEnter( event ); } ); mButtonUp = UIPushButton::New(); mButtonUp->setText( i18n( "uifiledialog_go_up", "Up" ) ) @@ -198,7 +198,7 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, const std::string& defaultFilePa ->setParent( hLayout ); mFile->setLayoutMargin( Rectf( 0, 0, 4, 0 ) ); mFile->addEventListener( Event::OnPressEnter, - cb::Make1( this, &UIFileDialog::onPressFileEnter ) ); + [this] ( auto event ) { onPressFileEnter( event ); } ); mButtonOpen = UIPushButton::New(); mButtonOpen diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index 35fd11c97..7511efb11 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -59,7 +59,7 @@ UIListBox::UIListBox( const std::string& tag ) : mVScrollBar->setEnabled( false )->setVisible( false ); mVScrollBar->addEventListener( Event::OnSizeChange, cb ); mVScrollBar->addEventListener( Event::OnValueChange, - cb::Make1( this, &UIListBox::onScrollValueChange ) ); + [this] ( auto event ) { onScrollValueChange( event ); } ); mHScrollBar = UIScrollBar::NewHorizontal(); mHScrollBar->setParent( this ); @@ -68,7 +68,7 @@ UIListBox::UIListBox( const std::string& tag ) : mHScrollBar->setEnabled( false )->setVisible( false ); mHScrollBar->addEventListener( Event::OnSizeChange, cb ); mHScrollBar->addEventListener( Event::OnValueChange, - cb::Make1( this, &UIListBox::onHScrollValueChange ) ); + [this] ( auto event ) { onHScrollValueChange( event ); } ); mDummyItem = createListBoxItem( "" ); mDummyItem->setSize( 0, 0 ); diff --git a/src/eepp/ui/uiscrollablewidget.cpp b/src/eepp/ui/uiscrollablewidget.cpp index bc3f3a843..29cb7cca0 100644 --- a/src/eepp/ui/uiscrollablewidget.cpp +++ b/src/eepp/ui/uiscrollablewidget.cpp @@ -19,9 +19,9 @@ UIScrollableWidget::UIScrollableWidget( const std::string& tag ) : mHScroll->setParent( this ); mVScroll->addEventListener( Event::OnValueChange, - cb::Make1( this, &UIScrollableWidget::onValueChangeCb ) ); + [this] ( auto event ) { onValueChangeCb( event ); } ); mHScroll->addEventListener( Event::OnValueChange, - cb::Make1( this, &UIScrollableWidget::onValueChangeCb ) ); + [this] ( auto event ) { onValueChangeCb( event ); } ); applyDefaultTheme(); } diff --git a/src/eepp/ui/uiscrollbar.cpp b/src/eepp/ui/uiscrollbar.cpp index 47ac23ec5..c1e78519b 100644 --- a/src/eepp/ui/uiscrollbar.cpp +++ b/src/eepp/ui/uiscrollbar.cpp @@ -61,7 +61,7 @@ UIScrollBar::UIScrollBar( const std::string& tag, const UIOrientation& orientati mSlider->setAllowHalfSliderOut( false ); mSlider->setExpandBackground( false ); mSlider->addEventListener( Event::OnValueChange, - cb::Make1( this, &UIScrollBar::onValueChangeCb ) ); + [this] ( auto event ) { onValueChangeCb( event ); } ); if ( orientation == UIOrientation::Vertical ) { mSlider->getSliderButton()->setElementTag( mTag + "::vbutton" ); mSlider->getBackSlider()->setElementTag( mTag + "::vback" ); diff --git a/src/eepp/ui/uiscrollview.cpp b/src/eepp/ui/uiscrollview.cpp index 368ed526e..f6868ca21 100644 --- a/src/eepp/ui/uiscrollview.cpp +++ b/src/eepp/ui/uiscrollview.cpp @@ -30,9 +30,9 @@ UIScrollView::UIScrollView() : mContainer->enableReportSizeChangeToChilds(); mVScroll->addEventListener( Event::OnValueChange, - cb::Make1( this, &UIScrollView::onValueChangeCb ) ); + [this] ( auto event ) { onValueChangeCb( event ); } ); mHScroll->addEventListener( Event::OnValueChange, - cb::Make1( this, &UIScrollView::onValueChangeCb ) ); + [this] ( auto event ) { onValueChangeCb( event ); } ); applyDefaultTheme(); } @@ -76,9 +76,9 @@ void UIScrollView::onChildCountChange( Node* child, const bool& removed ) { mScrollView = child; mScrollView->setParent( mContainer ); mSizeChangeCb = mScrollView->addEventListener( - Event::OnSizeChange, cb::Make1( this, &UIScrollView::onScrollViewSizeChange ) ); + Event::OnSizeChange, [this] ( auto event ) { onScrollViewSizeChange( event ); } ); mPosChangeCb = mScrollView->addEventListener( - Event::OnPositionChange, cb::Make1( this, &UIScrollView::onScrollViewPositionChange ) ); + Event::OnPositionChange, [this] ( auto event ) { onScrollViewPositionChange( event ); } ); containerUpdate(); } diff --git a/src/eepp/ui/uiwidgettable.cpp b/src/eepp/ui/uiwidgettable.cpp index f715d4e39..a99768db3 100644 --- a/src/eepp/ui/uiwidgettable.cpp +++ b/src/eepp/ui/uiwidgettable.cpp @@ -58,9 +58,9 @@ UIWidgetTable::UIWidgetTable() : mVScrollBar->setEnabled( ScrollBarMode::AlwaysOn == mVScrollMode ); mVScrollBar->addEventListener( Event::OnValueChange, - cb::Make1( this, &UIWidgetTable::onScrollValueChange ) ); + [this] ( auto event ) { onScrollValueChange( event ); } ); mHScrollBar->addEventListener( Event::OnValueChange, - cb::Make1( this, &UIWidgetTable::onScrollValueChange ) ); + [this] ( auto event ) { onScrollValueChange( event ); } ); mVScrollBar->addEventListener( Event::OnSizeChange, cb ); mHScrollBar->addEventListener( Event::OnSizeChange, cb ); diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index 929964930..f46865dcb 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -84,7 +84,7 @@ UIWindow::UIWindow( UIWindow::WindowBaseContainerType type, const StyleConfig& w mContainer->setClipType( ClipType::ContentBox ); mContainer->enableReportSizeChangeToChilds(); mContainer->addEventListener( Event::OnPositionChange, - cb::Make1( this, &UIWindow::onContainerPositionChange ) ); + [this] ( auto event ) { onContainerPositionChange( event ); } ); updateWinFlags(); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/mapeditor.cpp b/src/modules/maps/src/eepp/maps/mapeditor/mapeditor.cpp index c05f573a3..c245fcf52 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/mapeditor.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/mapeditor.cpp @@ -73,11 +73,11 @@ MapEditor::MapEditor( UIWindow* AttatchTo, const MapEditorCloseCb& callback ) : mUIContainer = mUIWindow->getContainer(); mUIWindow->setTitle( "Map Editor" ); mUIWindow->addEventListener( Event::OnWindowClose, - cb::Make1( this, &MapEditor::windowClose ) ); + [this]( auto event ) { windowClose( event ); } ); } else { mUIContainer = SceneManager::instance()->getUISceneNode(); mUIContainer->addEventListener( Event::OnClose, - cb::Make1( this, &MapEditor::windowClose ) ); + [this]( auto event ) { windowClose( event ); } ); } createME(); @@ -139,7 +139,7 @@ void MapEditor::createMenuBar() { PU1->add( "Quit", PU1->getUISceneNode()->findIconDrawable( "quit", PixelDensity::dpToPxI( 16 ) ) ); - PU1->addEventListener( Event::OnItemClicked, cb::Make1( this, &MapEditor::fileMenuClick ) ); + PU1->addEventListener( Event::OnItemClicked, [this]( auto event ) { fileMenuClick( event ); } ); MenuBar->addMenuButton( "File", PU1 ); UIPopUpMenu* PU3 = UIPopUpMenu::New(); @@ -166,7 +166,7 @@ void MapEditor::createMenuBar() { PU3->addSeparator(); - PU3->addEventListener( Event::OnItemClicked, cb::Make1( this, &MapEditor::viewMenuClick ) ); + PU3->addEventListener( Event::OnItemClicked, [this]( auto event ) { viewMenuClick( event ); } ); MenuBar->addMenuButton( "View", PU3 ); UIPopUpMenu* PU4 = UIPopUpMenu::New(); @@ -174,7 +174,7 @@ void MapEditor::createMenuBar() { PU4->add( "Properties..." ); PU4->add( "Resize..." ); - PU4->addEventListener( Event::OnItemClicked, cb::Make1( this, &MapEditor::mapMenuClick ) ); + PU4->addEventListener( Event::OnItemClicked, [this]( auto event ) { mapMenuClick( event ); } ); MenuBar->addMenuButton( "Map", PU4 ); UIPopUpMenu* PU5 = UIPopUpMenu::New(); @@ -196,7 +196,8 @@ void MapEditor::createMenuBar() { mLayerChkVisible = PU5->addCheckBox( "Visible" ); - PU5->addEventListener( Event::OnItemClicked, cb::Make1( this, &MapEditor::layerMenuClick ) ); + PU5->addEventListener( Event::OnItemClicked, + [this]( auto event ) { layerMenuClick( event ); } ); MenuBar->addMenuButton( "Layer", PU5 ); UIPopUpMenu* PU6 = UIPopUpMenu::New(); @@ -204,7 +205,7 @@ void MapEditor::createMenuBar() { PU6->add( "New Texture Atlas..." ); PU6->add( "Add External Texture Atlas..." ); MenuBar->addMenuButton( "Atlases", PU6 ); - PU6->addEventListener( Event::OnItemClicked, cb::Make1( this, &MapEditor::mapMenuClick ) ); + PU6->addEventListener( Event::OnItemClicked, [this]( auto event ) { mapMenuClick( event ); } ); mWinContainer = UIWidget::New(); mWinContainer->enableReportSizeChangeToChilds(); @@ -249,7 +250,7 @@ void MapEditor::createETGMenu() { ->setPosition( ContPosX, DistFromTopMenu ); mTabWidget->addEventListener( Event::OnTabSelected, - cb::Make1( this, &MapEditor::onTabSelected ) ); + [this]( auto event ) { onTabSelected( event ); } ); createTabs(); @@ -313,7 +314,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { ->setPosition( TAB_CONT_X_DIST, Txt->getPosition().y + Txt->getSize().getHeight() + 4 ); mGOTypeList->addEventListener( Event::OnItemSelected, - cb::Make1( this, &MapEditor::onTypeChange ) ); + [this]( auto event ) { onTypeChange( event ); } ); fillGotyList(); mBtnGOTypeAdd = UIPushButton::New(); @@ -327,7 +328,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { ->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); mBtnGOTypeAdd->setTooltipText( "Adds a new game object type\nunknown by the map editor." ); mBtnGOTypeAdd->addEventListener( Event::MouseClick, - cb::Make1( this, &MapEditor::addNewGOType ) ); + [this]( auto event ) { addNewGOType( event ); } ); if ( NULL == mBtnGOTypeAdd->getIcon()->getDrawable() ) mBtnGOTypeAdd->setText( "..." ); @@ -344,7 +345,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { ->setPosition( TAB_CONT_X_DIST, Txt->getPosition().y + Txt->getSize().getHeight() + 4 ); mLayerList->addEventListener( Event::OnItemSelected, - cb::Make1( this, &MapEditor::onLayerSelect ) ); + [this]( auto event ) { onLayerSelect( event ); } ); Txt = createTextBox( "Game Object Flags:", mTextureRegionCont, Sizef( Width, 16 ), Vector2f( TAB_CONT_X_DIST, mLayerList->getPosition().y + @@ -360,7 +361,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { ->setPosition( TAB_CONT_X_DIST, Txt->getPosition().y + Txt->getSize().getHeight() + 4 ); mChkMirrored->setText( "Mirrored" ); mChkMirrored->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::chkClickMirrored ) ); + [this]( auto event ) { chkClickMirrored( event ); } ); mChkFliped = UICheckBox::New(); mChkFliped->setFontStyle( Text::Shadow ) @@ -370,7 +371,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mChkMirrored->getPosition().y ); mChkFliped->setText( "Fliped" ); mChkFliped->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::chkClickFlipped ) ); + [this]( auto event ) { chkClickFlipped( event ); } ); mChkBlocked = UICheckBox::New(); mChkBlocked->setFontStyle( Text::Shadow ) @@ -381,7 +382,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mChkBlocked->setText( "Blocked" ); mChkBlocked->setTooltipText( "Blocks the tile occupied by the sprite." ); mChkBlocked->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::chkClickBlocked ) ); + [this]( auto event ) { chkClickBlocked( event ); } ); mChkAnim = UICheckBox::New(); mChkAnim->setFontStyle( Text::Shadow ) @@ -392,7 +393,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mChkAnim->setText( "Animated" ); mChkAnim->setTooltipText( "Indicates if the Sprite is animated." ); mChkAnim->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::chkClickAnimated ) ); + [this]( auto event ) { chkClickAnimated( event ); } ); mChkRot90 = UICheckBox::New(); mChkRot90->setFontStyle( Text::Shadow ) @@ -402,7 +403,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mChkBlocked->getPosition().y + mChkBlocked->getSize().getHeight() + 4 ); mChkRot90->setText( String::fromUtf8( std::string_view{ "Rotate 90ยบ" } ) ); mChkRot90->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::chkClickRot90 ) ); + [this]( auto event ) { chkClickRot90( event ); } ); mChkAutoFix = UICheckBox::New(); mChkAutoFix->setFontStyle( Text::Shadow ) @@ -414,7 +415,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mChkAutoFix->setTooltipText( "In a tiled layer if the sprite is moved,\nit will update the " "current tile position automatically." ); mChkAutoFix->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::chkClickAutoFix ) ); + [this]( auto event ) { chkClickAutoFix( event ); } ); mChkBlendAdd = UICheckBox::New(); mChkBlendAdd->setFontStyle( Text::Shadow ) @@ -425,7 +426,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mChkBlendAdd->setText( "Additive Blend" ); mChkBlendAdd->setTooltipText( "Use additive blend mode." ); mChkBlendAdd->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::chkClickAutoFix ) ); + [this]( auto event ) { chkClickAutoFix( event ); } ); Txt = createTextBox( "Game Object Data:", mTextureRegionCont, Sizef( Width, 16 ), Vector2f( TAB_CONT_X_DIST, mChkBlendAdd->getPosition().y + @@ -440,7 +441,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mChkDI->setText( "Add as DataId" ); mChkDI->setTooltipText( "If the resource it's not a sprite,\nyou can reference it with a data id" ); - mChkDI->addEventListener( Event::OnValueChange, cb::Make1( this, &MapEditor::chkClickDI ) ); + mChkDI->addEventListener( Event::OnValueChange, [this]( auto event ) { chkClickDI( event ); } ); mSGCont = UIWidget::New(); mSGCont->setParent( mTextureRegionCont ) @@ -459,8 +460,8 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { ->setParent( mSGCont ) ->setSize( Width, 0 ) ->setPosition( 0, Txt->getPosition().y + Txt->getSize().getHeight() + 4 ); - mTextureAtlasesList->addEventListener( Event::OnItemSelected, - cb::Make1( this, &MapEditor::onTextureAtlasChange ) ); + mTextureAtlasesList->addEventListener( + Event::OnItemSelected, [this]( auto event ) { onTextureAtlasChange( event ); } ); mTextureRegionList = UIListBox::New(); mTextureRegionList->setParent( mSGCont ) @@ -470,8 +471,8 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mTextureRegionList->getContainerPadding().Top + mTextureRegionList->getContainerPadding().Bottom ); mTextureRegionList->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); - mTextureRegionList->addEventListener( Event::OnItemSelected, - cb::Make1( this, &MapEditor::onTextureRegionChange ) ); + mTextureRegionList->addEventListener( + Event::OnItemSelected, [this]( auto event ) { onTextureRegionChange( event ); } ); mGfxPreview = UITextureRegion::New(); mGfxPreview->setScaleType( UIScaleType::FitInside ) @@ -510,7 +511,8 @@ void MapEditor::createLighContainer() { ->setSize( mLightCont->getSize().getWidth() - TAB_CONT_X_DIST * 2, 0 ) ->setPosition( TAB_CONT_X_DIST, 0 ); NewLightBut->setText( "New Light" ); - NewLightBut->addEventListener( Event::MouseClick, cb::Make1( this, &MapEditor::onNewLight ) ); + NewLightBut->addEventListener( Event::MouseClick, + [this]( auto event ) { onNewLight( event ); } ); UITextView* Txt = createTextBox( "Light Color:", mLightCont, Sizef(), Vector2f( TAB_CONT_X_DIST, 32 ), @@ -539,7 +541,7 @@ void MapEditor::createLighContainer() { mUIRedSlider->setMaxValue( 255 ); mUIRedSlider->setValue( 255 ); mUIRedSlider->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::onRedChange ) ); + [this]( auto event ) { onRedChange( event ); } ); mUIRedTxt = createTextBox( String::toString( (Uint32)255 ), mLightCont, Sizef(), @@ -559,7 +561,7 @@ void MapEditor::createLighContainer() { mUIGreenSlider->setMaxValue( 255 ); mUIGreenSlider->setValue( 255 ); mUIGreenSlider->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::onGreenChange ) ); + [this]( auto event ) { onGreenChange( event ); } ); mUIGreenTxt = createTextBox( String::toString( (Uint32)255 ), mLightCont, Sizef(), @@ -579,7 +581,7 @@ void MapEditor::createLighContainer() { mUIBlueSlider->setMaxValue( 255 ); mUIBlueSlider->setValue( 255 ); mUIBlueSlider->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::onBlueChange ) ); + [this]( auto event ) { onBlueChange( event ); } ); mUIBlueTxt = createTextBox( String::toString( (Uint32)255 ), mLightCont, Sizef(), @@ -599,7 +601,7 @@ void MapEditor::createLighContainer() { Txt->getPosition().y + Txt->getSize().getHeight() + 8 ); mLightRadius->setMaxValue( 2000 ); mLightRadius->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::onLightRadiusChangeVal ) ); + [this]( auto event ) { onLightRadiusChangeVal( event ); } ); mLightTypeChk = UICheckBox::New(); mLightTypeChk->setFlags( UI_AUTO_SIZE ) @@ -609,7 +611,7 @@ void MapEditor::createLighContainer() { mLightTypeChk->setText( "Isometric Light" ); mLightTypeChk->setChecked( false ); mLightTypeChk->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::onLightTypeChange ) ); + [this]( auto event ) { onLightTypeChange( event ); } ); } UISelectButton* MapEditor::addObjContButton( String text, Uint32 mode ) { @@ -620,7 +622,8 @@ UISelectButton* MapEditor::addObjContButton( String text, Uint32 mode ) { Button->setText( text ); Button->setData( mode ); - Button->addEventListener( Event::MouseClick, cb::Make1( this, &MapEditor::onObjectModeSel ) ); + Button->addEventListener( Event::MouseClick, + [this]( auto event ) { onObjectModeSel( event ); } ); mLastSelButtonY += Button->getSize().getHeight() + 4; @@ -644,7 +647,7 @@ void MapEditor::createObjectsContainer() { mChkClampToTile->resetFlags( ChkFlags )->setParent( mObjectCont )->setPosition( 12, nextY ); mChkClampToTile->setText( "Clamp Position to Tile" ); mChkClampToTile->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::chkClickClampToTile ) ); + [this]( auto event ) { chkClickClampToTile( event ); } ); mChkClampToTile->setChecked( true ); } @@ -687,14 +690,18 @@ void MapEditor::createUIMap() { mUIMap->setVisible( true ); mUIMap->setEnabled( true ); createNewEmptyMap(); - mUIMap->addEventListener( Event::OnSizeChange, cb::Make1( this, &MapEditor::onMapSizeChange ) ); - mUIMap->addEventListener( Event::MouseDown, cb::Make1( this, &MapEditor::onMapMouseDown ) ); - mUIMap->addEventListener( Event::MouseClick, cb::Make1( this, &MapEditor::onMapMouseClick ) ); - mUIMap->setLightSelectCb( cb::Make1( this, &MapEditor::onLightSelect ) ); - mUIMap->setLightRadiusChangeCb( cb::Make1( this, &MapEditor::onLightRadiusChange ) ); - mUIMap->setAddObjectCallback( cb::Make2( this, &MapEditor::onAddObject ) ); - mUIMap->setAlertCb( cb::Make2( this, &MapEditor::createAlert ) ); - mUIMap->setUpdateScrollCb( cb::Make0( this, &MapEditor::updateScroll ) ); + mUIMap->addEventListener( Event::OnSizeChange, + [this]( auto event ) { onMapSizeChange( event ); } ); + mUIMap->addEventListener( Event::MouseDown, [this]( auto event ) { onMapMouseDown( event ); } ); + mUIMap->addEventListener( Event::MouseClick, + [this]( auto event ) { onMapMouseClick( event ); } ); + mUIMap->setLightSelectCb( [this]( auto event ) { onLightSelect( event ); } ); + mUIMap->setLightRadiusChangeCb( [this]( auto event ) { onLightRadiusChange( event ); } ); + mUIMap->setAddObjectCallback( + [this]( Uint32 Type, Polygon2f poly ) { onAddObject( Type, poly ); } ); + mUIMap->setAlertCb( + [this]( const String& title, const String& text ) { return createAlert( title, text ); } ); + mUIMap->setUpdateScrollCb( [this] { updateScroll(); } ); mUIMap->setTileBox( mTileBox ); mMapHScroll = UIScrollBar::New(); @@ -704,7 +711,7 @@ void MapEditor::createUIMap() { ->setPosition( 0, mWinContainer->getSize().getHeight() - ScrollH ); mMapHScroll->setAnchors( UI_ANCHOR_LEFT | UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); mMapHScroll->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::onScrollMapH ) ); + [this]( auto event ) { onScrollMapH( event ); } ); mMapVScroll = UIScrollBar::New(); mMapVScroll->setParent( mWinContainer ) @@ -712,7 +719,7 @@ void MapEditor::createUIMap() { ->setPosition( mWinContainer->getSize().getWidth() - 225 - ScrollV, 0 ); mMapVScroll->setAnchors( UI_ANCHOR_TOP | UI_ANCHOR_BOTTOM ); mMapVScroll->addEventListener( Event::OnValueChange, - cb::Make1( this, &MapEditor::onScrollMapV ) ); + [this]( auto event ) { onScrollMapV( event ); } ); mapCreated(); } @@ -936,7 +943,9 @@ void MapEditor::chkClickAnimated( const Event* ) { } void MapEditor::addNewGOType( const Event* ) { - eeNew( UIGOTypeNew, ( cb::Make2( this, &MapEditor::onNewGOTypeAdded ) ) ); + eeNew( UIGOTypeNew, ( [this]( std::string name, String::HashType hash ) { + onNewGOTypeAdded( name, hash ); + } ) ); } void MapEditor::onNewGOTypeAdded( std::string name, String::HashType ) { @@ -1023,7 +1032,7 @@ void MapEditor::onTextureAtlasChange( const Event* ) { } void MapEditor::createNewMap() { - eeNew( UIMapNew, ( mUIMap, cb::Make0( this, &MapEditor::mapCreated ) ) ); + eeNew( UIMapNew, ( mUIMap, [this] { mapCreated(); } ) ); } void MapEditor::createNewEmptyMap() { @@ -1136,7 +1145,7 @@ void MapEditor::fileMenuClick( const Event* Event ) { UIFileDialog* TGDialog = UIFileDialog::New( UIFileDialog::DefaultFlags, "*.eem" ); TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Open Map" ); - TGDialog->addEventListener( Event::OpenFile, cb::Make1( this, &MapEditor::mapOpen ) ); + TGDialog->addEventListener( Event::OpenFile, [this]( auto event ) { mapOpen( event ); } ); TGDialog->center(); TGDialog->show(); } else if ( "Save As..." == txt ) { @@ -1144,7 +1153,7 @@ void MapEditor::fileMenuClick( const Event* Event ) { UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::SaveDialog, "*.eem" ); TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Save Map" ); - TGDialog->addEventListener( Event::SaveFile, cb::Make1( this, &MapEditor::mapSave ) ); + TGDialog->addEventListener( Event::SaveFile, [this]( auto event ) { mapSave( event ); } ); TGDialog->center(); TGDialog->show(); } else if ( "Save" == txt ) { @@ -1155,7 +1164,7 @@ void MapEditor::fileMenuClick( const Event* Event ) { UIMessageBox* MsgBox = UIMessageBox::New( UIMessageBox::OK_CANCEL, "Do you really want to close the current map?\nAll changes will be lost." ); - MsgBox->addEventListener( Event::OnConfirm, cb::Make1( this, &MapEditor::onMapClose ) ); + MsgBox->addEventListener( Event::OnConfirm, [this]( auto event ) { onMapClose( event ); } ); MsgBox->setTitle( "Close Map?" ); MsgBox->center(); MsgBox->show(); @@ -1279,13 +1288,14 @@ void MapEditor::mapMenuClick( const Event* Event ) { TGDialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); TGDialog->setTitle( "Load Texture Atlas..." ); TGDialog->addEventListener( Event::OpenFile, - cb::Make1( this, &MapEditor::cextureAtlasOpen ) ); + [this]( auto event ) { cextureAtlasOpen( event ); } ); TGDialog->center(); TGDialog->show(); } else if ( "Properties..." == txt ) { eeNew( TileMapProperties, ( mUIMap->Map() ) ); } else if ( "Resize..." ) { - eeNew( UIMapNew, ( mUIMap, cb::Make0( this, &MapEditor::onMapLoad ), true ) ); + eeNew( UIMapNew, ( + mUIMap, [this] { onMapLoad(); }, true ) ); } } @@ -1297,10 +1307,10 @@ void MapEditor::layerMenuClick( const Event* Event ) { if ( "Add Tile Layer..." == txt ) { eeNew( UIMapLayerNew, - ( mUIMap, MAP_LAYER_TILED, cb::Make1( this, &MapEditor::onLayerAdd ) ) ); + ( mUIMap, MAP_LAYER_TILED, [this]( auto event ) { onLayerAdd( event ); } ) ); } else if ( "Add Object Layer..." == txt ) { eeNew( UIMapLayerNew, - ( mUIMap, MAP_LAYER_OBJECT, cb::Make1( this, &MapEditor::onLayerAdd ) ) ); + ( mUIMap, MAP_LAYER_OBJECT, [this]( auto event ) { onLayerAdd( event ); } ) ); } else if ( "Remove Layer" == txt ) { removeLayer(); } else if ( "Move Layer Up" == txt ) { @@ -1309,8 +1319,7 @@ void MapEditor::layerMenuClick( const Event* Event ) { moveLayerDown(); } else if ( "Layer Properties..." == txt ) { if ( NULL != mCurLayer ) { - eeNew( MapLayerProperties, - ( mCurLayer, cb::Make0( this, &MapEditor::refreshLayersList ) ) ); + eeNew( MapLayerProperties, ( mCurLayer, [this] { refreshLayersList(); } ) ); } else { createNoLayerAlert( "Error retrieving layer properties" ); } diff --git a/src/modules/maps/src/eepp/maps/mapeditor/maplayerproperties.cpp b/src/modules/maps/src/eepp/maps/mapeditor/maplayerproperties.cpp index 06f068875..1a61d719d 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/maplayerproperties.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/maplayerproperties.cpp @@ -28,7 +28,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : ->setMinWindowSize( 500, 500 ); mUIWindow->addEventListener( Event::OnWindowClose, - cb::Make1( this, &MapLayerProperties::onWindowClose ) ); + [this] ( auto event ) { onWindowClose( event ); } ); mUIWindow->setTitle( "Layer Properties" ); Int32 InitialY = 16; @@ -47,7 +47,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : ->setPosition( Txt->getPosition().x + DistFromTitle, Txt->getPosition().y + DistFromTitle ); mUIInput->setText( mLayer->getName() ); mUIInput->addEventListener( Event::OnPressEnter, - cb::Make1( this, &MapLayerProperties::onOKClick ) ); + [this] ( auto event ) { onOKClick( event ); } ); UITextView* TxtBox = UITextView::New(); TxtBox->setFontStyle( Text::Shadow ) @@ -72,7 +72,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); OKButton->addEventListener( Event::MouseClick, - cb::Make1( this, &MapLayerProperties::onOKClick ) ); + [this] ( auto event ) { onOKClick( event ); } ); OKButton->setText( "OK" ); OKButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); @@ -83,7 +83,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : OKButton->getPosition().y ); CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); CancelButton->addEventListener( Event::MouseClick, - cb::Make1( this, &MapLayerProperties::onCancelClick ) ); + [this] ( auto event ) { onCancelClick( event ); } ); CancelButton->setText( "Cancel" ); CancelButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); @@ -107,7 +107,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : AddButton->setIcon( sceneNode->findIconDrawable( "add", PixelDensity::dpToPxI( 16 ) ) ); AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); AddButton->addEventListener( Event::MouseClick, - cb::Make1( this, &MapLayerProperties::onAddCellClick ) ); + [this] ( auto event ) { onAddCellClick( event ); } ); if ( NULL == AddButton->getIcon()->getDrawable() ) AddButton->setText( "+" ); @@ -119,7 +119,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : RemoveButton->setIcon( sceneNode->findIconDrawable( "remove", PixelDensity::dpToPxI( 16 ) ) ); RemoveButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); RemoveButton->addEventListener( Event::MouseClick, - cb::Make1( this, &MapLayerProperties::onRemoveCellClick ) ); + [this] ( auto event ) { onRemoveCellClick( event ); } ); if ( NULL == RemoveButton->getIcon()->getDrawable() ) RemoveButton->setText( "-" ); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/mapobjectproperties.cpp b/src/modules/maps/src/eepp/maps/mapeditor/mapobjectproperties.cpp index 3b4c1e6f2..9b54a93c4 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/mapobjectproperties.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/mapobjectproperties.cpp @@ -43,7 +43,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : ->setMinWindowSize( 500, 500 ); mUIWindow->addEventListener( Event::OnWindowClose, - cb::Make1( this, &MapObjectProperties::onWindowClose ) ); + [this] ( auto event ) { onWindowClose( event ); } ); mUIWindow->setTitle( "Object Properties" ); Int32 InitialY = 16; @@ -59,7 +59,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : mUIInput->setMaxLength( 64 ); mUIInput->setText( mObj->getName() ); mUIInput->addEventListener( Event::OnPressEnter, - cb::Make1( this, &MapObjectProperties::onOKClick ) ); + [this] ( auto event ) { onOKClick( event ); } ); UITextView* Txt2 = createTextBox( "Object type:", mUIWindow->getContainer(), Sizef(), Vector2f( 50 + 192, InitialY ), @@ -72,7 +72,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : mUIInput2->setMaxLength( 64 ); mUIInput2->setText( mObj->getTypeName() ); mUIInput2->addEventListener( Event::OnPressEnter, - cb::Make1( this, &MapObjectProperties::onOKClick ) ); + [this] ( auto event ) { onOKClick( event ); } ); Uint32 TxtBoxFlags = UI_NODE_DEFAULT_FLAGS | UI_HALIGN_CENTER | UI_VALIGN_CENTER; createTextBox( "Property Name", mUIWindow->getContainer(), Sizef( 192, 24 ), @@ -90,7 +90,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); OKButton->addEventListener( Event::MouseClick, - cb::Make1( this, &MapObjectProperties::onOKClick ) ); + [this] ( auto event ) { onOKClick( event ); } ); OKButton->setText( "OK" ); OKButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); @@ -101,7 +101,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : OKButton->getPosition().y ); CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); CancelButton->addEventListener( Event::MouseClick, - cb::Make1( this, &MapObjectProperties::onCancelClick ) ); + [this] ( auto event ) { onCancelClick( event ); } ); CancelButton->setText( "Cancel" ); CancelButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); @@ -125,7 +125,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : AddButton->setIcon( sceneNode->findIconDrawable( "add", PixelDensity::dpToPxI( 16 ) ) ); AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); AddButton->addEventListener( Event::MouseClick, - cb::Make1( this, &MapObjectProperties::onAddCellClick ) ); + [this] ( auto event ) { onAddCellClick( event ); } ); if ( NULL == AddButton->getIcon()->getDrawable() ) AddButton->setText( "+" ); @@ -137,7 +137,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : RemoveButton->setIcon( sceneNode->findIconDrawable( "remove", PixelDensity::dpToPxI( 16 ) ) ); RemoveButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); RemoveButton->addEventListener( Event::MouseClick, - cb::Make1( this, &MapObjectProperties::onRemoveCellClick ) ); + [this] ( auto event ) { onRemoveCellClick( event ); } ); if ( NULL == RemoveButton->getIcon()->getDrawable() ) RemoveButton->setText( "-" ); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/tilemapproperties.cpp b/src/modules/maps/src/eepp/maps/mapeditor/tilemapproperties.cpp index 553413bad..bd2b4a321 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/tilemapproperties.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/tilemapproperties.cpp @@ -44,7 +44,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : ->setMinWindowSize( 500, 500 ); mUIWindow->addEventListener( Event::OnWindowClose, - cb::Make1( this, &TileMapProperties::onWindowClose ) ); + [this] ( auto event ) { onWindowClose( event ); } ); mUIWindow->setTitle( "Map Properties" ); Uint32 DiffIfLights = 0; @@ -78,7 +78,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : mUIRedSlider->setMaxValue( 255 ); mUIRedSlider->setValue( mMap->getBaseColor().r ); mUIRedSlider->addEventListener( Event::OnValueChange, - cb::Make1( this, &TileMapProperties::onRedChange ) ); + [this] ( auto event ) { onRedChange( event ); } ); mUIRedTxt = createTextBox( String::toString( (Uint32)mMap->getBaseColor().r ), mUIWindow->getContainer(), Sizef(), @@ -99,7 +99,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : mUIGreenSlider->setMaxValue( 255 ); mUIGreenSlider->setValue( mMap->getBaseColor().g ); mUIGreenSlider->addEventListener( Event::OnValueChange, - cb::Make1( this, &TileMapProperties::onGreenChange ) ); + [this] ( auto event ) { onGreenChange( event ); } ); mUIGreenTxt = createTextBox( String::toString( (Uint32)mMap->getBaseColor().g ), mUIWindow->getContainer(), Sizef(), @@ -119,7 +119,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : mUIBlueSlider->setMaxValue( 255 ); mUIBlueSlider->setValue( mMap->getBaseColor().b ); mUIBlueSlider->addEventListener( Event::OnValueChange, - cb::Make1( this, &TileMapProperties::onBlueChange ) ); + [this] ( auto event ) { onBlueChange( event ); } ); mUIBlueTxt = createTextBox( String::toString( (Uint32)mMap->getBaseColor().b ), mUIWindow->getContainer(), Sizef(), @@ -142,7 +142,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); OKButton->addEventListener( Event::MouseClick, - cb::Make1( this, &TileMapProperties::onOKClick ) ); + [this] ( auto event ) { onOKClick( event ); } ); OKButton->setText( "OK" ); OKButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); @@ -153,7 +153,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : OKButton->getPosition().y ); CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); CancelButton->addEventListener( Event::MouseClick, - cb::Make1( this, &TileMapProperties::onCancelClick ) ); + [this] ( auto event ) { onCancelClick( event ); } ); CancelButton->setText( "Cancel" ); CancelButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); @@ -177,7 +177,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : AddButton->setIcon( sceneNode->findIconDrawable( "add", PixelDensity::dpToPxI( 16 ) ) ); AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); AddButton->addEventListener( Event::MouseClick, - cb::Make1( this, &TileMapProperties::onAddCellClick ) ); + [this] ( auto event ) { onAddCellClick( event ); } ); if ( NULL == AddButton->getIcon()->getDrawable() ) AddButton->setText( "+" ); @@ -189,7 +189,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : RemoveButton->setIcon( sceneNode->findIconDrawable( "remove", PixelDensity::dpToPxI( 16 ) ) ); RemoveButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); RemoveButton->addEventListener( Event::MouseClick, - cb::Make1( this, &TileMapProperties::onRemoveCellClick ) ); + [this] ( auto event ) { onRemoveCellClick( event ); } ); if ( NULL == RemoveButton->getIcon()->getDrawable() ) RemoveButton->setText( "-" ); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/uigotypenew.cpp b/src/modules/maps/src/eepp/maps/mapeditor/uigotypenew.cpp index 8f7f91804..cba453cb4 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/uigotypenew.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/uigotypenew.cpp @@ -23,7 +23,7 @@ UIGOTypeNew::UIGOTypeNew( std::function Cb ) : ->setMinWindowSize( 278, 114 ); mUIWindow->addEventListener( Event::OnWindowClose, - cb::Make1( this, &UIGOTypeNew::onWindowClose ) ); + [this] ( auto event ) { onWindowClose( event ); } ); mUIWindow->setTitle( "Add GameObject Type" ); Int32 InitialY = 16; @@ -47,8 +47,8 @@ UIGOTypeNew::UIGOTypeNew( std::function Cb ) : OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); - OKButton->addEventListener( Event::MouseClick, cb::Make1( this, &UIGOTypeNew::onOKClick ) ); - mUIInput->addEventListener( Event::OnPressEnter, cb::Make1( this, &UIGOTypeNew::onOKClick ) ); + OKButton->addEventListener( Event::MouseClick, [this] ( auto event ) { onOKClick( event ); } ); + mUIInput->addEventListener( Event::OnPressEnter, [this] ( auto event ) { onOKClick( event ); } ); OKButton->setText( "Add" ); @@ -59,7 +59,7 @@ UIGOTypeNew::UIGOTypeNew( std::function Cb ) : OKButton->getPosition().y ); CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); CancelButton->addEventListener( Event::MouseClick, - cb::Make1( this, &UIGOTypeNew::onCancelClick ) ); + [this] ( auto event ) { onCancelClick( event ); } ); CancelButton->setText( "Cancel" ); mUIWindow->center(); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/uimap.cpp b/src/modules/maps/src/eepp/maps/mapeditor/uimap.cpp index f6e0f82c1..5f120e476 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/uimap.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/uimap.cpp @@ -42,7 +42,7 @@ UIMap::UIMap( UITheme* Theme, TileMap* Map ) : mMap->setBackColor( Color( 100, 100, 100, 100 ) ); mMap->setGridLinesColor( Color( 150, 150, 150, 150 ) ); mMap->setScale( PixelDensity::getPixelDensity() ); - mMap->setDrawCallback( cb::Make0( this, &UIMap::mapDraw ) ); + mMap->setDrawCallback( [this] { mapDraw(); } ); mMap->setViewSize( mSize ); mDragButton = EE_BUTTON_MMASK; @@ -586,7 +586,7 @@ void UIMap::createObjPopUpMenu() { Menu->add( "Remove Object" ); Menu->addSeparator(); Menu->add( "Object Properties..." ); - Menu->addEventListener( Event::OnItemClicked, cb::Make1( this, &UIMap::objItemClick ) ); + Menu->addEventListener( Event::OnItemClicked, [this] ( auto event ) { objItemClick( event ); } ); if ( Menu->show() ) { Vector2f Pos = getEventDispatcher()->getMousePosf(); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/uimaplayernew.cpp b/src/modules/maps/src/eepp/maps/mapeditor/uimaplayernew.cpp index 4c69e9cde..9bc97c16c 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/uimaplayernew.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/uimaplayernew.cpp @@ -28,7 +28,7 @@ UIMapLayerNew::UIMapLayerNew( UIMap* Map, EE_LAYER_TYPE Type, NewLayerCb newLaye ->setMinWindowSize( 278, 114 ); mUIWindow->addEventListener( Event::OnWindowClose, - cb::Make1( this, &UIMapLayerNew::onWindowClose ) ); + [this] ( auto event ) { onWindowClose( event ); } ); if ( MAP_LAYER_TILED == mType ) mUIWindow->setTitle( "New Tile Layer" ); @@ -57,9 +57,9 @@ UIMapLayerNew::UIMapLayerNew( UIMap* Map, EE_LAYER_TYPE Type, NewLayerCb newLaye OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); - OKButton->addEventListener( Event::MouseClick, cb::Make1( this, &UIMapLayerNew::onOKClick ) ); + OKButton->addEventListener( Event::MouseClick, [this] ( auto event ) { onOKClick( event ); } ); mUILayerName->addEventListener( Event::OnPressEnter, - cb::Make1( this, &UIMapLayerNew::onOKClick ) ); + [this] ( auto event ) { onOKClick( event ); } ); OKButton->setText( "Add" ); @@ -70,10 +70,10 @@ UIMapLayerNew::UIMapLayerNew( UIMap* Map, EE_LAYER_TYPE Type, NewLayerCb newLaye OKButton->getPosition().y ); CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); CancelButton->addEventListener( Event::MouseClick, - cb::Make1( this, &UIMapLayerNew::onCancelClick ) ); + [this] ( auto event ) { onCancelClick( event ); } ); CancelButton->setText( "Cancel" ); - mUIWindow->addEventListener( Event::KeyUp, cb::Make1( this, &UIMapLayerNew::onOnKeyUp ) ); + mUIWindow->addEventListener( Event::KeyUp, [this] ( auto event ) { onOnKeyUp( event ); } ); mUIWindow->center(); mUIWindow->show(); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/uimapnew.cpp b/src/modules/maps/src/eepp/maps/mapeditor/uimapnew.cpp index b5155d4fa..a4fa986ad 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/uimapnew.cpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/uimapnew.cpp @@ -43,7 +43,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) ->setMinWindowSize( 320, 380 ); mUIWindow->addEventListener( Event::OnWindowClose, - cb::Make1( this, &UIMapNew::onWindowClose ) ); + [this] ( auto event ) { onWindowClose( event ); } ); if ( !mResizeMap ) { mUIWindow->setTitle( "New Map" ); @@ -217,7 +217,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) mUIRedSlider->setMaxValue( 255 ); mUIRedSlider->setValue( 255 ); mUIRedSlider->addEventListener( Event::OnValueChange, - cb::Make1( this, &UIMapNew::onRedChange ) ); + [this] ( auto event ) { onRedChange( event ); } ); mUIRedTxt = createTextBox( String::toString( 255 ), mUIWindow->getContainer(), Sizef(), @@ -242,7 +242,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) mUIGreenSlider->setMaxValue( 255 ); mUIGreenSlider->setValue( 255 ); mUIGreenSlider->addEventListener( Event::OnValueChange, - cb::Make1( this, &UIMapNew::onGreenChange ) ); + [this] ( auto event ) { onGreenChange( event ); } ); mUIGreenTxt = createTextBox( String::toString( 255 ), mUIWindow->getContainer(), Sizef(), @@ -267,7 +267,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) mUIBlueSlider->setMaxValue( 255 ); mUIBlueSlider->setValue( 255 ); mUIBlueSlider->addEventListener( Event::OnValueChange, - cb::Make1( this, &UIMapNew::onBlueChange ) ); + [this] ( auto event ) { onBlueChange( event ); } ); mUIBlueTxt = createTextBox( String::toString( 255 ), mUIWindow->getContainer(), Sizef(), @@ -285,7 +285,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); - OKButton->addEventListener( Event::MouseClick, cb::Make1( this, &UIMapNew::onOKClick ) ); + OKButton->addEventListener( Event::MouseClick, [this] ( auto event ) { onOKClick( event ); } ); OKButton->setText( "OK" ); UIPushButton* CancelButton = UIPushButton::New(); @@ -295,7 +295,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) OKButton->getPosition().y ); CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); CancelButton->addEventListener( Event::MouseClick, - cb::Make1( this, &UIMapNew::onCancelClick ) ); + [this] ( auto event ) { onCancelClick( event ); } ); CancelButton->setText( "Cancel" ); mUIWindow->center(); diff --git a/src/modules/maps/src/eepp/maps/mapeditor/uimapnew.hpp b/src/modules/maps/src/eepp/maps/mapeditor/uimapnew.hpp index 8c79d70fb..32bf40767 100644 --- a/src/modules/maps/src/eepp/maps/mapeditor/uimapnew.hpp +++ b/src/modules/maps/src/eepp/maps/mapeditor/uimapnew.hpp @@ -15,8 +15,7 @@ namespace EE { namespace Maps { namespace Private { class EE_MAPS_API UIMapNew { public: - UIMapNew( UIMap* Map, std::function NewMapCb = cb::Callback0(), - bool ResizeMap = false ); + UIMapNew( UIMap* Map, std::function NewMapCb = {}, bool ResizeMap = false ); virtual ~UIMapNew(); diff --git a/src/tests/test_all/test.cpp b/src/tests/test_all/test.cpp index 36f52b75b..4719c7daa 100644 --- a/src/tests/test_all/test.cpp +++ b/src/tests/test_all/test.cpp @@ -138,7 +138,7 @@ void EETest::init() { setScreen( StartScreen ); mWindow->setTitle( "eepp - Test Application" ); - mWindow->pushResizeCallback( cb::Make1( this, &EETest::onWindowResize ) ); + mWindow->pushResizeCallback( [this]( auto event ) { onWindowResize( event ); } ); TF = TextureFactory::instance(); TF->allocate( 40 ); @@ -152,12 +152,12 @@ void EETest::init() { PS.resize( 5 ); - Scenes[0] = cb::Make0( this, &EETest::physicsUpdate ); - Scenes[1] = cb::Make0( this, &EETest::screen1 ); - Scenes[2] = cb::Make0( this, &EETest::screen2 ); - Scenes[3] = cb::Make0( this, &EETest::screen3 ); - Scenes[4] = cb::Make0( this, &EETest::screen4 ); - Scenes[5] = cb::Make0( this, &EETest::screen5 ); + Scenes[0] = [this] { physicsUpdate(); }; + Scenes[1] = [this] { screen1(); }; + Scenes[2] = [this] { screen2(); }; + Scenes[3] = [this] { screen3(); }; + Scenes[4] = [this] { screen4(); }; + Scenes[5] = [this] { screen5(); }; setRandomSeed( static_cast( Sys::getSystemTime() * 1000 ) ); @@ -276,7 +276,7 @@ void EETest::onFontLoaded() { Con = UIConsole::NewOpt( monospace, true, true, 8191 ); Con->setQuakeMode( true ); Con->setVisible( false ); - Con->addCommand( "setparticlesnum", cb::Make1( this, &EETest::cmdSetPartsNum ) ); + Con->addCommand( "setparticlesnum", [this]( auto event ) { cmdSetPartsNum( event ); } ); mEEText.create( TTF, "Entropia Engine++\nCTRL + Number to change Demo Screen\nRight click to " "see the PopUp Menu" ); @@ -372,8 +372,8 @@ void EETest::createBaseUI() { tWin->setTitle( "Widgets Test" ); - tWin->addEventListener( Event::MouseUp, cb::Make1( this, &EETest::onWinMouseUp ) ); - C->addEventListener( Event::MouseUp, cb::Make1( this, &EETest::onWinMouseUp ) ); + tWin->addEventListener( Event::MouseUp, [this]( auto event ) { onWinMouseUp( event ); } ); + C->addEventListener( Event::MouseUp, [this]( auto event ) { onWinMouseUp( event ); } ); UISprite* sprite = UISprite::New(); sprite->setFlags( UI_AUTO_SIZE ); @@ -397,7 +397,7 @@ void EETest::createBaseUI() { Button->setParent( C )->setPosition( 225, 215 )->setSize( 90, 0 ); Button->setIcon( mSceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); Button->setText( "Click Me" ); - Button->addEventListener( Event::MouseClick, cb::Make1( this, &EETest::onButtonClick ) ); + Button->addEventListener( Event::MouseClick, [this]( auto event ) { onButtonClick( event ); } ); Button->setTooltipText( "Click and see what happens..." ); UICheckBox* Checkbox = UICheckBox::New(); @@ -418,7 +418,7 @@ void EETest::createBaseUI() { ->setPosition( 220, 80 ) ->setSize( 80, 24 ); mSlider->addEventListener( Event::OnValueChange, - cb::Make1( this, &EETest::onSliderValueChange ) ); + [this]( auto event ) { onSliderValueChange( event ); } ); UISlider::New() ->setOrientation( UIOrientation::Vertical ) @@ -437,7 +437,8 @@ void EETest::createBaseUI() { mScrollBar = UIScrollBar::New(); mScrollBar->setParent( C )->setSize( 0, 240 ); - mScrollBar->addEventListener( Event::OnValueChange, cb::Make1( this, &EETest::onValueChange ) ); + mScrollBar->addEventListener( Event::OnValueChange, + [this]( auto event ) { onValueChange( event ); } ); mProgressBar = UIProgressBar::New(); mProgressBar->setParent( C )->setSize( 200, 24 )->setPosition( 20, 190 ); @@ -559,12 +560,12 @@ void EETest::createBaseUI() { Menu->addSeparator(); Menu->add( "Quit" ); - Menu->addEventListener( Event::OnItemClicked, cb::Make1( this, &EETest::onItemClick ) ); + Menu->addEventListener( Event::OnItemClicked, [this]( auto event ) { onItemClick( event ); } ); Menu->getItem( "Quit" )->addEventListener( Event::MouseUp, - cb::Make1( this, &EETest::onQuitClick ) ); + [this]( auto event ) { onQuitClick( event ); } ); SceneManager::instance()->getUISceneNode()->getRoot()->addEventListener( - Event::MouseClick, cb::Make1( this, &EETest::onMainClick ) ); + Event::MouseClick, [this]( auto event ) { onMainClick( event ); } ); #ifdef EE_PLATFORM_TOUCH UISkin nSkin( "button-te" ); @@ -584,7 +585,7 @@ void EETest::createBaseUI() { mShowMenu->setPosition( screenSize.getWidth() - mShowMenu->getSize().getWidth() - 32, screenSize.getHeight() - mShowMenu->getSize().getHeight() - 9 ); mShowMenu->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); - mShowMenu->addEventListener( Event::MouseClick, cb::Make1( this, &EETest::onShowMenu ) ); + mShowMenu->addEventListener( Event::MouseClick, [this]( auto event ) { onShowMenu( event ); } ); #endif } @@ -659,9 +660,10 @@ void EETest::createNewUI() { scrollView->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ) ->setParent( relLay ); scrollView->getContainer()->addEventListener( Event::MouseClick, - cb::Make1( this, &EETest::onMainClick ) ); + [this]( auto event ) { onMainClick( event ); } ); container->setParent( scrollView ); - container->addEventListener( Event::MouseClick, cb::Make1( this, &EETest::onMainClick ) ); + container->addEventListener( Event::MouseClick, + [this]( auto event ) { onMainClick( event ); } ); UILoader* loader = UILoader::New(); loader->setOutlineThickness( 4 ) @@ -1011,7 +1013,7 @@ void EETest::createMapEditor() { tWin->setStyleConfig( windowStyleConfig ); Clock mapEditorTime; - mMapEditor = MapEditor::New( tWin, cb::Make0( this, &EETest::onMapEditorClose ) ); + mMapEditor = MapEditor::New( tWin, [this] { onMapEditorClose(); } ); Log::info( "Map Editor created in: %s.", mapEditorTime.getElapsedTime().toString().c_str() ); tWin->center(); tWin->show(); @@ -1076,7 +1078,8 @@ void EETest::createDecoratedWindow() { ->setMinWindowSize( 530, 350 ) ->setPosition( 200, 50 ); - mUIWindow->addEventListener( Event::OnWindowClose, cb::Make1( this, &EETest::onCloseClick ) ); + mUIWindow->addEventListener( Event::OnWindowClose, + [this]( auto event ) { onCloseClick( event ); } ); mUIWindow->setTitle( "Test Window" ); mUIWindow->addEventListener( Event::OnDragStart, onWinDragStart ); mUIWindow->addEventListener( Event::OnDragStop, onWinDragStop ); @@ -1138,7 +1141,7 @@ void EETest::createDecoratedWindow() { Button->setText( "Click Me" ); Button->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::WrapContent ) ->setParent( lay ); - Button->addEventListener( Event::MouseClick, cb::Make1( this, &EETest::onButtonClick ) ); + Button->addEventListener( Event::MouseClick, [this]( auto event ) { onButtonClick( event ); } ); mUIWindow->setKeyBindingCommand( "button-click", [this] { addFlyingIcon(); } ); mUIWindow->addKeyBinding( { KEY_C, KEYMOD_LALT }, "button-click" ); @@ -1380,7 +1383,7 @@ void EETest::loadTextures() { SndMng.loadFromFile( "mysound", MyPath + "sounds/sound.ogg" ); mResLoad.setThreaded( EE->isSharedGLContextEnabled() ); - mResLoad.load( cb::Make1( this, &EETest::onTextureLoaded ) ); + mResLoad.load( [this]( auto event ) { onTextureLoaded( event ); } ); TN.resize( 12 ); TNP.resize( 12 ); @@ -1423,7 +1426,8 @@ void EETest::loadTextures() { SP.addFrame( TN[4], Sizef( 0, 0 ), Vector2i( 0, 0 ), Rect( mx * 64, my * 64, mx * 64 + 64, my * 64 + 64 ) ); - PS[0].setCallbackReset( cb::Make2( this, &EETest::particlesCallback ) ); + PS[0].setCallbackReset( + [this]( Particle* P, ParticleSystem* Me ) { particlesCallback( P, Me ); } ); PS[0].create( ParticleEffect::Callback, 500, TN[5], Vector2f( 0, 0 ), 16, true ); PS[1].create( ParticleEffect::Heal, 250, TN[5], Vector2f( mWindow->getWidth() * 0.5f, mWindow->getHeight() * 0.5f ), 16, true ); @@ -2355,7 +2359,8 @@ cpBool EETest::catcherBarBegin( Arbiter* arb, Physics::Space*, void* ) { emitter->queue++; - mSpace->addPostStepCallback( cb::Make3( this, &EETest::postStepRemove ), b, NULL ); + mSpace->addPostStepCallback( + [this]( Space* s, void* tshape, void* v ) { postStepRemove( s, tshape, v ); }, b, NULL ); return cpFalse; } @@ -2391,15 +2396,17 @@ void EETest::demo2Create() { Space::CollisionHandler handler; handler.a = BLOCKING_SENSOR_TYPE; handler.b = BALL_TYPE; - handler.begin = cb::Make3( this, &EETest::blockerBegin ); - handler.separate = cb::Make3( this, &EETest::blockerSeparate ); + handler.begin = [this]( Arbiter* arb, Space* s, void* v ) { return blockerBegin( arb, s, v ); }; + handler.separate = [this]( Arbiter* arb, Space* s, void* v ) { blockerSeparate( arb, s, v ); }; mSpace->addCollisionHandler( handler ); handler.reset(); // Reset all the values and the callbacks ( set the callbacks as !IsSet() handler.a = CATCH_SENSOR_TYPE; handler.b = BALL_TYPE; - handler.begin = cb::Make3( this, &EETest::catcherBarBegin ); + handler.begin = [this]( Arbiter* arb, Physics::Space* s, void* v ) { + return catcherBarBegin( arb, s, v ); + }; mSpace->addCollisionHandler( handler ); } @@ -2448,14 +2455,14 @@ void EETest::physicsCreate() { physicDemo demo; - demo.init = cb::Make0( this, &EETest::demo1Create ); - demo.update = cb::Make0( this, &EETest::demo1Update ); - demo.destroy = cb::Make0( this, &EETest::demo1Destroy ); + demo.init = [this] { demo1Create(); }; + demo.update = [this] { demo1Update(); }; + demo.destroy = [this] { demo1Destroy(); }; mDemo.push_back( demo ); - demo.init = cb::Make0( this, &EETest::demo2Create ); - demo.update = cb::Make0( this, &EETest::demo2Update ); - demo.destroy = cb::Make0( this, &EETest::demo2Destroy ); + demo.init = [this] { demo2Create(); }; + demo.update = [this] { demo2Update(); }; + demo.destroy = [this] { demo2Destroy(); }; mDemo.push_back( demo ); changeDemo( 0 ); diff --git a/src/tools/ecode/globalsearchcontroller.cpp b/src/tools/ecode/globalsearchcontroller.cpp index 662f8fb25..42f7a8309 100644 --- a/src/tools/ecode/globalsearchcontroller.cpp +++ b/src/tools/ecode/globalsearchcontroller.cpp @@ -1,5 +1,5 @@ -#include "globalsearchcontroller.hpp" #include "ecode.hpp" +#include "globalsearchcontroller.hpp" #include "uitreeviewglobalsearch.hpp" namespace ecode { @@ -33,6 +33,26 @@ static bool replaceInFile( const std::string& path, const std::string& replaceTe return true; } +static bool replaceInFile( const std::string& path, const std::vector& replaceTexts, + const std::vector>& replacements ) { + std::string data; + if ( !FileSystem::fileGet( path, data ) ) + return false; + + Int64 diff = 0; + int pos = 0; + for ( const auto& range : replacements ) { + data.replace( range.first + diff, range.second - range.first, replaceTexts[pos] ); + diff += replaceTexts[pos].size() - ( range.second - range.first ); + pos++; + } + + if ( !FileSystem::fileWrite( path, (const Uint8*)data.c_str(), data.size() ) ) + return false; + + return true; +} + size_t GlobalSearchController::replaceInFiles( const std::string& replaceText, std::shared_ptr model ) { size_t count = 0; @@ -42,6 +62,39 @@ size_t GlobalSearchController::replaceInFiles( const std::string& replaceText, } const ProjectSearch::Result& res = model.get()->getResult(); + bool hasCaptures = + model->isResultFromLuaPattern() && LuaPattern::find( replaceText, "$%d+" ).isValid(); + + if ( hasCaptures ) { + for ( const auto& fileResult : res ) { + std::vector> replacements; + std::vector replaceTexts; + + for ( const auto& result : fileResult.results ) { + if ( !result.selected ) + continue; + replacements.push_back( { result.start, result.end } ); + std::string newText( replaceText ); + LuaPattern ptrn( "$(%d+)" ); + for ( auto& match : ptrn.gmatch( replaceText ) ) { + std::string matchSubStr( match.group( 0 ) ); // $1 $2 ... + std::string matchNum( match.group( 1 ) ); // 1 2 ... + int num; + if ( String::fromString( num, matchNum ) && num > 0 && + num - 1 < static_cast( result.captures.size() ) ) { + String::replaceAll( newText, matchSubStr, result.captures[num - 1] ); + replaceTexts.emplace_back( std::move( newText ) ); + } + } + } + + if ( replacements.size() == replaceTexts.size() && + replaceInFile( fileResult.file, replaceTexts, replacements ) ) + count += replacements.size(); + } + + return count; + } for ( const auto& fileResult : res ) { std::vector> replacements; @@ -116,13 +169,12 @@ void GlobalSearchController::initGlobalSearchBar( mGlobalSearchHistoryList = mGlobalSearchBarLayout->find( "global_search_history" ); mGlobalSearchBarLayout->setCommand( "global-search-clear-history", [this] { clearHistory(); } ); - mGlobalSearchBarLayout->setCommand( - "search-in-files", - [this, caseSensitiveChk, wholeWordChk, luaPatternChk, escapeSequenceChk] { - doGlobalSearch( mGlobalSearchInput->getText(), caseSensitiveChk->isChecked(), - wholeWordChk->isChecked(), luaPatternChk->isChecked(), - escapeSequenceChk->isChecked(), false ); - } ); + mGlobalSearchBarLayout->setCommand( "search-in-files", [this, caseSensitiveChk, wholeWordChk, + luaPatternChk, escapeSequenceChk] { + doGlobalSearch( mGlobalSearchInput->getText(), caseSensitiveChk->isChecked(), + wholeWordChk->isChecked(), luaPatternChk->isChecked(), + escapeSequenceChk->isChecked(), false ); + } ); mGlobalSearchBarLayout->setCommand( "search-again", [this, caseSensitiveChk, wholeWordChk, luaPatternChk, escapeSequenceChk] { auto listBox = mGlobalSearchHistoryList->getListBox(); @@ -275,22 +327,22 @@ void GlobalSearchController::initGlobalSearchBar( escapeSequenceChk->isChecked(), true ); } } ); - mGlobalSearchBarLayout->setCommand( "replace-in-files", [this, replaceInput, - escapeSequenceChk] { - auto listBox = mGlobalSearchHistoryList->getListBox(); - if ( listBox->getItemSelectedIndex() < mGlobalSearchHistory.size() ) { - const auto& replaceData = mGlobalSearchHistory[mGlobalSearchHistory.size() - 1 - - listBox->getItemSelectedIndex()]; - String text( replaceInput->getText() ); - if ( escapeSequenceChk->isChecked() ) - text.unescape(); - size_t count = replaceInFiles( text.toUtf8(), replaceData.second ); - mGlobalSearchBarLayout->execute( "search-again" ); - mGlobalSearchBarLayout->execute( "close-global-searchbar" ); - mApp->getNotificationCenter()->addNotification( - String::format( "Replaced %zu occurrences.", count ) ); - } - } ); + mGlobalSearchBarLayout->setCommand( + "replace-in-files", [this, replaceInput, escapeSequenceChk] { + auto listBox = mGlobalSearchHistoryList->getListBox(); + if ( listBox->getItemSelectedIndex() < mGlobalSearchHistory.size() ) { + const auto& replaceData = mGlobalSearchHistory[mGlobalSearchHistory.size() - 1 - + listBox->getItemSelectedIndex()]; + String text( replaceInput->getText() ); + if ( escapeSequenceChk->isChecked() ) + text.unescape(); + size_t count = replaceInFiles( text.toUtf8(), replaceData.second ); + mGlobalSearchBarLayout->execute( "search-again" ); + mGlobalSearchBarLayout->execute( "close-global-searchbar" ); + mApp->getNotificationCenter()->addNotification( + String::format( "Replaced %zu occurrences.", count ) ); + } + } ); mGlobalSearchTreeSearch = UITreeViewGlobalSearch::New( mSplitter->getCurrentColorScheme(), false ); mGlobalSearchTreeReplace = @@ -500,14 +552,15 @@ void GlobalSearchController::doGlobalSearch( String text, bool caseSensitive, bo #if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN || defined( __EMSCRIPTEN_PTHREADS__ ) mApp->getThreadPool(), #endif - [this, clock, search, loader, searchReplace, searchAgain, - escapeSequence]( const ProjectSearch::Result& res ) { + [this, clock, search, loader, searchReplace, searchAgain, escapeSequence, + luaPattern]( const ProjectSearch::Result& res ) { Log::info( "Global search for \"%s\" took %.2fms", search.c_str(), clock->getElapsedTime().asMilliseconds() ); eeDelete( clock ); mUISceneNode->runOnMainThread( [this, loader, res, search, searchReplace, - searchAgain, escapeSequence] { + searchAgain, escapeSequence, luaPattern] { auto model = ProjectSearch::asModel( res ); + model->setResultFromLuaPattern( luaPattern ); updateGlobalSearchHistory( model, search, searchReplace, searchAgain, escapeSequence ); updateGlobalSearchBarResults( search, model, searchReplace, escapeSequence ); diff --git a/src/tools/ecode/projectsearch.cpp b/src/tools/ecode/projectsearch.cpp index e33a2bf8a..dd6784cdc 100644 --- a/src/tools/ecode/projectsearch.cpp +++ b/src/tools/ecode/projectsearch.cpp @@ -25,7 +25,7 @@ static int countNewLines( const std::string& text, const size_t& start, const si return count; } -static String textLine( const std::string& fileText, const size_t& fromPos, size_t& relCol ) { +static String textLine( const std::string& fileText, const size_t& fromPos, Int64& relCol ) { const char* stringStartPtr = fileText.c_str(); const char* startPtr = fileText.c_str() + fromPos; const char* endPtr = startPtr; @@ -68,7 +68,7 @@ searchInFileHorspool( const std::string& file, const std::string& text, const bo searchRes += text.size(); continue; } - size_t relCol; + Int64 relCol; totNl += countNewLines( fileText, lSearchRes, searchRes ); String str( textLine( caseSensitive ? fileText : fileTextOriginal, searchRes, relCol ) ); @@ -91,8 +91,8 @@ searchInFileLuaPattern( const std::string& file, const std::string& text, const std::string fileText; FileSystem::fileGet( file, fileText ); LuaPattern pattern( text ); - std::vector res; - size_t totNl = 0; + std::vector results; + Int64 totNl = 0; bool matched = false; Int64 searchRes = 0; std::string fileTextOriginal; @@ -102,28 +102,43 @@ searchInFileLuaPattern( const std::string& file, const std::string& text, const String::toLowerInPlace( fileText ); } + LuaPattern::Range matches[12]; do { int start, end = 0; - if ( ( matched = pattern.find( fileText, start, end, searchRes ) ) ) { + + if ( ( matched = pattern.matches( fileText, matches, searchRes ) ) ) { + start = matches[0].start; + end = matches[0].end; + if ( wholeWord && !String::isWholeWord( fileText, fileText.substr( start, end - start ), start ) ) { searchRes = end; continue; } - size_t relCol; + + Int64 relCol; totNl += countNewLines( fileText, searchRes, start ); String str( textLine( caseSensitive ? fileText : fileTextOriginal, start, relCol ) ); int len = end - start; - res.push_back( - { str, - { { (Int64)totNl, (Int64)relCol }, { (Int64)totNl, (Int64)( relCol + len ) } }, - start, - end } ); + ProjectSearch::ResultData::Result res; + res.line = std::move( str ); + res.position = { { totNl, (Int64)relCol }, { totNl, (Int64)( relCol + len ) } }; + res.start = start; + res.end = end; + for ( size_t c = 1; c < 12; c++ ) { + if ( matches[c].isValid() ) { + res.captures.push_back( + fileText.substr( matches[c].start, matches[c].end - matches[c].start ) ); + } else { + break; + } + } + results.emplace_back( std::move( res ) ); searchRes = end; } } while ( matched ); - return res; + return results; } void ProjectSearch::find( const std::vector files, const std::string& string, diff --git a/src/tools/ecode/projectsearch.hpp b/src/tools/ecode/projectsearch.hpp index cd9fd5121..2af00a29f 100644 --- a/src/tools/ecode/projectsearch.hpp +++ b/src/tools/ecode/projectsearch.hpp @@ -28,6 +28,7 @@ class ProjectSearch { Int64 start{ 0 }; Int64 end{ 0 }; bool selected{ true }; + std::vector captures; }; std::string file; std::vector results; @@ -190,9 +191,14 @@ class ProjectSearch { bool isResultFromSymbolReference() const { return mResultFromSymbolReference; } + void setResultFromLuaPattern( bool ref ) { mResultFromLuaPattern = ref; } + + bool isResultFromLuaPattern() const { return mResultFromLuaPattern; } + protected: Result mResult; bool mResultFromSymbolReference{ false }; + bool mResultFromLuaPattern{ false }; }; static std::shared_ptr asModel( const Result& result ) {