diff options
author | jmarshallnz <jmarshallnz@svn> | 2010-03-25 01:51:33 +0000 |
---|---|---|
committer | jmarshallnz <jmarshallnz@svn> | 2010-03-25 01:51:33 +0000 |
commit | 002fb7812778df0dc924f5159236a19a052661cf (patch) | |
tree | cf431675891ca52d41f7d69c8a15cd1a101a7fd0 | |
parent | 4c60cde8e90155bc71d564adbad820f4f438133d (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
-rw-r--r-- | guilib/GUIBaseContainer.h | 1 | ||||
-rw-r--r-- | guilib/GUIFixedListContainer.cpp | 48 | ||||
-rw-r--r-- | guilib/GUIFixedListContainer.h | 1 | ||||
-rw-r--r-- | guilib/GUIListContainer.cpp | 39 | ||||
-rw-r--r-- | guilib/GUIListContainer.h | 1 | ||||
-rw-r--r-- | guilib/GUIPanelContainer.cpp | 16 | ||||
-rw-r--r-- | guilib/GUIPanelContainer.h | 1 |
7 files changed, 72 insertions, 35 deletions
diff --git a/guilib/GUIBaseContainer.h b/guilib/GUIBaseContainer.h index ab6cf2626b..893d9b240d 100644 --- a/guilib/GUIBaseContainer.h +++ b/guilib/GUIBaseContainer.h @@ -109,6 +109,7 @@ protected: virtual void CalculateLayout(); virtual void SelectItem(int item) {}; virtual bool SelectItemFromPoint(const CPoint &point) { return false; }; + virtual int GetCursorFromPoint(const CPoint &point, CPoint *itemPoint = NULL) const { return -1; }; virtual void Reset(); virtual unsigned int GetNumItems() const { return m_items.size(); }; virtual int GetCurrentPage() const; 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); } diff --git a/guilib/GUIFixedListContainer.h b/guilib/GUIFixedListContainer.h index 90219b714c..78ee3ba7b7 100644 --- a/guilib/GUIFixedListContainer.h +++ b/guilib/GUIFixedListContainer.h @@ -48,6 +48,7 @@ protected: virtual bool MoveUp(bool wrapAround); virtual void ValidateOffset(); virtual bool SelectItemFromPoint(const CPoint &point); + virtual int GetCursorFromPoint(const CPoint &point, CPoint *itemPoint = NULL) const; virtual void SelectItem(int item); virtual bool HasNextPage() const; virtual bool HasPreviousPage() const; diff --git a/guilib/GUIListContainer.cpp b/guilib/GUIListContainer.cpp index a35a3b5ad3..f37fc7e930 100644 --- a/guilib/GUIListContainer.cpp +++ b/guilib/GUIListContainer.cpp @@ -244,10 +244,10 @@ void CGUIListContainer::SelectItem(int item) } } -bool CGUIListContainer::SelectItemFromPoint(const CPoint &point) +int CGUIListContainer::GetCursorFromPoint(const CPoint &point, CPoint *itemPoint) const { if (!m_focusedLayout || !m_layout) - return false; + return -1; int row = 0; float pos = (m_orientation == VERTICAL) ? point.y : point.x; @@ -257,26 +257,31 @@ bool CGUIListContainer::SelectItemFromPoint(const CPoint &point) if (pos < layout->Size(m_orientation) && row + m_offset < (int)m_items.size()) { // found correct "row" -> check horizontal if (!InsideLayout(layout, point)) - return false; + return -1; - SetContainerMoving(row - m_cursor); - m_cursor = row; - CGUIListItemLayout *focusedLayout = GetFocusedLayout(); - if (focusedLayout) - { - CPoint pt(point); - if (m_orientation == VERTICAL) - pt.y = pos; - else - pt.x = pos; - focusedLayout->SelectItemFromPoint(pt); - } - return true; + if (itemPoint) + *itemPoint = m_orientation == VERTICAL ? CPoint(point.x, pos) : CPoint(pos, point.y); + return row; } row++; pos -= layout->Size(m_orientation); } - return false; + return -1; +} + +bool CGUIListContainer::SelectItemFromPoint(const CPoint &point) +{ + CPoint itemPoint; + int row = GetCursorFromPoint(point, &itemPoint); + if (row < 0) + return false; + + SetContainerMoving(row - m_cursor); + m_cursor = row; + CGUIListItemLayout *focusedLayout = GetFocusedLayout(); + if (focusedLayout) + focusedLayout->SelectItemFromPoint(itemPoint); + return true; } //#ifdef PRE_SKIN_VERSION_9_10_COMPATIBILITY diff --git a/guilib/GUIListContainer.h b/guilib/GUIListContainer.h index 2f667127b1..cb650e1653 100644 --- a/guilib/GUIListContainer.h +++ b/guilib/GUIListContainer.h @@ -59,5 +59,6 @@ protected: virtual void ValidateOffset(); virtual void SelectItem(int item); virtual bool SelectItemFromPoint(const CPoint &point); + virtual int GetCursorFromPoint(const CPoint &point, CPoint *itemPoint = NULL) const; }; diff --git a/guilib/GUIPanelContainer.cpp b/guilib/GUIPanelContainer.cpp index 94d1c5ae6f..3031c571b9 100644 --- a/guilib/GUIPanelContainer.cpp +++ b/guilib/GUIPanelContainer.cpp @@ -403,10 +403,10 @@ int CGUIPanelContainer::CorrectOffset(int offset, int cursor) const return offset * m_itemsPerRow + cursor; } -bool CGUIPanelContainer::SelectItemFromPoint(const CPoint &point) +int CGUIPanelContainer::GetCursorFromPoint(const CPoint &point, CPoint *itemPoint) const { if (!m_layout) - return false; + return -1; float sizeX = m_orientation == VERTICAL ? m_layout->Size(HORIZONTAL) : m_layout->Size(VERTICAL); float sizeY = m_orientation == VERTICAL ? m_layout->Size(VERTICAL) : m_layout->Size(HORIZONTAL); @@ -420,8 +420,7 @@ bool CGUIPanelContainer::SelectItemFromPoint(const CPoint &point) int item = x + y * m_itemsPerRow; if (posX < sizeX && posY < sizeY && item + m_offset < (int)m_items.size()) { // found - SetCursor(item); - return true; + return item; } posX -= sizeX; } @@ -430,6 +429,15 @@ bool CGUIPanelContainer::SelectItemFromPoint(const CPoint &point) return false; } +bool CGUIPanelContainer::SelectItemFromPoint(const CPoint &point) +{ + int cursor = GetCursorFromPoint(point); + if (cursor < 0) + return false; + SetCursor(cursor); + return true; +} + bool CGUIPanelContainer::GetCondition(int condition, int data) const { // probably only works vertically atm... int row = m_cursor / m_itemsPerRow; diff --git a/guilib/GUIPanelContainer.h b/guilib/GUIPanelContainer.h index 86ff4cdf38..f6f7b2a43f 100644 --- a/guilib/GUIPanelContainer.h +++ b/guilib/GUIPanelContainer.h @@ -59,6 +59,7 @@ protected: unsigned int GetRows() const; virtual int CorrectOffset(int offset, int cursor) const; virtual bool SelectItemFromPoint(const CPoint &point); + virtual int GetCursorFromPoint(const CPoint &point, CPoint *itemPoint = NULL) const; void SetCursor(int cursor); virtual void SelectItem(int item); virtual bool HasPreviousPage() const; |