ManaPlus
modelistmodel.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "render/graphics.h"
25 
26 #include "utils/sdlhelper.h"
27 #include "utils/stringutils.h"
28 
30 
31 #include <algorithm>
32 
33 #include "debug.h"
34 
35 #ifndef ANDROID
36 static bool modeSorter(const std::string &mode1, const std::string &mode2)
37 {
38  const int width1 = atoi(mode1.substr(0, mode1.find('x')).c_str());
39  const int height1 = atoi(mode1.substr(mode1.find('x') + 1).c_str());
40  if ((width1 == 0) || (height1 == 0))
41  return false;
42 
43  const int width2 = atoi(mode2.substr(0, mode2.find('x')).c_str());
44  const int height2 = atoi(mode2.substr(mode2.find('x') + 1).c_str());
45  if ((width2 == 0) || (height2 == 0))
46  return false;
47  if (width1 != width2)
48  return width1 < width2;
49 
50  if (height1 != height2)
51  return height1 < height2;
52 
53  return false;
54 }
55 #endif // ANDROID
56 
58  ListModel(),
59  mVideoModes()
60 {
62 #ifndef ANDROID
63  addCustomMode("640x480");
64  addCustomMode("800x600");
65  addCustomMode("1024x768");
66  addCustomMode("1280x1024");
67  addCustomMode("1400x900");
68  addCustomMode("1500x990");
71 
72  std::sort(mVideoModes.begin(), mVideoModes.end(), &modeSorter);
73  mVideoModes.push_back("custom");
74 #endif // ANDROID
75 }
76 
77 #ifndef ANDROID
78 void ModeListModel::addCustomMode(const std::string &mode)
79 {
80  StringVectCIter it = mVideoModes.begin();
81  const StringVectCIter it_end = mVideoModes.end();
82  while (it != it_end)
83  {
84  if (*it == mode)
85  return;
86  ++ it;
87  }
88  mVideoModes.push_back(mode);
89 }
90 #endif // ANDROID
91 
92 int ModeListModel::getIndexOf(const std::string &widthXHeightMode)
93 {
94  std::string currentMode;
95  for (int i = 0; i < getNumberOfElements(); i++)
96  {
97  currentMode = getElementAt(i);
98  if (currentMode == widthXHeightMode)
99  return i;
100  }
101  return -1;
102 }
int mActualHeight
Definition: graphics.h:487
int mActualWidth
Definition: graphics.h:486
StringVect mVideoModes
Definition: modelistmodel.h:65
int getIndexOf(const std::string &widthXHeightMode)
void addCustomMode(const std::string &mode)
std::string getElementAt(int i)
Definition: modelistmodel.h:50
int getNumberOfElements()
Definition: modelistmodel.h:44
Graphics * mainGraphics
Definition: graphics.cpp:109
static bool modeSorter(const std::string &mode1, const std::string &mode2)
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
bool getAllVideoModes(StringVect &modeList)
Definition: sdlhelper.cpp:44
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:31