CreedVI / Raylib-J

Handmade Java binding for Raylib
zlib License
94 stars 16 forks source link

Add `ToggleBorderlessWindowed` and `GetMonitorRefreshRate` #46

Closed ejenk0 closed 5 months ago

ejenk0 commented 5 months ago

NOTE: This is untested! (hence Draft status) I haven't been able to successfully build with the new build system. As soon as I am able I will test these changes. This PR is now tested and ready for review.

This PR will increase raylib coverage (raylib.h/raymath.h) from 75.29% (at 4c7478e) to 75.59% (0.3% increase).

ejenk0 commented 5 months ago

Latest commit fixes some problems with ToggleBorderlessWindowed and ToggleFullscreen where they would not correctly restore size/position of the window when toggling off. It also replaces the GetWindowPosition implementation with a more memory safe version and uses it in both functions. The old int[]{} method was not working to store window positions, so this commit uses IntBuffers instead in a try-with-resource block. There is still one remaining use of nglfwGetWindowPosition but that didn't seem to be a drop-in replacement so I have left it for now.

ejenk0 commented 5 months ago

This PR is ready for review. If it is helpful, here is the code I used to test everything:

public class HelloWorld {
    public static void main(String[] args) {
        Raylib rlj = new Raylib();
        rlj.core.InitWindow(800, 600, "Raylib-J Test");

        while (!rlj.core.WindowShouldClose()) {
            rlj.core.BeginDrawing();
            rlj.core.ClearBackground(Color.RAYWHITE);
            rlj.text.DrawText(
                "Congrats! You created your first window!",
                400 - (rlj.text.MeasureText("Congrats! You created your first window!", 20) / 2),
                300,
                20,
                Color.DARKGRAY
            );
            rlj.text.DrawText(
                rlj.core.GetMonitorRefreshRate(0) + "Hz detected",
                400,
                400,
                20,
                Color.DARKGRAY
            );

            if (rlj.core.IsKeyPressed(Keyboard.KEY_B)) {
                rlj.core.ToggleBorderlessWindowed();
            }

            if (rlj.core.IsKeyPressed(Keyboard.KEY_F)) {
                rlj.core.ToggleFullscreen();
            }

            if (rlj.core.IsKeyPressed(Keyboard.KEY_P)) {
                Vector2 pos = rlj.core.GetWindowPosition();
                System.out.println(
                    "Window Position: " + pos.x + ", " + pos.y
                );
            }

            rlj.core.EndDrawing();
        }
    }
}
CreedVI commented 5 months ago

I'll review when I get home from work! Thanks for your support on the project recently!

ejenk0 commented 5 months ago

I'll review when I get home from work! Thanks for your support on the project recently!

NP! Please feel free to criticise or nit pick or reject, these PRs are unsolicited after all 😅. Let me know if there is any part of the project you'd like some help on.