This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
MyGameFramework/lib/gwen/gwen_hook.h
Gered c5cdddbeaa initial commit
current versions of all of my basic framework sources, build configurations/scripts, and supporting assets
2013-01-31 12:53:05 -05:00

83 lines
1.6 KiB
C++

/*
GWEN
Copyright (c) 2010 Facepunch Studios
See license in Gwen.h
*/
#pragma once
#ifndef GWEN_HOOK_H
#define GWEN_HOOK_H
#include "gwen.h"
#include <stl/list.h>
#ifdef GWEN_HOOKSYSTEM
namespace Gwen
{
namespace Hook
{
class GWEN_EXPORT BaseHook
{
public:
virtual bool OnControlClicked( Gwen::Controls::Base*, int /*iMouseX*/, int /*iMouseY*/ ){ return false; };
};
typedef stl::list<BaseHook*> HookList;
GWEN_EXPORT HookList& GetHookList();
GWEN_EXPORT void AddHook( BaseHook* pHook );
GWEN_EXPORT void RemoveHook( BaseHook* pHook );
template< typename fnc >
bool CallHook( fnc f )
{
for ( HookList::iterator it = GetHookList().begin(); it != GetHookList().end(); ++it )
{
if ( ((*it)->*f)() ) return true;
}
return false;
}
template< typename fnc, typename AA >
bool CallHook( fnc f, AA a )
{
for ( HookList::iterator it = GetHookList().begin(); it != GetHookList().end(); ++it )
{
if ( ((*it)->*f)( a ) ) return true;
}
return false;
}
template< typename fnc, typename AA, typename AB >
bool CallHook( fnc f, AA a, AB b )
{
for ( HookList::iterator it = GetHookList().begin(); it != GetHookList().end(); ++it )
{
if ( ((*it)->*f)( a, b ) ) return true;
}
return false;
}
template< typename fnc, typename AA, typename AB, typename AC >
bool CallHook( fnc f, AA a, AB b, AC c )
{
for ( HookList::iterator it = GetHookList().begin(); it != GetHookList().end(); ++it )
{
if ( ((*it)->*f)( a, b, c ) ) return true;
}
return false;
}
}
}
#endif
#endif