aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Sommerfeld <kai.sommerfeld@gmx.com>2017-02-17 22:07:32 +0100
committerKai Sommerfeld <kai.sommerfeld@gmx.com>2017-02-18 19:13:30 +0100
commitcacc4ec3faaa76d23336425ca2f02be887eee4e7 (patch)
tree419b95dd79b3d44db1e2b3600f7d844618077be0
parent3bd7a6d56eaa0c1e33e7e3c37075d01430774085 (diff)
[EPG] Trac 17323: Guide window: Fix jumping selection on channel change while navigatimg the grid.
-rw-r--r--xbmc/epg/GUIEPGGridContainer.cpp76
-rw-r--r--xbmc/epg/GUIEPGGridContainer.h7
2 files changed, 18 insertions, 65 deletions
diff --git a/xbmc/epg/GUIEPGGridContainer.cpp b/xbmc/epg/GUIEPGGridContainer.cpp
index 16fee97192..90f4a2adfe 100644
--- a/xbmc/epg/GUIEPGGridContainer.cpp
+++ b/xbmc/epg/GUIEPGGridContainer.cpp
@@ -39,7 +39,6 @@
using namespace PVR;
using namespace EPG;
-#define SHORTGAP 5 // how many blocks is considered a short-gap in nav logic
#define BLOCKJUMP 4 // how many blocks are jumped with each analogue scroll action
static const int BLOCK_SCROLL_OFFSET = 60 / CGUIEPGGridContainerModel::MINSPERBLOCK; // how many blocks are jumped if we are at left/right edge of grid
static const int PAGE_NOW_OFFSET = CGUIEPGGridContainerModel::GRID_START_PADDING / CGUIEPGGridContainerModel::MINSPERBLOCK; // this is the 'now' block relative to page start
@@ -62,6 +61,7 @@ CGUIEPGGridContainer::CGUIEPGGridContainer(int parentID, int controlID, float po
m_blocksPerPage(timeBlocks),
m_blockCursor(0),
m_blockOffset(0),
+ m_blockTravelAxis(0),
m_cacheChannelItems(preloadItems),
m_cacheProgrammeItems(preloadItems),
m_cacheRulerItems(preloadItems),
@@ -698,8 +698,8 @@ void CGUIEPGGridContainer::OnDown()
}
else if (action.GetNavigation() == GetID() || !action.HasActionsMeetingCondition()) // wrap around
{
- SetChannel(0);
ScrollToChannelOffset(0);
+ SetChannel(0);
}
else
CGUIControl::OnDown();
@@ -784,31 +784,24 @@ void CGUIEPGGridContainer::SetChannel(const CPVRChannelPtr &channel)
}
}
-void CGUIEPGGridContainer::SetChannel(int channel, bool bFindClosestItem /* = true */)
+void CGUIEPGGridContainer::SetChannel(int channel)
{
CSingleLock lock(m_critSection);
- if (!bFindClosestItem || m_blockCursor + m_blockOffset == 0 || m_blockOffset + m_blockCursor + GetItemSize(m_item) == m_gridModel->GetBlockCount())
+ int channelIndex = channel + m_channelOffset;
+ int blockIndex = m_blockCursor + m_blockOffset;
+ if (channelIndex < m_gridModel->ChannelItemsSize() && blockIndex < m_gridModel->GetBlockCount())
{
- m_item = GetItem(channel);
+ m_item = m_gridModel->GetGridItemPtr(channelIndex, m_blockTravelAxis);
if (m_item)
{
m_channelCursor = channel;
- SetBlock(GetBlock(m_item->item, channel));
+ SetBlock(GetBlock(m_item->item, channel), false);
}
- return;
- }
-
- /* basic checks failed, need to correctly identify nearest item */
- m_item = GetClosestItem(channel);
- if (m_item)
- {
- m_channelCursor = channel;
- SetBlock(GetBlock(m_item->item, m_channelCursor));
}
}
-void CGUIEPGGridContainer::SetBlock(int block)
+void CGUIEPGGridContainer::SetBlock(int block, bool bUpdateBlockTravelAxis /* = true */)
{
CSingleLock lock(m_critSection);
@@ -819,6 +812,9 @@ void CGUIEPGGridContainer::SetBlock(int block)
else
m_blockCursor = block;
+ if (bUpdateBlockTravelAxis)
+ m_blockTravelAxis = m_blockOffset + m_blockCursor;
+
m_item = GetItem(m_channelCursor);
}
@@ -1090,48 +1086,6 @@ std::string CGUIEPGGridContainer::GetLabel(int info) const
return label;
}
-GridItem *CGUIEPGGridContainer::GetClosestItem(int channel)
-{
- GridItem *closest = GetItem(channel);
-
- if (!closest)
- return nullptr;
-
- int block = GetBlock(closest->item, channel);
- int left; // num blocks to start of previous item
- int right; // num blocks to start of next item
-
- if (block == m_blockCursor)
- return closest; // item & m_item start together
-
- if (block + GetItemSize(closest) == m_blockCursor + GetItemSize(m_item))
- return closest; // closest item ends when current does
-
- if (block > m_blockCursor) // item starts after m_item
- {
- left = m_blockCursor - GetBlock(closest->item, channel);
- right = block - m_blockCursor;
- }
- else
- {
- left = m_blockCursor - block;
- right = GetBlock(GetNextItem(channel)->item, channel) - m_blockCursor;
- }
-
- if (right <= SHORTGAP && right <= left && m_blockCursor + right < m_blocksPerPage)
- return m_gridModel->GetGridItemPtr(channel + m_channelOffset, m_blockCursor + right + m_blockOffset);
-
- return m_gridModel->GetGridItemPtr(channel + m_channelOffset, m_blockCursor - left + m_blockOffset);
-}
-
-int CGUIEPGGridContainer::GetItemSize(GridItem *item)
-{
- if (!item)
- return MathUtils::round_int(m_blockSize); // stops it crashing
-
- return MathUtils::round_int(item->width / m_blockSize);
-}
-
int CGUIEPGGridContainer::GetBlock(const CGUIListItemPtr &item, int channel)
{
if (!item)
@@ -1428,18 +1382,18 @@ void CGUIEPGGridContainer::GoToChannel(int channelIndex)
{
// last page
ScrollToChannelOffset(m_gridModel->ChannelItemsSize() - m_channelsPerPage);
- SetChannel(channelIndex - (m_gridModel->ChannelItemsSize() - m_channelsPerPage), false);
+ SetChannel(channelIndex - (m_gridModel->ChannelItemsSize() - m_channelsPerPage));
}
else if (channelIndex < m_channelsPerPage)
{
// first page
ScrollToChannelOffset(0);
- SetChannel(channelIndex, false);
+ SetChannel(channelIndex);
}
else
{
ScrollToChannelOffset(channelIndex - m_channelCursor);
- SetChannel(m_channelCursor, false);
+ SetChannel(m_channelCursor);
}
}
diff --git a/xbmc/epg/GUIEPGGridContainer.h b/xbmc/epg/GUIEPGGridContainer.h
index 55f3af91c8..8ba370a0ff 100644
--- a/xbmc/epg/GUIEPGGridContainer.h
+++ b/xbmc/epg/GUIEPGGridContainer.h
@@ -90,8 +90,8 @@ namespace EPG
bool OnClick(int actionID);
bool SelectItemFromPoint(const CPoint &point, bool justGrid = true);
- void SetChannel(int channel, bool bFindClosestItem = true);
- void SetBlock(int block);
+ void SetChannel(int channel);
+ void SetBlock(int block, bool bUpdateBlockTravelAxis = true);
void ChannelScroll(int amount);
void ProgrammesScroll(int amount);
void ValidateOffset();
@@ -100,9 +100,7 @@ namespace EPG
GridItem *GetItem(int channel);
GridItem *GetNextItem(int channel);
GridItem *GetPrevItem(int channel);
- GridItem *GetClosestItem(int channel);
- int GetItemSize(GridItem *item);
int GetBlock(const CGUIListItemPtr &item, int channel);
int GetRealBlock(const CGUIListItemPtr &item, int channel);
void MoveToRow(int row);
@@ -163,6 +161,7 @@ namespace EPG
int m_blocksPerPage;
int m_blockCursor;
int m_blockOffset;
+ int m_blockTravelAxis;
int m_cacheChannelItems;
int m_cacheProgrammeItems;
int m_cacheRulerItems;