From 0a71bbe065b0dd7cf1e71cc25f7dd19dc9881b4d Mon Sep 17 00:00:00 2001 From: "Stefanos A." Date: Tue, 24 Dec 2013 17:06:39 +0100 Subject: [PATCH] Improved ToString implementation --- Source/OpenTK/Input/GamePadButtons.cs | 14 +------------- Source/OpenTK/Input/GamePadThumbSticks.cs | 4 ++-- Source/OpenTK/Input/GamePadTriggers.cs | 2 +- Source/OpenTK/Input/Joystick.cs | 5 +++++ Source/OpenTK/Input/JoystickState.cs | 6 +++--- 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/Source/OpenTK/Input/GamePadButtons.cs b/Source/OpenTK/Input/GamePadButtons.cs index aeb97b59..c13a9f0c 100644 --- a/Source/OpenTK/Input/GamePadButtons.cs +++ b/Source/OpenTK/Input/GamePadButtons.cs @@ -109,19 +109,7 @@ namespace OpenTK.Input public override string ToString() { - return String.Format( - "{{{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}}}", - A == ButtonState.Pressed ? "A" : String.Empty, - B == ButtonState.Pressed ? "B" : String.Empty, - X == ButtonState.Pressed ? "X" : String.Empty, - Y == ButtonState.Pressed ? "Y" : String.Empty, - LeftShoulder == ButtonState.Pressed ? "L" : String.Empty, - RightShoulder == ButtonState.Pressed ? "R" : String.Empty, - Back == ButtonState.Pressed ? " Back" : String.Empty, - Start == ButtonState.Pressed ? " Start" : String.Empty, - BigButton == ButtonState.Pressed ? " Big" : String.Empty, - LeftStick == ButtonState.Pressed ? " LStick" : String.Empty, - RightStick == ButtonState.Pressed ? " RStick" : String.Empty); + return Convert.ToString((int)buttons, 2).PadLeft(10, '0'); } public override int GetHashCode() diff --git a/Source/OpenTK/Input/GamePadThumbSticks.cs b/Source/OpenTK/Input/GamePadThumbSticks.cs index 59eb4ee3..63838c6f 100644 --- a/Source/OpenTK/Input/GamePadThumbSticks.cs +++ b/Source/OpenTK/Input/GamePadThumbSticks.cs @@ -73,8 +73,8 @@ namespace OpenTK.Input public override string ToString() { return String.Format( - "{{Left: {0}; Right: {1}}}", - Left, Right); + "{{Left: ({0:f4}; {1:f4}); Right: ({2:f4}; {3:f4})}}", + Left.X, Left.Y, Right.X, Right.Y); } public override int GetHashCode() diff --git a/Source/OpenTK/Input/GamePadTriggers.cs b/Source/OpenTK/Input/GamePadTriggers.cs index ecff49c7..0e505d81 100644 --- a/Source/OpenTK/Input/GamePadTriggers.cs +++ b/Source/OpenTK/Input/GamePadTriggers.cs @@ -69,7 +69,7 @@ namespace OpenTK.Input public override string ToString() { return String.Format( - "{{Left: {0}; Right: {1}}}", + "{{Left: {0:f2}; Right: {1:f2}}}", Left, Right); } diff --git a/Source/OpenTK/Input/Joystick.cs b/Source/OpenTK/Input/Joystick.cs index 0458abed..378b11f4 100644 --- a/Source/OpenTK/Input/Joystick.cs +++ b/Source/OpenTK/Input/Joystick.cs @@ -47,5 +47,10 @@ namespace OpenTK.Input { return implementation.GetState(index); } + + //public string GetName(int index) + //{ + // return implementation.GetName(index); + //} } } diff --git a/Source/OpenTK/Input/JoystickState.cs b/Source/OpenTK/Input/JoystickState.cs index 1b2a1299..e14ac2d2 100644 --- a/Source/OpenTK/Input/JoystickState.cs +++ b/Source/OpenTK/Input/JoystickState.cs @@ -41,7 +41,7 @@ namespace OpenTK.Input internal const int MaxAxes = 10; internal const int MaxButtons = 32; - const float ConversionFactor = 1.0f / (short.MaxValue + 1); + const float ConversionFactor = 1.0f / (short.MaxValue + 0.5f); unsafe fixed short axes[MaxAxes]; int buttons; @@ -94,12 +94,12 @@ namespace OpenTK.Input for (int i = 0; i < MaxAxes; i++) { sb.Append(" "); - sb.Append(GetAxis(i)); + sb.Append(String.Format("{0:f4}", GetAxis(i))); } return String.Format( "{{Axes:{0}; Buttons: {1}; IsConnected: {2}}}", sb.ToString(), - Convert.ToString((int)buttons, 2), + Convert.ToString((int)buttons, 2).PadLeft(16, '0'), IsConnected); }