CmInput.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. void initClipRect(Rect& clipRect);
  14. void registerInputHandler(InputHandlerPtr inputHandler);
  15. /**
  16. * @brief Called every frame. Should only be called by Application.
  17. */
  18. void update();
  19. /**
  20. * @brief Returns smoothed mouse/joystick input in the horizontal axis.
  21. *
  22. * @return The horizontal axis value ranging [-1.0f, 1.0f].
  23. */
  24. float getHorizontalAxis() const;
  25. /**
  26. * @brief Returns smoothed mouse/joystick input in the vertical axis.
  27. *
  28. * @return The vertical axis value ranging [-1.0f, 1.0f].
  29. */
  30. float getVerticalAxis() const;
  31. bool isButtonDown(MouseButton button) const;
  32. bool isKeyDown(KeyCode keyCode) const;
  33. private:
  34. InputHandlerPtr mInputHandler;
  35. float mSmoothHorizontalAxis;
  36. float mSmoothVerticalAxis;
  37. float* mHorizontalHistoryBuffer;
  38. float* mVerticalHistoryBuffer;
  39. float* mTimesHistoryBuffer;
  40. int mCurrentBufferIdx;
  41. Int2 mMouseLastRel;
  42. Rect mClipRect;
  43. bool mUsingClipRect;
  44. bool mMouseButtonState[MB_Count];
  45. bool mKeyState[KC_Count];
  46. void keyDown(KeyCode keyCode);
  47. void keyUp(KeyCode keyCode);
  48. void mouseMoved(const MouseEvent& event);
  49. void mouseDown(const MouseEvent& event, MouseButton buttonID);
  50. void mouseUp(const MouseEvent& event, MouseButton buttonID);
  51. /**
  52. * @brief Updates the input values that need smoothing.
  53. */
  54. void updateSmoothInput();
  55. /************************************************************************/
  56. /* STATICS */
  57. /************************************************************************/
  58. static const int HISTORY_BUFFER_SIZE; // Size of buffer used for input smoothing
  59. static const float WEIGHT_MODIFIER;
  60. };
  61. CM_EXPORT Input& gInput();
  62. }