Mana
Loading...
Searching...
No Matches
src
gui
widgets
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
22
#include "
gui/widgets/shortcutcontainer.h
"
23
24
#include "
gui/gui.h
"
25
26
#include "
resources/theme.h
"
27
28
ShortcutContainer::ShortcutContainer
()
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
38
void
ShortcutContainer::widgetResized
(
const
gcn::Event &event)
39
{
40
mGridWidth
= getWidth() /
mBoxWidth
;
41
42
if
(
mGridWidth
< 1)
43
mGridWidth
= 1;
44
45
mGridHeight
=
mMaxItems
/
mGridWidth
;
46
47
if
(
mMaxItems
%
mGridWidth
!= 0 ||
mGridHeight
< 1)
48
++
mGridHeight
;
49
50
setHeight(
mGridHeight
*
mBoxHeight
);
51
}
52
53
int
ShortcutContainer::getIndexFromGrid
(
int
pointX,
int
pointY)
const
54
{
55
const
gcn::Rectangle tRect(0, 0,
mGridWidth
*
mBoxWidth
,
56
mGridHeight
*
mBoxHeight
);
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
}
Gui::getTheme
Theme * getTheme() const
The global GUI theme.
Definition
gui.h:138
ShortcutContainer::mBoxWidth
int mBoxWidth
Definition
shortcutcontainer.h:69
ShortcutContainer::getIndexFromGrid
int getIndexFromGrid(int pointX, int pointY) const
Gets the index from the grid provided the point is in an item box.
Definition
shortcutcontainer.cpp:53
ShortcutContainer::widgetResized
void widgetResized(const gcn::Event &event) override
Invoked when a widget changes its size.
Definition
shortcutcontainer.cpp:38
ShortcutContainer::mGridWidth
int mGridWidth
Definition
shortcutcontainer.h:73
ShortcutContainer::ShortcutContainer
ShortcutContainer()
Definition
shortcutcontainer.cpp:28
ShortcutContainer::mBoxHeight
int mBoxHeight
Definition
shortcutcontainer.h:70
ShortcutContainer::mGridHeight
int mGridHeight
Definition
shortcutcontainer.h:74
ShortcutContainer::mMaxItems
int mMaxItems
Definition
shortcutcontainer.h:68
Skin::width
int width
Definition
theme.h:180
Theme::getSkin
const Skin & getSkin(SkinType skinType) const
Definition
theme.cpp:434
gui
Gui * gui
The GUI system.
Definition
gui.cpp:50
gui.h
shortcutcontainer.h
theme.h
SkinType::ShortcutBox
@ ShortcutBox
Generated by
1.9.8