Mana
Loading...
Searching...
No Matches
shortcutcontainer.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
23
24#include "gui/gui.h"
25
26#include "resources/theme.h"
27
29{
30 addMouseListener(this);
31 addWidgetListener(this);
32
33 auto &skin = gui->getTheme()->getSkin(SkinType::ShortcutBox);
34 mBoxWidth = skin.width;
35 mBoxHeight = skin.height;
36}
37
38void ShortcutContainer::widgetResized(const gcn::Event &event)
39{
40 mGridWidth = getWidth() / mBoxWidth;
41
42 if (mGridWidth < 1)
43 mGridWidth = 1;
44
46
47 if (mMaxItems % mGridWidth != 0 || mGridHeight < 1)
49
50 setHeight(mGridHeight * mBoxHeight);
51}
52
53int ShortcutContainer::getIndexFromGrid(int pointX, int pointY) const
54{
55 const gcn::Rectangle tRect(0, 0, mGridWidth * mBoxWidth,
57
58 int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth;
59
60 if (!tRect.isPointInRect(pointX, pointY) || index >= mMaxItems)
61 index = -1;
62
63 return index;
64}
Theme * getTheme() const
The global GUI theme.
Definition gui.h:138
int getIndexFromGrid(int pointX, int pointY) const
Gets the index from the grid provided the point is in an item box.
void widgetResized(const gcn::Event &event) override
Invoked when a widget changes its size.
int width
Definition theme.h:180
const Skin & getSkin(SkinType skinType) const
Definition theme.cpp:434
Gui * gui
The GUI system.
Definition gui.cpp:50