Input.pkg 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. $#include "Input.h"
  2. /// %Input state for a finger touch.
  3. struct TouchState
  4. {
  5. /// Touch (finger) ID.
  6. int touchID_ @ touchID;
  7. /// Position in screen coordinates.
  8. IntVector2 position_ @ position;
  9. /// Last position in screen coordinates.
  10. IntVector2 lastPosition_ @ lastPosition;
  11. /// Movement since last frame.
  12. IntVector2 delta_ @ delta;
  13. /// Finger pressure.
  14. float pressure_ @ pressure;
  15. };
  16. /// %Input state for a joystick.
  17. struct JoystickState
  18. {
  19. /// Return number of buttons.
  20. unsigned GetNumButtons() const;
  21. /// Return number of axes.
  22. unsigned GetNumAxes() const;
  23. /// Return number of hats.
  24. unsigned GetNumHats() const;
  25. /// Check if a button is held down.
  26. bool GetButtonDown(unsigned index) const;
  27. /// Check if a button has been pressed on this frame.
  28. bool GetButtonPress(unsigned index) const;
  29. /// Return axis position.
  30. float GetAxisPosition(unsigned index) const;
  31. /// Return hat position.
  32. int GetHatPosition(unsigned index) const;
  33. };
  34. /// %Input subsystem. Converts operating system window messages to input state and events.
  35. class Input : public Object
  36. {
  37. public:
  38. /// Set whether the operating system mouse cursor is visible. When not visible (default), is kept centered to prevent leaving the window.
  39. void SetMouseVisible(bool enable);
  40. /// Open a joystick. Return true if successful.
  41. bool OpenJoystick(unsigned index);
  42. /// Close a joystick.
  43. void CloseJoystick(unsigned index);
  44. /// Redetect joysticks. Return true if successful.
  45. bool DetectJoysticks();
  46. /// Check if a key is held down.
  47. bool GetKeyDown(int key) const;
  48. /// Check if a key has been pressed on this frame.
  49. bool GetKeyPress(int key) const;
  50. /// Check if a mouse button is held down.
  51. bool GetMouseButtonDown(int button) const;
  52. /// Check if a mouse button has been pressed on this frame.
  53. bool GetMouseButtonPress(int button) const;
  54. /// Check if a qualifier key is held down.
  55. bool GetQualifierDown(int qualifier) const;
  56. /// Check if a qualifier key has been pressed on this frame.
  57. bool GetQualifierPress(int qualifier) const;
  58. /// Return the currently held down qualifiers.
  59. int GetQualifiers() const;
  60. /// Return mouse position within window. Should only be used with a visible mouse cursor.
  61. IntVector2 GetMousePosition() const;
  62. /// Return mouse movement since last frame.
  63. const IntVector2& GetMouseMove() const;
  64. /// Return horizontal mouse movement since last frame.
  65. int GetMouseMoveX() const;
  66. /// Return vertical mouse movement since last frame.
  67. int GetMouseMoveY() const;
  68. /// Return mouse wheel movement since last frame.
  69. int GetMouseMoveWheel() const;
  70. /// Return number of active finger touches.
  71. unsigned GetNumTouches() const;
  72. /// Return active finger touch by index.
  73. TouchState* GetTouch(unsigned index) const;
  74. /// Return number of connected joysticks.
  75. unsigned GetNumJoysticks() const;
  76. /// Return joystick name by index.
  77. const String& GetJoystickName(unsigned index) const;
  78. /// Return joystick state by index. Automatically open if not opened yet.
  79. JoystickState* GetJoystick(unsigned index);
  80. /// Return whether fullscreen toggle is enabled.
  81. bool GetToggleFullscreen() const;
  82. /// Return whether the operating system mouse cursor is visible.
  83. bool IsMouseVisible() const;
  84. /// Return whether application window has input focus.
  85. bool HasFocus();
  86. /// Return whether application window is minimized.
  87. bool IsMinimized() const;
  88. };
  89. Input* GetInput();