1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-25 09:44:02 +00:00

Multi-display fixes

- Enumerate display modes to show in the resolution selector based on the
  screen we're on
- Correct graphics init code to use the display index specified in
  user settings
This commit is contained in:
fgenesis 2017-06-26 08:34:30 +02:00
parent 6f170de929
commit 78352d4402
3 changed files with 40 additions and 17 deletions

View file

@ -1809,6 +1809,7 @@ void InGameMenu::create()
resBox = new AquariaComboBox(Vector(0.7f, 1.0f)); resBox = new AquariaComboBox(Vector(0.7f, 1.0f));
resBox->position = Vector(196, 285); resBox->position = Vector(196, 285);
core->enumerateScreenModesIfNecessary();
for (size_t i = 0; i < core->screenModes.size(); i++) for (size_t i = 0; i < core->screenModes.size(); i++)
{ {
const ScreenMode& m = core->screenModes[i]; const ScreenMode& m = core->screenModes[i];

View file

@ -175,13 +175,6 @@ void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp, int di
display = oldDisplay; display = oldDisplay;
} }
// Move window to specified display if necessary
if(display != oldDisplay)
{
int center = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
SDL_SetWindowPosition(gScreen, center, center);
}
const bool useDesktop = w == 0 || h == 0 || (oldw && w == -1 && oldh && h == -1 && _useDesktopResolution); const bool useDesktop = w == 0 || h == 0 || (oldw && w == -1 && oldh && h == -1 && _useDesktopResolution);
#else #else
const bool useDesktop = false; const bool useDesktop = false;
@ -256,11 +249,18 @@ void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp, int di
useh = oldh; useh = oldh;
maximize = false; maximize = false;
} }
createWindow(usew, useh, useDesktop, false, bpp); createWindow(usew, useh, useDesktop, false, bpp, display);
reloadRes = true; reloadRes = true;
} }
// Move window to specified display if necessary
if(display != oldDisplay)
{
int center = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
SDL_SetWindowPosition(gScreen, center, center);
}
if(fullscreen) if(fullscreen)
{ {
int screenflags = useDesktop ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN; int screenflags = useDesktop ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN;
@ -528,6 +528,7 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
_fullscreen = false; _fullscreen = false;
_refreshRate = 0; _refreshRate = 0;
_useDesktopResolution = false; _useDesktopResolution = false;
_lastEnumeratedDisplayIndex = -1;
afterEffectManagerLayer = 0; afterEffectManagerLayer = 0;
renderObjectLayers.resize(1); renderObjectLayers.resize(1);
invGlobalScale = 1.0; invGlobalScale = 1.0;
@ -900,9 +901,9 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsyn
#endif #endif
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
createWindow(320, 240, false, false, bpp); createWindow(320, 240, false, false, bpp, display);
enumerateScreenModes(); enumerateScreenModes(display);
if (!lookup_all_glsyms()) if (!lookup_all_glsyms())
{ {
@ -927,7 +928,7 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsyn
return true; return true;
} }
void Core::createWindow(int w, int h, bool resizable, bool fullscreen, int bpp) void Core::createWindow(int w, int h, bool resizable, bool fullscreen, int bpp, int display)
{ {
#ifdef BBGE_BUILD_SDL2 #ifdef BBGE_BUILD_SDL2
if(gScreen) if(gScreen)
@ -955,7 +956,8 @@ void Core::createWindow(int w, int h, bool resizable, bool fullscreen, int bpp)
w = 640; w = 640;
if(h <= 0) if(h <= 0)
h = 480; h = 480;
gScreen = SDL_CreateWindow(appName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, flags); int pos = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
gScreen = SDL_CreateWindow(appName.c_str(), pos, pos, w, h, flags);
if (gScreen == NULL) if (gScreen == NULL)
{ {
std::ostringstream os; std::ostringstream os;
@ -1010,22 +1012,40 @@ void Core::createWindow(int w, int h, bool resizable, bool fullscreen, int bpp)
#endif #endif
} }
void Core::enumerateScreenModes() void Core::enumerateScreenModesIfNecessary(int display /* = -1 */)
{ {
if(display == -1)
{
#ifdef BBGE_BUILD_SDL2
if(gScreen)
display = SDL_GetWindowDisplayIndex(gScreen);
else
#endif
display = 0;
}
if(_lastEnumeratedDisplayIndex == display)
return;
enumerateScreenModes(display);
}
void Core::enumerateScreenModes(int display)
{
_lastEnumeratedDisplayIndex = display;
screenModes.clear(); screenModes.clear();
#ifdef BBGE_BUILD_SDL2 #ifdef BBGE_BUILD_SDL2
screenModes.push_back(ScreenMode(0, 0, 0)); // "Desktop" screen mode screenModes.push_back(ScreenMode(0, 0, 0)); // "Desktop" screen mode
SDL_DisplayMode mode; SDL_DisplayMode mode;
const int modecount = SDL_GetNumDisplayModes(0); const int modecount = SDL_GetNumDisplayModes(display);
if(modecount == 0){ if(modecount == 0){
debugLog("No modes available!"); debugLog("No modes available!");
return; return;
} }
for (int i = 0; i < modecount; i++) { for (int i = 0; i < modecount; i++) {
SDL_GetDisplayMode(0, i, &mode); SDL_GetDisplayMode(display, i, &mode);
if (mode.w && mode.h && (mode.w > mode.h)) if (mode.w && mode.h && (mode.w > mode.h))
{ {
screenModes.push_back(ScreenMode(mode.w, mode.h, mode.refresh_rate)); screenModes.push_back(ScreenMode(mode.w, mode.h, mode.refresh_rate));

View file

@ -427,7 +427,8 @@ public:
void enable2DWide(int rx, int ry); void enable2DWide(int rx, int ry);
void enumerateScreenModes(); void enumerateScreenModes(int display);
void enumerateScreenModesIfNecessary(int display = -1);
std::vector<ScreenMode> screenModes; std::vector<ScreenMode> screenModes;
@ -486,7 +487,7 @@ protected:
bool initInputLibrary(); bool initInputLibrary();
void initJoystickLibrary(); void initJoystickLibrary();
bool initGraphicsLibrary(int w, int h, bool fullscreen, bool vsync, int bpp, int display, int hz); bool initGraphicsLibrary(int w, int h, bool fullscreen, bool vsync, int bpp, int display, int hz);
void createWindow(int w, int h, bool resizable, bool fullscreen, int bpp); void createWindow(int w, int h, bool resizable, bool fullscreen, int bpp, int display);
void shutdownInputLibrary(); void shutdownInputLibrary();
void shutdownJoystickLibrary(); void shutdownJoystickLibrary();
void shutdownGraphicsLibrary(); void shutdownGraphicsLibrary();
@ -518,6 +519,7 @@ protected:
int _vsync, _bpp, _refreshRate; int _vsync, _bpp, _refreshRate;
bool _fullscreen, _useDesktopResolution; bool _fullscreen, _useDesktopResolution;
int winPosX, winPosY; // pre-fullscreen int winPosX, winPosY; // pre-fullscreen
int _lastEnumeratedDisplayIndex;
CountedPtr<Texture> texError; CountedPtr<Texture> texError;