コード例 #1
0
ファイル: state.cpp プロジェクト: AUmrysh/Machine
void State::OnEvent(const sf::Event::Event &e)
{
	switch (e.Type)
	{
		case sf::Event::KeyPressed:
			OnKeyPressed(e.Key.Code, e.Key.Alt, e.Key.Control, e.Key.Shift);
			break;

		case sf::Event::KeyReleased:
			OnKeyReleased(e.Key.Code, e.Key.Alt, e.Key.Control, e.Key.Shift);
			break;

		case sf::Event::MouseMoved:
			OnMouseMoved(e.MouseMove.X, e.MouseMove.Y);
			break;

		case sf::Event::MouseButtonPressed:
		{
			int x = e.MouseButton.X;
			int y = e.MouseButton.Y;

			switch (e.MouseButton.Button)
			{
				case sf::Mouse::Left:
					OnMouseLeftDown(x, y);
					buttons_[0] = true;
					break;

				case sf::Mouse::Right:
					OnMouseRightDown(x, y);
					buttons_[1] = true;
					break;

				case sf::Mouse::Middle:
					OnMouseMiddleDown(x, y);
					buttons_[2] = true;
					break;
			}

			break;
		}

		case sf::Event::MouseButtonReleased:
		{
			int x = e.MouseButton.X;
			int y = e.MouseButton.Y;

			switch (e.MouseButton.Button)
			{
				case sf::Mouse::Left:
					OnMouseLeftUp(x, y);

					if (buttons_[0])
					{
						buttons_[0] = false;
						OnMouseLeftClick(x, y);
					}

					break;

				case sf::Mouse::Right:
					OnMouseRightUp(x, y);

					if (buttons_[1])
					{
						buttons_[1] = false;
						OnMouseRightClick(x, y);
					}

					break;

				case sf::Mouse::Middle:
					OnMouseMiddleUp(x, y);

					if (buttons_[2])
					{
						buttons_[2] = false;
						OnMouseMiddleClick(x, y);
					}

					break;
			}

			break;
		}

		case sf::Event::MouseEntered:
			OnMouseEntered();
			break;

		case sf::Event::MouseLeft:
			OnMouseExited();
			break;

		case sf::Event::GainedFocus:
			OnGainedFocus();
			break;

		case sf::Event::LostFocus:
			OnLostFocus();
			break;
	}
}
コード例 #2
0
void EventHandler::OnEvent (sf::Event* event)
{
	switch (event->type)
	{
		case sf::Event::Closed:
			//Window closed:
			OnClosed();
			break;
		case sf::Event::Resized:
			//Window resized:
			OnWindowResized (event->size);
		case sf::Event::GainedFocus:
			//Window gained focus:
			OnGainedFocus();
			break;
		case sf::Event::LostFocus:
			//Window lost focus:
			OnLostFocus();
			break;
			break;
		case sf::Event::TextEntered:
			//Text entered:
			OnTextEntered (event->text);
			break;
		case sf::Event::KeyPressed:
			//Key pressed:
			OnKeyPressed (event->key);
			break;
		case sf::Event::KeyReleased:
			//Key released:
			OnKeyReleased (event->key);
			break;
		case sf::Event::MouseWheelMoved:
			//Mouse wheel moved:
			OnMouseWheelMoved (event->mouseWheel);
			break;
		case sf::Event::MouseButtonPressed:
			//Mouse button pressed:
			OnMouseButtonPressed (event->mouseButton);
			break;
		case sf::Event::MouseButtonReleased:
			//Mouse button released:
			OnMouseButtonReleased(event->mouseButton);
			break;
		case sf::Event::MouseMoved:
			//Mouse moved:
			OnMouseMoved (event->mouseMove);
			break;
		case sf::Event::MouseEntered:
			//Mouse entered Window bounds:
			OnMouseEntered();
			break;
		case sf::Event::MouseLeft:
			//Mouse left Window bounds:
			OnMouseLeft();
			break;
		case sf::Event::JoystickButtonPressed:
			//Joystick button pressed:
			OnJoystickButtonPressed (event->joystickButton);
			break;
		case sf::Event::JoystickButtonReleased:
			//Joystick button released:
			OnJoystickButtonReleased(event->joystickButton);
			break;
		case sf::Event::JoystickMoved:
			//Joystick moved:
			OnJoystickMoved(event->joystickMove);
			break;
		case sf::Event::JoystickConnected:
			//Joystick connected:
			OnJoystickConnected (event->joystickConnect);
			break;
		case sf::Event::JoystickDisconnected:
			//Joystick disconnected:
			OnJoystickDisconnected (event->joystickConnect);
			break;
		

	}
}