예제 #1
0
void InputEventController::ProcessInputEvent(const SDL_Event &evt)
{
	switch (evt.type) {
		case SDL_KEYDOWN: OnKeyPressed(evt.key); break;
		case SDL_KEYUP: OnKeyReleased(evt.key); break;
		case SDL_TEXTINPUT: OnTextInput(evt.text); break;

		case SDL_MOUSEMOTION: OnMouseMoved(evt.motion); break;
		case SDL_MOUSEBUTTONDOWN: OnMousePressed(evt.button); break;
		case SDL_MOUSEBUTTONUP: OnMouseReleased(evt.button); break;
		case SDL_MOUSEWHEEL: OnMouseWheel(evt.wheel); break;

		default:
			HR_LOG(info) << "Unhandled input event type: " << evt.type;
	}
}
예제 #2
0
bool TextEntry::OnKeyDown(const SDL_Keysym *sym)
{
	bool accepted = false;
	bool changed = false;

	int oldNewlineCount = m_newlineCount;

	// XXX moving the cursor is not UTF-8 safe
	if (sym->sym == SDLK_LEFT || sym->sym == SDLK_RIGHT) {
		bool forward = (sym->sym == SDLK_RIGHT);
		int direction = (forward) ? 1 : -1;
		if (!(sym->mod & KMOD_CTRL)) {
			SetCursorPos(m_cursPos + direction);
		} else {
			int inspect_offset = (forward) ? 0 : -1; // When going back, we need the character before the cursor.
			int ending = (forward) ? m_text.size() : 0;
			int current = m_cursPos+inspect_offset;
			bool found_word = false;

			while(current != ending) {
				bool alphanum;

				alphanum = Text::is_alphanumunderscore(m_text[current]);

				if (found_word && !alphanum) { // Word boundary.
					current -= inspect_offset; // Make up for the initial offset.
					break;
				}
				current += direction;
				found_word = found_word || alphanum; // You need to be in a word before finding its boudaries.
			}
			SetCursorPos(current);
		}
		accepted = true;
	}

	// XXX deleting characters is not UTF-8 safe
	if (sym->sym == SDLK_BACKSPACE) {
		if (m_cursPos > 0) {
			if (m_text[m_cursPos-1] == '\n')
				--m_newlineCount;
			m_text = m_text.substr(0, m_cursPos-1) + m_text.substr(m_cursPos);
			SetCursorPos(m_cursPos-1);
			changed = true;
		}
		accepted = true;
	}
	if (sym->sym == SDLK_DELETE) {
		if (m_cursPos < signed(m_text.size())) {
			if (m_text[m_cursPos] == '\n')
				--m_newlineCount;
			m_text = m_text.substr(0, m_cursPos) + m_text.substr(m_cursPos+1);
			changed = true;
		}
		accepted = true;
	}

	if (sym->sym == SDLK_HOME) {
		size_t pos = m_text.rfind('\n', std::max(m_cursPos-1, 0));
		if (pos == std::string::npos)
			pos = 0;
		else
			++pos;
		m_cursPos = int(pos);
		accepted = true;
	}
	if (sym->sym == SDLK_END) {
		size_t pos = m_text.find('\n', m_cursPos);
		if (pos == std::string::npos)
			pos = m_text.size();
		m_cursPos = int(pos);
		accepted = true;
	}
	if (sym->sym == SDLK_RETURN) {
		switch (m_newlineMode) {
			case IgnoreNewline:
				accepted = false;
				break;
			case AcceptNewline:
				accepted = true;
				break;
			case AcceptCtrlNewline:
				accepted = sym->mod & KMOD_CTRL;
				break;
		}
		if (accepted) {
			++m_newlineCount;
			OnTextInput('\n');
		}
	}

	if (oldNewlineCount != m_newlineCount)
		ResizeRequest();

	onKeyPress.emit(sym);
	if (changed) onValueChanged.emit();

	return accepted;
}
예제 #3
0
void Control::NotificationTextInput(const SDL_TextInputEvent& textEvent)
{
    OnTextInput(textEvent);
}
예제 #4
0
void Events::Poll()
{
    GamePad::Clear();
    Joystick::Clear();
    Keyboard::Clear();
    Mouse::Clear();

    while (SDL_PollEvent(&mEvent))
    {
        switch (mEvent.type)
        {
        case SDL_QUIT:
            OnQuit();
            break;
        case SDL_APP_TERMINATING:
            OnAppTerminating();
            break;
        case SDL_APP_LOWMEMORY:
            OnAppLowMemory();
            break;
        case SDL_APP_WILLENTERBACKGROUND:
            OnAppWillEnterBackground();
            break;
        case SDL_APP_DIDENTERBACKGROUND:
            OnAppDidEnterBackground();
            break;
        case SDL_APP_WILLENTERFOREGROUND:
            OnAppWillEnterForeground();
            break;
        case SDL_APP_DIDENTERFOREGROUND:
            OnAppDidEnterForeground();
            break;
        case SDL_WINDOWEVENT:
            OnWindowEvent();
            break;
        case SDL_SYSWMEVENT:
            OnSysWMEvent();
            break;
        case SDL_KEYDOWN:
            OnKeyDown(mEvent.key.keysym.sym, mEvent.key.keysym.mod, mEvent.key.repeat);
            Keyboard::SetKey(mEvent.key.keysym.sym, true);
            break;
        case SDL_KEYUP:
            OnKeyUp(mEvent.key.keysym.sym, mEvent.key.keysym.mod, mEvent.key.repeat);
            Keyboard::SetKey(mEvent.key.keysym.sym, false);
            break;
        case SDL_TEXTEDITING:
            OnTextEditing();
            break;
        case SDL_TEXTINPUT:
            OnTextInput();
            break;
        case SDL_MOUSEMOTION:
            OnMouseMotion(mEvent.motion.x, mEvent.motion.y, mEvent.motion.xrel, mEvent.motion.yrel);
            Mouse::SetPosition(mEvent.motion.x, mEvent.motion.y);
            break;
        case SDL_MOUSEBUTTONDOWN:
            switch(mEvent.button.button)
            {
            case SDL_BUTTON_LEFT:
                OnMouseLeftButtonDown(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_RIGHT:
                OnMouseRightButtonDown(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_MIDDLE:
                OnMouseMiddleButtonDown(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_X1:
                OnMouseLeftButtonDown(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_X2:
                OnMouseLeftButtonDown(mEvent.button.x, mEvent.button.y);
                break;
            }
            break;
        case SDL_MOUSEBUTTONUP:
            switch(mEvent.button.button)
            {
            case SDL_BUTTON_LEFT:
                OnMouseLeftButtonUp(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_RIGHT:
                OnMouseRightButtonUp(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_MIDDLE:
                OnMouseMiddleButtonUp(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_X1:
                OnMouseLeftButtonUp(mEvent.button.x, mEvent.button.y);
                break;
            case SDL_BUTTON_X2:
                OnMouseLeftButtonUp(mEvent.button.x, mEvent.button.y);
                break;
            }
            break;
        case SDL_MOUSEWHEEL:
            OnMouseWheel(mEvent.wheel.x, mEvent.wheel.y);
            Mouse::SetScroll(mEvent.wheel.x, mEvent.wheel.y);
            break;
        case SDL_JOYAXISMOTION:
            OnJoyAxisMotion();
            break;
        case SDL_JOYBALLMOTION:
            OnJoyBallMotion();
            break;
        case SDL_JOYHATMOTION:
            OnJoyHatMotion();
            break;
        case SDL_JOYBUTTONDOWN:
            OnJoyBallButtonDown();
            break;
        case SDL_JOYBUTTONUP:
            OnJoyBallButtonUp();
            break;
        case SDL_JOYDEVICEADDED:
            OnJoyDeviceAdded();
            break;
        case SDL_JOYDEVICEREMOVED:
            OnJoyDeviceRemoved();
            break;
        case SDL_CONTROLLERAXISMOTION:
            OnControllerAxisMotion(mEvent.caxis.axis, mEvent.caxis.value, mEvent.caxis.which);
            GamePad::SetAxis(mEvent.caxis.axis, mEvent.caxis.value, mEvent.caxis.which);
            break;
        case SDL_CONTROLLERBUTTONDOWN:
            OnControllerButtonDown(mEvent.cbutton.button, mEvent.cbutton.which);
            GamePad::SetButton(mEvent.cbutton.button, true, mEvent.cbutton.which);
            break;
        case SDL_CONTROLLERBUTTONUP:
            OnControllerButtonUp(mEvent.cbutton.button, mEvent.cbutton.which);
            GamePad::SetButton(mEvent.cbutton.button, false, mEvent.cbutton.which);
            break;
        case SDL_CONTROLLERDEVICEADDED:
            OnControllerDeviceAdded(mEvent.cdevice.which);
            GamePad::Add(mEvent.cdevice.which);
            break;
        case SDL_CONTROLLERDEVICEREMOVED:
            OnControllerDeviceRemoved(mEvent.cdevice.which);
            GamePad::Remove(mEvent.cdevice.which);
            break;
        case SDL_CONTROLLERDEVICEREMAPPED:
            OnControllerDeviceRemapped(mEvent.cdevice.which);
            break;
        case SDL_FINGERDOWN:
            OnFingerDown();
            break;
        case SDL_FINGERUP:
            OnFingerUp();
            break;
        case SDL_FINGERMOTION:
            OnFingerMotion();
            break;
        case SDL_DOLLARGESTURE:
            OnDollarGesture();
            break;
        case SDL_DOLLARRECORD:
            OnDollarRecord();
            break;
        case SDL_MULTIGESTURE:
            OnMultiGesture();
            break;
        case SDL_CLIPBOARDUPDATE:
            OnClipboardUpdate();
            break;
        case SDL_DROPFILE:
            OnDropFile();
            break;
        case SDL_USEREVENT:
            OnUserEvent();
            break;
        default:
            OnUndefined();
            break;
        }
    }
}