mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
new methods
This commit is contained in:
parent
0895fe7a34
commit
5eda2823ab
@ -80,16 +80,16 @@ dispatch_event(const CPT_Event &event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// now for callback hooks
|
// now for callback hooks
|
||||||
CallbackHooks::const_iterator cbhi;
|
CallbackHooks::const_iterator chi;
|
||||||
cbhi = _cbhooks.find(event->get_name());
|
chi = _cbhooks.find(event->get_name());
|
||||||
|
|
||||||
if (cbhi != _cbhooks.end()) {
|
if (chi != _cbhooks.end()) {
|
||||||
// found one
|
// found one
|
||||||
CallbackFunctions copy_functions = (*cbhi).second;
|
CallbackFunctions copy_functions = (*chi).second;
|
||||||
|
|
||||||
CallbackFunctions::const_iterator cbfi;
|
CallbackFunctions::const_iterator cfi;
|
||||||
for (cbfi = copy_functions.begin(); cbfi != copy_functions.end(); ++cbfi) {
|
for (cfi = copy_functions.begin(); cfi != copy_functions.end(); ++cfi) {
|
||||||
((*cbfi).first)(event, (*cbfi).second);
|
((*cfi).first)(event, (*cfi).second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,21 +105,21 @@ write(ostream &out) const {
|
|||||||
Hooks::const_iterator hi;
|
Hooks::const_iterator hi;
|
||||||
hi = _hooks.begin();
|
hi = _hooks.begin();
|
||||||
|
|
||||||
CallbackHooks::const_iterator cbhi;
|
CallbackHooks::const_iterator chi;
|
||||||
cbhi = _cbhooks.begin();
|
chi = _cbhooks.begin();
|
||||||
|
|
||||||
while (hi != _hooks.end() && cbhi != _cbhooks.end()) {
|
while (hi != _hooks.end() && chi != _cbhooks.end()) {
|
||||||
if ((*hi).first < (*cbhi).first) {
|
if ((*hi).first < (*chi).first) {
|
||||||
write_hook(out, *hi);
|
write_hook(out, *hi);
|
||||||
++hi;
|
++hi;
|
||||||
} else if ((*cbhi).first < (*hi).first) {
|
} else if ((*chi).first < (*hi).first) {
|
||||||
write_cbhook(out, *cbhi);
|
write_cbhook(out, *chi);
|
||||||
++cbhi;
|
++chi;
|
||||||
} else {
|
} else {
|
||||||
write_hook(out, *hi);
|
write_hook(out, *hi);
|
||||||
write_cbhook(out, *cbhi);
|
write_cbhook(out, *chi);
|
||||||
++hi;
|
++hi;
|
||||||
++cbhi;
|
++chi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,9 +128,9 @@ write(ostream &out) const {
|
|||||||
++hi;
|
++hi;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (cbhi != _cbhooks.end()) {
|
while (chi != _cbhooks.end()) {
|
||||||
write_cbhook(out, *cbhi);
|
write_cbhook(out, *chi);
|
||||||
++cbhi;
|
++chi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,6 +235,66 @@ remove_hook(const string &event_name, EventCallbackFunction *function,
|
|||||||
return _cbhooks[event_name].erase(CallbackFunction(function, data)) != 0;
|
return _cbhooks[event_name].erase(CallbackFunction(function, data)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: EventHandler::remove_hooks
|
||||||
|
// Access: Public
|
||||||
|
// Description: Removes all functions from the named event hook.
|
||||||
|
// Returns true if any functions were removed, false if
|
||||||
|
// there were no functions added to the hook.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
bool EventHandler::
|
||||||
|
remove_hooks(const string &event_name) {
|
||||||
|
assert(!event_name.empty());
|
||||||
|
bool any_removed = false;
|
||||||
|
|
||||||
|
Hooks::iterator hi = _hooks.find(event_name);
|
||||||
|
if (hi != _hooks.end()) {
|
||||||
|
if (!(*hi).second.empty()) {
|
||||||
|
any_removed = true;
|
||||||
|
}
|
||||||
|
_hooks.erase(hi);
|
||||||
|
}
|
||||||
|
|
||||||
|
CallbackHooks::iterator chi = _cbhooks.find(event_name);
|
||||||
|
if (chi != _cbhooks.end()) {
|
||||||
|
if (!(*chi).second.empty()) {
|
||||||
|
any_removed = true;
|
||||||
|
}
|
||||||
|
_cbhooks.erase(chi);
|
||||||
|
}
|
||||||
|
|
||||||
|
return any_removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: EventHandler::remove_hooks_with
|
||||||
|
// Access: Public
|
||||||
|
// Description: Removes all CallbackFunction hooks that have the
|
||||||
|
// indicated pointer as the associated data pointer.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
bool EventHandler::
|
||||||
|
remove_hooks_with(void *data) {
|
||||||
|
bool any_removed = false;
|
||||||
|
|
||||||
|
CallbackHooks::iterator chi;
|
||||||
|
for (chi = _cbhooks.begin(); chi != _cbhooks.end(); ++chi) {
|
||||||
|
CallbackFunctions &funcs = (*chi).second;
|
||||||
|
CallbackFunctions::iterator cfi;
|
||||||
|
|
||||||
|
CallbackFunctions new_funcs;
|
||||||
|
for (cfi = funcs.begin(); cfi != funcs.end(); ++cfi) {
|
||||||
|
if ((*cfi).second == data) {
|
||||||
|
any_removed = true;
|
||||||
|
} else {
|
||||||
|
new_funcs.insert(*cfi, new_funcs.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
funcs.swap(new_funcs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return any_removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: EventHandler::remove_all_hooks
|
// Function: EventHandler::remove_all_hooks
|
||||||
|
@ -68,6 +68,9 @@ public:
|
|||||||
bool remove_hook(const string &event_name, EventCallbackFunction *function,
|
bool remove_hook(const string &event_name, EventCallbackFunction *function,
|
||||||
void *data);
|
void *data);
|
||||||
|
|
||||||
|
bool remove_hooks(const string &event_name);
|
||||||
|
bool remove_hooks_with(void *data);
|
||||||
|
|
||||||
void remove_all_hooks();
|
void remove_all_hooks();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user