Changeset View
Changeset View
Standalone View
Standalone View
source/gui/IGUIObject.cpp
/* Copyright (C) 2016 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 487 Lines • ▼ Show 20 Lines | void IGUIObject::ScriptEvent(const CStr& Action, JS::HandleValue Argument) | ||||
} | } | ||||
} | } | ||||
JSObject* IGUIObject::GetJSObject() | JSObject* IGUIObject::GetJSObject() | ||||
{ | { | ||||
JSContext* cx = m_pGUI->GetScriptInterface()->GetContext(); | JSContext* cx = m_pGUI->GetScriptInterface()->GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
// Cache the object when somebody first asks for it, because otherwise | // Cache the object when somebody first asks for it, because otherwise | ||||
// we end up doing far too much object allocation. TODO: Would be nice to | // we end up doing far too much object allocation. | ||||
// not have these objects hang around forever using up memory, though. | |||||
if (!m_JSObject.initialized()) | if (m_JSObjectValue.isUndefined()) | ||||
{ | { | ||||
m_JSObject.init(cx, m_pGUI->GetScriptInterface()->CreateCustomObject("GUIObject")); | m_JSObjectValue = JS::Heap<JS::Value>(JS::ObjectValue(*m_pGUI->GetScriptInterface()->CreateCustomObject("GUIObject"))); | ||||
JS_SetPrivate(m_JSObject.get(), this); | JS_SetPrivate(&m_JSObjectValue.toObject(), this); | ||||
} | } | ||||
return m_JSObject.get(); | |||||
return &(m_JSObjectValue.toObject()); | |||||
} | } | ||||
CStr IGUIObject::GetPresentableName() const | CStr IGUIObject::GetPresentableName() const | ||||
{ | { | ||||
// __internal(), must be at least 13 letters to be able to be | // __internal(), must be at least 13 letters to be able to be | ||||
// an internal name | // an internal name | ||||
if (m_Name.length() <= 12) | if (m_Name.length() <= 12) | ||||
return m_Name; | return m_Name; | ||||
Show All 16 Lines | |||||
bool IGUIObject::IsRootObject() const | bool IGUIObject::IsRootObject() const | ||||
{ | { | ||||
return GetGUI() != 0 && m_pParent == GetGUI()->m_BaseObject; | return GetGUI() != 0 && m_pParent == GetGUI()->m_BaseObject; | ||||
} | } | ||||
void IGUIObject::TraceMember(JSTracer* trc) | void IGUIObject::TraceMember(JSTracer* trc) | ||||
{ | { | ||||
JS_CallValueTracer(trc, &m_JSObjectValue, "IGUIObject::m_JSObjectValue"); | |||||
for (std::pair<const CStr, JS::Heap<JSObject*>>& handler : m_ScriptHandlers) | for (std::pair<const CStr, JS::Heap<JSObject*>>& handler : m_ScriptHandlers) | ||||
JS_CallObjectTracer(trc, &handler.second, "IGUIObject::m_ScriptHandlers"); | JS_CallObjectTracer(trc, &handler.second, "IGUIObject::m_ScriptHandlers"); | ||||
} | } | ||||
PSRETURN IGUIObject::LogInvalidSettings(const CStr8& Setting) const | PSRETURN IGUIObject::LogInvalidSettings(const CStr8& Setting) const | ||||
{ | { | ||||
LOGWARNING("IGUIObject: setting %s was not found on an object", Setting.c_str()); | LOGWARNING("IGUIObject: setting %s was not found on an object", Setting.c_str()); | ||||
return PSRETURN_GUI_InvalidSetting; | return PSRETURN_GUI_InvalidSetting; | ||||
} | } |
Wildfire Games · Phabricator