Changeset View
Changeset View
Standalone View
Standalone View
source/gui/ObjectBases/IGUIObject.cpp
Show First 20 Lines • Show All 330 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void IGUIObject::SetScriptHandler(const CStr& eventName, JS::HandleObject Function) | void IGUIObject::SetScriptHandler(const CStr& eventName, JS::HandleObject Function) | ||||
{ | { | ||||
if (m_ScriptHandlers.empty()) | if (m_ScriptHandlers.empty()) | ||||
JS_AddExtraGCRootsTracer(m_pGUI.GetScriptInterface()->GetJSRuntime(), Trace, this); | JS_AddExtraGCRootsTracer(m_pGUI.GetScriptInterface()->GetJSRuntime(), Trace, this); | ||||
m_ScriptHandlers[eventName] = JS::Heap<JSObject*>(Function); | m_ScriptHandlers[eventName] = JS::Heap<JSObject*>(Function); | ||||
auto it = m_pGUI.m_EventIGUIObjects.find(eventName); | |||||
if (it == m_pGUI.m_EventIGUIObjects.end()) | |||||
m_pGUI.m_EventIGUIObjects.emplace(eventName, std::set<IGUIObject*>{this}); | |||||
else | |||||
it->second.insert(this); | |||||
} | } | ||||
void IGUIObject::UnsetScriptHandler(const CStr& eventName) | void IGUIObject::UnsetScriptHandler(const CStr& eventName) | ||||
{ | { | ||||
std::map<CStr, JS::Heap<JSObject*> >::iterator it = m_ScriptHandlers.find(eventName); | std::map<CStr, JS::Heap<JSObject*> >::iterator it = m_ScriptHandlers.find(eventName); | ||||
if (it == m_ScriptHandlers.end()) | if (it == m_ScriptHandlers.end()) | ||||
return; | return; | ||||
m_ScriptHandlers.erase(it); | m_ScriptHandlers.erase(it); | ||||
if (m_ScriptHandlers.empty()) | if (m_ScriptHandlers.empty()) | ||||
JS_RemoveExtraGCRootsTracer(m_pGUI.GetScriptInterface()->GetJSRuntime(), Trace, this); | JS_RemoveExtraGCRootsTracer(m_pGUI.GetScriptInterface()->GetJSRuntime(), Trace, this); | ||||
{ | |||||
auto it = m_pGUI.m_EventIGUIObjects.find(eventName); | |||||
if (it != m_pGUI.m_EventIGUIObjects.end()) | |||||
{ | |||||
it->second.erase(this); | |||||
if (!it->second.size()) | |||||
m_pGUI.m_EventIGUIObjects.erase(eventName); | |||||
} | |||||
} | |||||
} | } | ||||
InReaction IGUIObject::SendEvent(EGUIMessageType type, const CStr& eventName) | InReaction IGUIObject::SendEvent(EGUIMessageType type, const CStr& eventName) | ||||
{ | { | ||||
PROFILE2_EVENT("gui event"); | PROFILE2_EVENT("gui event"); | ||||
PROFILE2_ATTR("type: %s", eventName.c_str()); | PROFILE2_ATTR("type: %s", eventName.c_str()); | ||||
PROFILE2_ATTR("object: %s", m_Name.c_str()); | PROFILE2_ATTR("object: %s", m_Name.c_str()); | ||||
▲ Show 20 Lines • Show All 167 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator