diff options
author | Kai Sommerfeld <kai.sommerfeld@gmx.com> | 2017-02-22 07:52:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-22 07:52:50 +0100 |
commit | d2417c78950c3db8d2f9c2adb02afb59b99a4a12 (patch) | |
tree | 97b2a91fb51900b0c8c1e4e0b1e5076f633c696c | |
parent | d02c4ddebdc37c05fa58f59f6673ce4c08f4f047 (diff) | |
parent | 5f9ba0d89172e3597e2b517f2a73059164d9723e (diff) |
Merge pull request #11706 from ksooo/krypton-epg-gridcontainer-fixes
[EPG] Trac 17323: Krypton: Guide window fixes
-rw-r--r-- | xbmc/epg/GUIEPGGridContainer.cpp | 86 | ||||
-rw-r--r-- | xbmc/epg/GUIEPGGridContainer.h | 9 | ||||
-rw-r--r-- | xbmc/epg/GUIEPGGridContainerModel.cpp | 24 | ||||
-rw-r--r-- | xbmc/epg/GUIEPGGridContainerModel.h | 7 |
4 files changed, 50 insertions, 76 deletions
diff --git a/xbmc/epg/GUIEPGGridContainer.cpp b/xbmc/epg/GUIEPGGridContainer.cpp index 16fee97192..44ff0dd816 100644 --- a/xbmc/epg/GUIEPGGridContainer.cpp +++ b/xbmc/epg/GUIEPGGridContainer.cpp @@ -39,10 +39,8 @@ 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 CGUIEPGGridContainer::CGUIEPGGridContainer(int parentID, int controlID, float posX, float posY, float width, float height, int scrollTime, int preloadItems, int timeBlocks, int rulerUnit, @@ -62,6 +60,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 +697,8 @@ void CGUIEPGGridContainer::OnDown() } else if (action.GetNavigation() == GetID() || !action.HasActionsMeetingCondition()) // wrap around { - SetChannel(0); ScrollToChannelOffset(0); + SetChannel(0); } else CGUIControl::OnDown(); @@ -784,31 +783,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 +811,9 @@ void CGUIEPGGridContainer::SetBlock(int block) else m_blockCursor = block; + if (bUpdateBlockTravelAxis) + m_blockTravelAxis = m_blockOffset + m_blockCursor; + m_item = GetItem(m_channelCursor); } @@ -1036,6 +1031,11 @@ CEpgInfoTagPtr CGUIEPGGridContainer::GetSelectedEpgInfoTag() const return tag; } +unsigned int CGUIEPGGridContainer::GetPageNowOffset() const +{ + return m_gridModel->GetGridStartPadding() / CGUIEPGGridContainerModel::MINSPERBLOCK; // this is the 'now' block relative to page start +} + CGUIListItemPtr CGUIEPGGridContainer::GetListItem(int offset, unsigned int flag) const { if (!m_gridModel->HasChannelItems()) @@ -1090,48 +1090,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) @@ -1385,9 +1343,9 @@ void CGUIEPGGridContainer::GoToEnd() void CGUIEPGGridContainer::GoToNow() { CDateTime currentDate = CDateTime::GetCurrentDateTime().GetAsUTCDateTime(); - int offset = (currentDate - m_gridModel->GetGridStart()).GetSecondsTotal() / 60 / CGUIEPGGridContainerModel::MINSPERBLOCK - PAGE_NOW_OFFSET; + int offset = (currentDate - m_gridModel->GetGridStart()).GetSecondsTotal() / 60 / CGUIEPGGridContainerModel::MINSPERBLOCK - GetPageNowOffset(); ScrollToBlockOffset(offset); - SetBlock(PAGE_NOW_OFFSET); + SetBlock(GetPageNowOffset()); } void CGUIEPGGridContainer::SetTimelineItems(const std::unique_ptr<CFileItemList> &items, const CDateTime &gridStart, const CDateTime &gridEnd) @@ -1428,18 +1386,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..cf6a901cfe 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); @@ -155,6 +153,8 @@ namespace EPG EPG::CEpgInfoTagPtr GetSelectedEpgInfoTag() const; + unsigned int GetPageNowOffset() const; + int m_rulerUnit; //! number of blocks that makes up one element of the ruler int m_channelsPerPage; int m_programmesPerPage; @@ -163,6 +163,7 @@ namespace EPG int m_blocksPerPage; int m_blockCursor; int m_blockOffset; + int m_blockTravelAxis; int m_cacheChannelItems; int m_cacheProgrammeItems; int m_cacheRulerItems; diff --git a/xbmc/epg/GUIEPGGridContainerModel.cpp b/xbmc/epg/GUIEPGGridContainerModel.cpp index dbc867cdd1..1abc733f16 100644 --- a/xbmc/epg/GUIEPGGridContainerModel.cpp +++ b/xbmc/epg/GUIEPGGridContainerModel.cpp @@ -18,12 +18,14 @@ * */ +#include "GUIEPGGridContainerModel.h" + #include "FileItem.h" #include "epg/EpgInfoTag.h" +#include "settings/AdvancedSettings.h" #include "utils/Variant.h" -#include "pvr/channels/PVRChannel.h" -#include "GUIEPGGridContainerModel.h" +#include "pvr/channels/PVRChannel.h" class CGUIListItem; typedef std::shared_ptr<CGUIListItem> CGUIListItemPtr; @@ -31,6 +33,8 @@ typedef std::shared_ptr<CGUIListItem> CGUIListItemPtr; using namespace EPG; using namespace PVR; +static const unsigned int GRID_START_PADDING = 30; // minutes + void CGUIEPGGridContainerModel::SetInvalid() { for (const auto &programme : m_programmeItems) @@ -109,13 +113,13 @@ void CGUIEPGGridContainerModel::Refresh(const std::unique_ptr<CFileItemList> &it if (gridStart >= gridEnd) { // default to start "now minus GRID_START_PADDING minutes" and end "start plus one page". - m_gridStart = CDateTime::GetCurrentDateTime().GetAsUTCDateTime() - CDateTimeSpan(0, 0, GRID_START_PADDING, 0); + m_gridStart = CDateTime::GetCurrentDateTime().GetAsUTCDateTime() - CDateTimeSpan(0, 0, GetGridStartPadding(), 0); m_gridEnd = m_gridStart + CDateTimeSpan(0, 0, iBlocksPerPage * MINSPERBLOCK, 0); } - else if (gridStart > (CDateTime::GetCurrentDateTime().GetAsUTCDateTime() - CDateTimeSpan(0, 0, GRID_START_PADDING, 0))) + else if (gridStart > (CDateTime::GetCurrentDateTime().GetAsUTCDateTime() - CDateTimeSpan(0, 0, GetGridStartPadding(), 0))) { // adjust to start "now minus GRID_START_PADDING minutes". - m_gridStart = CDateTime::GetCurrentDateTime().GetAsUTCDateTime() - CDateTimeSpan(0, 0, GRID_START_PADDING, 0); + m_gridStart = CDateTime::GetCurrentDateTime().GetAsUTCDateTime() - CDateTimeSpan(0, 0, GetGridStartPadding(), 0); m_gridEnd = gridEnd; } else @@ -312,6 +316,16 @@ void CGUIEPGGridContainerModel::FindChannelAndBlockIndex(int channelUid, unsigne } } +unsigned int CGUIEPGGridContainerModel::GetGridStartPadding() const +{ + int iEpgLingerTime = g_advancedSettings.m_iEpgLingerTime; + + if (iEpgLingerTime < GRID_START_PADDING) + return iEpgLingerTime; + + return GRID_START_PADDING; // minutes +} + void CGUIEPGGridContainerModel::FreeChannelMemory(int keepStart, int keepEnd) { if (keepStart < keepEnd) diff --git a/xbmc/epg/GUIEPGGridContainerModel.h b/xbmc/epg/GUIEPGGridContainerModel.h index 3ad9a36bf5..06e66ecaa0 100644 --- a/xbmc/epg/GUIEPGGridContainerModel.h +++ b/xbmc/epg/GUIEPGGridContainerModel.h @@ -44,9 +44,8 @@ namespace EPG class CGUIEPGGridContainerModel { public: - static const int MINSPERBLOCK = 5; // minutes - static const int MAXBLOCKS = 33 * 24 * 60 / MINSPERBLOCK; //! 33 days of 5 minute blocks (31 days for upcoming data + 1 day for past data + 1 day for fillers) - static const int GRID_START_PADDING = 30; // minutes; latest grid start 'now - GRID_START_PADDING', will be adjusted to this value if shall be set to later + static const int MINSPERBLOCK = 5; // minutes + static const int MAXBLOCKS = 33 * 24 * 60 / MINSPERBLOCK; //! 33 days of 5 minute blocks (31 days for upcoming data + 1 day for past data + 1 day for fillers) CGUIEPGGridContainerModel() : m_blocks(0) {} virtual ~CGUIEPGGridContainerModel() { Reset(); } @@ -84,6 +83,8 @@ namespace EPG const CDateTime &GetGridStart() const { return m_gridStart; } const CDateTime &GetGridEnd() const { return m_gridEnd; } + unsigned int GetGridStartPadding() const; + private: void FreeItemsMemory(); void Reset(); |