-
Notifications
You must be signed in to change notification settings - Fork 87
Window adjustments and fixes for all backends #234
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
Draft
AloXado320
wants to merge
8
commits into
ButterscotchRunner:main
Choose a base branch
from
AloXado320:backend_upd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0c4fc30
Window adjustments and fixes for all backends
AloXado320 3905ddf
Fix build for older SDL1 versions
AloXado320 ffd39ea
Better screen detection for old SDL1, remove stdio env set
AloXado320 f144c4e
platformdefs: convert macros to inline functions
AloXado320 519892e
Properly fix GLFW2 sleep
AloXado320 b031c4a
Better scaling (#1)
Un1q32 518ef94
Do size correction when resizing again, fix SDL3 window scale
AloXado320 f74a613
Made prints more clear about the max resolution
AloXado320 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,9 +41,10 @@ bool platformGetScaledWindowSize(int32_t* outW, int32_t* outH) { | |
|
|
||
| void platformSetWindowSize(int32_t width, int32_t height) { | ||
| if (width <= 0 || height <= 0) return; | ||
| PLATFORM_CACHE_WINDOW_SIZE(width, height); | ||
| fbWidth = width; | ||
| fbHeight = height; | ||
| scr = SDL_SetVideoMode(width, height, 0, (gfx == SOFTWARE ? 0 : SDL_OPENGL) | SDL_RESIZABLE); | ||
| scr = SDL_SetVideoMode(fbWidth, fbHeight, 0, (gfx == SOFTWARE ? 0 : SDL_OPENGL) | SDL_RESIZABLE); | ||
| } | ||
|
|
||
| void platformGetMousePos(double *xPos, double *yPos) { | ||
|
|
@@ -59,30 +60,71 @@ static bool platformGetWindowFocus(void) { | |
| return SDL_GetAppState() & SDL_APPINPUTFOCUS; | ||
| } | ||
|
|
||
| // SDL1.2 redirects stdio messages to stdout.txt and stderr.txt on Windows in SDL_main | ||
|
AloXado320 marked this conversation as resolved.
Outdated
|
||
| // So set the env variable to 0 before it reaches out main so there's no need to set it manually | ||
| #ifdef _WIN32 | ||
| #if defined(__GNUC__) || defined(__clang__) | ||
| __attribute__((constructor)) static void platformDisableRedirect(void) { | ||
| SDL_putenv("SDL_STDIO_REDIRECT=0"); | ||
| } | ||
| #elif defined(_MSC_VER) | ||
| static int platformDisableRedirect(void) { | ||
| SDL_putenv("SDL_STDIO_REDIRECT=0"); | ||
| return 0; | ||
| } | ||
| #pragma section(".CRT$XCU", read) | ||
| __declspec(allocate(".CRT$XCU")) static int (*pDisableRedirect)(void) = platformDisableRedirect; | ||
| #endif | ||
| #endif | ||
|
|
||
| bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless) { | ||
| if (headless && gfx != SOFTWARE) { | ||
| fprintf(stderr, "Headless mode on SDL 1.2 requires the software renderer!\n"); | ||
| return false; | ||
| } | ||
|
|
||
| #if SDL_VERSION_ATLEAST(1, 2, 10) // Old SDL1.2: Center pos doesn't matter assuming it's running in low res | ||
| SDL_putenv("SDL_VIDEO_WINDOW_POS=center"); | ||
| #endif | ||
|
|
||
| // Init SDL | ||
| if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER)) { | ||
| fprintf(stderr, "Failed to initialize SDL\n"); | ||
| return false; | ||
| } | ||
|
|
||
| fbWidth = reqW; | ||
| fbHeight = reqH; | ||
| if(!headless) { | ||
| int finalW = reqW; | ||
| int finalH = reqH; | ||
| #if SDL_VERSION_ATLEAST(1, 2, 10) | ||
| const SDL_VideoInfo* info = SDL_GetVideoInfo(); | ||
| if (info && (reqW >= info->current_w || reqH >= info->current_h)) { | ||
| PLATFORM_GET_BEST_FIT_RES(reqW, reqH, info->current_w, info->current_h, finalW, finalH); | ||
| fprintf(stderr, "Warning: Requested resolution %dx%d is bigger than the screen, adjusting to %dx%d\n", | ||
| reqW, reqH, finalW, finalH); | ||
| } | ||
| #else | ||
| // Old SDL1.2: Set a period appropriate resolution as fallback | ||
| int oldW = 1024; | ||
|
AloXado320 marked this conversation as resolved.
Outdated
|
||
| int oldH = 768; | ||
| if (reqW >= oldW || reqH >= oldH) { | ||
| PLATFORM_GET_BEST_FIT_RES(reqW, reqH, oldW, oldH, finalW, finalH); | ||
| fprintf(stderr, "Warning: Requested resolution %dx%d is bigger than the screen, adjusting to %dx%d\n", | ||
| reqW, reqH, finalW, finalH); | ||
| } | ||
| #endif | ||
|
|
||
| fbWidth = finalW; | ||
| fbHeight = finalH; | ||
| if (!headless) { | ||
| scr = SDL_SetVideoMode(fbWidth, fbHeight, 0, (gfx == SOFTWARE ? 0 : SDL_OPENGL) | SDL_RESIZABLE); | ||
| if (!scr && gfx == SOFTWARE) { | ||
| SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN); | ||
| if (modes && modes != (SDL_Rect**) -1 && modes[0]) { | ||
| fprintf(stderr, "Warning: %dx%d unavailable, falling back to %dx%d: %s\n", | ||
| reqW, reqH, modes[0]->w, modes[0]->h, SDL_GetError()); | ||
| scr = SDL_SetVideoMode(modes[0]->w, modes[0]->h, 0, 0); | ||
| fbWidth, fbHeight, modes[0]->w, modes[0]->h, SDL_GetError()); | ||
| fbWidth = modes[0]->w; | ||
| fbHeight = modes[0]->h; | ||
| scr = SDL_SetVideoMode(fbWidth, fbHeight, 0, 0); | ||
| } | ||
| } | ||
| if (!scr) { | ||
|
|
@@ -217,21 +259,30 @@ static int32_t SDLMouseButtonToGml(int sdlButton) { | |
| bool platformHandleEvents(void) { | ||
| SDL_Event e; | ||
| while (SDL_PollEvent(&e)) { | ||
| switch (e.type) { | ||
| default: | ||
| if (InputRecording_isPlaybackActive(globalInputRecording)) continue; | ||
| break; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this break; it does nothing |
||
| case SDL_VIDEORESIZE: | ||
| case SDL_QUIT: | ||
| break; | ||
| } | ||
| switch(e.type) { | ||
| case SDL_KEYDOWN: | ||
| // SDL1.2 needs to manually intercept Alt+F4 to exit properly | ||
| if (e.key.keysym.sym == SDLK_F4 && (e.key.keysym.mod & KMOD_ALT)) { | ||
| return true; | ||
| } | ||
| // During playback, suppress real keyboard input | ||
| if (InputRecording_isPlaybackActive(globalInputRecording)) break; | ||
| RunnerKeyboard_onKeyDown(g_runner->keyboard, SDLKeyToGml(e.key.keysym.sym)); | ||
| if (e.key.keysym.unicode != 0) | ||
| RunnerKeyboard_onCharacter(g_runner->keyboard, e.key.keysym.unicode); | ||
| break; | ||
| case SDL_KEYUP: | ||
| // During playback, suppress real keyboard input | ||
| if (InputRecording_isPlaybackActive(globalInputRecording)) break; | ||
| RunnerKeyboard_onKeyUp(g_runner->keyboard, SDLKeyToGml(e.key.keysym.sym)); | ||
| break; | ||
| case SDL_MOUSEBUTTONDOWN: | ||
| if (InputRecording_isPlaybackActive(globalInputRecording)) break; | ||
| if (e.button.button == SDL_BUTTON_WHEELUP) { | ||
| RunnerMouse_onWheel(g_runner->mouse, 1.0); | ||
| } else if (e.button.button == SDL_BUTTON_WHEELDOWN) { | ||
|
|
@@ -242,7 +293,6 @@ bool platformHandleEvents(void) { | |
| } | ||
| break; | ||
| case SDL_MOUSEBUTTONUP: | ||
| if (InputRecording_isPlaybackActive(globalInputRecording)) break; | ||
| if (e.button.button != SDL_BUTTON_WHEELUP && e.button.button != SDL_BUTTON_WHEELDOWN) { | ||
| int32_t gmlBtn = SDLMouseButtonToGml(e.button.button); | ||
| if (gmlBtn >= 0) RunnerMouse_onButtonUp(g_runner->mouse, gmlBtn); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.