summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/graphicsmanager.cpp52
-rw-r--r--src/graphicsmanager.h4
-rw-r--r--src/gui/setup_video.cpp24
-rw-r--r--src/utils/stringutils.cpp13
-rw-r--r--src/utils/stringutils.h3
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<int> 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<SDL_Rect **>(nullptr))
+ {
+ logger->log1("No modes available");
+ return false;
+ }
+ else if (modes == reinterpret_cast<SDL_Rect **>(-1))
+ {
+ logger->log1("All resolutions available");
+ return true;
+ }
+ else
+ {
+ for (int i = 0; modes[i]; ++ i)
+ {
+ const std::string modeString =
+ toString(static_cast<int>(modes[i]->w)) + "x"
+ + toString(static_cast<int>(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 <set>
#include <string>
@@ -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<SDL_Rect **>(nullptr))
- {
- logger->log1("No modes available");
- }
- else if (modes == reinterpret_cast<SDL_Rect **>(-1))
- {
- logger->log1("All resolutions available");
- }
- else
- {
- for (int i = 0; modes[i]; ++ i)
- {
- const std::string modeString =
- toString(static_cast<int>(modes[i]->w)) + "x"
- + toString(static_cast<int>(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<std::string> &tokens, const std::string &text,
}
}
+void splitToIntVector(std::vector<int> &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<std::string> &tokens,
const std::string &text, const char separator);
+void splitToIntVector(std::vector<int> &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);