InputHandler.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /// Fetches events from SDL input system and prepares them for processing
  38. void fetchEvents();
  39. /// Performs actual processing and dispatching of previously fetched events
  40. void processEvents();
  41. /// drops all incoming events without processing them
  42. /// returns true if input event has been found
  43. bool ignoreEventsUntilInput();
  44. void fakeMoveCursor(float dx, float dy);
  45. /// Initiates text input in selected area, potentially creating IME popup (mobile systems only at the moment)
  46. void startTextInput(const Rect & where);
  47. /// Ends any existing text input state
  48. void stopTextInput();
  49. /// Returns true if selected mouse button is pressed at the moment
  50. bool isMouseButtonPressed(MouseButton button) const;
  51. /// Generates new user event that will be processed on next frame
  52. void pushUserEvent(EUserEvent usercode, void * userdata);
  53. /// Returns current position of cursor, in VCMI logical screen coordinates
  54. const Point & getCursorPosition() const;
  55. /// returns true if chosen keyboard key is currently pressed down
  56. bool isKeyboardAltDown() const;
  57. bool isKeyboardCtrlDown() const;
  58. bool isKeyboardShiftDown() const;
  59. };