From 9374b6b41b0c773ae3cf31c3c0b4edeaf5f1b5c6 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Thu, 19 Dec 2013 16:27:57 +0100 Subject: [PATCH] Implemented GamePadButtons --- Source/OpenTK/Input/Buttons.cs | 213 ++++++++++++++++++++++++++ Source/OpenTK/Input/GamePadButton.cs | 68 -------- Source/OpenTK/Input/GamePadButtons.cs | 131 ++++++++++++++++ 3 files changed, 344 insertions(+), 68 deletions(-) create mode 100644 Source/OpenTK/Input/Buttons.cs delete mode 100644 Source/OpenTK/Input/GamePadButton.cs create mode 100644 Source/OpenTK/Input/GamePadButtons.cs diff --git a/Source/OpenTK/Input/Buttons.cs b/Source/OpenTK/Input/Buttons.cs new file mode 100644 index 00000000..739a8fcd --- /dev/null +++ b/Source/OpenTK/Input/Buttons.cs @@ -0,0 +1,213 @@ +// +// GamePadButton.cs +// +// Author: +// robert <${AuthorEmail}> +// +// Copyright (c) 2012 robert +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; + +namespace OpenTK.Input +{ + public enum Buttons + { + /// + /// DPad up direction button + /// + DPadUp = 1 << 0, + + /// + /// DPad down direction button + /// + DPadDown = 1 << 1, + + /// + /// DPad left direction button + /// + DPadLeft = 1 << 2, + + /// + /// DPad right direction button + /// + DPadRight = 1 << 3, + + /// + /// Start button + /// + Start = 1 << 4, + + /// + /// Back button + /// + Back = 1 << 5, + + /// + /// Left stick button + /// + LeftStick = 1 << 6, + + /// + /// Right stick button + /// + RightStick = 1 << 7, + + /// + /// Left shoulder button + /// + LeftShoulder = 1 << 8, + + /// + /// Right shoulder button + /// + RightShoulder = 1 << 9, + + /// + /// Home button + /// + Home = 1 << 11, + + /// + /// Home button + /// + BigButton = Home, + + /// + /// A button + /// + A = 1 << 12, + + /// + /// B button + /// + B = 1 << 13, + + /// + /// X button + /// + X = 1 << 14, + + /// + /// Y button + /// + Y = 1 << 15, + + /// + /// Left thumbstick left direction button + /// + LeftThumbstickLeft = 1 << 21, + + /// + /// Right trigger button + /// + RightTrigger = 1 << 22, + + /// + /// Left trigger button + /// + LeftTrigger = 1 << 23, + + /// + /// Right thumbstick up direction button + /// + RightThumbstickUp = 1 << 24, + + /// + /// Right thumbstick down direction button + /// + RightThumbstickDown = 1 << 25, + + /// + /// Right stick right direction button + /// + RightThumbstickRight = 1 << 26, + + /// + /// Right stick left direction button + /// + RightThumbstickLeft = 1 << 27, + + /// + /// Left stick up direction button + /// + LeftThumbstickUp = 1 << 28, + + /// + /// Left stick down direction button + /// + LeftThumbstickDown = 1 << 29, + + /// + /// Left stick right direction button + /// + LeftThumbstickRight = 1 << 30, + + /// The first button of the gamepad. + Button0 = A, + /// The second button of the gamepad. + Button1 = B, + /// The third button of the gamepad. + Button2 = X, + /// The fourth button of the gamepad. + Button3 = Y, + /// The fifth button of the gamepad. + Button4 = Start, + /// The sixth button of the gamepad. + Button5 = Back, + /// The seventh button of the gamepad. + Button6 = LeftStick, + /// The eighth button of the gamepad. + Button7 = RightStick, + /// The ninth button of the gamepad. + Button8 = LeftShoulder, + /// The tenth button of the gamepad. + Button9 = RightShoulder, + /// The eleventh button of the gamepad. + Button10 = Home, + /// The twelfth button of the gamepad. + Button11 = DPadUp, + /// The thirteenth button of the gamepad. + Button12 = DPadDown, + /// The fourteenth button of the gamepad. + Button13 = DPadLeft, + /// The fifteenth button of the gamepad. + Button14 = DPadRight, + /// The sixteenth button of the gamepad. + Button15 = LeftTrigger, + /// The seventeenth button of the gamepad. + Button16 = RightTrigger, + /// The eighteenth button of the gamepad. + Button17 = LeftThumbstickUp, + /// The nineteenth button of the gamepad. + Button18 = LeftThumbstickDown, + /// The twentieth button of the gamepad. + Button19 = LeftThumbstickLeft, + /// The twentieth-one button of the gamepad. + Button20 = LeftThumbstickRight, + /// The twentieth-one button of the gamepad. + Button21 = RightThumbstickUp, + /// The twentieth-one button of the gamepad. + Button22 = RightThumbstickDown, + /// The twentieth-one button of the gamepad. + Button23 = RightThumbstickLeft, + /// The twentieth-one button of the gamepad. + Button24 = RightThumbstickRight, + } +} diff --git a/Source/OpenTK/Input/GamePadButton.cs b/Source/OpenTK/Input/GamePadButton.cs deleted file mode 100644 index f4f543ad..00000000 --- a/Source/OpenTK/Input/GamePadButton.cs +++ /dev/null @@ -1,68 +0,0 @@ -// -// GamePadButton.cs -// -// Author: -// robert <${AuthorEmail}> -// -// Copyright (c) 2012 robert -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -using System; - -namespace OpenTK -{ - public enum GamePadButton - { - /// The first button of the gamepad. - Button0 = 0, - /// The second button of the gamepad. - Button1, - /// The third button of the gamepad. - Button2, - /// The fourth button of the gamepad. - Button3, - /// The fifth button of the gamepad. - Button4, - /// The sixth button of the gamepad. - Button5, - /// The seventh button of the gamepad. - Button6, - /// The eighth button of the gamepad. - Button7, - /// The ninth button of the gamepad. - Button8, - /// The tenth button of the gamepad. - Button9, - /// The eleventh button of the gamepad. - Button10, - /// The twelfth button of the gamepad. - Button11, - /// The thirteenth button of the gamepad. - Button12, - /// The fourteenth button of the gamepad. - Button13, - /// The fifteenth button of the gamepad. - Button14, - /// The sixteenth button of the gamepad. - Button15, - /// The last button of the gamepad. - LastButton - } -} - diff --git a/Source/OpenTK/Input/GamePadButtons.cs b/Source/OpenTK/Input/GamePadButtons.cs new file mode 100644 index 00000000..199e593f --- /dev/null +++ b/Source/OpenTK/Input/GamePadButtons.cs @@ -0,0 +1,131 @@ +// #region License +// +// GamePadButtons.cs +// +// Author: +// Stefanos A. +// +// Copyright (c) 2006-2013 Stefanos Apostolopoulos +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// #endregion +using System; + +namespace OpenTK.Input +{ + + public struct GamePadButtons : IEquatable + { + Buttons buttons; + + public GamePadButtons(Buttons state) + { + buttons = state; + } + + #region Public Members + + public ButtonState A + { + get { return GetButton(Buttons.A); } + } + + public ButtonState B + { + get { return GetButton(Buttons.B); } + } + + public ButtonState X + { + get { return GetButton(Buttons.X); } + } + + public ButtonState Y + { + get { return GetButton(Buttons.Y); } + } + + public ButtonState Back + { + get { return GetButton(Buttons.Back); } + } + + public ButtonState BigButton + { + get { return GetButton(Buttons.BigButton); } + } + + public ButtonState LeftShoulder + { + get { return GetButton(Buttons.LeftShoulder); } + } + + public ButtonState LeftStick + { + get { return GetButton(Buttons.LeftStick); } + } + + public ButtonState RightShoulder + { + get { return GetButton(Buttons.RightShoulder); } + } + + public ButtonState RightStick + { + get { return GetButton(Buttons.RightStick); } + } + + public ButtonState Start + { + get { return GetButton(Buttons.Start); } + } + + public static bool operator ==(GamePadButtons left, GamePadButtons right) + { + return left.Equals(right); + } + + public static bool operator !=(GamePadButtons left, GamePadButtons right) + { + return !left.Equals(right); + } + + #endregion + + #region IEquatable Members + + public bool Equals(GamePadButtons other) + { + return buttons == other.buttons; + } + + #endregion + + #region Private Members + + ButtonState GetButton(Buttons b) + { + return (buttons & b) != 0 ? ButtonState.Pressed : ButtonState.Released; + } + + #endregion + } +} +