1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/client/eventsSDL/InputHandler.h

88 lines
2.3 KiB
C++
Raw Normal View History

/*
* 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;
struct SDL_UserEvent;
class InputSourceMouse;
class InputSourceKeyboard;
class InputSourceTouch;
class InputSourceText;
class InputHandler
{
2023-05-19 17:15:56 +02:00
std::vector<SDL_Event> eventsQueue;
boost::mutex eventsMutex;
Point cursorPosition;
std::vector<SDL_Event> acquireEvents();
void preprocessEvent(const SDL_Event & event);
void handleCurrentEvent(const SDL_Event & current);
void handleUserEvent(const SDL_UserEvent & current);
std::unique_ptr<InputSourceMouse> mouseHandler;
std::unique_ptr<InputSourceKeyboard> keyboardHandler;
std::unique_ptr<InputSourceTouch> fingerHandler;
std::unique_ptr<InputSourceText> textHandler;
public:
InputHandler();
~InputHandler();
2023-05-20 00:51:10 +02:00
/// Fetches events from SDL input system and prepares them for processing
void fetchEvents();
2023-05-20 00:51:10 +02:00
/// Performs actual processing and dispatching of previously fetched events
void processEvents();
/// drops all incoming events without processing them
/// returns true if input event has been found
bool ignoreEventsUntilInput();
/// 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)
void startTextInput(const Rect & where);
2023-05-20 00:51:10 +02:00
/// Ends any existing text input state
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
/// returns true if system has active touchscreen
bool hasTouchInputDevice() const;
/// Calls provided functor in main thread on next execution frame
void dispatchMainThread(const std::function<void()> & functor);
2023-05-20 00:51:10 +02:00
/// Returns current position of cursor, in VCMI logical screen coordinates
const Point & getCursorPosition() const;
/// returns true if chosen keyboard key is currently pressed down
bool isKeyboardAltDown() const;
bool isKeyboardCtrlDown() const;
bool isKeyboardShiftDown() const;
};