InputHandler.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. class InputSourceMouse;
  16. class InputSourceKeyboard;
  17. class InputSourceTouch;
  18. class InputSourceText;
  19. class UserEventHandler;
  20. class InputHandler
  21. {
  22. std::vector<SDL_Event> eventsQueue;
  23. boost::mutex eventsMutex;
  24. Point cursorPosition;
  25. void preprocessEvent(const SDL_Event & event);
  26. void handleCurrentEvent(const SDL_Event & current);
  27. std::unique_ptr<InputSourceMouse> mouseHandler;
  28. std::unique_ptr<InputSourceKeyboard> keyboardHandler;
  29. std::unique_ptr<InputSourceTouch> fingerHandler;
  30. std::unique_ptr<InputSourceText> textHandler;
  31. std::unique_ptr<UserEventHandler> userHandler;
  32. public:
  33. InputHandler();
  34. ~InputHandler();
  35. /// Fetches events from SDL input system and prepares them for processing
  36. void fetchEvents();
  37. /// Performs actual processing and dispatching of previously fetched events
  38. void processEvents();
  39. /// drops all incoming events without processing them
  40. /// returns true if input event has been found
  41. bool ignoreEventsUntilInput();
  42. /// Moves cursor by specified distance
  43. void moveCursorPosition(const Point & distance);
  44. /// Moves cursor to a specified position
  45. void setCursorPosition(const Point & position);
  46. /// Initiates text input in selected area, potentially creating IME popup (mobile systems only at the moment)
  47. void startTextInput(const Rect & where);
  48. /// Ends any existing text input state
  49. void stopTextInput();
  50. /// returns true if system has active touchscreen
  51. bool hasTouchInputDevice() const;
  52. /// Generates new user event that will be processed on next frame
  53. void pushUserEvent(EUserEvent usercode, void * userdata);
  54. /// Returns current position of cursor, in VCMI logical screen coordinates
  55. const Point & getCursorPosition() const;
  56. /// returns true if chosen keyboard key is currently pressed down
  57. bool isKeyboardAltDown() const;
  58. bool isKeyboardCtrlDown() const;
  59. bool isKeyboardShiftDown() const;
  60. };