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 +++++++++++++++++++++++++++++++++++++++++++++-- src/graphicsmanager.h | 4 ++++ src/gui/setup_video.cpp | 24 +--------------------- src/utils/stringutils.cpp | 13 ++++++++++++ src/utils/stringutils.h | 3 +++ 5 files changed, 71 insertions(+), 25 deletions(-) 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() { diff --git a/src/graphicsmanager.h b/src/graphicsmanager.h index ccc988523..7dbd5ea4d 100644 --- a/src/graphicsmanager.h +++ b/src/graphicsmanager.h @@ -37,6 +37,8 @@ #endif +#include "utils/stringvector.h" + #include #include @@ -62,6 +64,8 @@ class GraphicsManager final Graphics *createGraphics(); + bool getAllVideoModes(StringVect &modeList); + #ifdef USE_OPENGL TestMain *startDetection(); diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 688519743..0188eb6b7 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -132,29 +132,7 @@ static bool modeSorter(std::string mode1, std::string mode2) ModeListModel::ModeListModel() { - /* 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"); - } - else if (modes == reinterpret_cast(-1)) - { - logger->log1("All resolutions available"); - } - 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)); - mVideoModes.push_back(modeString); - } - } + graphicsManager.getAllVideoModes(mVideoModes); addCustomMode("640x480"); addCustomMode("800x600"); addCustomMode("1024x768"); diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index e28013320..8c6d88d1c 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -476,6 +476,19 @@ void splitToStringSet(std::set &tokens, const std::string &text, } } +void splitToIntVector(std::vector &tokens, const std::string &text, + const char separator) +{ + std::stringstream ss(text); + std::string item; + while (std::getline(ss, item, separator)) + { + item = trim(item); + if (!item.empty()) + tokens.push_back(atoi(item.c_str())); + } +} + std::string combineDye(std::string file, std::string dye) { if (dye.empty()) diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 9355e1720..2b10b7631 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -191,6 +191,9 @@ void splitToStringVector(StringVect &tokens, void splitToStringSet(std::set &tokens, const std::string &text, const char separator); +void splitToIntVector(std::vector &tokens, + const std::string &text, const char separator); + std::string combineDye(std::string file, std::string dye); std::string combineDye2(std::string file, std::string dye); -- cgit v1.2.3-70-g09d2