GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/models/modelistmodel.cpp Lines: 33 35 94.3 %
Date: 2017-11-29 Branches: 24 48 50.0 %

Line Branch Exec Source
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-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "render/graphics.h"
24
25
#include "utils/sdlhelper.h"
26
#include "utils/stringutils.h"
27
28
#include "gui/models/modelistmodel.h"
29
30
#include <algorithm>
31
32
#include "debug.h"
33
34
#ifndef ANDROID
35
40
static bool modeSorter(const std::string &mode1, const std::string &mode2)
36
{
37
160
    const int width1 = atoi(mode1.substr(0, mode1.find('x')).c_str());
38
160
    const int height1 = atoi(mode1.substr(mode1.find('x') + 1).c_str());
39
40
    if ((width1 == 0) || (height1 == 0))
40
        return false;
41
42
160
    const int width2 = atoi(mode2.substr(0, mode2.find('x')).c_str());
43
160
    const int height2 = atoi(mode2.substr(mode2.find('x') + 1).c_str());
44
40
    if ((width2 == 0) || (height2 == 0))
45
        return false;
46
40
    if (width1 != width2)
47
40
        return width1 < width2;
48
49
    if (height1 != height2)
50
        return height1 < height2;
51
52
    return false;
53
}
54
#endif  // ANDROID
55
56
4
ModeListModel::ModeListModel() :
57
    ListModel(),
58
12
    mVideoModes()
59
{
60
4
    SDL::getAllVideoModes(mVideoModes);
61
#ifndef ANDROID
62

16
    addCustomMode("640x480");
63

16
    addCustomMode("800x600");
64

16
    addCustomMode("1024x768");
65

16
    addCustomMode("1280x1024");
66

16
    addCustomMode("1400x900");
67

16
    addCustomMode("1500x990");
68

12
    addCustomMode(toString(mainGraphics->mActualWidth).append("x")
69
12
        .append(toString(mainGraphics->mActualHeight)));
70
71
16
    std::sort(mVideoModes.begin(), mVideoModes.end(), &modeSorter);
72
20
    mVideoModes.push_back("custom");
73
#endif  // ANDROID
74
4
}
75
76
#ifndef ANDROID
77
28
void ModeListModel::addCustomMode(const std::string &mode)
78
{
79
84
    StringVectCIter it = mVideoModes.begin();
80
84
    const StringVectCIter it_end = mVideoModes.end();
81
88
    while (it != it_end)
82
    {
83
64
        if (*it == mode)
84
            return;
85
        ++ it;
86
    }
87
24
    mVideoModes.push_back(mode);
88
}
89
#endif  // ANDROID
90
91
4
int ModeListModel::getIndexOf(const std::string &widthXHeightMode)
92
{
93
8
    std::string currentMode;
94
8
    for (int i = 0; i < getNumberOfElements(); i++)
95
    {
96
8
        currentMode = getElementAt(i);
97
        if (currentMode == widthXHeightMode)
98
            return i;
99
    }
100
    return -1;
101
}