CmInput.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /**
  34. * @brief Gets all the characters inputted since the last frame.
  35. */
  36. WString getInputString() const { return mInputHandler->getInputString(); }
  37. private:
  38. InputHandlerPtr mInputHandler;
  39. float mSmoothHorizontalAxis;
  40. float mSmoothVerticalAxis;
  41. float* mHorizontalHistoryBuffer;
  42. float* mVerticalHistoryBuffer;
  43. float* mTimesHistoryBuffer;
  44. int mCurrentBufferIdx;
  45. Int2 mMouseLastRel;
  46. Rect mClipRect;
  47. bool mUsingClipRect;
  48. bool mMouseButtonState[MB_Count];
  49. bool mKeyState[KC_Count];
  50. void keyDown(KeyCode keyCode);
  51. void keyUp(KeyCode keyCode);
  52. void mouseMoved(const MouseEvent& event);
  53. void mouseDown(const MouseEvent& event, MouseButton buttonID);
  54. void mouseUp(const MouseEvent& event, MouseButton buttonID);
  55. /**
  56. * @brief Updates the input values that need smoothing.
  57. */
  58. void updateSmoothInput();
  59. /************************************************************************/
  60. /* STATICS */
  61. /************************************************************************/
  62. static const int HISTORY_BUFFER_SIZE; // Size of buffer used for input smoothing
  63. static const float WEIGHT_MODIFIER;
  64. };
  65. CM_EXPORT Input& gInput();
  66. }