From 0432ac76d278fd283d7c460f2bef17b043f589c7 Mon Sep 17 00:00:00 2001 From: Jak <45759112+jakkosdev@users.noreply.github.com> Date: Thu, 26 May 2022 11:13:30 +0100 Subject: [PATCH 1/2] add gamepad input example --- examples/core/gamepad_input.jl | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 examples/core/gamepad_input.jl diff --git a/examples/core/gamepad_input.jl b/examples/core/gamepad_input.jl new file mode 100644 index 0000000..d3625e3 --- /dev/null +++ b/examples/core/gamepad_input.jl @@ -0,0 +1,46 @@ +using Raylib + +function main() + + screenWidth = 800 + screenHeight = 450 + + Raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input") + + Raylib.SetTargetFPS(60) + + while !Raylib.WindowShouldClose() + + Raylib.BeginDrawing() + + Raylib.ClearBackground(Raylib.RAYWHITE) + + if Raylib.IsGamepadAvailable(0) + + Raylib.DrawText("GP1: $(Raylib.GetGamepadName(0))", 10, 10, 10, Raylib.BLACK) + + Raylib.DrawText("- GENERIC GAMEPAD -", 280, 180, 20, Raylib.GRAY) + + Raylib.DrawText("DETECTED AXIS [$(Raylib.GetGamepadAxisCount(0))]:", 10, 50, 10, Raylib.MAROON) + + for i in 0:Raylib.GetGamepadAxisCount(0)-1 + Raylib.DrawText("AXIS $i: $(Raylib.GetGamepadAxisMovement(0, i))", 20, 70 + 20*i, 10, Raylib.DARKGRAY) + end + + if Raylib.GetGamepadButtonPressed() != -1 + Raylib.DrawText("DETECTED BUTTON: $(Raylib.GetGamepadButtonPressed())", 10, 430, 10, Raylib.RED) + else + Raylib.DrawText("DETECTED BUTTON: NONE", 10, 430, 10, Raylib.GRAY) + end + + else + Raylib.DrawText("GP1: NOT DETECTED", 10, 10, 10, Raylib.GRAY) + end + + Raylib.EndDrawing() + + end + + Raylib.CloseWindow() + +end \ No newline at end of file From 2d3cb57e8b866d2b3bd88ecc2cfb292fb9e51804 Mon Sep 17 00:00:00 2001 From: Jak Kos <45759112+jakkosdev@users.noreply.github.com> Date: Thu, 26 May 2022 12:38:59 +0100 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Peter --- examples/core/gamepad_input.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/core/gamepad_input.jl b/examples/core/gamepad_input.jl index d3625e3..6981d74 100644 --- a/examples/core/gamepad_input.jl +++ b/examples/core/gamepad_input.jl @@ -17,7 +17,8 @@ function main() if Raylib.IsGamepadAvailable(0) - Raylib.DrawText("GP1: $(Raylib.GetGamepadName(0))", 10, 10, 10, Raylib.BLACK) + gamepad_name = unsafe_string(Raylib.GetGamepadName(0)) + Raylib.DrawText("GP1: $(gamepad_name)", 10, 10, 10, Raylib.BLACK) Raylib.DrawText("- GENERIC GAMEPAD -", 280, 180, 20, Raylib.GRAY) @@ -43,4 +44,4 @@ function main() Raylib.CloseWindow() -end \ No newline at end of file +end