Example #1
1
bool EventDispatcher::DispatchSDLEvent(const SDL_Event &event)
{
	switch (event.type) {
		case SDL_KEYDOWN:
			return Dispatch(KeyboardEvent(KeyboardEvent::KEY_DOWN, KeySym(event.key.keysym.sym, SDL_Keymod(event.key.keysym.mod))));

		case SDL_KEYUP:
			return Dispatch(KeyboardEvent(KeyboardEvent::KEY_UP, KeySym(event.key.keysym.sym, SDL_Keymod(event.key.keysym.mod))));

		case SDL_TEXTINPUT:
			Uint32 unicode;
			Text::utf8_decode_char(&unicode, event.text.text);
			return Dispatch(TextInputEvent(unicode));

		case SDL_MOUSEWHEEL:
			return Dispatch(MouseWheelEvent(event.wheel.y > 0 ? MouseWheelEvent::WHEEL_UP : MouseWheelEvent::WHEEL_DOWN, m_lastMousePosition));

		case SDL_MOUSEBUTTONDOWN:
			return Dispatch(MouseButtonEvent(MouseButtonEvent::BUTTON_DOWN, MouseButtonFromSDLButton(event.button.button), Point(event.button.x,event.button.y)));

		case SDL_MOUSEBUTTONUP:
			return Dispatch(MouseButtonEvent(MouseButtonEvent::BUTTON_UP, MouseButtonFromSDLButton(event.button.button), Point(event.button.x,event.button.y)));

		case SDL_MOUSEMOTION:
			return Dispatch(MouseMotionEvent(Point(event.motion.x,event.motion.y), Point(event.motion.xrel, event.motion.yrel)));
	}

	return false;
}
Example #2
1
bool EventDispatcher::DispatchSDLEvent(const SDL_Event &event)
{
	switch (event.type) {
		case SDL_KEYDOWN:
			return Dispatch(KeyboardEvent(KeyboardEvent::KEY_DOWN, KeySym(event.key.keysym.sym, SDL_Keymod(event.key.keysym.mod)), event.key.repeat));

		case SDL_KEYUP:
			return Dispatch(KeyboardEvent(KeyboardEvent::KEY_UP, KeySym(event.key.keysym.sym, SDL_Keymod(event.key.keysym.mod)), event.key.repeat));

		case SDL_TEXTINPUT:
			Uint32 unicode;
			Text::utf8_decode_char(&unicode, event.text.text);
			return Dispatch(TextInputEvent(unicode));

		case SDL_MOUSEWHEEL:
			return Dispatch(MouseWheelEvent(event.wheel.y > 0 ? MouseWheelEvent::WHEEL_UP : MouseWheelEvent::WHEEL_DOWN, m_lastMousePosition));

		case SDL_MOUSEBUTTONDOWN:
			return Dispatch(MouseButtonEvent(MouseButtonEvent::BUTTON_DOWN, MouseButtonFromSDLButton(event.button.button), Point(event.button.x,event.button.y)));

		case SDL_MOUSEBUTTONUP:
			return Dispatch(MouseButtonEvent(MouseButtonEvent::BUTTON_UP, MouseButtonFromSDLButton(event.button.button), Point(event.button.x,event.button.y)));

		case SDL_MOUSEMOTION:
			return Dispatch(MouseMotionEvent(Point(event.motion.x,event.motion.y), Point(event.motion.xrel, event.motion.yrel)));

		case SDL_JOYAXISMOTION:
			// SDL joystick axis value is documented to have the range -32768 to 32767
			// unfortunately this places the centre at -0.5, not at zero, which is clearly nuts...
			// so since that doesn't make any sense, we assume the range is *actually* -32767 to +32767,
			// and scale it accordingly, clamping the output so that if we *do* get -32768, it turns into -1
			return Dispatch(JoystickAxisMotionEvent(event.jaxis.which, Clamp(event.jaxis.value * (1.0f / 32767.0f), -1.0f, 1.0f), event.jaxis.axis));

		case SDL_JOYHATMOTION:
			return Dispatch(JoystickHatMotionEvent(event.jhat.which, JoystickHatMotionEvent::JoystickHatDirection(event.jhat.value), event.jhat.hat));

		case SDL_JOYBUTTONDOWN:
			return Dispatch(JoystickButtonEvent(event.jbutton.which, JoystickButtonEvent::BUTTON_DOWN, event.jbutton.button));

		case SDL_JOYBUTTONUP:
			return Dispatch(JoystickButtonEvent(event.jbutton.which, JoystickButtonEvent::BUTTON_UP, event.jbutton.button));
	}

	return false;
}
Example #3
0
void EventLoop::processSystemEvents()
{
	sf::Event ev;
	EventPtr evtWrapper;
	while (m_system.m_appWindow.GetEvent(ev))  {
		switch (ev.Type)  {
		case sf::Event::Closed:
			handleEvent(CloseEvent(ev));
		break;
		case sf::Event::MouseButtonPressed:
			handleEvent(MouseDownEvent(ev));
		break;
		case sf::Event::MouseButtonReleased:
			handleEvent(MouseUpEvent(ev));
		break;
		case sf::Event::MouseWheelMoved:
			handleEvent(MouseWheelEvent(ev));
		break;
		case sf::Event::KeyPressed:
			handleEvent(KeyDownEvent(ev));
		break;
		case sf::Event::KeyReleased:
			handleEvent(KeyUpEvent(ev));
		break;
		}
	}
}
Example #4
0
	void Application::processEvents(Context& context)
	{
		SDL_Event event;

		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
			case SDL_KEYDOWN:
			case SDL_KEYUP:
				keyEvent(context, createKeyPressEvent(event.key));
				break;
			case SDL_TEXTINPUT:
				textInputEvent(context, TextInputEvent(event.text.text));
				break;
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				mouseButtonEvent(context, createMouseButtonEvent(event.button, video.getScreen().getClientHeight()));
				break;
			case SDL_MOUSEMOTION:
				mouseMotionEvent(context, createMouseMotionEvent(event.motion, video.getScreen().getClientHeight()));
				break;
			case SDL_MOUSEWHEEL:
				mouseWheelEvent(context, MouseWheelEvent(0, 0, event.wheel.x, event.wheel.y));
				break;
			case SDL_QUIT:
				requestClose = true;
				break;
			default:
				break;
			}
		}
	}
