summaryrefslogtreecommitdiff
path: root/src/video/sdl2_v.cpp
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-01-16 15:25:01 +0100
committerPatric Stout <github@truebrain.nl>2021-01-30 21:43:59 +0100
commitf31b65825f160032451e743c044b9ac0027a8172 (patch)
treec286dd927634f1609036fdf653b1011cdfb1f485 /src/video/sdl2_v.cpp
parent6916fc76bd3f2ababefaace061b62a7aeaa4f419 (diff)
downloadopenttd-f31b65825f160032451e743c044b9ac0027a8172.tar.xz
Codechange: [SDL2] Move FindStartupDisplay to its own function
Diffstat (limited to 'src/video/sdl2_v.cpp')
-rw-r--r--src/video/sdl2_v.cpp40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp
index f4ea0dddb..251a6513f 100644
--- a/src/video/sdl2_v.cpp
+++ b/src/video/sdl2_v.cpp
@@ -258,6 +258,27 @@ static void GetAvailableVideoMode(uint *w, uint *h)
*h = _resolutions[best].height;
}
+static uint FindStartupDisplay(uint startup_display)
+{
+ int num_displays = SDL_GetNumVideoDisplays();
+
+ /* If the user indicated a valid monitor, use that. */
+ if (IsInsideBS(startup_display, 0, num_displays)) return startup_display;
+
+ /* Mouse position decides which display to use. */
+ int mx, my;
+ SDL_GetGlobalMouseState(&mx, &my);
+ for (int display = 0; display < num_displays; ++display) {
+ SDL_Rect r;
+ if (SDL_GetDisplayBounds(display, &r) == 0 && IsInsideBS(mx, r.x, r.w) && IsInsideBS(my, r.y, r.h)) {
+ DEBUG(driver, 1, "SDL2: Mouse is at (%d, %d), use display %d (%d, %d, %d, %d)", mx, my, display, r.x, r.y, r.w, r.h);
+ return display;
+ }
+ }
+
+ return 0;
+}
+
bool VideoDriver_SDL::CreateMainSurface(uint w, uint h, bool resize)
{
SDL_Surface *newscreen;
@@ -689,27 +710,12 @@ const char *VideoDriver_SDL::Start(const StringList &parm)
}
if (ret_code < 0) return SDL_GetError();
- this->startup_display = GetDriverParamInt(parm, "display", -1);
- int num_displays = SDL_GetNumVideoDisplays();
- if (!IsInsideBS(this->startup_display, 0, num_displays)) {
- /* Mouse position decides which display to use */
- int mx, my;
- SDL_GetGlobalMouseState(&mx, &my);
- this->startup_display = 0; // used when mouse is on no screen...
- for (int display = 0; display < num_displays; ++display) {
- SDL_Rect r;
- if (SDL_GetDisplayBounds(display, &r) == 0 && IsInsideBS(mx, r.x, r.w) && IsInsideBS(my, r.y, r.h)) {
- DEBUG(driver, 1, "SDL2: Mouse is at (%d, %d), use display %d (%d, %d, %d, %d)", mx, my, display, r.x, r.y, r.w, r.h);
- this->startup_display = display;
- break;
- }
- }
- }
-
this->UpdateAutoResolution();
FindResolutions();
+ this->startup_display = FindStartupDisplay(GetDriverParamInt(parm, "display", -1));
+
if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height, false)) {
return SDL_GetError();
}