CmInput.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmModule.h"
  4. #include "CmRect.h"
  5. #include "CmInputHandler.h"
  6. namespace CamelotFramework
  7. {
  8. class CM_EXPORT Input : public Module<Input>
  9. {
  10. public:
  11. Input();
  12. ~Input();
  13. boost::signal<void(KeyCode)> onKeyDown;
  14. boost::signal<void(KeyCode)> onKeyUp;
  15. boost::signal<void(const MouseEvent&)> onMouseMoved;
  16. boost::signal<void(const MouseEvent&, MouseButton)> onMouseDown;
  17. boost::signal<void(const MouseEvent&, MouseButton)> onMouseUp;
  18. void initClipRect(Rect& clipRect);
  19. void registerInputHandler(InputHandlerPtr inputHandler);
  20. /**
  21. * @brief Called every frame. Should only be called by Application.
  22. */
  23. void update();
  24. /**
  25. * @brief Returns smoothed mouse/joystick input in the horizontal axis.
  26. *
  27. * @return The horizontal axis value ranging [-1.0f, 1.0f].
  28. */
  29. float getHorizontalAxis() const;
  30. /**
  31. * @brief Returns smoothed mouse/joystick input in the vertical axis.
  32. *
  33. * @return The vertical axis value ranging [-1.0f, 1.0f].
  34. */
  35. float getVerticalAxis() const;
  36. private:
  37. InputHandlerPtr mInputHandler;
  38. float mSmoothHorizontalAxis;
  39. float mSmoothVerticalAxis;
  40. float* mHorizontalHistoryBuffer;
  41. float* mVerticalHistoryBuffer;
  42. float* mTimesHistoryBuffer;
  43. int mCurrentBufferIdx;
  44. Point mMouseLastRel;
  45. Rect mClipRect;
  46. bool mUsingClipRect;
  47. void keyDown(KeyCode keyCode);
  48. void keyUp(KeyCode keyCode);
  49. void mouseMoved(const MouseEvent& event);
  50. void mouseDown(const MouseEvent& event, MouseButton buttonID);
  51. void mouseUp(const MouseEvent& event, MouseButton buttonID);
  52. /**
  53. * @brief Updates the input values that need smoothing.
  54. */
  55. void updateSmoothInput();
  56. /************************************************************************/
  57. /* STATICS */
  58. /************************************************************************/
  59. static const int HISTORY_BUFFER_SIZE; // Size of buffer used for input smoothing
  60. static const float WEIGHT_MODIFIER;
  61. };
  62. CM_EXPORT Input& gInput();
  63. }