Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/ObjectBases/IGUIObject.cpp
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
IGUIObject::~IGUIObject() | IGUIObject::~IGUIObject() | ||||
{ | { | ||||
for (const std::pair<CStr, IGUISetting*>& p : m_Settings) | for (const std::pair<CStr, IGUISetting*>& p : m_Settings) | ||||
delete p.second; | delete p.second; | ||||
if (!m_ScriptHandlers.empty()) | if (!m_ScriptHandlers.empty()) | ||||
JS_RemoveExtraGCRootsTracer(m_pGUI.GetScriptInterface()->GetJSRuntime(), Trace, this); | JS_RemoveExtraGCRootsTracer(m_pGUI.GetScriptInterface()->GetGeneralJSContext(), Trace, this); | ||||
// m_Children is deleted along all other GUI Objects in the CGUI destructor | // m_Children is deleted along all other GUI Objects in the CGUI destructor | ||||
} | } | ||||
void IGUIObject::AddChild(IGUIObject& pChild) | void IGUIObject::AddChild(IGUIObject& pChild) | ||||
{ | { | ||||
pChild.SetParent(this); | pChild.SetParent(this); | ||||
m_Children.push_back(&pChild); | m_Children.push_back(&pChild); | ||||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | void IGUIObject::RegisterScriptHandler(const CStr& eventName, const CStr& Code, CGUI& pGUI) | ||||
JS::RootedObject funcObj(rq.cx, JS_GetFunctionObject(func)); | JS::RootedObject funcObj(rq.cx, JS_GetFunctionObject(func)); | ||||
SetScriptHandler(eventName, funcObj); | SetScriptHandler(eventName, funcObj); | ||||
} | } | ||||
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()->GetGeneralJSContext(), Trace, this); | ||||
m_ScriptHandlers[eventName] = JS::Heap<JSObject*>(Function); | m_ScriptHandlers[eventName] = JS::Heap<JSObject*>(Function); | ||||
auto it = m_pGUI.m_EventIGUIObjects.find(eventName); | auto it = m_pGUI.m_EventIGUIObjects.find(eventName); | ||||
if (it == m_pGUI.m_EventIGUIObjects.end()) | if (it == m_pGUI.m_EventIGUIObjects.end()) | ||||
m_pGUI.m_EventIGUIObjects.emplace(eventName, std::set<IGUIObject*>{this}); | m_pGUI.m_EventIGUIObjects.emplace(eventName, std::set<IGUIObject*>{this}); | ||||
else | else | ||||
it->second.insert(this); | 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()->GetGeneralJSContext(), Trace, this); | ||||
{ | { | ||||
auto it = m_pGUI.m_EventIGUIObjects.find(eventName); | auto it = m_pGUI.m_EventIGUIObjects.find(eventName); | ||||
if (it != m_pGUI.m_EventIGUIObjects.end()) | if (it != m_pGUI.m_EventIGUIObjects.end()) | ||||
{ | { | ||||
it->second.erase(this); | it->second.erase(this); | ||||
if (!it->second.size()) | if (!it->second.size()) | ||||
m_pGUI.m_EventIGUIObjects.erase(eventName); | m_pGUI.m_EventIGUIObjects.erase(eventName); | ||||
} | } | ||||
Show All 32 Lines | InReaction IGUIObject::SendMouseEvent(EGUIMessageType type, const CStr& eventName) | ||||
ScriptInterface::CreateObject( | ScriptInterface::CreateObject( | ||||
rq, | rq, | ||||
&mouse, | &mouse, | ||||
"x", mousePos.x, | "x", mousePos.x, | ||||
"y", mousePos.y, | "y", mousePos.y, | ||||
"buttons", m_pGUI.GetMouseButtons()); | "buttons", m_pGUI.GetMouseButtons()); | ||||
JS::AutoValueVector paramData(rq.cx); | JS::AutoValueVector paramData(rq.cx); | ||||
paramData.append(mouse); | (void)paramData.append(mouse); | ||||
ScriptEvent(eventName, paramData); | ScriptEvent(eventName, paramData); | ||||
return msg.skipped ? IN_PASS : IN_HANDLED; | return msg.skipped ? IN_PASS : IN_HANDLED; | ||||
} | } | ||||
void IGUIObject::ScriptEvent(const CStr& eventName) | void IGUIObject::ScriptEvent(const CStr& eventName) | ||||
{ | { | ||||
ScriptEventWithReturn(eventName); | ScriptEventWithReturn(eventName); | ||||
▲ Show 20 Lines • Show All 138 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator