mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
add has_hook
This commit is contained in:
parent
6faea2fcad
commit
70d1868ce3
@ -163,10 +163,37 @@ add_hook(const string &event_name, EventFunction *function) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool EventHandler::
|
||||
add_hook(const string &event_name, EventCallbackFunction *function,
|
||||
void *data) {
|
||||
void *data) {
|
||||
return _cbhooks[event_name].insert(CallbackFunction(function, data)).second;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EventHandler::has_hook
|
||||
// Access: Public
|
||||
// Description: Returns true if there is any hook added on the
|
||||
// indicated event name, false otherwise.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool EventHandler::
|
||||
has_hook(const string &event_name) const {
|
||||
Hooks::const_iterator hi;
|
||||
hi = _hooks.find(event_name);
|
||||
if (hi != _hooks.end()) {
|
||||
if (!(*hi).second.empty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
CallbackHooks::const_iterator chi;
|
||||
chi = _cbhooks.find(event_name);
|
||||
if (chi != _cbhooks.end()) {
|
||||
if (!(*chi).second.empty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EventHandler::remove_hook
|
||||
@ -191,7 +218,7 @@ remove_hook(const string &event_name, EventFunction *function) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool EventHandler::
|
||||
remove_hook(const string &event_name, EventCallbackFunction *function,
|
||||
void *data) {
|
||||
void *data) {
|
||||
return _cbhooks[event_name].erase(CallbackFunction(function, data)) != 0;
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ class EXPCL_PANDAEXPRESS EventHandler : public TypedObject {
|
||||
public:
|
||||
// Define a function type suitable for receiving events.
|
||||
typedef void EventFunction(CPT_Event);
|
||||
typedef void EventCallbackFunction(CPT(Event), void*);
|
||||
typedef void EventCallbackFunction(CPT_Event, void *);
|
||||
|
||||
PUBLISHED:
|
||||
EventHandler(EventQueue *queue);
|
||||
@ -59,10 +59,11 @@ PUBLISHED:
|
||||
public:
|
||||
bool add_hook(const string &event_name, EventFunction *function);
|
||||
bool add_hook(const string &event_name, EventCallbackFunction *function,
|
||||
void*);
|
||||
void *data);
|
||||
bool has_hook(const string &event_name) const;
|
||||
bool remove_hook(const string &event_name, EventFunction *function);
|
||||
bool remove_hook(const string &event_name, EventCallbackFunction *function,
|
||||
void*);
|
||||
void *data);
|
||||
|
||||
void remove_all_hooks();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user