Mana
Loading...
Searching...
No Matches
setup.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "setup.h"
23
24#include "main.h"
25
26#include "gui/setup_audio.h"
27#include "gui/setup_colors.h"
28#include "gui/setup_joystick.h"
29#include "gui/setup_keyboard.h"
30#include "gui/setup_players.h"
31#include "gui/setup_video.h"
32#include "gui/setup_interface.h"
33
34#include "gui/widgets/button.h"
35#include "gui/widgets/label.h"
36#include "gui/widgets/layout.h"
38
39#include "utils/gettext.h"
40
41extern Window *statusWindow;
42
44 Window(_("Setup"))
45{
46 setWindowName("Setup");
47 setCloseButton(true);
48 setResizable(true);
49
50 mResetWindows = new Button(_("Reset Windows"), "Reset Windows", this);
51 mResetWindows->setEnabled(false);
52
53 place(2, 5, mResetWindows);
54 place(3, 5, new Button(_("Apply"), "Apply", this));
55 place(4, 5, new Button(_("Cancel"), "Cancel", this));
56
57 auto *panel = new TabbedArea;
58
59 mTabs.emplace_back(new Setup_Video);
60 mTabs.emplace_back(new Setup_Audio);
61 mTabs.emplace_back(new Setup_Interface);
62 mTabs.emplace_back(new Setup_Joystick);
63 mTabs.emplace_back(new Setup_Keyboard);
64 mTabs.emplace_back(new Setup_Colors);
65 mTabs.emplace_back(new Setup_Players);
66
67 for (auto &tab : mTabs)
68 panel->addTab(tab->getName(), tab.get());
69
70 place(0, 0, panel, 5, 5);
71 place(0, 5, new Label(FULL_VERSION));
72
73 // Determine minimum width by layout
74 int width = 0, height = 350;
75 getLayout().reflow(width, height);
76
77 setMinWidth(width + 2 * getPadding());
78 setMinHeight(height + getPadding() + getTitleBarHeight());
79 setDefaultSize(395, 360 + getPadding() + getTitleBarHeight(), WindowAlignment::Center);
81}
82
83Setup::~Setup() = default;
84
85void Setup::action(const gcn::ActionEvent &event)
86{
87 if (event.getId() == "Apply")
88 {
89 setVisible(false);
90
91 for (auto &tab : mTabs)
92 tab->apply();
93 }
94 else if (event.getId() == "Cancel")
95 {
96 setVisible(false);
97
98 for (auto &tab : mTabs)
99 tab->cancel();
100 }
101 else if (event.getId() == "Reset Windows")
102 {
103 for (auto &window : mWindowsToReset)
104 window->resetToDefaultSize();
105 }
106}
107
109{
110 mWindowsToReset.push_back(window);
111 mResetWindows->setEnabled(true);
112}
113
115{
116 mWindowsToReset.clear();
117 mResetWindows->setEnabled(false);
118}
119
Button widget.
Definition button.h:38
Label widget.
Definition label.h:34
void reflow(int &nW, int &nH)
Sets the positions of all the widgets.
Definition layout.cpp:321
The setup dialog.
Definition setup.h:48
Setup()
Definition setup.cpp:43
gcn::Button * mResetWindows
Definition setup.h:67
void action(const gcn::ActionEvent &event) override
Event handling method.
Definition setup.cpp:85
std::vector< std::unique_ptr< SetupTab > > mTabs
Definition setup.h:65
void clearWindowsForReset()
Definition setup.cpp:114
std::vector< Window * > mWindowsToReset
Definition setup.h:66
void registerWindowForReset(Window *window)
Enables the Reset Windows button.
Definition setup.cpp:108
~Setup() override
A tabbed area, the same as the guichan tabbed area in 0.8, but extended.
Definition tabbedarea.h:40
void addTab(gcn::Tab *tab, gcn::Widget *widget) override
Add a tab.
A window.
Definition window.h:59
virtual void setVisible(bool visible)
Overloads window setVisible by Guichan to allow sticky window handling.
Definition window.cpp:282
void setMinHeight(int height)
Sets the minimum height of the window.
Definition window.cpp:197
Layout & getLayout()
Gets the layout handler for this window.
Definition window.cpp:714
void setWindowName(const std::string &name)
Sets the name of the window.
Definition window.h:272
void setResizable(bool resize)
Sets whether or not the window can be resized.
Definition window.cpp:212
LayoutCell & place(int x, int y, gcn::Widget *, int w=1, int h=1)
Adds a widget to the window and sets it at given cell.
Definition window.cpp:737
void setCloseButton(bool flag)
Sets whether or not the window has a close button.
Definition window.cpp:262
void setDefaultSize()
Set the default win pos and size to the current ones.
Definition window.cpp:545
void loadWindowState()
Reads the position (and the size for resizable windows) in the configuration based on the given strin...
Definition window.cpp:467
void setMinWidth(int width)
Sets the minimum width of the window.
Definition window.cpp:192
#define _(s)
Definition gettext.h:38
#define FULL_VERSION
Definition main.h:55
Window * statusWindow
Definition game.cpp:94
Setup * setupWindow
Definition setup.cpp:120