InputHandler.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. float pointerSpeedMultiplier;
  26. int mouseButtonsMask;
  27. void preprocessEvent(const SDL_Event & event);
  28. void handleCurrentEvent(const SDL_Event & 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. std::unique_ptr<UserEventHandler> userHandler;
  34. public:
  35. InputHandler();
  36. ~InputHandler();
  37. void fetchEvents();
  38. void processEvents();
  39. /// drops all incoming events without processing them
  40. /// returns true if input event has been found
  41. bool ignoreEventsUntilInput();
  42. void fakeMoveCursor(float dx, float dy);
  43. void startTextInput(const Rect & where);
  44. void stopTextInput();
  45. bool isMouseButtonPressed(MouseButton button) const;
  46. void pushUserEvent(EUserEvent usercode, void * userdata);
  47. const Point & getCursorPosition() const;
  48. /// returns true if chosen keyboard key is currently pressed down
  49. bool isKeyboardAltDown() const;
  50. bool isKeyboardCtrlDown() const;
  51. bool isKeyboardShiftDown() const;
  52. };