示例#1
0
void SDLWrapper::processEvents()
{
	SDL_Event event;
	while (SDL_PollEvent(&event))
	{
		switch (event.type) {

		case SDL_MOUSEMOTION:
			if (m_onMouseMove)
				m_onMouseMove(event.motion.x, event.motion.y);
			break;

		case SDL_MOUSEWHEEL:
			if(m_onMouseWheel)
				m_onMouseWheel(event.wheel.x, event.wheel.y);
			break;

		case SDL_KEYDOWN:
			std::clog << "sym " << (int)(event.key.keysym.sym) << " scancode " << event.key.keysym.scancode << std::endl;
			{
				auto itFind = m_keyboardEventBindings.find(event.key.keysym.sym);
				if (itFind != m_keyboardEventBindings.end())
					itFind->second();
			}
			break;

		case SDL_QUIT:
			if (m_quitEvent)
				m_quitEvent();
		}
	}
}
示例#2
0
void InputHandler::update()
{
    SDL_Event event;

    while(SDL_PollEvent(&event))
    {
        if(event.type == SDL_QUIT)
        {
            SharedGame::Instance().quit();
        }

        // update the state of keys
        m_keystates = (Uint8*)SDL_GetKeyboardState(0);

        if(m_bJoysticksInitialised)
        {
            if(event.type == SDL_JOYAXISMOTION)
            {
                m_onJoystickAxisMove(event);
            }

            if(event.type == SDL_JOYBUTTONDOWN)
            {
                m_onJoystickButtonDown(event);
            }

            if(event.type == SDL_JOYBUTTONUP)
            {
                m_onJoystickButtonUp(event);
            }
        }


        if(event.type == SDL_MOUSEBUTTONDOWN)
        {
            m_onMouseButtonDown(event);
        }

        if(event.type == SDL_MOUSEBUTTONUP)
        {
            m_onMouseButtonUp(event);
        }

        if(event.type == SDL_MOUSEMOTION)
        {
            m_onMouseMove(event);
        }
    }
}