From 109a9a97e598f10e673fc235000bcec415fe047d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 21 Jun 2011 22:18:08 +0300 Subject: Add hardcoded modes to video modes list in settings. --- src/gui/setup_video.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 59f3ccf34..d007bc275 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -53,6 +53,7 @@ #include +#include #include #include @@ -99,9 +100,33 @@ class ModeListModel : public gcn::ListModel int getIndexOf(const std::string &widthXHeightMode); private: + void addCustomMode(std::string mode); + std::vector mVideoModes; }; +bool modeSorter(std::string mode1, std::string mode2); + +bool modeSorter(std::string mode1, std::string mode2) +{ + const int width1 = atoi(mode1.substr(0, mode1.find("x")).c_str()); + const int height1 = atoi(mode1.substr(mode1.find("x") + 1).c_str()); + if (!width1 || !height1) + return false; + + const int width2 = atoi(mode2.substr(0, mode2.find("x")).c_str()); + const int height2 = atoi(mode2.substr(mode2.find("x") + 1).c_str()); + if (!width2 || !height2) + return false; + if (width1 != width2) + return width1 < width2; + + if (height1 != height2) + return height1 < height2; + + return false; +} + ModeListModel::ModeListModel() { /* Get available fullscreen/hardware modes */ @@ -126,9 +151,32 @@ ModeListModel::ModeListModel() mVideoModes.push_back(modeString); } } + addCustomMode("640x480"); + addCustomMode("800x600"); + addCustomMode("1024x768"); + addCustomMode("1280x1024"); + addCustomMode("1400x900"); + addCustomMode("1500x990"); + addCustomMode(toString(graphics->getWidth()) + "x" + + toString(graphics->getHeight())); + + std::sort(mVideoModes.begin(), mVideoModes.end(), modeSorter); mVideoModes.push_back("custom"); } +void ModeListModel::addCustomMode(std::string mode) +{ + std::vector::iterator it = mVideoModes.begin(); + std::vector::iterator it_end = mVideoModes.end(); + while (it != it_end) + { + if (*it == mode) + return; + ++ it; + } + mVideoModes.push_back(mode); +} + int ModeListModel::getIndexOf(const std::string &widthXHeightMode) { std::string currentMode = ""; -- cgit v1.2.3-60-g2f50