1
0
mirror of https://github.com/vcmi/vcmi.git synced 2026-05-22 09:55:17 +02:00
Files
vcmi/client/eventsSDL/InputHandler.h
T
Boris Nagaev 38bfd1c7e5 Fix broken relative local include paths
Many quoted local includes had an incorrect ../ depth and resolved to
non-existent files from the including file's directory.

This was easy to miss because normal target include directories and PCH
usage masked some failures, and several stale paths lived in files that
are only compiled in optional test configurations. As a result, the
problem mostly surfaced in stricter or broader fresh builds.

Audit all C++ and header local includes, keep them relative, and adjust
paths so each include resolves to an existing in-tree header. For
headers that were renamed or moved, update includes to their current
relative location instead of switching to include-root form.

A few legacy ERM tests also used dynamic_ptr_cast at call sites where we
had to replace stale headers. The helper/header path they relied on is
no longer present after 81af66d35b, so
those downcasts are now explicit dynamic_cast calls with the same intent.
2026-03-26 20:14:59 -05:00

136 lines
3.4 KiB
C++

/*
* 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"
#include <tbb/concurrent_queue.h>
enum class EUserEvent;
enum class MouseButton;
union SDL_Event;
struct SDL_UserEvent;
class InputSourceMouse;
class InputSourceKeyboard;
class InputSourceTouch;
class InputSourceText;
class InputSourceGameController;
enum class InputMode
{
KEYBOARD_AND_MOUSE,
TOUCH,
CONTROLLER
};
enum class PowerStateMode
{
UNKNOWN,
CHARGING,
ON_BATTERY
};
struct PowerState {
PowerStateMode powerState;
int seconds;
int percent;
};
class InputHandler
{
std::vector<SDL_Event> eventsQueue;
tbb::concurrent_queue<std::unique_ptr<std::function<void()>>> dispatchedTasks;
std::mutex eventsMutex;
Point cursorPosition;
const bool enableMouse;
const bool enableTouch;
const bool enableController;
InputMode currentInputMode;
void setCurrentInputMode(InputMode modi);
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;
std::unique_ptr<InputSourceGameController> gameControllerHandler;
// Cached power state updated asynchronously via TBB
std::atomic<int> cachedPowerStateMode;
std::atomic<int> cachedPowerStateSeconds;
std::atomic<int> cachedPowerStatePercent;
uint32_t powerStateFrameCounter;
void updatePowerState();
public:
InputHandler();
~InputHandler();
/// Fetches events from SDL input system and prepares them for processing
void fetchEvents();
/// 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);
/// Initiates text input in selected area, potentially creating IME popup (mobile systems only at the moment)
void startTextInput(const Rect & where);
/// Ends any existing text input state
void stopTextInput();
/// do a haptic feedback
void hapticFeedback();
/// Get the number of milliseconds since SDL library initialization
uint32_t getTicks();
/// returns true if system has active touchscreen
bool hasTouchInputDevice() const;
/// returns number of fingers on touchscreen
int getNumTouchFingers() const;
/// Calls provided functor in main thread on next execution frame
void dispatchMainThread(const std::function<void()> & functor);
/// 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 isKeyboardCmdDown() const;
bool isKeyboardCtrlDown() const;
bool isKeyboardShiftDown() const;
InputMode getCurrentInputMode();
void copyToClipBoard(const std::string & text);
PowerState getPowerState();
};