Root/src/menusettingmultistring.cpp

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#include "menusettingmultistring.h"
21#include "gmenu2x.h"
22#include "iconbutton.h"
23#include "FastDelegate.h"
24
25#include <algorithm>
26
27using std::find;
28using std::string;
29using std::vector;
30using fastdelegate::MakeDelegate;
31
32MenuSettingMultiString::MenuSettingMultiString(
33        GMenu2X *gmenu2x, const string &name,
34        const string &description, string *value,
35        const vector<string> *choices_)
36    : MenuSettingStringBase(gmenu2x, name, description, value)
37    , choices(choices_)
38{
39    setSel(find(choices->begin(), choices->end(), *value) - choices->begin());
40
41    IconButton *btn;
42
43    btn = new IconButton(gmenu2x, "skin:imgs/buttons/left.png");
44    btn->setAction(MakeDelegate(this, &MenuSettingMultiString::decSel));
45    buttonBox.add(btn);
46
47    btn = new IconButton(gmenu2x, "skin:imgs/buttons/right.png", gmenu2x->tr["Change value"]);
48    btn->setAction(MakeDelegate(this, &MenuSettingMultiString::incSel));
49    buttonBox.add(btn);
50}
51
52void MenuSettingMultiString::manageInput(bevent_t *event)
53{
54    switch(event->button) {
55        case LEFT:
56            decSel();
57            break;
58        case RIGHT:
59            incSel();
60            break;
61        default:
62            break;
63    }
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