CmOSInputHandler.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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&)> 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. WString mInputString;
  34. boost::signals::connection mCharInputConn;
  35. boost::signals::connection mMouseMovedConn;
  36. /**
  37. * @brief Called from the message loop.
  38. */
  39. void charInput(UINT32 character);
  40. /**
  41. * @brief Called from the message loop.
  42. */
  43. void mouseMoved(const Int2& mousePos);
  44. };
  45. }