| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- $#include "Input.h"
- /// %Input state for a finger touch.
- struct TouchState
- {
- /// Touch (finger) ID.
- int touchID_ @ touchID;
- /// Position in screen coordinates.
- IntVector2 position_ @ position;
- /// Last position in screen coordinates.
- IntVector2 lastPosition_ @ lastPosition;
- /// Movement since last frame.
- IntVector2 delta_ @ delta;
- /// Finger pressure.
- float pressure_ @ pressure;
- };
- /// %Input state for a joystick.
- struct JoystickState
- {
- /// Return number of buttons.
- unsigned GetNumButtons() const { return buttons_.Size(); }
- /// Return number of axes.
- unsigned GetNumAxes() const { return axes_.Size(); }
- /// Return number of hats.
- unsigned GetNumHats() const { return hats_.Size(); }
-
- /// Check if a button is held down.
- bool GetButtonDown(unsigned index) const
- {
- if (index < buttons_.Size())
- return buttons_[index];
- else
- return false;
- }
-
- /// Check if a button has been pressed on this frame.
- bool GetButtonPress(unsigned index) const
- {
- if (index < buttons_.Size())
- return buttonPress_[index];
- else
- return false;
- }
-
- /// Return axis position.
- float GetAxisPosition(unsigned index) const
- {
- if (index < axes_.Size())
- return axes_[index];
- else
- return 0.0f;
- }
-
- /// Return hat position.
- int GetHatPosition(unsigned index) const
- {
- if (index < hats_.Size())
- return hats_[index];
- else
- return HAT_CENTER;
- }
- };
- /// %Input subsystem. Converts operating system window messages to input state and events.
- class Input : public Object
- {
- public:
- /// Set whether the operating system mouse cursor is visible. When not visible (default), is kept centered to prevent leaving the window.
- void SetMouseVisible(bool enable);
- /// Open a joystick. Return true if successful.
- bool OpenJoystick(unsigned index);
- /// Close a joystick.
- void CloseJoystick(unsigned index);
- /// Redetect joysticks. Return true if successful.
- bool DetectJoysticks();
-
- /// Check if a key is held down.
- bool GetKeyDown(int key) const;
- /// Check if a key has been pressed on this frame.
- bool GetKeyPress(int key) const;
- /// Check if a mouse button is held down.
- bool GetMouseButtonDown(int button) const;
- /// Check if a mouse button has been pressed on this frame.
- bool GetMouseButtonPress(int button) const;
- /// Check if a qualifier key is held down.
- bool GetQualifierDown(int qualifier) const;
- /// Check if a qualifier key has been pressed on this frame.
- bool GetQualifierPress(int qualifier) const;
- /// Return the currently held down qualifiers.
- int GetQualifiers() const;
- /// Return mouse position within window. Should only be used with a visible mouse cursor.
- IntVector2 GetMousePosition() const;
- /// Return mouse movement since last frame.
- const IntVector2& GetMouseMove() const { return mouseMove_; }
- /// Return horizontal mouse movement since last frame.
- int GetMouseMoveX() const { return mouseMove_.x_; }
- /// Return vertical mouse movement since last frame.
- int GetMouseMoveY() const { return mouseMove_.y_; }
- /// Return mouse wheel movement since last frame.
- int GetMouseMoveWheel() const { return mouseMoveWheel_; }
- /// Return number of active finger touches.
- unsigned GetNumTouches() const { return touches_.Size(); }
- /// Return active finger touch by index.
- TouchState* GetTouch(unsigned index) const;
- /// Return number of connected joysticks.
- unsigned GetNumJoysticks() const { return joysticks_.Size(); }
- /// Return joystick name by index.
- const String& GetJoystickName(unsigned index) const;
- /// Return joystick state by index. Automatically open if not opened yet.
- JoystickState* GetJoystick(unsigned index);
- /// Return whether fullscreen toggle is enabled.
- bool GetToggleFullscreen() const { return toggleFullscreen_; }
- /// Return whether the operating system mouse cursor is visible.
- bool IsMouseVisible() const { return mouseVisible_; }
- /// Return whether application window has input focus.
- bool HasFocus() { return inputFocus_; }
- /// Return whether application window is minimized.
- bool IsMinimized() const;
- };
|