InputHandler.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * InputHandler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../lib/Rect.h"
  12. enum class EUserEvent;
  13. enum class MouseButton;
  14. union SDL_Event;
  15. struct SDL_UserEvent;
  16. class InputSourceMouse;
  17. class InputSourceKeyboard;
  18. class InputSourceTouch;
  19. class InputSourceText;
  20. class InputSourceGameController;
  21. class InputHandler
  22. {
  23. std::vector<SDL_Event> eventsQueue;
  24. boost::mutex eventsMutex;
  25. Point cursorPosition;
  26. std::vector<SDL_Event> acquireEvents();
  27. void preprocessEvent(const SDL_Event & event);
  28. void handleCurrentEvent(const SDL_Event & current);
  29. void handleUserEvent(const SDL_UserEvent & current);
  30. std::unique_ptr<InputSourceMouse> mouseHandler;
  31. std::unique_ptr<InputSourceKeyboard> keyboardHandler;
  32. std::unique_ptr<InputSourceTouch> fingerHandler;
  33. std::unique_ptr<InputSourceText> textHandler;
  34. std::unique_ptr<InputSourceGameController> gameControllerHandler;
  35. public:
  36. InputHandler();
  37. ~InputHandler();
  38. /// Fetches events from SDL input system and prepares them for processing
  39. void fetchEvents();
  40. /// Performs actual processing and dispatching of previously fetched events
  41. void processEvents();
  42. /// drops all incoming events without processing them
  43. /// returns true if input event has been found
  44. bool ignoreEventsUntilInput();
  45. /// Moves cursor by specified distance
  46. void moveCursorPosition(const Point & distance);
  47. /// Moves cursor to a specified position
  48. void setCursorPosition(const Point & position);
  49. /// Initiates text input in selected area, potentially creating IME popup (mobile systems only at the moment)
  50. void startTextInput(const Rect & where);
  51. /// Ends any existing text input state
  52. void stopTextInput();
  53. /// do a haptic feedback
  54. void hapticFeedback();
  55. /// Get the number of milliseconds since SDL library initialization
  56. uint32_t getTicks();
  57. /// returns true if system has active touchscreen
  58. bool hasTouchInputDevice() const;
  59. /// Calls provided functor in main thread on next execution frame
  60. void dispatchMainThread(const std::function<void()> & functor);
  61. /// Returns current position of cursor, in VCMI logical screen coordinates
  62. const Point & getCursorPosition() const;
  63. /// returns true if chosen keyboard key is currently pressed down
  64. bool isKeyboardAltDown() const;
  65. bool isKeyboardCtrlDown() const;
  66. bool isKeyboardShiftDown() const;
  67. };