Mana
Loading...
Searching...
No Matches
shortcutwindow.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2007-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 "gui/shortcutwindow.h"
23
24#include "gui/setup.h"
25
26#include "gui/widgets/layout.h"
29
30static constexpr int GRAB_MARGIN = 4;
31
32ShortcutWindow::ShortcutWindow(const std::string &title,
33 ShortcutContainer *content)
34 : Window(SkinType::ToolWindow, std::string())
35{
36 setWindowName(title);
37 // no title presented, title bar gets some extra space so window can be moved.
38 setTitleBarHeight(getPadding() + GRAB_MARGIN);
39 setShowTitle(false);
40 setResizable(true);
41 setDefaultVisible(false);
42 setSaveVisible(true);
44
45 auto scrollArea = new ScrollArea(content);
46 scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
47 scrollArea->setOpaque(false);
48
49 const int border = (getPadding() + content->getFrameSize()) * 2;
50 setMinWidth(content->getBoxWidth() + border);
51 setMinHeight(content->getBoxHeight() + border + GRAB_MARGIN);
52
53 const int maxContentWidth = content->getBoxWidth() * content->getMaxItems();
54 const int maxContentHeight = content->getBoxHeight() * content->getMaxItems();
55 setMaxWidth(std::max(getMinWidth(), maxContentWidth + border));
56 setMaxHeight(std::max(getMinHeight(), maxContentHeight + border + GRAB_MARGIN));
57
59
60 place(0, 0, scrollArea, 5, 5).setPadding(0);
61
62 Layout &layout = getLayout();
64 layout.setMargin(0);
65
67}
void setRowHeight(int n, int h)
Definition layout.h:221
LayoutCell & setPadding(int p)
Sets the padding around the cell content.
Definition layout.h:179
This class is an helper for setting the position of widgets.
Definition layout.h:281
@ AUTO_SET
Uses the share as the new size.
Definition layout.h:304
void setMargin(int m)
Sets the margin around the layout.
Definition layout.h:288
A scroll area.
Definition scrollarea.h:38
void registerWindowForReset(Window *window)
Enables the Reset Windows button.
Definition setup.cpp:108
A generic shortcut container.
ShortcutWindow(const std::string &title, ShortcutContainer *content)
A window.
Definition window.h:59
void setDefaultVisible(bool save)
Sets whether the window is visible by default.
Definition window.h:215
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
int getMinWidth() const
Definition window.h:150
void setResizable(bool resize)
Sets whether or not the window can be resized.
Definition window.cpp:212
void setSaveVisible(bool save)
Sets whether the window will save it's visibility.
Definition window.h:225
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 setShowTitle(bool flag)
Sets flag to show a title or not.
Definition window.h:176
int getMaxHeight() const
Definition window.h:171
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
int getMinHeight() const
Definition window.h:157
void setMaxHeight(int height)
Sets the minimum height of the window.
Definition window.cpp:207
void setMinWidth(int width)
Sets the minimum width of the window.
Definition window.cpp:192
void setMaxWidth(int width)
Sets the maximum width of the window.
Definition window.cpp:202
Setup * setupWindow
Definition setup.cpp:120
SkinType
Definition theme.h:69