summaryrefslogtreecommitdiff
path: root/src/gui/shortcutcontainer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/shortcutcontainer.cpp')
-rw-r--r--src/gui/shortcutcontainer.cpp32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/gui/shortcutcontainer.cpp b/src/gui/shortcutcontainer.cpp
index 13ff042d..50ec9d06 100644
--- a/src/gui/shortcutcontainer.cpp
+++ b/src/gui/shortcutcontainer.cpp
@@ -39,34 +39,28 @@ ShortcutContainer::ShortcutContainer():
void ShortcutContainer::widgetResized(const gcn::Event &event)
{
mGridWidth = getWidth() / mBoxWidth;
+
if (mGridWidth < 1)
- {
mGridWidth = 1;
- }
-
- setHeight((mMaxItems / mGridWidth +
- (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight);
mGridHeight = getHeight() / mBoxHeight;
+
if (mGridHeight < 1)
- {
mGridHeight = 1;
- }
+
+ setHeight((mMaxItems / mGridWidth +
+ (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight);
}
int ShortcutContainer::getIndexFromGrid(int pointX, int pointY) const
{
- const gcn::Rectangle tRect = gcn::Rectangle(
- 0, 0, mGridWidth * mBoxWidth, mGridHeight * mBoxHeight);
- if (!tRect.isPointInRect(pointX, pointY))
- {
- return -1;
- }
- const int index = ((pointY / mBoxHeight) * mGridWidth) +
- pointX / mBoxWidth;
- if (index >= mMaxItems)
- {
- return -1;
- }
+ const gcn::Rectangle tRect = gcn::Rectangle(0, 0, mGridWidth * mBoxWidth,
+ mGridHeight * mBoxHeight);
+
+ int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth;
+
+ if (!tRect.isPointInRect(pointX, pointY) || index >= mMaxItems)
+ index = -1;
+
return index;
}