Example #5
0
bool Widget::TriggerMouseWheel(const MouseWheelEvent &event, bool handled)
{
	HandleMouseWheel(event);
	if (!handled) handled = onMouseWheel.emit(event);
	if (GetContainer()) {
		MouseWheelEvent translatedEvent = MouseWheelEvent(event.direction, event.pos+GetPosition());
		handled = GetContainer()->TriggerMouseWheel(translatedEvent, handled);
	}
	return handled;
}
Example #6
0
bool Widget::TriggerMouseWheel(const MouseWheelEvent &event, bool emit)
{
	HandleMouseWheel(event);
	if (emit) emit = !onMouseWheel.emit(event);
	if (GetContainer()) {
		MouseWheelEvent translatedEvent = MouseWheelEvent(event.direction, event.pos+GetPosition());
		GetContainer()->TriggerMouseWheel(translatedEvent, emit);
	}
	return !emit;
}
void WinInputManager::Run(UINT const & msg, WPARAM wParam, LPARAM lParam)
{
    if (m_listenerList.empty())
        return;

    eKeyCodes KeyIndex;
    wchar_t buffer[1];
    BYTE lpKeyState[256];

    CursorEvent();
    switch (msg)
    {
    case WM_KEYDOWN:
        KeyIndex = static_cast<eKeyCodes>(wParam);
        GetKeyboardState(lpKeyState);
        ToUnicode(wParam, HIWORD(lParam) & 0xFF, lpKeyState, buffer, 1, 0);
        KeyEvent(KeyIndex, buffer[0], true);
        break;
    case WM_KEYUP:
        KeyIndex = static_cast<eKeyCodes>(wParam);
        GetKeyboardState(lpKeyState);
        ToUnicode(wParam, HIWORD(lParam) & 0xFF, lpKeyState, buffer, 1, 0);
        KeyEvent(KeyIndex, buffer[0], false);
        break;
    case WM_LBUTTONDOWN:
        MouseEvent(MOUSE_LEFT, true);
        break;
    case WM_LBUTTONUP:
        MouseEvent(MOUSE_LEFT, false);
        break;
    case WM_RBUTTONDOWN:
        MouseEvent(MOUSE_RIGHT, true);
        break;
    case WM_RBUTTONUP:
        MouseEvent(MOUSE_RIGHT, false);
        break;
    case WM_MBUTTONDOWN:
        MouseEvent(MOUSE_MIDDLE, true);
        break;
    case WM_MBUTTONUP:
        MouseEvent(MOUSE_MIDDLE, false);
        break;
    case WM_MOUSEWHEEL:
        MouseWheelEvent((short)GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA);
        break;
    }
}