2
* @file legacy/options_screen.h
3
* @brief Public interface for the Legacy options screen.
7
* Copyright 2011 Stephen M. Webb <stephen.webb@bregmasoft.ca>
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 3 of the License, or
12
* (at your option) any later version.
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.
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/>.
22
#include "legacy_config.h"
23
#include "legacy/options_screen.h"
25
#include <guichan.hpp>
26
#include "legacy/dialog.h"
27
#include "legacy/game_loop.h"
33
static const std::string menu_audio = "Audio Settings";
34
static const std::string menu_video = "Video Settings";
35
static const std::string menu_back = "Back";
41
: public gcn::ListModel
46
m_items.push_back(menu_audio);
47
m_items.push_back(menu_video);
48
m_items.push_back(menu_back);
60
return m_items.size();
64
maxWidth(gcn::Font* font) const
69
for (auto s = m_items.begin(); s != m_items.end(); ++s)
71
maxWidth = std::max(maxWidth, font->getWidth(*s));
78
std::vector<std::string> m_items;
80
} // anonymous namespace
83
Legacy::OptionsScreen::
84
OptionsScreen(GameLoop* gameLoop, Config& config LEGACY_UNUSED)
85
: m_gameLoop(gameLoop)
86
, m_menu(new gcn::ListBox(new Menu()))
88
this->setBaseColor(gcn::Color(0x00, 0x00, 0x00, 0xff));
89
this->add(m_menu.get());
91
m_menu->setForegroundColor(gcn::Color(0xff, 0xe3, 0xab, 0xff));
92
m_menu->setBackgroundColor(gcn::Color(0xff, 0xff, 0xff, 0x00));
93
m_menu->setSelectionColor(gcn::Color(0x27, 0x40, 0x74, 0xff));
94
m_menu->setActionEventId("selected");
95
m_menu->addActionListener(this);
96
m_menu->setSelected(0);
98
addWidgetListener(this);
102
void Legacy::OptionsScreen::
103
action(const gcn::ActionEvent& event LEGACY_UNUSED)
105
gcn::ListModel* model = m_menu->getListModel();
106
int selected = m_menu->getSelected();
107
std::string label = model->getElementAt(selected);
108
if (label == menu_back)
110
m_gameLoop->popScreen();
115
"Unfinished business",
116
"Sorry, this function is not yet available.");
121
void Legacy::OptionsScreen::
124
m_menu->requestFocus();
129
* Menu placement is relative to the window size.
131
void Legacy::OptionsScreen::
132
widgetResized(const gcn::Event &event LEGACY_UNUSED)
134
gcn::Rectangle dimension = getDimension();
136
Menu* listModel = static_cast<Menu*>(m_menu->getListModel());
137
int menuWidth = listModel->maxWidth(getFont());
138
m_menu->setPosition((dimension.width - menuWidth) / 2, dimension.height / 3);
139
m_menu->setWidth(listModel->maxWidth(getFont()));
143
void Legacy::OptionsScreen::
144
_setParent(Widget* parent)
146
this->setDimension(parent->getDimension());
147
gcn::Container::_setParent(parent);