Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rcore] Add GetWindowPosition() implementation for PLATFORM_WEB and fixes #3636 style/format #3637

Merged
merged 2 commits into from Dec 15, 2023

Conversation

ghost
Copy link

@ghost ghost commented Dec 14, 2023

Changes

  1. Adds implementation for GetWindowPosition() that was missing for PLATFORM_WEB. Does that by using emscripten EM_ASM_INT and DOM window.screenX and window.screenY (R621-R625).

  2. Fixes [rcore] Add GetMonitorWidth() and GetMonitorHeight() implementations for PLATFORM_WEB #3636 style/format to match the pattern generally used on raylib. Does that by changing w to width (R576-R578), h to height (R585-R587) and adding relevant notes (R575, R584). My apologies for missing the code style/convention on the previous PR.

Notes

  • Returned position of GetWindowPosition() is relative to the current monitor where the browser window is located.

Code example

  • This change can be tested for PLATFORM_WEB (requires ASYNCIFY) with:
#include "raylib.h"

int main(void) {
    InitWindow(800, 450, "test");
    SetTargetFPS(60);
    while (!WindowShouldClose()) {
        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText(TextFormat("Window position: %f x %f", GetWindowPosition().x, GetWindowPosition().y), 20, 20, 20, BLACK);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

Environment

  • Compiled on Linux (Ubuntu 22.04 64-bit) and tested on Firefox (115.3.1esr 64-bit) and Chromium (117.0.5938.149 64-bit) for both minshell.html and shell.html files.

Edits

  • 1: added line marks, typo.

@raysan5 raysan5 merged commit 489f0b9 into raysan5:master Dec 15, 2023
14 checks passed
@raysan5
Copy link
Owner

raysan5 commented Dec 15, 2023

@ubkp Nice! Thanks for the improvement! Actually, the w and h was something I wanted to comment, I prefer to avoid single-letter variables when possible, mostly for students reviewing the library. :)

@ghost
Copy link
Author

ghost commented Dec 15, 2023

@raysan5 Yeah, sorry about that. I was working on a different codebase which had a different code style and forgot to follow the code convention, my bad.

@ghost ghost deleted the add/web-windowposition branch December 15, 2023 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant