Root/src/menusettingmultistring.cpp

Source at commit 73ceffa51d3450d2d20ce933e7fc6da187e09fc8 created 7 years 5 months ago.
By Maarten ter Huurne, Fix bug in section directory creation method
1/***************************************************************************
2 * Copyright (C) 2006 by Massimiliano Torromeo *
3 * massimiliano.torromeo@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#include "menusettingmultistring.h"
22#include "gmenu2x.h"
23#include "iconbutton.h"
24
25#include <algorithm>
26
27using std::bind;
28using std::find;
29using std::string;
30using std::vector;
31using std::unique_ptr;
32
33MenuSettingMultiString::MenuSettingMultiString(
34        GMenu2X& gmenu2x,
35        const string &name, const string &description,
36        string *value, const vector<string> *choices_)
37    : MenuSettingStringBase(gmenu2x, name, description, value)
38    , choices(choices_)
39{
40    setSel(find(choices->begin(), choices->end(), *value) - choices->begin());
41
42    buttonBox.add(unique_ptr<IconButton>(new IconButton(
43            gmenu2x, "skin:imgs/buttons/left.png", "",
44            bind(&MenuSettingMultiString::decSel, this))));
45    buttonBox.add(unique_ptr<IconButton>(new IconButton(
46            gmenu2x, "skin:imgs/buttons/right.png",
47            gmenu2x.tr["Change value"],
48            bind(&MenuSettingMultiString::incSel, this))));
49}
50
51bool MenuSettingMultiString::handleButtonPress(InputManager::Button button)
52{
53    switch (button) {
54        case InputManager::LEFT:
55            decSel();
56            break;
57        case InputManager::RIGHT:
58            incSel();
59            break;
60        default:
61            return false;
62    }
63    return true;
64}
65
66void MenuSettingMultiString::incSel()
67{
68    setSel(selected + 1);
69}
70
71void MenuSettingMultiString::decSel()
72{
73    setSel(selected - 1);
74}
75
76void MenuSettingMultiString::setSel(int sel)
77{
78    if (sel < 0) {
79        sel = choices->size()-1;
80    } else if (sel >= (int)choices->size()) {
81        sel = 0;
82    }
83    selected = sel;
84    setValue((*choices)[sel]);
85}
86

Archive Download this file



interactive