Fixed problem where Xbox controller wouldn't appear for InputGamepad.
I've fixed the problems associated with this file which I detailed in my issue report [here](https://github.com/ChrisDill/Raylib-cs/issues/195) (issue #195). My version of Raylib-cs is slightly different from the bleeding edge master branch but still recent, and my project setup is slightly different too, but I think this change should still work. You should test it to double check though.
This commit is contained in:
parent
335d5587b0
commit
356155b5fa
1 changed files with 267 additions and 262 deletions
|
|
@ -16,309 +16,314 @@
|
|||
********************************************************************************************/
|
||||
|
||||
using System.Numerics;
|
||||
using Raylib_cs;
|
||||
using static Raylib_cs.Raylib;
|
||||
|
||||
namespace Examples.Core;
|
||||
|
||||
public class InputGamepad
|
||||
namespace Examples.Core
|
||||
{
|
||||
// NOTE: Gamepad name ID depends on drivers and OS
|
||||
// public const string XBOX360_NAME_ID = "Microsoft;
|
||||
// public const string PS3_NAME_ID = "PLAYSTATION(R)3;
|
||||
public const string XBOX360_NAME_ID = "Xbox";
|
||||
public const string PS3_NAME_ID = "PLAYSTATION(R)3";
|
||||
|
||||
public static int Main()
|
||||
public class InputGamepad
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
// NOTE: Gamepad name ID depends on drivers and OS
|
||||
// These are some possible names the gamepads could have.
|
||||
public const string XBOX360_LEGACY_NAME_ID = "Xbox Controller";
|
||||
public const string XBOX360_NAME_ID = "Xbox 360 Controller";
|
||||
public const string XBOX360_NAME_ID_RPI = "Microsoft X-Box 360 pad";
|
||||
public const string PS3_NAME_ID = "PLAYSTATION(R)3 Controller";
|
||||
|
||||
// Set MSAA 4X hint before windows creation
|
||||
SetConfigFlags(ConfigFlags.FLAG_MSAA_4X_HINT);
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
|
||||
|
||||
Texture2D texPs3Pad = LoadTexture("resources/ps3.png");
|
||||
Texture2D texXboxPad = LoadTexture("resources/xbox.png");
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose())
|
||||
public static int Main()
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// ...
|
||||
//----------------------------------------------------------------------------------
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
ClearBackground(Color.RAYWHITE);
|
||||
// Set MSAA 4X hint before windows creation
|
||||
SetConfigFlags(ConfigFlags.FLAG_MSAA_4X_HINT);
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
|
||||
|
||||
if (IsGamepadAvailable(0))
|
||||
Texture2D texPs3Pad = LoadTexture("resources/ps3.png");
|
||||
Texture2D texXboxPad = LoadTexture("resources/xbox.png");
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
string gamepadName = GetGamepadName_(0);
|
||||
DrawText($"GP1: {gamepadName}", 10, 10, 10, Color.BLACK);
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// ...
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
if (gamepadName == XBOX360_NAME_ID)
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
ClearBackground(Color.RAYWHITE);
|
||||
|
||||
if (IsGamepadAvailable(0))
|
||||
{
|
||||
DrawTexture(texXboxPad, 0, 0, Color.DARKGRAY);
|
||||
string gamepadName = GetGamepadName_(0);
|
||||
DrawText($"GP1: {gamepadName}", 10, 10, 10, Color.BLACK);
|
||||
|
||||
// Draw buttons: xbox home
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE))
|
||||
if (gamepadName == XBOX360_LEGACY_NAME_ID ||
|
||||
gamepadName == XBOX360_NAME_ID ||
|
||||
gamepadName == XBOX360_NAME_ID_RPI)
|
||||
{
|
||||
DrawCircle(394, 89, 19, Color.RED);
|
||||
DrawTexture(texXboxPad, 0, 0, Color.DARKGRAY);
|
||||
|
||||
// Draw buttons: xbox home
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE))
|
||||
{
|
||||
DrawCircle(394, 89, 19, Color.RED);
|
||||
}
|
||||
|
||||
// Draw buttons: basic
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE_RIGHT))
|
||||
{
|
||||
DrawCircle(436, 150, 9, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE_LEFT))
|
||||
{
|
||||
DrawCircle(352, 150, 9, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_LEFT))
|
||||
{
|
||||
DrawCircle(501, 151, 15, Color.BLUE);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_DOWN))
|
||||
{
|
||||
DrawCircle(536, 187, 15, Color.LIME);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
|
||||
{
|
||||
DrawCircle(572, 151, 15, Color.MAROON);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_UP))
|
||||
{
|
||||
DrawCircle(536, 115, 15, Color.GOLD);
|
||||
}
|
||||
|
||||
// Draw buttons: d-pad
|
||||
DrawRectangle(317, 202, 19, 71, Color.BLACK);
|
||||
DrawRectangle(293, 228, 69, 19, Color.BLACK);
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_UP))
|
||||
{
|
||||
DrawRectangle(317, 202, 19, 26, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_DOWN))
|
||||
{
|
||||
DrawRectangle(317, 202 + 45, 19, 26, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_LEFT))
|
||||
{
|
||||
DrawRectangle(292, 228, 25, 19, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_RIGHT))
|
||||
{
|
||||
DrawRectangle(292 + 44, 228, 26, 19, Color.RED);
|
||||
}
|
||||
|
||||
// Draw buttons: left-right back
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_TRIGGER_1))
|
||||
{
|
||||
DrawCircle(259, 61, 20, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_TRIGGER_1))
|
||||
{
|
||||
DrawCircle(536, 61, 20, Color.RED);
|
||||
}
|
||||
|
||||
// Draw axis: left joystick
|
||||
DrawCircle(259, 152, 39, Color.BLACK);
|
||||
DrawCircle(259, 152, 34, Color.LIGHTGRAY);
|
||||
DrawCircle(
|
||||
259 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_X) * 20),
|
||||
152 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_Y) * 20),
|
||||
25,
|
||||
Color.BLACK
|
||||
);
|
||||
|
||||
// Draw axis: right joystick
|
||||
DrawCircle(461, 237, 38, Color.BLACK);
|
||||
DrawCircle(461, 237, 33, Color.LIGHTGRAY);
|
||||
DrawCircle(
|
||||
461 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_X) * 20),
|
||||
237 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_Y) * 20),
|
||||
25, Color.BLACK
|
||||
);
|
||||
|
||||
// Draw axis: left-right triggers
|
||||
float leftTriggerX = GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_TRIGGER);
|
||||
float rightTriggerX = GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_TRIGGER);
|
||||
DrawRectangle(170, 30, 15, 70, Color.GRAY);
|
||||
DrawRectangle(604, 30, 15, 70, Color.GRAY);
|
||||
DrawRectangle(170, 30, 15, (int)(((1.0f + leftTriggerX) / 2.0f) * 70), Color.RED);
|
||||
DrawRectangle(604, 30, 15, (int)(((1.0f + rightTriggerX) / 2.0f) * 70), Color.RED);
|
||||
}
|
||||
else if (gamepadName == PS3_NAME_ID)
|
||||
{
|
||||
DrawTexture(texPs3Pad, 0, 0, Color.DARKGRAY);
|
||||
|
||||
// Draw buttons: ps
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE))
|
||||
{
|
||||
DrawCircle(396, 222, 13, Color.RED);
|
||||
}
|
||||
|
||||
// Draw buttons: basic
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE_LEFT))
|
||||
{
|
||||
DrawRectangle(328, 170, 32, 13, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE_RIGHT))
|
||||
{
|
||||
DrawTriangle(
|
||||
new Vector2(436, 168),
|
||||
new Vector2(436, 185),
|
||||
new Vector2(464, 177),
|
||||
Color.RED
|
||||
);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_UP))
|
||||
{
|
||||
DrawCircle(557, 144, 13, Color.LIME);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
|
||||
{
|
||||
DrawCircle(586, 173, 13, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_DOWN))
|
||||
{
|
||||
DrawCircle(557, 203, 13, Color.VIOLET);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_LEFT))
|
||||
{
|
||||
DrawCircle(527, 173, 13, Color.PINK);
|
||||
}
|
||||
|
||||
// Draw buttons: d-pad
|
||||
DrawRectangle(225, 132, 24, 84, Color.BLACK);
|
||||
DrawRectangle(195, 161, 84, 25, Color.BLACK);
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_UP))
|
||||
{
|
||||
DrawRectangle(225, 132, 24, 29, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_DOWN))
|
||||
{
|
||||
DrawRectangle(225, 132 + 54, 24, 30, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_LEFT))
|
||||
{
|
||||
DrawRectangle(195, 161, 30, 25, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_RIGHT))
|
||||
{
|
||||
DrawRectangle(195 + 54, 161, 30, 25, Color.RED);
|
||||
}
|
||||
|
||||
// Draw buttons: left-right back buttons
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_TRIGGER_1))
|
||||
{
|
||||
DrawCircle(239, 82, 20, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_TRIGGER_1))
|
||||
{
|
||||
DrawCircle(557, 82, 20, Color.RED);
|
||||
}
|
||||
|
||||
// Draw axis: left joystick
|
||||
DrawCircle(319, 255, 35, Color.BLACK);
|
||||
DrawCircle(319, 255, 31, Color.LIGHTGRAY);
|
||||
DrawCircle(
|
||||
319 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_X) * 20),
|
||||
255 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_Y) * 20),
|
||||
25,
|
||||
Color.BLACK
|
||||
);
|
||||
|
||||
// Draw axis: right joystick
|
||||
DrawCircle(475, 255, 35, Color.BLACK);
|
||||
DrawCircle(475, 255, 31, Color.LIGHTGRAY);
|
||||
DrawCircle(
|
||||
475 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_X) * 20),
|
||||
255 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_Y) * 20),
|
||||
25,
|
||||
Color.BLACK
|
||||
);
|
||||
|
||||
// Draw axis: left-right triggers
|
||||
float leftTriggerX = GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_TRIGGER);
|
||||
float rightTriggerX = GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_TRIGGER);
|
||||
DrawRectangle(169, 48, 15, 70, Color.GRAY);
|
||||
DrawRectangle(611, 48, 15, 70, Color.GRAY);
|
||||
DrawRectangle(169, 48, 15, (int)(((1.0f - leftTriggerX) / 2.0f) * 70), Color.RED);
|
||||
DrawRectangle(611, 48, 15, (int)(((1.0f - rightTriggerX) / 2.0f) * 70), Color.RED);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawText("- GENERIC GAMEPAD -", 280, 180, 20, Color.GRAY);
|
||||
// TODO: Draw generic gamepad
|
||||
}
|
||||
|
||||
// Draw buttons: basic
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE_RIGHT))
|
||||
DrawText($"DETECTED AXIS [{GetGamepadAxisCount(0)}]:", 10, 50, 10, Color.MAROON);
|
||||
|
||||
for (int i = 0; i < GetGamepadAxisCount(0); i++)
|
||||
{
|
||||
DrawCircle(436, 150, 9, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE_LEFT))
|
||||
{
|
||||
DrawCircle(352, 150, 9, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_LEFT))
|
||||
{
|
||||
DrawCircle(501, 151, 15, Color.BLUE);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_DOWN))
|
||||
{
|
||||
DrawCircle(536, 187, 15, Color.LIME);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
|
||||
{
|
||||
DrawCircle(572, 151, 15, Color.MAROON);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_UP))
|
||||
{
|
||||
DrawCircle(536, 115, 15, Color.GOLD);
|
||||
}
|
||||
|
||||
// Draw buttons: d-pad
|
||||
DrawRectangle(317, 202, 19, 71, Color.BLACK);
|
||||
DrawRectangle(293, 228, 69, 19, Color.BLACK);
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_UP))
|
||||
{
|
||||
DrawRectangle(317, 202, 19, 26, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_DOWN))
|
||||
{
|
||||
DrawRectangle(317, 202 + 45, 19, 26, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_LEFT))
|
||||
{
|
||||
DrawRectangle(292, 228, 25, 19, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_RIGHT))
|
||||
{
|
||||
DrawRectangle(292 + 44, 228, 26, 19, Color.RED);
|
||||
}
|
||||
|
||||
// Draw buttons: left-right back
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_TRIGGER_1))
|
||||
{
|
||||
DrawCircle(259, 61, 20, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_TRIGGER_1))
|
||||
{
|
||||
DrawCircle(536, 61, 20, Color.RED);
|
||||
}
|
||||
|
||||
// Draw axis: left joystick
|
||||
DrawCircle(259, 152, 39, Color.BLACK);
|
||||
DrawCircle(259, 152, 34, Color.LIGHTGRAY);
|
||||
DrawCircle(
|
||||
259 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_X) * 20),
|
||||
152 - (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_Y) * 20),
|
||||
25,
|
||||
Color.BLACK
|
||||
);
|
||||
|
||||
// Draw axis: right joystick
|
||||
DrawCircle(461, 237, 38, Color.BLACK);
|
||||
DrawCircle(461, 237, 33, Color.LIGHTGRAY);
|
||||
DrawCircle(
|
||||
461 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_X) * 20),
|
||||
237 - (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_Y) * 20),
|
||||
25, Color.BLACK
|
||||
);
|
||||
|
||||
// Draw axis: left-right triggers
|
||||
float leftTriggerX = GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_TRIGGER);
|
||||
float rightTriggerX = GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_TRIGGER);
|
||||
DrawRectangle(170, 30, 15, 70, Color.GRAY);
|
||||
DrawRectangle(604, 30, 15, 70, Color.GRAY);
|
||||
DrawRectangle(170, 30, 15, (int)(((1.0f + leftTriggerX) / 2.0f) * 70), Color.RED);
|
||||
DrawRectangle(604, 30, 15, (int)(((1.0f + rightTriggerX) / 2.0f) * 70), Color.RED);
|
||||
}
|
||||
else if (gamepadName == PS3_NAME_ID)
|
||||
{
|
||||
DrawTexture(texPs3Pad, 0, 0, Color.DARKGRAY);
|
||||
|
||||
// Draw buttons: ps
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE))
|
||||
{
|
||||
DrawCircle(396, 222, 13, Color.RED);
|
||||
}
|
||||
|
||||
// Draw buttons: basic
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE_LEFT))
|
||||
{
|
||||
DrawRectangle(328, 170, 32, 13, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE_RIGHT))
|
||||
{
|
||||
DrawTriangle(
|
||||
new Vector2(436, 168),
|
||||
new Vector2(436, 185),
|
||||
new Vector2(464, 177),
|
||||
Color.RED
|
||||
DrawText(
|
||||
$"AXIS {i}: {GetGamepadAxisMovement(0, (GamepadAxis)i)}",
|
||||
20,
|
||||
70 + 20 * i,
|
||||
10,
|
||||
Color.DARKGRAY
|
||||
);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_UP))
|
||||
if (GetGamepadButtonPressed() != (int)GamepadButton.GAMEPAD_BUTTON_UNKNOWN)
|
||||
{
|
||||
DrawCircle(557, 144, 13, Color.LIME);
|
||||
DrawText($"DETECTED BUTTON: {GetGamepadButtonPressed()}", 10, 430, 10, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
|
||||
else
|
||||
{
|
||||
DrawCircle(586, 173, 13, Color.RED);
|
||||
DrawText("DETECTED BUTTON: NONE", 10, 430, 10, Color.GRAY);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_DOWN))
|
||||
{
|
||||
DrawCircle(557, 203, 13, Color.VIOLET);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_LEFT))
|
||||
{
|
||||
DrawCircle(527, 173, 13, Color.PINK);
|
||||
}
|
||||
|
||||
// Draw buttons: d-pad
|
||||
DrawRectangle(225, 132, 24, 84, Color.BLACK);
|
||||
DrawRectangle(195, 161, 84, 25, Color.BLACK);
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_UP))
|
||||
{
|
||||
DrawRectangle(225, 132, 24, 29, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_DOWN))
|
||||
{
|
||||
DrawRectangle(225, 132 + 54, 24, 30, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_LEFT))
|
||||
{
|
||||
DrawRectangle(195, 161, 30, 25, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_RIGHT))
|
||||
{
|
||||
DrawRectangle(195 + 54, 161, 30, 25, Color.RED);
|
||||
}
|
||||
|
||||
// Draw buttons: left-right back buttons
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_TRIGGER_1))
|
||||
{
|
||||
DrawCircle(239, 82, 20, Color.RED);
|
||||
}
|
||||
|
||||
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_TRIGGER_1))
|
||||
{
|
||||
DrawCircle(557, 82, 20, Color.RED);
|
||||
}
|
||||
|
||||
// Draw axis: left joystick
|
||||
DrawCircle(319, 255, 35, Color.BLACK);
|
||||
DrawCircle(319, 255, 31, Color.LIGHTGRAY);
|
||||
DrawCircle(
|
||||
319 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_X) * 20),
|
||||
255 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_Y) * 20),
|
||||
25,
|
||||
Color.BLACK
|
||||
);
|
||||
|
||||
// Draw axis: right joystick
|
||||
DrawCircle(475, 255, 35, Color.BLACK);
|
||||
DrawCircle(475, 255, 31, Color.LIGHTGRAY);
|
||||
DrawCircle(
|
||||
475 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_X) * 20),
|
||||
255 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_Y) * 20),
|
||||
25,
|
||||
Color.BLACK
|
||||
);
|
||||
|
||||
// Draw axis: left-right triggers
|
||||
float leftTriggerX = GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_TRIGGER);
|
||||
float rightTriggerX = GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_TRIGGER);
|
||||
DrawRectangle(169, 48, 15, 70, Color.GRAY);
|
||||
DrawRectangle(611, 48, 15, 70, Color.GRAY);
|
||||
DrawRectangle(169, 48, 15, (int)(((1.0f - leftTriggerX) / 2.0f) * 70), Color.RED);
|
||||
DrawRectangle(611, 48, 15, (int)(((1.0f - rightTriggerX) / 2.0f) * 70), Color.RED);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawText("- GENERIC GAMEPAD -", 280, 180, 20, Color.GRAY);
|
||||
// TODO: Draw generic gamepad
|
||||
DrawText("GP1: NOT DETECTED", 10, 10, 10, Color.GRAY);
|
||||
DrawTexture(texXboxPad, 0, 0, Color.LIGHTGRAY);
|
||||
}
|
||||
|
||||
DrawText($"DETECTED AXIS [{GetGamepadAxisCount(0)}]:", 10, 50, 10, Color.MAROON);
|
||||
|
||||
for (int i = 0; i < GetGamepadAxisCount(0); i++)
|
||||
{
|
||||
DrawText(
|
||||
$"AXIS {i}: {GetGamepadAxisMovement(0, (GamepadAxis)i)}",
|
||||
20,
|
||||
70 + 20 * i,
|
||||
10,
|
||||
Color.DARKGRAY
|
||||
);
|
||||
}
|
||||
|
||||
if (GetGamepadButtonPressed() != (int)GamepadButton.GAMEPAD_BUTTON_UNKNOWN)
|
||||
{
|
||||
DrawText($"DETECTED BUTTON: {GetGamepadButtonPressed()}", 10, 430, 10, Color.RED);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawText("DETECTED BUTTON: NONE", 10, 430, 10, Color.GRAY);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawText("GP1: NOT DETECTED", 10, 10, 10, Color.GRAY);
|
||||
DrawTexture(texXboxPad, 0, 0, Color.LIGHTGRAY);
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texPs3Pad);
|
||||
UnloadTexture(texXboxPad);
|
||||
|
||||
CloseWindow();
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texPs3Pad);
|
||||
UnloadTexture(texXboxPad);
|
||||
|
||||
CloseWindow();
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue