InputHandler.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 InputHandler
  21. {
  22. std::vector<SDL_Event> eventsQueue;
  23. boost::mutex eventsMutex;
  24. Point cursorPosition;
  25. std::vector<SDL_Event> acquireEvents();
  26. void preprocessEvent(const SDL_Event & event);
  27. void handleCurrentEvent(const SDL_Event & current);
  28. void handleUserEvent(const SDL_UserEvent & current);
  29. std::unique_ptr<InputSourceMouse> mouseHandler;
  30. std::unique_ptr<InputSourceKeyboard> keyboardHandler;
  31. std::unique_ptr<InputSourceTouch> fingerHandler;
  32. std::unique_ptr<InputSourceText> textHandler;
  33. public:
  34. InputHandler();
  35. ~InputHandler();
  36. /// Fetches events from SDL input system and prepares them for processing
  37. void fetchEvents();
  38. /// Performs actual processing and dispatching of previously fetched events
  39. void processEvents();
  40. /// drops all incoming events without processing them
  41. /// returns true if input event has been found
  42. bool ignoreEventsUntilInput();
  43. /// Moves cursor by specified distance
  44. void moveCursorPosition(const Point & distance);
  45. /// Moves cursor to a specified position
  46. void setCursorPosition(const Point & position);
  47. /// Initiates text input in selected area, potentially creating IME popup (mobile systems only at the moment)
  48. void startTextInput(const Rect & where);
  49. /// Ends any existing text input state
  50. void stopTextInput();
  51. /// do a haptic feedback
  52. void hapticFeedback();
  53. /// Get the number of milliseconds since SDL library initialization
  54. uint32_t getTicks();
  55. /// returns true if system has active touchscreen
  56. bool hasTouchInputDevice() const;
  57. /// Calls provided functor in main thread on next execution frame
  58. void dispatchMainThread(const std::function<void()> & functor);
  59. /// Returns current position of cursor, in VCMI logical screen coordinates
  60. const Point & getCursorPosition() const;
  61. /// returns true if chosen keyboard key is currently pressed down
  62. bool isKeyboardAltDown() const;
  63. bool isKeyboardCtrlDown() const;
  64. bool isKeyboardShiftDown() const;
  65. };