コード例 #1
0
IGUIDocument* GUISystem::LoadDocument(const char* file, const char* id)
{
	assert(m_pContext);

	// Check for an existing document with this ID
	Rocket::Core::ElementDocument* pExisting = m_pContext->GetDocument(id);
	
	Rocket::Core::ElementDocument* pED = m_pContext->LoadDocument(file);
	if (pED)
	{
		if (pExisting)
		{
			// Delete existing document now that new one has been successfully loaded
			pExisting->Hide();
			m_pContext->UnloadDocument(pExisting);
		}

		pED->SetId(id);
		return InstanceDocument(pED, true);
	}

	return NULL;
}
コード例 #2
0
// Loads a window and binds the event handler for it.
Rocket::Core::ElementDocument* EventManager::LoadWindow(const Rocket::Core::String& window_name)
{
    // Set the event handler for the new screen, if one has been registered.
    EventHandler* old_event_handler = event_handler;
    EventHandlerMap::iterator iterator = event_handlers.find(window_name);
    if (iterator != event_handlers.end())
    {
        event_handler = iterator->second;
        //Rocket::Core::Log::Message(Rocket::Core::Log::LT_INFO, "%s", window_name.CString());
    }
    else
        event_handler = NULL;

    // Attempt to load the referenced RML document.
    Rocket::Core::String document_path = Rocket::Core::String("data/") + window_name + Rocket::Core::String(".rml");
    Rocket::Core::ElementDocument* document = Context->LoadDocument(document_path.CString());
    if (document == nullptr)
    {
        event_handler = old_event_handler;
        return nullptr;
    }

    document->SetId(window_name);

    // Set the element's title on the title; IDd 'title' in the RML.
    Rocket::Core::Element* title = document->GetElementById("title");
    if (title != NULL)
        title->SetInnerRML(document->GetTitle());

    document->Focus();
    document->Show();

    // Remove the caller's reference.
    document->RemoveReference();

    return document;
}