コード例 #1
0
// Releases all event handlers registered with the manager.
void EventManager::Shutdown()
{
    for (EventHandlerMap::iterator i = event_handlers.begin(); i != event_handlers.end(); ++i)
        delete (*i).second;

    event_handlers.clear();
    event_handler = NULL;
}
コード例 #2
0
// Processes an event coming through from Rocket.
void EventManager::ProcessEvent(Rocket::Core::Event& event, const Rocket::Core::String& value)
{
    Rocket::Core::StringList commands;
    Rocket::Core::StringUtilities::ExpandString(commands, value, ';');

    if(commands.size() == 0)
    {
        //send only the event to event handlers
        for(EventHandlerMap::iterator it = event_handlers.begin(); it != event_handlers.end(); it++)
            if(it->second != NULL)
                it->second->ProcessEvent(event, "");
    }
    else
    {
        for (size_t i = 0; i < commands.size(); ++i)
        {
            // Check for a generic 'load' or 'exit' command.
            Rocket::Core::StringList values;
            Rocket::Core::StringUtilities::ExpandString(values, commands[i], ' ');

            //if (values.empty())
            //	return;

            if (values[0] == "goto" &&
                    values.size() > 1)
            {
                // Load the window, and if successful close the old window.
                if (LoadWindow(values[1]))
                    event.GetTargetElement()->GetOwnerDocument()->Close();
            }
            else if (values[0] == "load" &&
                     values.size() > 1)
            {
                // Load the window.
                LoadWindow(values[1]);
            }
            else if (values[0] == "close")
            {
                Rocket::Core::ElementDocument* target_document = NULL;

                if (values.size() > 1)
                    target_document = Context->GetDocument(values[1].CString());
                else
                    target_document = event.GetTargetElement()->GetOwnerDocument();

                if (target_document != NULL)
                    target_document->Close();
            }
            else if (values[0] == "exit")
            {
                Shell::RequestExit();
            }
            /*
            		else if (values[0] == "pause")
            		{
            			GameDetails::SetPaused(true);
            		}
            		else if (values[0] == "unpause")
            		{
            			GameDetails::SetPaused(false);
            		}
            */
            else
            {
                //send the event to all windows
                for(EventHandlerMap::iterator it = event_handlers.begin(); it != event_handlers.end(); it++)
                    if(it->second != NULL)
                        it->second->ProcessEvent(event, commands[i]);

                /*
                if (event_handler != NULL)
                {
                	event_handler->ProcessEvent(event, commands[i]);
                }
                */
            }
        }
    }
}