CmOSInputHandler.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include <boost/signal.hpp>
  4. #include "CmInt2.h"
  5. namespace CamelotFramework
  6. {
  7. /**
  8. * @brief Represents a specific way of acquiring OS input. InputManager (which provides a higher level input)
  9. * must have at least one OSInputHandler attached. Attach events handler to the provided signals to handle input.
  10. *
  11. * @note Unlike RawInputHandler this class receives input from the operating system, and is used for receiving
  12. * text input, cursor position and similar.
  13. */
  14. class CM_EXPORT OSInputHandler
  15. {
  16. public:
  17. OSInputHandler();
  18. virtual ~OSInputHandler();
  19. boost::signal<void(UINT32)> onCharInput;
  20. boost::signal<void(const Int2&, float)> onMouseMoved;
  21. /**
  22. * @brief Called every frame by InputManager. Capture input here if needed.
  23. */
  24. virtual void update();
  25. /**
  26. * @brief Called by InputManager whenever window in focus changes.
  27. */
  28. virtual void inputWindowChanged(const RenderWindow& win) {}
  29. private:
  30. CM_MUTEX(mOSInputMutex);
  31. Int2 mLastMousePos;
  32. Int2 mMousePosition;
  33. float mMouseScroll;
  34. WString mInputString;
  35. boost::signals::connection mCharInputConn;
  36. boost::signals::connection mMouseMovedConn;
  37. boost::signals::connection mMouseWheelScrolledConn;
  38. /**
  39. * @brief Called from the message loop.
  40. */
  41. void charInput(UINT32 character);
  42. /**
  43. * @brief Called from the message loop.
  44. */
  45. void mouseMoved(const Int2& mousePos);
  46. /**
  47. * @brief Called from the message loop.
  48. */
  49. void mouseWheelScrolled(float scrollPos);
  50. };
  51. }