2023-05-18 19:32:29 +02:00
|
|
|
/*
|
|
|
|
* InputHandler.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../lib/Rect.h"
|
|
|
|
|
|
|
|
enum class EUserEvent;
|
|
|
|
enum class MouseButton;
|
|
|
|
union SDL_Event;
|
2023-06-26 20:51:10 +02:00
|
|
|
struct SDL_UserEvent;
|
2023-05-18 19:32:29 +02:00
|
|
|
|
|
|
|
class InputSourceMouse;
|
|
|
|
class InputSourceKeyboard;
|
|
|
|
class InputSourceTouch;
|
|
|
|
class InputSourceText;
|
2024-04-03 14:34:22 +02:00
|
|
|
class InputSourceGameController;
|
2023-05-18 19:32:29 +02:00
|
|
|
|
2024-07-19 11:41:00 +02:00
|
|
|
enum class InputMode
|
2024-07-19 03:00:19 +02:00
|
|
|
{
|
2024-07-19 17:58:23 +02:00
|
|
|
KEYBOARD_AND_MOUSE,
|
2024-07-19 03:00:19 +02:00
|
|
|
TOUCH,
|
|
|
|
CONTROLLER
|
|
|
|
};
|
|
|
|
|
2023-05-18 19:32:29 +02:00
|
|
|
class InputHandler
|
|
|
|
{
|
2023-05-19 17:15:56 +02:00
|
|
|
std::vector<SDL_Event> eventsQueue;
|
|
|
|
boost::mutex eventsMutex;
|
2023-05-18 22:31:05 +02:00
|
|
|
|
2023-05-18 19:32:29 +02:00
|
|
|
Point cursorPosition;
|
|
|
|
|
2024-04-30 19:11:09 +02:00
|
|
|
const bool enableMouse;
|
|
|
|
const bool enableTouch;
|
|
|
|
const bool enableController;
|
|
|
|
|
2024-07-19 11:41:00 +02:00
|
|
|
InputMode currentInputMode;
|
|
|
|
void setCurrentInputMode(InputMode modi);
|
2024-07-19 03:00:19 +02:00
|
|
|
|
2023-07-24 22:01:44 +02:00
|
|
|
std::vector<SDL_Event> acquireEvents();
|
|
|
|
|
2023-05-18 19:32:29 +02:00
|
|
|
void preprocessEvent(const SDL_Event & event);
|
|
|
|
void handleCurrentEvent(const SDL_Event & current);
|
2023-06-26 20:51:10 +02:00
|
|
|
void handleUserEvent(const SDL_UserEvent & current);
|
2023-05-18 19:32:29 +02:00
|
|
|
|
|
|
|
std::unique_ptr<InputSourceMouse> mouseHandler;
|
|
|
|
std::unique_ptr<InputSourceKeyboard> keyboardHandler;
|
|
|
|
std::unique_ptr<InputSourceTouch> fingerHandler;
|
|
|
|
std::unique_ptr<InputSourceText> textHandler;
|
2024-04-30 10:38:13 +02:00
|
|
|
std::unique_ptr<InputSourceGameController> gameControllerHandler;
|
2023-05-18 19:32:29 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
InputHandler();
|
|
|
|
~InputHandler();
|
|
|
|
|
2023-05-20 00:51:10 +02:00
|
|
|
/// Fetches events from SDL input system and prepares them for processing
|
2023-05-18 19:32:29 +02:00
|
|
|
void fetchEvents();
|
2023-05-20 00:51:10 +02:00
|
|
|
/// Performs actual processing and dispatching of previously fetched events
|
2023-05-18 19:32:29 +02:00
|
|
|
void processEvents();
|
|
|
|
|
2023-05-18 22:31:05 +02:00
|
|
|
/// drops all incoming events without processing them
|
|
|
|
/// returns true if input event has been found
|
|
|
|
bool ignoreEventsUntilInput();
|
|
|
|
|
2023-05-26 14:55:31 +02:00
|
|
|
/// Moves cursor by specified distance
|
|
|
|
void moveCursorPosition(const Point & distance);
|
|
|
|
|
|
|
|
/// Moves cursor to a specified position
|
|
|
|
void setCursorPosition(const Point & position);
|
2023-05-20 00:51:10 +02:00
|
|
|
|
|
|
|
/// Initiates text input in selected area, potentially creating IME popup (mobile systems only at the moment)
|
2023-05-18 19:32:29 +02:00
|
|
|
void startTextInput(const Rect & where);
|
2023-05-20 00:51:10 +02:00
|
|
|
|
|
|
|
/// Ends any existing text input state
|
2023-05-18 19:32:29 +02:00
|
|
|
void stopTextInput();
|
2023-05-20 00:51:10 +02:00
|
|
|
|
2023-07-23 15:17:30 +02:00
|
|
|
/// do a haptic feedback
|
|
|
|
void hapticFeedback();
|
|
|
|
|
2023-08-26 19:53:36 +02:00
|
|
|
/// Get the number of milliseconds since SDL library initialization
|
2023-08-26 22:30:02 +02:00
|
|
|
uint32_t getTicks();
|
2023-08-26 19:53:36 +02:00
|
|
|
|
2023-05-30 19:08:27 +02:00
|
|
|
/// returns true if system has active touchscreen
|
|
|
|
bool hasTouchInputDevice() const;
|
|
|
|
|
2023-06-26 20:51:10 +02:00
|
|
|
/// Calls provided functor in main thread on next execution frame
|
|
|
|
void dispatchMainThread(const std::function<void()> & functor);
|
2023-05-18 19:32:29 +02:00
|
|
|
|
2023-05-20 00:51:10 +02:00
|
|
|
/// Returns current position of cursor, in VCMI logical screen coordinates
|
2023-05-18 19:32:29 +02:00
|
|
|
const Point & getCursorPosition() const;
|
|
|
|
|
|
|
|
/// returns true if chosen keyboard key is currently pressed down
|
|
|
|
bool isKeyboardAltDown() const;
|
2024-05-12 19:09:31 +02:00
|
|
|
bool isKeyboardCmdDown() const;
|
2023-05-18 19:32:29 +02:00
|
|
|
bool isKeyboardCtrlDown() const;
|
|
|
|
bool isKeyboardShiftDown() const;
|
2024-07-19 03:00:19 +02:00
|
|
|
|
2024-07-19 11:41:00 +02:00
|
|
|
InputMode getCurrentInputMode();
|
2023-05-18 19:32:29 +02:00
|
|
|
};
|