aboutsummaryrefslogtreecommitdiff
path: root/guilib/GUIFixedListContainer.cpp
diff options
context:
space:
mode:
authorjmarshallnz <jmarshallnz@svn>2010-03-25 01:51:33 +0000
committerjmarshallnz <jmarshallnz@svn>2010-03-25 01:51:33 +0000
commit002fb7812778df0dc924f5159236a19a052661cf (patch)
treecf431675891ca52d41f7d69c8a15cd1a101a7fd0 /guilib/GUIFixedListContainer.cpp
parent4c60cde8e90155bc71d564adbad820f4f438133d (diff)
refactor: Split the cursor finding logic out of SelectItemFromPoint.
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@28795 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
Diffstat (limited to 'guilib/GUIFixedListContainer.cpp')
-rw-r--r--guilib/GUIFixedListContainer.cpp48
1 files changed, 34 insertions, 14 deletions
diff --git a/guilib/GUIFixedListContainer.cpp b/guilib/GUIFixedListContainer.cpp
index 0d29b0baa5..1c10eb6781 100644
--- a/guilib/GUIFixedListContainer.cpp
+++ b/guilib/GUIFixedListContainer.cpp
@@ -168,6 +168,34 @@ void CGUIFixedListContainer::ValidateOffset()
}
}
+int CGUIFixedListContainer::GetCursorFromPoint(const CPoint &point, CPoint *itemPoint) const
+{
+ if (!m_focusedLayout || !m_layout)
+ return -1;
+ int minCursor, maxCursor;
+ GetCursorRange(minCursor, maxCursor);
+ // see if the point is either side of our focus range
+ float start = (minCursor + 0.2f) * m_layout->Size(m_orientation);
+ float end = (maxCursor - 0.2f) * m_layout->Size(m_orientation) + m_focusedLayout->Size(m_orientation);
+ float pos = (m_orientation == VERTICAL) ? point.y : point.x;
+ if (pos >= start && pos <= end)
+ { // select the appropriate item
+ pos -= minCursor * m_layout->Size(m_orientation);
+ for (int row = minCursor; row <= maxCursor; row++)
+ {
+ const CGUIListItemLayout *layout = (row == m_cursor) ? m_focusedLayout : m_layout;
+ if (pos < layout->Size(m_orientation))
+ {
+ if (!InsideLayout(layout, point))
+ return -1;
+ return row;
+ }
+ pos -= layout->Size(m_orientation);
+ }
+ }
+ return -1;
+}
+
bool CGUIFixedListContainer::SelectItemFromPoint(const CPoint &point)
{
if (!m_focusedLayout || !m_layout)
@@ -211,20 +239,12 @@ bool CGUIFixedListContainer::SelectItemFromPoint(const CPoint &point)
}
else
{ // select the appropriate item
- pos -= minCursor * sizeOfItem;
- for (int row = minCursor; row <= maxCursor; row++)
- {
- const CGUIListItemLayout *layout = (row == m_cursor) ? m_focusedLayout : m_layout;
- if (pos < layout->Size(m_orientation))
- {
- if (!InsideLayout(layout, point))
- return false;
- // calling SelectItem() here will focus the item and scroll, which isn't really what we're after
- m_cursor = row;
- return true;
- }
- pos -= layout->Size(m_orientation);
- }
+ int cursor = GetCursorFromPoint(point);
+ if (cursor < 0)
+ return false;
+ // calling SelectItem() here will focus the item and scroll, which isn't really what we're after
+ m_cursor = cursor;
+ return true;
}
return InsideLayout(m_focusedLayout, point);
}