Exemplo n.º 1
0
void Viewer::handleEvent()
{
    sf::Event event;
    while(m_window.pollEvent(event))
    {
        switch(event.type)
        {
        case sf::Event::Closed:
            m_applicationRunning=false;
            break;
        case sf::Event::Resized:
            m_window.setView(sf::View(sf::FloatRect(0, 0, event.size.width, event.size.height)));
            m_camera.setRatio( (float)(m_window.getSize().x)/(float)(m_window.getSize().y) );
            m_tengine.setWindowDimensions( m_window.getSize().x, m_window.getSize().y );
            glcheck(glViewport(0, 0, event.size.width, event.size.height));
            break;
        case sf::Event::KeyPressed:
            keyPressedEvent(event);
            break;

        case sf::Event::KeyReleased:
            keyReleasedEvent(event);
            break;
        case sf::Event::MouseWheelMoved:
            mouseWheelEvent(event);
            break;
        case sf::Event::MouseButtonPressed:
            mousePressEvent(event);
            break;
        case sf::Event::MouseButtonReleased:
            mouseReleaseEvent(event);
            break;
        case sf::Event::MouseMoved:
            mouseMoveEvent(event);
            break;
        default:
            break;
        }
    }

    if( m_camera.getMouseBehavior() == Camera::SPACESHIP_BEHAVIOR
            && (keyboard.forward || keyboard.backward || keyboard.left || keyboard.right ) )
    {
        float speed = keyboard.speed * Duration(clock::now() - m_lastEventHandleTime).count();
        if( keyboard.fast )
            speed *= float(15.0);
        else if ( keyboard.slow )
            speed *= float(0.5);
        glm::vec3 shift = speed * normalize( keyboard.direction );
        m_camera.setPosition( m_camera.getPosition()
                              + shift.x * m_camera.getRight()
                              + shift.y * m_camera.getUp()
                              + shift.z * m_camera.getForward() );
    }
    m_lastEventHandleTime = clock::now();
}
Exemplo n.º 2
0
void FocusManager::KeyReleased(int keyCode, int modifier)
{
	if(m_focusedComponent != 0 )
	{
		KeyEvent keyReleasedEvent(m_focusedComponent, KEY_RELEASED, keyCode, modifier);
		m_focusedComponent->ProcessKeyEvent(keyReleasedEvent);

		KeyEvent keyTypedEvent(m_focusedComponent, KEY_TYPED, keyCode, modifier);
		m_focusedComponent->ProcessKeyEvent(keyTypedEvent);
	}
}