xoreos  0.0.5
buttonsgroup.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
26 #include "src/common/util.h"
27 
30 
32 
33 namespace Engines {
34 
35 namespace NWN {
36 
38  _helpBox = helpBox;
39 }
40 
42 }
43 
44 void ButtonsGroup::addButton(WidgetButton *button, const Common::UString &helpTitle, const Common::UString &helpText) {
46 
47  _buttonsList.push_back(button);
48  _helpTexts.push_back(helpText);
49  _helpTitles.push_back(helpTitle);
50 }
51 
53  for (std::vector<WidgetButton *>::iterator it = _buttonsList.begin(); it != _buttonsList.end(); ++it) {
54  if (*it == button){
55  _buttonsList.erase(it);
56  break;
57  }
58  }
59 }
60 
62  if (!button)
63  return;
64 
65  for (std::vector<WidgetButton *>::iterator it = _buttonsList.begin();
66  it != _buttonsList.end(); ++it) {
67  // First we check if the button belongs to this group.
68  if (*it == button) {
69  _helpBox->setText("fnt_galahad14", _helpTexts[std::distance(_buttonsList.begin(), it)], 1.0f);
70  _helpBox->setTitle("fnt_galahad14", _helpTitles[std::distance(_buttonsList.begin(), it)]);
71 
72  if ((*it)->getMode() == WidgetButton::kModeUnchanged)
73  break;
74 
75  (*it)->setPressed(true);
76 
77  for (std::vector<WidgetButton *>::iterator jt = _buttonsList.begin();
78  jt != _buttonsList.end(); ++jt) {
79 
80  if (jt == it)
81  continue;
82 
83  (*jt)->setPressed(false);
84  }
85 
86  break;
87  }
88  }
89 }
90 
91 void ButtonsGroup::setActive(size_t button) {
92  if (button >= _buttonsList.size())
93  error("Wrong ID buttons");
94 
95 
96  setActive(_buttonsList[button]);
97 }
98 
100  for (std::vector<WidgetButton *>::iterator it = _buttonsList.begin(); it != _buttonsList.end(); ++it)
101  (*it)->setPressed(false);
102 }
103 
104 size_t ButtonsGroup::getChoice() const {
105  for (std::vector<WidgetButton *>::const_iterator it = _buttonsList.begin(); it != _buttonsList.end(); ++it) {
106  if ((*it)->isPressed()) {
107  return std::distance(_buttonsList.begin(), it);
108  }
109  }
110 
111  warning("No button chosen, returning first button");
112  return 0;
113 }
114 
115 const std::vector< WidgetButton* > &ButtonsGroup::getButtonsList() const {
116  return _buttonsList;
117 }
118 
119 } // End of namespace NWN
120 
121 } // End of namespace Engines
std::vector< Common::UString > _helpTitles
Definition: buttonsgroup.h:62
A NWN editbox widget.
A NWN button widget.
std::vector< Common::UString > _helpTexts
Definition: buttonsgroup.h:63
void addButton(WidgetButton *button, const Common::UString &helpTitle, const Common::UString &helpText)
A class holding an UTF-8 string.
Definition: ustring.h:48
Utility class that handles group of WidgetButton where only one button can be toggled.
A NWN button widget.
Definition: button.h:39
void setText(const Common::UString &font, const Common::UString &text, float spacing=0.0f)
Definition: listbox.cpp:523
void setMode(Mode mode)
Definition: button.cpp:82
Utility templates and functions.
void removeButton(WidgetButton *button)
ButtonsGroup(WidgetEditBox *helpBox)
const std::vector< WidgetButton * > & getButtonsList() const
void warning(const char *s,...)
Definition: util.cpp:33
WidgetEditBox * _helpBox
Definition: buttonsgroup.h:61
void setTitle(const Common::UString &font, const Common::UString &title)
Set title text if available.
Definition: editbox.cpp:59
A NWN editbox widget.
Definition: editbox.h:43
void NORETURN_PRE error(const char *s,...)
Definition: util.cpp:86
std::vector< WidgetButton * > _buttonsList
Definition: buttonsgroup.h:59
void setActive(WidgetButton *button)