From 7ed530350226d268c3ccb80952f4176589e9a32a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 27 Oct 2012 03:35:10 +0300 Subject: Autoselect resolution under android. --- src/graphicsmanager.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'src/graphicsmanager.cpp') diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp index 67bfa8847..5abd85297 100644 --- a/src/graphicsmanager.cpp +++ b/src/graphicsmanager.cpp @@ -264,14 +264,31 @@ Graphics *GraphicsManager::createGraphics() void GraphicsManager::setVideoMode() { - const int width = config.getIntValue("screenwidth"); - const int height = config.getIntValue("screenheight"); + int width = config.getIntValue("screenwidth"); + int height = config.getIntValue("screenheight"); const int bpp = 0; const bool fullscreen = config.getBoolValue("screen"); const bool hwaccel = config.getBoolValue("hwaccel"); const bool enableResize = config.getBoolValue("enableresize"); const bool noFrame = config.getBoolValue("noframe"); +#ifdef ANDROID + StringVect videoModes; + getAllVideoModes(videoModes); + if (!videoModes.empty()) + { + std::string str = videoModes[0]; + std::vector res; + splitToIntVector(res, videoModes[0], 'x'); + if (res.size() == 2) + { + width = res[0]; + height = res[1]; + logger->log("Autoselect mode %dx%d", width, height); + } + } +#endif + // Try to set the desired video mode if (!mainGraphics->setVideoMode(width, height, bpp, fullscreen, hwaccel, enableResize, noFrame)) @@ -302,6 +319,37 @@ void GraphicsManager::setVideoMode() } } +bool GraphicsManager::getAllVideoModes(StringVect &modeList) +{ + /* Get available fullscreen/hardware modes */ + SDL_Rect **const modes = SDL_ListModes(nullptr, + SDL_FULLSCREEN | SDL_HWSURFACE); + + /* Check which modes are available */ + if (modes == static_cast(nullptr)) + { + logger->log1("No modes available"); + return false; + } + else if (modes == reinterpret_cast(-1)) + { + logger->log1("All resolutions available"); + return true; + } + else + { + for (int i = 0; modes[i]; ++ i) + { + const std::string modeString = + toString(static_cast(modes[i]->w)) + "x" + + toString(static_cast(modes[i]->h)); + logger->log("support mode: " + modeString); + modeList.push_back(modeString); + } + return true; + } +} + #ifdef USE_OPENGL void GraphicsManager::updateExtensions() { -- cgit v1.2.3-60-g2f50