diff --git a/framework/platform-dx/gamepad.cpp b/framework/platform-dx/gamepad.cpp index 23bf0d1..ec22f4e 100644 --- a/framework/platform-dx/gamepad.cpp +++ b/framework/platform-dx/gamepad.cpp @@ -14,20 +14,7 @@ namespace xna { static_cast(index) ); - GamePadState pad; - pad.Dpad = GamePadDPad( - static_cast(state.dpad.up), - static_cast(state.dpad.right), - static_cast(state.dpad.down), - static_cast(state.dpad.left)); - - pad.IsConnected = state.connected; - pad.PackedNumber = state.packet; - pad.ThumbSticks = GamePadThumbSticks( - Vector2(state.thumbSticks.leftX, state.thumbSticks.leftY), - Vector2(state.thumbSticks.rightX, state.thumbSticks.rightY)); - pad.Triggers = GamePadTriggers(state.triggers.left, state.triggers.right); - pad.Buttons = GamePadButtons( + const auto buttons = GamePadButtons( static_cast(state.buttons.a), static_cast(state.buttons.b), static_cast(state.buttons.x), @@ -39,7 +26,21 @@ namespace xna { static_cast(state.buttons.back), static_cast(state.buttons.start), static_cast(state.buttons.view)); - + + const auto dpad = GamePadDPad( + static_cast(state.dpad.up), + static_cast(state.dpad.right), + static_cast(state.dpad.down), + static_cast(state.dpad.left)); + + const auto isConnected = state.connected; + + const auto thumbSticks = GamePadThumbSticks( + Vector2(state.thumbSticks.leftX, state.thumbSticks.leftY), + Vector2(state.thumbSticks.rightX, state.thumbSticks.rightY)); + const auto triggers = GamePadTriggers(state.triggers.left, state.triggers.right); + + const auto pad = GamePadState(thumbSticks, triggers, buttons, dpad, isConnected); return pad; } @@ -51,21 +52,34 @@ namespace xna { static_cast(index), static_cast(deadZone) ); + + const auto buttons = GamePadButtons( + static_cast(state.buttons.a), + static_cast(state.buttons.b), + static_cast(state.buttons.x), + static_cast(state.buttons.y), + static_cast(state.buttons.leftStick), + static_cast(state.buttons.rightStick), + static_cast(state.buttons.leftShoulder), + static_cast(state.buttons.rightShoulder), + static_cast(state.buttons.back), + static_cast(state.buttons.start), + static_cast(state.buttons.view)); - GamePadState pad; - pad.Dpad = GamePadDPad( + const auto dpad = GamePadDPad( static_cast(state.dpad.up), static_cast(state.dpad.right), static_cast(state.dpad.down), static_cast(state.dpad.left)); - pad.IsConnected = state.connected; - pad.PackedNumber = state.packet; - pad.ThumbSticks = GamePadThumbSticks( + const auto isConnected = state.connected; + + const auto thumbSticks = GamePadThumbSticks( Vector2(state.thumbSticks.leftX, state.thumbSticks.leftY), Vector2(state.thumbSticks.rightX, state.thumbSticks.rightY)); - pad.Triggers = GamePadTriggers(state.triggers.left, state.triggers.right); + const auto triggers = GamePadTriggers(state.triggers.left, state.triggers.right); + const auto pad = GamePadState(thumbSticks, triggers, buttons, dpad, isConnected); return pad; } @@ -74,12 +88,11 @@ namespace xna { return GamePadCapabilities(); const auto capabilities = impl->_dxGamePad->GetCapabilities(static_cast(index)); - GamePadCapabilities cap; - cap.Connected = capabilities.connected; - cap.Id = capabilities.id; - cap.Pid = capabilities.pid; - cap.Type = static_cast(capabilities.gamepadType); - cap.Vid = capabilities.vid; + const auto gamePadType = static_cast(capabilities.gamepadType); + const auto cap = GamePadCapabilities( + capabilities.connected, + gamePadType); + return cap; } diff --git a/inc/xna/enumerations.hpp b/inc/xna/enumerations.hpp index 17f1471..dd0657f 100644 --- a/inc/xna/enumerations.hpp +++ b/inc/xna/enumerations.hpp @@ -80,40 +80,6 @@ namespace xna { Static, }; - enum class Buttons { - A = 4096, // 0x00001000 - B = 8192, // 0x00002000 - X = 16384, // 0x00004000 - Y = 32768, // 0x00008000 - Back = 32, // 0x00000020 - Start = 16, // 0x00000010 - DPadUp = 1, - DPadDown = 2, - DPadLeft = 4, - DPadRight = 8, - LeftShoulder = 256, // 0x00000100 - RightShoulder = 512, // 0x00000200 - LeftStick = 64, // 0x00000040 - RightStick = 128, // 0x00000080 - BigButton = 2048, // 0x00000800 - LeftThumbstickLeft = 2097152, // 0x00200000 - LeftThumbstickRight = 1073741824, // 0x40000000 - LeftThumbstickDown = 536870912, // 0x20000000 - LeftThumbstickUp = 268435456, // 0x10000000 - RightThumbstickLeft = 134217728, // 0x08000000 - RightThumbstickRight = 67108864, // 0x04000000 - RightThumbstickDown = 33554432, // 0x02000000 - RightThumbstickUp = 16777216, // 0x01000000 - LeftTrigger = 8388608, // 0x00800000 - RightTrigger = 4194304, // 0x00400000 - }; - - enum class ButtonState - { - Released, - Pressed, - }; - enum class ClearOptions { DepthBuffer, Stencil, @@ -234,27 +200,6 @@ namespace xna { Drawable, }; - enum class GamePadCapabilitiesType - { - Unknown = 0, - Gamepad, - Wheel, - ArdaceStick, - FlightStick, - DancePAd, - Guitar, - GuitarAlternate, - DrumKit, - GuitarBass = 11, - ArcadePad = 19, - }; - - enum class GamePadDeadZone { - IndependentAxes, - Circular, - None, - }; - //Identifies the set of supported devices for the game based on device capabilities. enum class GraphicsProfile { //Use a limited set of graphic features and capabilities, allowing the game to support the widest variety of devices, including all Windows-based computers. @@ -264,192 +209,6 @@ namespace xna { HiDef }; - enum class Keys : unsigned char { - None = 0, - - Back = 0x8, - Tab = 0x9, - - Enter = 0xd, - - Pause = 0x13, - CapsLock = 0x14, - Kana = 0x15, - ImeOn = 0x16, - - Kanji = 0x19, - - ImeOff = 0x1a, - Escape = 0x1b, - ImeConvert = 0x1c, - ImeNoConvert = 0x1d, - - Space = 0x20, - PageUp = 0x21, - PageDown = 0x22, - End = 0x23, - Home = 0x24, - Left = 0x25, - Up = 0x26, - Right = 0x27, - Down = 0x28, - Select = 0x29, - Print = 0x2a, - Execute = 0x2b, - PrintScreen = 0x2c, - Insert = 0x2d, - Delete = 0x2e, - Help = 0x2f, - D0 = 0x30, - D1 = 0x31, - D2 = 0x32, - D3 = 0x33, - D4 = 0x34, - D5 = 0x35, - D6 = 0x36, - D7 = 0x37, - D8 = 0x38, - D9 = 0x39, - - A = 0x41, - B = 0x42, - C = 0x43, - D = 0x44, - E = 0x45, - F = 0x46, - G = 0x47, - H = 0x48, - I = 0x49, - J = 0x4a, - K = 0x4b, - L = 0x4c, - M = 0x4d, - N = 0x4e, - O = 0x4f, - P = 0x50, - Q = 0x51, - R = 0x52, - S = 0x53, - T = 0x54, - U = 0x55, - V = 0x56, - W = 0x57, - X = 0x58, - Y = 0x59, - Z = 0x5a, - LeftWindows = 0x5b, - RightWindows = 0x5c, - Apps = 0x5d, - - Sleep = 0x5f, - NumPad0 = 0x60, - NumPad1 = 0x61, - NumPad2 = 0x62, - NumPad3 = 0x63, - NumPad4 = 0x64, - NumPad5 = 0x65, - NumPad6 = 0x66, - NumPad7 = 0x67, - NumPad8 = 0x68, - NumPad9 = 0x69, - Multiply = 0x6a, - Add = 0x6b, - Separator = 0x6c, - Subtract = 0x6d, - - Decimal = 0x6e, - Divide = 0x6f, - F1 = 0x70, - F2 = 0x71, - F3 = 0x72, - F4 = 0x73, - F5 = 0x74, - F6 = 0x75, - F7 = 0x76, - F8 = 0x77, - F9 = 0x78, - F10 = 0x79, - F11 = 0x7a, - F12 = 0x7b, - F13 = 0x7c, - F14 = 0x7d, - F15 = 0x7e, - F16 = 0x7f, - F17 = 0x80, - F18 = 0x81, - F19 = 0x82, - F20 = 0x83, - F21 = 0x84, - F22 = 0x85, - F23 = 0x86, - F24 = 0x87, - - NumLock = 0x90, - Scroll = 0x91, - - LeftShift = 0xa0, - RightShift = 0xa1, - LeftControl = 0xa2, - RightControl = 0xa3, - LeftAlt = 0xa4, - RightAlt = 0xa5, - BrowserBack = 0xa6, - BrowserForward = 0xa7, - BrowserRefresh = 0xa8, - BrowserStop = 0xa9, - BrowserSearch = 0xaa, - BrowserFavorites = 0xab, - BrowserHome = 0xac, - VolumeMute = 0xad, - VolumeDown = 0xae, - VolumeUp = 0xaf, - MediaNextTrack = 0xb0, - MediaPreviousTrack = 0xb1, - MediaStop = 0xb2, - MediaPlayPause = 0xb3, - LaunchMail = 0xb4, - SelectMedia = 0xb5, - LaunchApplication1 = 0xb6, - LaunchApplication2 = 0xb7, - - OemSemicolon = 0xba, - OemPlus = 0xbb, - OemComma = 0xbc, - OemMinus = 0xbd, - OemPeriod = 0xbe, - OemQuestion = 0xbf, - OemTilde = 0xc0, - - OemOpenBrackets = 0xdb, - OemPipe = 0xdc, - OemCloseBrackets = 0xdd, - OemQuotes = 0xde, - Oem8 = 0xdf, - - OemBackslash = 0xe2, - - ProcessKey = 0xe5, - - OemCopy = 0xf2, - OemAuto = 0xf3, - OemEnlW = 0xf4, - - Attn = 0xf6, - Crsel = 0xf7, - Exsel = 0xf8, - EraseEof = 0xf9, - Play = 0xfa, - Zoom = 0xfb, - - Pa1 = 0xfd, - OemClear = 0xfe, - }; - - enum class KeyState { - Up, - Down, - }; - enum class PlaneIntersectionType { Front, Back, @@ -483,9 +242,7 @@ namespace xna { DiscardContents, PreserveContents, PlatformContents - }; - - + }; enum class SpriteEffects { None = 0, diff --git a/inc/xna/input/gamepad.hpp b/inc/xna/input/gamepad.hpp index 0dfd0ff..f61ef7c 100644 --- a/inc/xna/input/gamepad.hpp +++ b/inc/xna/input/gamepad.hpp @@ -2,6 +2,7 @@ #define XNA_INPUT_GAMEPAD_HPP #include "../default.hpp" +#include "input-enums.hpp" #include "../common/numerics.hpp" namespace xna { @@ -9,14 +10,17 @@ namespace xna { struct GamePadTriggers { constexpr GamePadTriggers() = default; - constexpr GamePadTriggers(float left, float right) : _left(left), _right(right) { + constexpr GamePadTriggers(float left, float right) + : _left(left), _right(right) { clamp(); } + //Identifies the position of the left trigger on the Xbox Controller. constexpr float Left() const { return _left; } + //Identifies the position of the right trigger on the Xbox Controller. constexpr float Right() const { return _right; } @@ -25,7 +29,7 @@ namespace xna { return _left == other._left && _right == other._right; } - public: + private: float _left{ 0 }; float _right{ 0 }; @@ -46,10 +50,12 @@ namespace xna { clamp(); } + //Returns the position of the left Xbox Controller stick (thumbstick) as a 2D vector. constexpr Vector2 Left() const { return _left; } + //Returns the position of the right Xbox Controller stick (thumbstick) as a 2D vector. constexpr Vector2 Right() const { return _right; } @@ -76,14 +82,22 @@ namespace xna { constexpr GamePadDPad() = default; constexpr GamePadDPad(const ButtonState& up, const ButtonState& down, - const ButtonState& left, const ButtonState& right) - : Up(up), Right(right), Down(down), Left(left) { - } - - ButtonState Up{}; - ButtonState Right{}; - ButtonState Down{}; - ButtonState Left{}; + const ButtonState& left, const ButtonState& right) : up(up), down(down), left(left), right(right) {} + + //Identifies whether the Up direction on the Xbox Controller directional pad is pressed. + constexpr ButtonState Up() const { return up; } + //Identifies whether the Right direction on the Xbox Controller directional pad is pressed. + constexpr ButtonState Right() const { return right; } + //Identifies whether the Down direction on the Xbox Controller directional pad is pressed. + constexpr ButtonState Down() const { return down; } + //Identifies whether the Left direction on the Xbox Controller directional pad is pressed. + constexpr ButtonState Left() const { return left; } + + private: + ButtonState up{}; + ButtonState right{}; + ButtonState down{}; + ButtonState left{}; }; //Identifies whether buttons on an Xbox Controller are pressed or released. @@ -102,137 +116,178 @@ namespace xna { ButtonState back, ButtonState start, ButtonState bigButton) { - A = a; - B = b; - X = x; - Y = y; - LeftStick = leftStick; - RightStick = rightStick; - LeftShoulder = leftShoulder; - RightShoulder = rightShoulder; - Back = back; - Start = start; - BigButton = bigButton; + this->a = a; + this->b = b; + this->x = x; + this->y = y; + this->leftStick = leftStick; + this->rightStick = rightStick; + this->leftShoulder = leftShoulder; + this->rightShoulder = rightShoulder; + this->back = back; + this->start = start; + this->bigButton = bigButton; } constexpr GamePadButtons(Buttons buttons) { - A = static_cast((static_cast(buttons) & static_cast(Buttons::A))) == Buttons::A ? ButtonState::Pressed : ButtonState::Released; - B = static_cast((static_cast(buttons) & static_cast(Buttons::B))) == Buttons::B ? ButtonState::Pressed : ButtonState::Released; - X = static_cast((static_cast(buttons) & static_cast(Buttons::X))) == Buttons::X ? ButtonState::Pressed : ButtonState::Released; - Y = static_cast((static_cast(buttons) & static_cast(Buttons::Y))) == Buttons::Y ? ButtonState::Pressed : ButtonState::Released; - Start = static_cast((static_cast(buttons) & static_cast(Buttons::Start))) == Buttons::Start ? ButtonState::Pressed : ButtonState::Released; - Back = static_cast((static_cast(buttons) & static_cast(Buttons::Back))) == Buttons::Back ? ButtonState::Pressed : ButtonState::Released; - LeftStick = static_cast((static_cast(buttons) & static_cast(Buttons::LeftStick))) == Buttons::LeftStick ? ButtonState::Pressed : ButtonState::Released; - RightStick = static_cast((static_cast(buttons) & static_cast(Buttons::RightStick))) == Buttons::RightStick ? ButtonState::Pressed : ButtonState::Released; - LeftShoulder = static_cast((static_cast(buttons) & static_cast(Buttons::LeftShoulder))) == Buttons::LeftShoulder ? ButtonState::Pressed : ButtonState::Released; - RightShoulder = static_cast((static_cast(buttons) & static_cast(Buttons::RightShoulder))) == Buttons::RightShoulder ? ButtonState::Pressed : ButtonState::Released; - BigButton = static_cast((static_cast(buttons) & static_cast(Buttons::BigButton))) == Buttons::BigButton ? ButtonState::Pressed : ButtonState::Released; + a = static_cast((static_cast(buttons) & static_cast(Buttons::A))) == Buttons::A ? ButtonState::Pressed : ButtonState::Released; + b = static_cast((static_cast(buttons) & static_cast(Buttons::B))) == Buttons::B ? ButtonState::Pressed : ButtonState::Released; + x = static_cast((static_cast(buttons) & static_cast(Buttons::X))) == Buttons::X ? ButtonState::Pressed : ButtonState::Released; + y = static_cast((static_cast(buttons) & static_cast(Buttons::Y))) == Buttons::Y ? ButtonState::Pressed : ButtonState::Released; + start = static_cast((static_cast(buttons) & static_cast(Buttons::Start))) == Buttons::Start ? ButtonState::Pressed : ButtonState::Released; + back = static_cast((static_cast(buttons) & static_cast(Buttons::Back))) == Buttons::Back ? ButtonState::Pressed : ButtonState::Released; + leftStick = static_cast((static_cast(buttons) & static_cast(Buttons::LeftStick))) == Buttons::LeftStick ? ButtonState::Pressed : ButtonState::Released; + rightStick = static_cast((static_cast(buttons) & static_cast(Buttons::RightStick))) == Buttons::RightStick ? ButtonState::Pressed : ButtonState::Released; + leftShoulder = static_cast((static_cast(buttons) & static_cast(Buttons::LeftShoulder))) == Buttons::LeftShoulder ? ButtonState::Pressed : ButtonState::Released; + rightShoulder = static_cast((static_cast(buttons) & static_cast(Buttons::RightShoulder))) == Buttons::RightShoulder ? ButtonState::Pressed : ButtonState::Released; + bigButton = static_cast((static_cast(buttons) & static_cast(Buttons::BigButton))) == Buttons::BigButton ? ButtonState::Pressed : ButtonState::Released; } - ButtonState A{}; - ButtonState B{}; - ButtonState X{}; - ButtonState Y{}; - ButtonState LeftStick{}; - ButtonState RightStick{}; - ButtonState LeftShoulder{}; - ButtonState RightShoulder{}; - ButtonState Back{}; - ButtonState Start{}; - ButtonState BigButton{}; - }; + //Identifies if the A button on the Xbox Controller is pressed. + constexpr ButtonState A() const { return a; } + //Identifies if the B button on the Xbox Controller is pressed. + constexpr ButtonState B() const { return b; } + //Identifies if the X button on the Xbox Controller is pressed. + constexpr ButtonState X() const { return x; } + //Identifies if the Y button on the Xbox Controller is pressed. + constexpr ButtonState Y() const { return y; } + //Identifies if the left stick button on the Xbox Controller is pressed (the stick is "clicked" in + constexpr ButtonState LeftStick() const { return leftStick; } + //Identifies if the right stick button on the Xbox Controller is pressed (the stick is "clicked" in). + constexpr ButtonState RightStick() const { return rightStick; } + //Identifies if the left shoulder (bumper) button on the Xbox Controller is pressed. + constexpr ButtonState LeftShoulder() const { return leftShoulder; } + //Identifies if the right shoulder (bumper) button on the Xbox Controller is pressed. + constexpr ButtonState RightShoulder() const { return rightShoulder; } + //Identifies if the BACK button on the Xbox Controller is pressed. + constexpr ButtonState Back() const { return back; } + //Identifies if the START button on the Xbox Controller is pressed. + constexpr ButtonState Start() const { return start; } + //Identifies if the BigButton button is pressed. + constexpr ButtonState BigButton() const { return bigButton; } -#ifdef USING_GAMEINPUT - using GamePadId = APP_LOCAL_DEVICE_ID; -#elif defined(USING_WINDOWS_GAMING_INPUT) - using GamePadId = std::wstring; -#else - using GamePadId = uint64_t; -#endif + private: + ButtonState a{}; + ButtonState b{}; + ButtonState x{}; + ButtonState y{}; + ButtonState leftStick{}; + ButtonState rightStick{}; + ButtonState leftShoulder{}; + ButtonState rightShoulder{}; + ButtonState back{}; + ButtonState start{}; + ButtonState bigButton{}; + }; //Describes the capabilities of an Xbox Controller, including controller type, and identifies if the controller supports voice. struct GamePadCapabilities { - constexpr GamePadCapabilities() = default; + constexpr GamePadCapabilities() = default; + + constexpr GamePadCapabilities(bool isConnected, GamePadCapabilitiesType type) : isConnected(isConnected), type(type){} - GamePadCapabilitiesType Type{}; - bool Connected{ false }; - Ushort Vid{ 0 }; - Ushort Pid{ 0 }; - GamePadId Id{}; + //Indicates whether the Xbox Controller is connected. + constexpr bool IsConnected() const { return isConnected; } + //Gets the type of controller. + constexpr GamePadCapabilitiesType GamePadType() const { return type; } + + private: + GamePadCapabilitiesType type{}; + bool isConnected{ false }; }; //Represents specific information about the state of an Xbox Controller, including the current state of buttons and sticks. struct GamePadState { - constexpr GamePadState() = default; + constexpr GamePadState() = default; + constexpr GamePadState( + GamePadThumbSticks sticks, + GamePadTriggers triggers, + GamePadButtons buttons, + GamePadDPad dpad, bool isConnected + ) : buttons(buttons), dpad(dpad), triggers(triggers), thumbSticks(sticks), isConnected(isConnected){} + + //Determines whether specified input device buttons are pressed in this GamePadState. constexpr bool IsButtonDown(xna::Buttons button) const { switch (button) { case xna::Buttons::A: - return this->Buttons.A == ButtonState::Pressed; + return this->Buttons().A() == ButtonState::Pressed; case xna::Buttons::B: - return this->Buttons.B == ButtonState::Pressed; + return this->Buttons().B() == ButtonState::Pressed; case xna::Buttons::X: - return this->Buttons.X == ButtonState::Pressed; + return this->Buttons().X() == ButtonState::Pressed; case xna::Buttons::Y: - return this->Buttons.Y == ButtonState::Pressed; + return this->Buttons().Y() == ButtonState::Pressed; case xna::Buttons::Back: - return this->Buttons.Back == ButtonState::Pressed; + return this->Buttons().Back() == ButtonState::Pressed; case xna::Buttons::Start: - return this->Buttons.Start == ButtonState::Pressed; + return this->Buttons().Start() == ButtonState::Pressed; case xna::Buttons::DPadUp: - return this->Dpad.Up == ButtonState::Pressed; + return this->Dpad().Up() == ButtonState::Pressed; case xna::Buttons::DPadDown: - return this->Dpad.Down == ButtonState::Pressed; + return this->Dpad().Down() == ButtonState::Pressed; case xna::Buttons::DPadLeft: - return this->Dpad.Left == ButtonState::Pressed; + return this->Dpad().Left() == ButtonState::Pressed; case xna::Buttons::DPadRight: - return this->Dpad.Right == ButtonState::Pressed; + return this->Dpad().Right() == ButtonState::Pressed; case xna::Buttons::LeftShoulder: - return this->Buttons.LeftShoulder == ButtonState::Pressed; + return this->Buttons().LeftShoulder() == ButtonState::Pressed; case xna::Buttons::RightShoulder: - return this->Buttons.RightShoulder == ButtonState::Pressed; + return this->Buttons().RightShoulder() == ButtonState::Pressed; case xna::Buttons::LeftStick: - return this->Buttons.LeftStick == ButtonState::Pressed; + return this->Buttons().LeftStick() == ButtonState::Pressed; case xna::Buttons::RightStick: - return this->Buttons.RightStick == ButtonState::Pressed; + return this->Buttons().RightStick() == ButtonState::Pressed; case xna::Buttons::BigButton: - return this->Buttons.BigButton == ButtonState::Pressed; + return this->Buttons().BigButton() == ButtonState::Pressed; case xna::Buttons::LeftThumbstickLeft: - return this->ThumbSticks.Left().X < 0.5F; + return this->ThumbSticks().Left().X < 0.5F; case xna::Buttons::LeftThumbstickRight: - return this->ThumbSticks.Left().X > 0.5F; + return this->ThumbSticks().Left().X > 0.5F; case xna::Buttons::LeftThumbstickDown: - return this->ThumbSticks.Left().Y > 0.5F; + return this->ThumbSticks().Left().Y > 0.5F; case xna::Buttons::LeftThumbstickUp: - return this->ThumbSticks.Left().Y < 0.5F; + return this->ThumbSticks().Left().Y < 0.5F; case xna::Buttons::RightThumbstickLeft: - return this->ThumbSticks.Right().X < 0.5F; + return this->ThumbSticks().Right().X < 0.5F; case xna::Buttons::RightThumbstickRight: - return this->ThumbSticks.Right().X > 0.5F; + return this->ThumbSticks().Right().X > 0.5F; case xna::Buttons::RightThumbstickDown: - return this->ThumbSticks.Right().Y > 0.5F; + return this->ThumbSticks().Right().Y > 0.5F; case xna::Buttons::RightThumbstickUp: - return this->ThumbSticks.Right().Y < 0.5F; + return this->ThumbSticks().Right().Y < 0.5F; case xna::Buttons::LeftTrigger: - return this->Triggers.Left() > 0.5F; + return this->Triggers().Left() > 0.5F; case xna::Buttons::RightTrigger: - return this->Triggers.Right() > 0.5F; + return this->Triggers().Right() > 0.5F; default: return false; } } - + + //Determines whether specified input device buttons are up (not pressed) in this GamePadState. constexpr bool IsButtonUp(xna::Buttons button) const { return !IsButtonDown(button); } - GamePadButtons Buttons{}; - GamePadDPad Dpad{}; - bool IsConnected{false}; - Ulong PackedNumber{0}; - GamePadThumbSticks ThumbSticks{}; - GamePadTriggers Triggers{}; + //Returns a structure that identifies what buttons on the Xbox controller are pressed. + constexpr GamePadButtons Buttons() const { return buttons; } + //Returns a structure that identifies what directions of the directional pad on the Xbox Controller are pressed. + constexpr GamePadDPad Dpad() const { return dpad; } + //Indicates whether the Xbox Controller is connected. + constexpr bool IsConnected() const { return isConnected; } + //Returns a structure that indicates the position of the Xbox Controller sticks (thumbsticks). + constexpr GamePadThumbSticks ThumbSticks() const { return thumbSticks; } + //Returns a structure that identifies the position of triggers on the Xbox controller. + constexpr GamePadTriggers Triggers() const { return triggers; } + + private: + GamePadButtons buttons{}; + GamePadDPad dpad{}; + bool isConnected{ false }; + GamePadThumbSticks thumbSticks{}; + GamePadTriggers triggers{}; }; //Allows retrieval of user interaction with an Xbox Controller and setting of controller vibration motors. @@ -243,9 +298,9 @@ namespace xna { //Gets the current state of a game pad controller. As an option, it specifies a dead zone processing method for the analog sticks. static GamePadState GetState(PlayerIndex index, GamePadDeadZone deadZone); - //Retrieves the capabilities of an Xbox 360 Controller. + //Retrieves the capabilities of an Xbox Controller. static GamePadCapabilities GetCapabilities(PlayerIndex index); - //Sets the vibration motor speeds on an Xbox 360 Controller. + //Sets the vibration motor speeds on an Xbox Controller. static bool SetVibration(PlayerIndex index, float leftMotor, float rightMotor, float leftTrigger = 0, float rightTrigger = 0); private: diff --git a/inc/xna/input/input-enums.hpp b/inc/xna/input/input-enums.hpp new file mode 100644 index 0000000..1351924 --- /dev/null +++ b/inc/xna/input/input-enums.hpp @@ -0,0 +1,256 @@ +#ifndef XNA_INPUT_ENUMS_HPP +#define XNA_INPUT_ENUMS_HPP + +namespace xna { + //Identifies the state of a keyboard key. + enum class KeyState { + Up, + Down, + }; + + //Enumerates input device buttons. + enum class Buttons { + A = 4096, // 0x00001000 + B = 8192, // 0x00002000 + X = 16384, // 0x00004000 + Y = 32768, // 0x00008000 + Back = 32, // 0x00000020 + Start = 16, // 0x00000010 + DPadUp = 1, + DPadDown = 2, + DPadLeft = 4, + DPadRight = 8, + LeftShoulder = 256, // 0x00000100 + RightShoulder = 512, // 0x00000200 + LeftStick = 64, // 0x00000040 + RightStick = 128, // 0x00000080 + BigButton = 2048, // 0x00000800 + LeftThumbstickLeft = 2097152, // 0x00200000 + LeftThumbstickRight = 1073741824, // 0x40000000 + LeftThumbstickDown = 536870912, // 0x20000000 + LeftThumbstickUp = 268435456, // 0x10000000 + RightThumbstickLeft = 134217728, // 0x08000000 + RightThumbstickRight = 67108864, // 0x04000000 + RightThumbstickDown = 33554432, // 0x02000000 + RightThumbstickUp = 16777216, // 0x01000000 + LeftTrigger = 8388608, // 0x00800000 + RightTrigger = 4194304, // 0x00400000 + }; + + //Identifies the state of a controller button. + enum class ButtonState + { + Released, + Pressed, + }; + + //Describes the type of a specified Xbox Controller. + enum class GamePadCapabilitiesType + { + Unknown = 0, + Gamepad, + Wheel, + ArdaceStick, + FlightStick, + DancePAd, + Guitar, + GuitarAlternate, + DrumKit, + GuitarBass = 11, + ArcadePad = 19, + }; + + //Specifies a type of dead zone processing to apply to Xbox Controller analog sticks when calling GetState. + enum class GamePadDeadZone { + //The X and Y positions of each stick are compared against the dead zone independently. This setting is the default when calling GetState. + IndependentAxes, + //The combined X and Y position of each stick is compared to the dead zone. + //This provides better control than IndependentAxes when the stick is used as a two-dimensional control surface, such as when controlling a character's view in a first-person game. + Circular, + //The values of each stick are not processed and are returned by GetState as "raw" values. This is best if you intend to implement your own dead zone processing. + None, + }; + + enum class Keys : unsigned char { + None = 0, + + Back = 0x8, + Tab = 0x9, + + Enter = 0xd, + + Pause = 0x13, + CapsLock = 0x14, + Kana = 0x15, + ImeOn = 0x16, + + Kanji = 0x19, + + ImeOff = 0x1a, + Escape = 0x1b, + ImeConvert = 0x1c, + ImeNoConvert = 0x1d, + + Space = 0x20, + PageUp = 0x21, + PageDown = 0x22, + End = 0x23, + Home = 0x24, + Left = 0x25, + Up = 0x26, + Right = 0x27, + Down = 0x28, + Select = 0x29, + Print = 0x2a, + Execute = 0x2b, + PrintScreen = 0x2c, + Insert = 0x2d, + Delete = 0x2e, + Help = 0x2f, + D0 = 0x30, + D1 = 0x31, + D2 = 0x32, + D3 = 0x33, + D4 = 0x34, + D5 = 0x35, + D6 = 0x36, + D7 = 0x37, + D8 = 0x38, + D9 = 0x39, + + A = 0x41, + B = 0x42, + C = 0x43, + D = 0x44, + E = 0x45, + F = 0x46, + G = 0x47, + H = 0x48, + I = 0x49, + J = 0x4a, + K = 0x4b, + L = 0x4c, + M = 0x4d, + N = 0x4e, + O = 0x4f, + P = 0x50, + Q = 0x51, + R = 0x52, + S = 0x53, + T = 0x54, + U = 0x55, + V = 0x56, + W = 0x57, + X = 0x58, + Y = 0x59, + Z = 0x5a, + LeftWindows = 0x5b, + RightWindows = 0x5c, + Apps = 0x5d, + + Sleep = 0x5f, + NumPad0 = 0x60, + NumPad1 = 0x61, + NumPad2 = 0x62, + NumPad3 = 0x63, + NumPad4 = 0x64, + NumPad5 = 0x65, + NumPad6 = 0x66, + NumPad7 = 0x67, + NumPad8 = 0x68, + NumPad9 = 0x69, + Multiply = 0x6a, + Add = 0x6b, + Separator = 0x6c, + Subtract = 0x6d, + + Decimal = 0x6e, + Divide = 0x6f, + F1 = 0x70, + F2 = 0x71, + F3 = 0x72, + F4 = 0x73, + F5 = 0x74, + F6 = 0x75, + F7 = 0x76, + F8 = 0x77, + F9 = 0x78, + F10 = 0x79, + F11 = 0x7a, + F12 = 0x7b, + F13 = 0x7c, + F14 = 0x7d, + F15 = 0x7e, + F16 = 0x7f, + F17 = 0x80, + F18 = 0x81, + F19 = 0x82, + F20 = 0x83, + F21 = 0x84, + F22 = 0x85, + F23 = 0x86, + F24 = 0x87, + + NumLock = 0x90, + Scroll = 0x91, + + LeftShift = 0xa0, + RightShift = 0xa1, + LeftControl = 0xa2, + RightControl = 0xa3, + LeftAlt = 0xa4, + RightAlt = 0xa5, + BrowserBack = 0xa6, + BrowserForward = 0xa7, + BrowserRefresh = 0xa8, + BrowserStop = 0xa9, + BrowserSearch = 0xaa, + BrowserFavorites = 0xab, + BrowserHome = 0xac, + VolumeMute = 0xad, + VolumeDown = 0xae, + VolumeUp = 0xaf, + MediaNextTrack = 0xb0, + MediaPreviousTrack = 0xb1, + MediaStop = 0xb2, + MediaPlayPause = 0xb3, + LaunchMail = 0xb4, + SelectMedia = 0xb5, + LaunchApplication1 = 0xb6, + LaunchApplication2 = 0xb7, + + OemSemicolon = 0xba, + OemPlus = 0xbb, + OemComma = 0xbc, + OemMinus = 0xbd, + OemPeriod = 0xbe, + OemQuestion = 0xbf, + OemTilde = 0xc0, + + OemOpenBrackets = 0xdb, + OemPipe = 0xdc, + OemCloseBrackets = 0xdd, + OemQuotes = 0xde, + Oem8 = 0xdf, + + OemBackslash = 0xe2, + + ProcessKey = 0xe5, + + OemCopy = 0xf2, + OemAuto = 0xf3, + OemEnlW = 0xf4, + + Attn = 0xf6, + Crsel = 0xf7, + Exsel = 0xf8, + EraseEof = 0xf9, + Play = 0xfa, + Zoom = 0xfb, + + Pa1 = 0xfd, + OemClear = 0xfe, + }; +} + +#endif \ No newline at end of file diff --git a/inc/xna/input/keyboard.hpp b/inc/xna/input/keyboard.hpp index 510c601..25cd400 100644 --- a/inc/xna/input/keyboard.hpp +++ b/inc/xna/input/keyboard.hpp @@ -2,6 +2,7 @@ #define XNA_INPUT_KEYBOARD_HPP #include "../default.hpp" +#include "input-enums.hpp" namespace xna { //Represents a state of keystrokes recorded by a keyboard input device. diff --git a/inc/xna/input/mouse.hpp b/inc/xna/input/mouse.hpp index 41a55dc..f9e8dfc 100644 --- a/inc/xna/input/mouse.hpp +++ b/inc/xna/input/mouse.hpp @@ -2,6 +2,7 @@ #define XNA_INPUT_MOUSE_HPP #include "../default.hpp" +#include "input-enums.hpp" namespace xna { //Represents the state of a mouse input device, including mouse cursor position and buttons pressed.