Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/GUIManager.cpp
Show First 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | |||||
void CGUIManager::SGUIPage::LoadPage(shared_ptr<ScriptRuntime> scriptRuntime) | void CGUIManager::SGUIPage::LoadPage(shared_ptr<ScriptRuntime> scriptRuntime) | ||||
{ | { | ||||
// If we're hotloading then try to grab some data from the previous page | // If we're hotloading then try to grab some data from the previous page | ||||
shared_ptr<ScriptInterface::StructuredClone> hotloadData; | shared_ptr<ScriptInterface::StructuredClone> hotloadData; | ||||
if (gui) | if (gui) | ||||
{ | { | ||||
shared_ptr<ScriptInterface> scriptInterface = gui->GetScriptInterface(); | shared_ptr<ScriptInterface> scriptInterface = gui->GetScriptInterface(); | ||||
ScriptInterface::Request rq(*scriptInterface); | ScriptInterface::Request rq(scriptInterface); | ||||
JS::RootedValue global(rq.cx, scriptInterface->GetGlobalObject()); | JS::RootedValue global(rq.cx, rq.globalValue()); | ||||
JS::RootedValue hotloadDataVal(rq.cx); | JS::RootedValue hotloadDataVal(rq.cx); | ||||
scriptInterface->CallFunction(global, "getHotloadData", &hotloadDataVal); | scriptInterface->CallFunction(global, "getHotloadData", &hotloadDataVal); | ||||
hotloadData = scriptInterface->WriteStructuredClone(hotloadDataVal); | hotloadData = scriptInterface->WriteStructuredClone(hotloadDataVal); | ||||
} | } | ||||
g_CursorName = g_DefaultCursor; | g_CursorName = g_DefaultCursor; | ||||
inputs.clear(); | inputs.clear(); | ||||
gui.reset(new CGUI(scriptRuntime)); | gui.reset(new CGUI(scriptRuntime)); | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | else | ||||
VfsPath path = VfsPath("gui") / nameW; | VfsPath path = VfsPath("gui") / nameW; | ||||
gui->LoadXmlFile(path, inputs); | gui->LoadXmlFile(path, inputs); | ||||
} | } | ||||
} | } | ||||
gui->LoadedXmlFiles(); | gui->LoadedXmlFiles(); | ||||
shared_ptr<ScriptInterface> scriptInterface = gui->GetScriptInterface(); | shared_ptr<ScriptInterface> scriptInterface = gui->GetScriptInterface(); | ||||
ScriptInterface::Request rq(*scriptInterface); | ScriptInterface::Request rq(scriptInterface); | ||||
JS::RootedValue initDataVal(rq.cx); | JS::RootedValue initDataVal(rq.cx); | ||||
JS::RootedValue hotloadDataVal(rq.cx); | JS::RootedValue hotloadDataVal(rq.cx); | ||||
JS::RootedValue global(rq.cx, scriptInterface->GetGlobalObject()); | JS::RootedValue global(rq.cx, rq.globalValue()); | ||||
if (initData) | if (initData) | ||||
scriptInterface->ReadStructuredClone(initData, &initDataVal); | scriptInterface->ReadStructuredClone(initData, &initDataVal); | ||||
if (hotloadData) | if (hotloadData) | ||||
scriptInterface->ReadStructuredClone(hotloadData, &hotloadDataVal); | scriptInterface->ReadStructuredClone(hotloadData, &hotloadDataVal); | ||||
if (scriptInterface->HasProperty(global, "init") && | if (scriptInterface->HasProperty(global, "init") && | ||||
Show All 21 Lines | |||||
} | } | ||||
void CGUIManager::SGUIPage::PerformCallbackFunction(shared_ptr<ScriptInterface::StructuredClone> args) | void CGUIManager::SGUIPage::PerformCallbackFunction(shared_ptr<ScriptInterface::StructuredClone> args) | ||||
{ | { | ||||
if (!callbackFunction) | if (!callbackFunction) | ||||
return; | return; | ||||
shared_ptr<ScriptInterface> scriptInterface = gui->GetScriptInterface(); | shared_ptr<ScriptInterface> scriptInterface = gui->GetScriptInterface(); | ||||
ScriptInterface::Request rq(*scriptInterface); | ScriptInterface::Request rq(scriptInterface); | ||||
JS::RootedObject globalObj(rq.cx, &scriptInterface->GetGlobalObject().toObject()); | JS::RootedObject globalObj(rq.cx, rq.glob); | ||||
JS::RootedValue funcVal(rq.cx, *callbackFunction); | JS::RootedValue funcVal(rq.cx, *callbackFunction); | ||||
// Delete the callback function, so that it is not called again | // Delete the callback function, so that it is not called again | ||||
callbackFunction.reset(); | callbackFunction.reset(); | ||||
JS::RootedValue argVal(rq.cx); | JS::RootedValue argVal(rq.cx); | ||||
if (args) | if (args) | ||||
Show All 39 Lines | InReaction CGUIManager::HandleEvent(const SDL_Event_* ev) | ||||
// So we call two separate handler functions: | // So we call two separate handler functions: | ||||
bool handled = false; | bool handled = false; | ||||
{ | { | ||||
PROFILE("handleInputBeforeGui"); | PROFILE("handleInputBeforeGui"); | ||||
ScriptInterface::Request rq(*top()->GetScriptInterface()); | ScriptInterface::Request rq(*top()->GetScriptInterface()); | ||||
JS::RootedValue global(rq.cx, top()->GetGlobalObject()); | JS::RootedValue global(rq.cx, rq.globalValue()); | ||||
if (top()->GetScriptInterface()->CallFunction(global, "handleInputBeforeGui", handled, *ev, top()->FindObjectUnderMouse())) | if (top()->GetScriptInterface()->CallFunction(global, "handleInputBeforeGui", handled, *ev, top()->FindObjectUnderMouse())) | ||||
if (handled) | if (handled) | ||||
return IN_HANDLED; | return IN_HANDLED; | ||||
} | } | ||||
{ | { | ||||
PROFILE("handle event in native GUI"); | PROFILE("handle event in native GUI"); | ||||
InReaction r = top()->HandleEvent(ev); | InReaction r = top()->HandleEvent(ev); | ||||
if (r != IN_PASS) | if (r != IN_PASS) | ||||
return r; | return r; | ||||
} | } | ||||
{ | { | ||||
// We can't take the following lines out of this scope because top() may be another gui page than it was when calling handleInputBeforeGui! | // We can't take the following lines out of this scope because top() may be another gui page than it was when calling handleInputBeforeGui! | ||||
ScriptInterface::Request rq(*top()->GetScriptInterface()); | ScriptInterface::Request rq(*top()->GetScriptInterface()); | ||||
JS::RootedValue global(rq.cx, top()->GetGlobalObject()); | JS::RootedValue global(rq.cx, rq.globalValue()); | ||||
PROFILE("handleInputAfterGui"); | PROFILE("handleInputAfterGui"); | ||||
if (top()->GetScriptInterface()->CallFunction(global, "handleInputAfterGui", handled, *ev)) | if (top()->GetScriptInterface()->CallFunction(global, "handleInputAfterGui", handled, *ev)) | ||||
if (handled) | if (handled) | ||||
return IN_HANDLED; | return IN_HANDLED; | ||||
} | } | ||||
return IN_PASS; | return IN_PASS; | ||||
▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator