Exemple #1
0
void InputManager::HandleEvent( SDL_Event& ev )
{
    if ( ev.type == SDL_MOUSEMOTION )
    {
        HandleMouseMotionEvent( *reinterpret_cast<SDL_MouseMotionEvent*>( &ev ) );
    }
    else if ( ev.type == SDL_MOUSEBUTTONDOWN )
    {
        HandleMouseButtonEvent( *reinterpret_cast<SDL_MouseButtonEvent*>( &ev ), ButtonState::Pressed );
    }
    else if ( ev.type == SDL_MOUSEBUTTONUP )
    {
        HandleMouseButtonEvent( *reinterpret_cast<SDL_MouseButtonEvent*>( &ev ), ButtonState::Released );
    }
    else if ( ev.type == SDL_MOUSEWHEEL )
    {
        HandleMouseWheelEvent( ev.wheel );
    }
    else if ( ev.type == SDL_KEYDOWN )
    {
        HandleKeyboardEvent( ev.key, ButtonState::Pressed );
    }
    else if ( ev.type == SDL_KEYUP )
    {
        HandleKeyboardEvent( ev.key, ButtonState::Released );
    }

    if ( FrameWork::GetGuiManager() && FrameWork::GetGuiManager()->GetFocusedInputArea() )
    {
        HandleInputAreaEvent( ev );
    }
}
bool LocalEvent::HandleEvents(bool delay)
{
    SDL_Event event;

    ResetModes(MOUSE_MOTION);
    ResetModes(KEY_PRESSED);

    while(SDL_PollEvent(&event))
    {
	switch(event.type)
	{
	    case SDL_ACTIVEEVENT:
		if(event.active.state & SDL_APPACTIVE)
		{
#ifdef WITH_MIXER
		    if(Mixer::isValid())
		    {
			//iconify
			if(0 == event.active.gain)
			{
			    Mixer::Reset();
			    Music::Pause();
			    loop_delay = 100;
			}
			else
			    loop_delay = 1;
		    }
#endif
		}
		break;

	    // keyboard
	    case SDL_KEYDOWN:
	    case SDL_KEYUP:
                HandleKeyboardEvent(event.key);
	    	break;

	    // mouse motion
	    case SDL_MOUSEMOTION:
		HandleMouseMotionEvent(event.motion);
		break;

	    // mouse button
	    case SDL_MOUSEBUTTONDOWN:
	    case SDL_MOUSEBUTTONUP:
		HandleMouseButtonEvent(event.button);
		break;
	
	    // exit
	    case SDL_QUIT:
		Error::Except(__FUNCTION__, "SDL_QUIT");
		return false;

	    default:
		break;
	}

        // need for wheel up/down delay
        if(SDL_BUTTON_WHEELDOWN == event.button.button || SDL_BUTTON_WHEELUP == event.button.button) break;
    }

    // emulate press right
    if((modes & TAP_MODE) && (modes & CLOCK_ON))
    {
	clock.Stop();
	if(clock_delay < clock.Get())
	{
	    ResetModes(CLICK_LEFT);
	    ResetModes(CLOCK_ON);
	    mouse_pr = mouse_cu;
	    SetModes(MOUSE_PRESSED);
	    mouse_button = SDL_BUTTON_RIGHT;
	}
    }

    if(delay) SDL_Delay(loop_delay);

    return true;
}