return axis + id;
}
- static JoystickButton ParseButton(string item)
+ static int ParseButton(string item)
{
// item is in the format "b#" where # a zero-based integer number
- JoystickButton button = JoystickButton.Button0;
- int id = Int32.Parse(item.Substring(1));
- return button + id;
+ return Int32.Parse(item.Substring(1));
}
static JoystickHat ParseHat(string item, out HatPosition position)
struct GamePadConfigurationSource
{
ConfigurationType map_type;
- JoystickButton? map_button;
+ int? map_button;
JoystickAxis? map_axis;
JoystickHat? map_hat;
HatPosition? map_hat_position;
Axis = axis;
}
- public GamePadConfigurationSource(JoystickButton button)
+ public GamePadConfigurationSource(int button)
: this()
{
Type = ConfigurationType.Button;
private set { map_axis = value; }
}
- public JoystickButton Button
+ public int Button
{
get { return map_button.Value; }
private set { map_button = value; }
+++ /dev/null
-#region License
-//
-// JoystickButton.cs
-//
-// Author:
-// Stefanos A. <stapostol@gmail.com>
-//
-// 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;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenTK.Input
-{
- /// <summary>
- /// Defines available JoystickDevice buttons.
- /// </summary>
- public enum JoystickButton
- {
- /// <summary>The first button of the JoystickDevice.</summary>
- Button0 = 0,
- /// <summary>The second button of the JoystickDevice.</summary>
- Button1,
- /// <summary>The third button of the JoystickDevice.</summary>
- Button2,
- /// <summary>The fourth button of the JoystickDevice.</summary>
- Button3,
- /// <summary>The fifth button of the JoystickDevice.</summary>
- Button4,
- /// <summary>The sixth button of the JoystickDevice.</summary>
- Button5,
- /// <summary>The seventh button of the JoystickDevice.</summary>
- Button6,
- /// <summary>The eighth button of the JoystickDevice.</summary>
- Button7,
- /// <summary>The ninth button of the JoystickDevice.</summary>
- Button8,
- /// <summary>The tenth button of the JoystickDevice.</summary>
- Button9,
- /// <summary>The eleventh button of the JoystickDevice.</summary>
- Button10,
- /// <summary>The twelfth button of the JoystickDevice.</summary>
- Button11,
- /// <summary>The thirteenth button of the JoystickDevice.</summary>
- Button12,
- /// <summary>The fourteenth button of the JoystickDevice.</summary>
- Button13,
- /// <summary>The fifteenth button of the JoystickDevice.</summary>
- Button14,
- /// <summary>The sixteenth button of the JoystickDevice.</summary>
- Button15,
- /// <summary>The seventeenth button of the JoystickDevice.</summary>
- Button16,
- /// <summary>The eighteenth button of the JoystickDevice.</summary>
- Button17,
- /// <summary>The nineteenth button of the JoystickDevice.</summary>
- Button18,
- /// <summary>The twentieth button of the JoystickDevice.</summary>
- Button19,
- /// <summary>The twentyfirst button of the JoystickDevice.</summary>
- Button20,
- /// <summary>The twentysecond button of the JoystickDevice.</summary>
- Button21,
- /// <summary>The twentythird button of the JoystickDevice.</summary>
- Button22,
- /// <summary>The twentyfourth button of the JoystickDevice.</summary>
- Button23,
- /// <summary>The twentyfifth button of the JoystickDevice.</summary>
- Button24,
- /// <summary>The twentysixth button of the JoystickDevice.</summary>
- Button25,
- /// <summary>The twentyseventh button of the JoystickDevice.</summary>
- Button26,
- /// <summary>The twentyeighth button of the JoystickDevice.</summary>
- Button27,
- /// <summary>The twentynineth button of the JoystickDevice.</summary>
- Button28,
- /// <summary>The thirtieth button of the JoystickDevice.</summary>
- Button29,
- /// <summary>The thirtyfirst button of the JoystickDevice.</summary>
- Button30,
- /// <summary>The thirtysecond button of the JoystickDevice.</summary>
- Button31,
- /// <summary>The last supported button of the JoystickDevice.</summary>
- Last = Button31,
- }
-}
}
}
- internal void SetButton(JoystickButton button, bool @value)
+ internal void SetButton(int button, bool @value)
{
- if ((int)button < button_collection.Count)
+ if (button < button_collection.Count)
{
if (button_collection[button] != @value)
{
{
#region Fields
- JoystickButton button;
+ int button;
bool pressed;
#endregion
/// </summary>
/// <param name="button">The index of the joystick button for the event.</param>
/// <param name="pressed">The current state of the button.</param>
- internal JoystickButtonEventArgs(JoystickButton button, bool pressed)
+ internal JoystickButtonEventArgs(int button, bool pressed)
{
this.button = button;
this.pressed = pressed;
/// <summary>
/// The index of the joystick button for the event.
/// </summary>
- public JoystickButton Button { get { return this.button; } internal set { this.button = value; } }
+ public int Button { get { return this.button; } internal set { this.button = value; } }
/// <summary>
/// Gets a System.Boolean representing the state of the button for the event.
}
/// <summary>
- /// Gets a System.Boolean indicating whether the specified JoystickButton is pressed.
- /// </summary>
- /// <param name="button">The JoystickButton to check.</param>
- /// <returns>True if the JoystickButton is pressed; false otherwise.</returns>
- public bool this[JoystickButton button]
- {
- get { return button_state[(int)button]; }
- internal set { button_state[(int)button] = value; }
- }
-
- /// <summary>
/// Gets a System.Int32 indicating the available amount of JoystickButtons.
/// </summary>
public int Count
// If we ever add more values to JoystickAxis or JoystickButton
// then we'll need to increase these limits.
internal const int MaxAxes = (int)JoystickAxis.Last + 1;
- internal const int MaxButtons = (int)JoystickButton.Last + 1;
+ internal const int MaxButtons = 64;
internal const int MaxHats = (int)JoystickHat.Last + 1;
const float ConversionFactor = 1.0f / (short.MaxValue + 0.5f);
int packet_number;
- int buttons;
+ long buttons;
unsafe fixed short axes[MaxAxes];
JoystickHatState hat0;
JoystickHatState hat1;
}
/// <summary>
- /// Gets the current <see cref="ButtonState"/> of the specified <see cref="JoystickButton"/>.
+ /// Gets the current <see cref="ButtonState"/> of the specified button.
/// </summary>
/// <returns><see cref="ButtonState.Pressed"/> if the specified button is pressed; otherwise, <see cref="ButtonState.Released"/>.</returns>
- /// <param name="button">The <see cref="JoystickButton"/> to query.</param>
- public ButtonState GetButton(JoystickButton button)
+ /// <param name="button">The button to query.</param>
+ public ButtonState GetButton(int button)
{
- return (buttons & (1 << (int)button)) != 0 ? ButtonState.Pressed : ButtonState.Released;
+ return (buttons & ((long)1 << button)) != 0 ? ButtonState.Pressed : ButtonState.Released;
}
/// <summary>
}
/// <summary>
- /// Gets a value indicating whether the specified <see cref="JoystickButton"/> is currently pressed.
+ /// Gets a value indicating whether the specified button is currently pressed.
/// </summary>
/// <returns>true if the specified button is pressed; otherwise, false.</returns>
- /// <param name="button">The <see cref="JoystickButton"/> to query.</param>
- public bool IsButtonDown(JoystickButton button)
+ /// <param name="button">The button to query.</param>
+ public bool IsButtonDown(int button)
{
- return (buttons & (1 << (int)button)) != 0;
+ return (buttons & ((long)1 << button)) != 0;
}
/// <summary>
- /// Gets a value indicating whether the specified <see cref="JoystickButton"/> is currently released.
+ /// Gets a value indicating whether the specified button is currently released.
/// </summary>
/// <returns>true if the specified button is released; otherwise, false.</returns>
- /// <param name="button">The <see cref="JoystickButton"/> to query.</param>
- public bool IsButtonUp(JoystickButton button)
+ /// <param name="button">The button to query.</param>
+ public bool IsButtonUp(int button)
{
- return (buttons & (1 << (int)button)) == 0;
+ return (buttons & ((long)1 << button)) == 0;
}
/// <summary>
return String.Format(
"{{Axes:{0}; Buttons: {1}; Hat: {2}; IsConnected: {3}}}",
sb.ToString(),
- Convert.ToString((int)buttons, 2).PadLeft(16, '0'),
+ Convert.ToString(buttons, 2).PadLeft(16, '0'),
hat0,
IsConnected);
}
buttons = 0;
}
- internal void SetButton(JoystickButton button, bool value)
+ internal void SetButton(int button, bool value)
{
- int index = (int)button;
- if (index < 0 || index >= MaxButtons)
+ if (button < 0 || button >= MaxButtons)
throw new ArgumentOutOfRangeException("button");
if (value)
{
- buttons |= 1 << index;
+ buttons |= (long)1 << button;
}
else
{
- buttons &= ~(1 << index);
+ buttons &= ~((long)1 << button);
}
}
<Compile Include="Input\IMouseDriver2.cs" />
<Compile Include="Input\Joystick.cs" />
<Compile Include="Input\JoystickAxis.cs" />
- <Compile Include="Input\JoystickButton.cs" />
<Compile Include="Input\JoystickCapabilities.cs" />
<Compile Include="Input\JoystickState.cs" />
<Compile Include="InteropHelper.cs" />
}
for (int button_index = 0; button_index < caps.ButtonCount; button_index++)
{
- JoystickButton button = JoystickButton.Button0 + button_index;
- joysticks[i].SetButton(button, state.GetButton(button) == ButtonState.Pressed);
+ joysticks[i].SetButton(button_index, state.GetButton(button_index) == ButtonState.Pressed);
}
for (int hat_index = 0; hat_index < caps.HatCount; hat_index++)
{
public readonly Dictionary<EvdevAxis, AxisInfo> AxisMap =
new Dictionary<EvdevAxis, AxisInfo>();
- public readonly Dictionary<EvdevButton, JoystickButton> ButtonMap =
- new Dictionary<EvdevButton, JoystickButton>();
+ public readonly Dictionary<EvdevButton, int> ButtonMap =
+ new Dictionary<EvdevButton, int>();
}
sealed class LinuxJoystick : IJoystickDriver2
{
if (TestBit(keybit, (int)button))
{
- stick.ButtonMap.Add(button, (JoystickButton)buttons++);
+ stick.ButtonMap.Add(button, buttons++);
}
}
}
case EvdevType.KEY:
{
- JoystickButton button;
+ int button;
if (js.ButtonMap.TryGetValue((EvdevButton)e->Code, out button))
{
js.State.SetButton(button, e->Value != 0);
case HIDPage.Button:
{
bool pressed = GetJoystickButton(val, elem);
- JoystickButton button = JoystickButton.Button0 + joy.Elements[cookie].Index;
- if (button >= JoystickButton.Button0 && button <= JoystickButton.Last)
+ int button = joy.Elements[cookie].Index;
+ if (button >= 0 && button <= 64)
{
joy.State.SetButton(button, pressed);
}
case ConfigurationType.Button:
{
// JoystickButton -> Buttons/GamePadAxes mapping
- JoystickButton source_button = map.Source.Button;
+ int source_button = map.Source.Button;
bool pressed = joy.GetButton(source_button) == ButtonState.Pressed;
switch (map.Target.Type)
{
int index = sdl_instanceid_to_joysticks[id];
JoystickDevice<Sdl2JoystickDetails> joystick = (JoystickDevice<Sdl2JoystickDetails>)joysticks[index];
- joystick.SetButton((JoystickButton)ev.Button, ev.State == State.Pressed);
+ joystick.SetButton(ev.Button, ev.State == State.Pressed);
joystick.Details.PacketNumber = Math.Max(0, unchecked(joystick.Details.PacketNumber + 1));
}
else
for (int i = 0; i < joystick.Button.Count; i++)
{
- state.SetButton(JoystickButton.Button0 + i, joystick.Button[i]);
+ state.SetButton(i, joystick.Button[i]);
}
for (int i = 0; i < joystick.Details.HatCount; i++)
readonly Dictionary<int, JoystickAxis> axes =
new Dictionary<int,JoystickAxis>();
- readonly Dictionary<int, JoystickButton> buttons =
- new Dictionary<int, JoystickButton>();
+ readonly Dictionary<int, int> buttons =
+ new Dictionary<int, int>();
readonly Dictionary<int, JoystickHat> hats =
new Dictionary<int, JoystickHat>();
public void SetButton(short collection, HIDPage page, short usage, bool value)
{
- JoystickButton button = GetButton(collection, page, usage);
+ int button = GetButton(collection, page, usage);
State.SetButton(button, value);
}
return axes[key];
}
- JoystickButton GetButton(short collection, HIDPage page, short usage)
+ int GetButton(short collection, HIDPage page, short usage)
{
int key = MakeKey(collection, page, usage);
if (!buttons.ContainsKey(key))
{
- buttons.Add(key, JoystickButton.Button0 + buttons.Count);
+ buttons.Add(key, buttons.Count);
}
return buttons[key];
}
for (int i = 0; i < stick.ButtonCaps.Count; i++)
{
- short* usage_list = stackalloc short[(int)JoystickButton.Last + 1];
- int usage_length = (int)JoystickButton.Last;
+ short* usage_list = stackalloc short[64];
+ int usage_length = 64;
HIDPage page = stick.ButtonCaps[i].UsagePage;
short collection = stick.ButtonCaps[i].LinkCollection;
for (short usage = stick.ButtonCaps[i].Range.UsageMin; usage <= stick.ButtonCaps[i].Range.UsageMax; usage++)
{
Debug.Print("Found button {0} ({1} / {2})",
- JoystickButton.Button0 + stick.GetCapabilities().ButtonCount,
+ stick.GetCapabilities().ButtonCount,
page, usage);
stick.SetButton(collection, page, usage, false);
}
else
{
Debug.Print("Found button {0} ({1} / {2})",
- JoystickButton.Button0 + stick.GetCapabilities().ButtonCount,
+ stick.GetCapabilities().ButtonCount,
page, stick.ButtonCaps[i].NotRange.Usage);
stick.SetButton(collection, page, stick.ButtonCaps[i].NotRange.Usage, false);
}
state.SetAxis(JoystickAxis.Axis4, (short)Math.Min(short.MaxValue, -xstate.GamePad.ThumbRY));
state.SetAxis(JoystickAxis.Axis5, (short)Common.HidHelper.ScaleValue(xstate.GamePad.RightTrigger, 0, byte.MaxValue, short.MinValue, short.MaxValue));
- state.SetButton(JoystickButton.Button0, (xstate.GamePad.Buttons & XInputButtons.A) != 0);
- state.SetButton(JoystickButton.Button1, (xstate.GamePad.Buttons & XInputButtons.B) != 0);
- state.SetButton(JoystickButton.Button2, (xstate.GamePad.Buttons & XInputButtons.X) != 0);
- state.SetButton(JoystickButton.Button3, (xstate.GamePad.Buttons & XInputButtons.Y) != 0);
- state.SetButton(JoystickButton.Button4, (xstate.GamePad.Buttons & XInputButtons.LeftShoulder) != 0);
- state.SetButton(JoystickButton.Button5, (xstate.GamePad.Buttons & XInputButtons.RightShoulder) != 0);
- state.SetButton(JoystickButton.Button6, (xstate.GamePad.Buttons & XInputButtons.Back) != 0);
- state.SetButton(JoystickButton.Button7, (xstate.GamePad.Buttons & XInputButtons.Start) != 0);
- state.SetButton(JoystickButton.Button8, (xstate.GamePad.Buttons & XInputButtons.LeftThumb) != 0);
- state.SetButton(JoystickButton.Button9, (xstate.GamePad.Buttons & XInputButtons.RightThumb) != 0);
- state.SetButton(JoystickButton.Button10, (xstate.GamePad.Buttons & XInputButtons.Guide) != 0);
+ state.SetButton(0, (xstate.GamePad.Buttons & XInputButtons.A) != 0);
+ state.SetButton(1, (xstate.GamePad.Buttons & XInputButtons.B) != 0);
+ state.SetButton(2, (xstate.GamePad.Buttons & XInputButtons.X) != 0);
+ state.SetButton(3, (xstate.GamePad.Buttons & XInputButtons.Y) != 0);
+ state.SetButton(4, (xstate.GamePad.Buttons & XInputButtons.LeftShoulder) != 0);
+ state.SetButton(5, (xstate.GamePad.Buttons & XInputButtons.RightShoulder) != 0);
+ state.SetButton(6, (xstate.GamePad.Buttons & XInputButtons.Back) != 0);
+ state.SetButton(7, (xstate.GamePad.Buttons & XInputButtons.Start) != 0);
+ state.SetButton(8, (xstate.GamePad.Buttons & XInputButtons.LeftThumb) != 0);
+ state.SetButton(9, (xstate.GamePad.Buttons & XInputButtons.RightThumb) != 0);
+ state.SetButton(10, (xstate.GamePad.Buttons & XInputButtons.Guide) != 0);
state.SetHat(JoystickHat.Hat0, new JoystickHatState(TranslateHat(xstate.GamePad.Buttons)));
}