OpenRCT2/src/openrct2-ui/input/InputManager.h

78 lines
2.0 KiB
C
Raw Normal View History

2020-12-13 04:40:10 +01:00
/*****************************************************************************
* Copyright (c) 2014-2023 OpenRCT2 developers
2020-12-13 04:40:10 +01:00
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
2020-12-15 20:55:49 +01:00
#include <openrct2/world/Location.hpp>
2020-12-13 04:40:10 +01:00
#include <queue>
#include <string_view>
2020-12-13 04:40:10 +01:00
2020-12-16 00:14:40 +01:00
typedef struct _SDL_Joystick SDL_Joystick;
typedef union SDL_Event SDL_Event;
2020-12-13 04:40:10 +01:00
namespace OpenRCT2::Ui
{
2021-01-16 20:07:07 +01:00
class RegisteredShortcut;
struct ShortcutInput;
2020-12-13 04:40:10 +01:00
enum class InputDeviceKind
{
Mouse,
Keyboard,
2020-12-16 00:14:40 +01:00
JoyButton,
JoyHat,
2020-12-13 04:40:10 +01:00
};
enum class InputEventState
{
Down,
Release,
};
struct InputEvent
{
InputDeviceKind DeviceKind;
2020-12-13 23:51:50 +01:00
uint32_t Modifiers;
2020-12-13 04:40:10 +01:00
uint32_t Button;
InputEventState State;
};
class InputManager
{
private:
uint32_t _lastJoystickCheck{};
2020-12-16 00:14:40 +01:00
std::vector<SDL_Joystick*> _joysticks;
2020-12-13 04:40:10 +01:00
std::queue<InputEvent> _events;
2020-12-15 20:55:49 +01:00
ScreenCoordsXY _viewScroll;
uint32_t _mouseState{};
2021-01-16 20:07:07 +01:00
std::vector<uint8_t> _keyboardState;
2020-12-13 04:40:10 +01:00
2020-12-16 00:14:40 +01:00
void CheckJoysticks();
2020-12-15 20:55:49 +01:00
void HandleViewScrolling();
2020-12-15 00:12:19 +01:00
void HandleModifiers();
void ProcessEvents();
2020-12-13 04:40:10 +01:00
void Process(const InputEvent& e);
2020-12-15 00:12:19 +01:00
void ProcessInGameConsole(const InputEvent& e);
void ProcessChat(const InputEvent& e);
2021-01-16 20:07:07 +01:00
void ProcessHoldEvents();
void ProcessViewScrollEvent(std::string_view shortcutId, const ScreenCoordsXY& delta);
2021-01-16 20:07:07 +01:00
bool GetState(const RegisteredShortcut& shortcut) const;
bool GetState(const ShortcutInput& shortcut) const;
2020-12-13 04:40:10 +01:00
bool HasTextInputFocus() const;
2020-12-13 04:40:10 +01:00
public:
2020-12-16 00:14:40 +01:00
void QueueInputEvent(const SDL_Event& e);
2020-12-13 04:40:10 +01:00
void QueueInputEvent(InputEvent&& e);
void Process();
};
} // namespace OpenRCT2::Ui