2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "guilib/DirtyRegion.h"
12 #include "guilib/GUIControl.h"
13 #include "guilib/GUIListItemLayout.h"
14 #include "guilib/GUITexture.h"
15 #include "guilib/IGUIContainer.h"
16 #include "threads/CriticalSection.h"
17 #include "utils/Geometry.h"
28 class CGUIListItemLayout
;
33 class CPVRChannelGroupMember
;
34 class CPVRChannelNumber
;
36 class CGUIEPGGridContainerModel
;
38 class CGUIEPGGridContainer
: public IGUIContainer
41 CGUIEPGGridContainer(int parentID
, int controlID
, float posX
, float posY
, float width
, float height
,
42 ORIENTATION orientation
, int scrollTime
, int preloadItems
, int minutesPerPage
,
43 int rulerUnit
, const CTextureInfo
& progressIndicatorTexture
);
44 CGUIEPGGridContainer(const CGUIEPGGridContainer
& other
);
46 CGUIEPGGridContainer
* Clone() const override
{ return new CGUIEPGGridContainer(*this); }
49 * @brief Check whether the control currently holds data.
50 * @return true if the control has data, false otherwise.
54 void AllocResources() override
;
55 void FreeResources(bool immediately
) override
;
57 bool OnAction(const CAction
& action
) override
;
58 void OnDown() override
;
60 void OnLeft() override
;
61 void OnRight() override
;
62 bool OnMouseOver(const CPoint
& point
) override
;
63 bool OnMessage(CGUIMessage
& message
) override
;
64 void SetFocus(bool focus
) override
;
65 std::string
GetDescription() const override
;
66 EVENT_RESULT
OnMouseEvent(const CPoint
& point
, const KODI::MOUSE::CMouseEvent
& event
) override
;
68 void Process(unsigned int currentTime
, CDirtyRegionList
& dirtyregions
) override
;
69 void Render() override
;
71 std::shared_ptr
<CGUIListItem
> GetListItem(int offset
, unsigned int flag
= 0) const override
;
72 std::string
GetLabel(int info
) const override
;
74 std::shared_ptr
<CFileItem
> GetSelectedGridItem(int offset
= 0) const;
75 std::shared_ptr
<CPVRChannelGroupMember
> GetSelectedChannelGroupMember() const;
76 CDateTime
GetSelectedDate() const;
78 void LoadLayout(TiXmlElement
* layout
);
79 void SetPageControl(int id
);
81 /*! \brief Set the offset of the first item in the container from the container's position
82 Useful for lists/panels where the focused item may be larger than the non-focused items and thus
83 normally cut off from the clipping window defined by the container's position + size.
84 \param offset CPoint holding the offset in skin coordinates.
86 void SetRenderOffset(const CPoint
& offset
);
89 void JumpToDate(const CDateTime
& date
);
94 void GoToDate(const CDateTime
& date
);
96 void GoToFirstChannel();
97 void GoToLastChannel();
102 void GoToMostRight();
104 void SetTimelineItems(const std::unique_ptr
<CFileItemList
>& items
,
105 const CDateTime
& gridStart
,
106 const CDateTime
& gridEnd
);
108 std::unique_ptr
<CFileItemList
> GetCurrentTimeLineItems() const;
111 * @brief Set the control's selection to the given channel and set the control's view port to show the channel.
112 * @param channel the channel.
113 * @return true if the selection was set to the given channel, false otherwise.
115 bool SetChannel(const std::shared_ptr
<CPVRChannel
>& channel
);
118 * @brief Set the control's selection to the given channel and set the control's view port to show the channel.
119 * @param channel the channel's path.
120 * @return true if the selection was set to the given channel, false otherwise.
122 bool SetChannel(const std::string
& channel
);
125 * @brief Set the control's selection to the given channel and set the control's view port to show the channel.
126 * @param channelNumber the channel's number.
127 * @return true if the selection was set to the given channel, false otherwise.
129 bool SetChannel(const CPVRChannelNumber
& channelNumber
);
132 bool OnClick(int actionID
);
133 bool SelectItemFromPoint(const CPoint
& point
, bool justGrid
= true);
135 void SetChannel(int channel
);
137 void SetBlock(int block
, bool bUpdateBlockTravelAxis
= true);
138 void UpdateBlock(bool bUpdateBlockTravelAxis
= true);
140 void ChannelScroll(int amount
);
141 void ProgrammesScroll(int amount
);
142 void ValidateOffset();
145 void SetItem(const std::pair
<std::shared_ptr
<CFileItem
>, int>& itemInfo
);
146 bool SetItem(const std::shared_ptr
<CFileItem
>& item
, int channelIndex
, int blockIndex
);
147 std::shared_ptr
<CFileItem
> GetItem() const;
148 std::pair
<std::shared_ptr
<CFileItem
>, int> GetNextItem() const;
149 std::pair
<std::shared_ptr
<CFileItem
>, int> GetPrevItem() const;
152 void MoveToRow(int row
);
154 CGUIListItemLayout
* GetFocusedLayout() const;
156 void ScrollToBlockOffset(int offset
);
157 void ScrollToChannelOffset(int offset
);
158 void GoToBlock(int blockIndex
);
159 void GoToChannel(int channelIndex
);
160 void UpdateScrollOffset(unsigned int currentTime
);
161 void ProcessItem(float posX
, float posY
, const std::shared_ptr
<CFileItem
>& item
, std::shared_ptr
<CFileItem
>& lastitem
, bool focused
, CGUIListItemLayout
* normallayout
, CGUIListItemLayout
* focusedlayout
, unsigned int currentTime
, CDirtyRegionList
& dirtyregions
, float resize
= -1.0f
);
162 void RenderItem(float posX
, float posY
, CGUIListItem
* item
, bool focused
);
163 void GetCurrentLayouts();
165 void ProcessChannels(unsigned int currentTime
, CDirtyRegionList
& dirtyregions
);
166 void ProcessRuler(unsigned int currentTime
, CDirtyRegionList
& dirtyregions
);
167 void ProcessRulerDate(unsigned int currentTime
, CDirtyRegionList
& dirtyregions
);
168 void ProcessProgrammeGrid(unsigned int currentTime
, CDirtyRegionList
& dirtyregions
);
169 void ProcessProgressIndicator(unsigned int currentTime
, CDirtyRegionList
& dirtyregions
);
170 void RenderChannels();
171 void RenderRulerDate();
173 void RenderProgrammeGrid();
174 void RenderProgressIndicator();
176 CPoint m_renderOffset
; ///< \brief render offset of the first item in the list \sa SetRenderOffset
178 ORIENTATION m_orientation
;
180 std::vector
<CGUIListItemLayout
> m_channelLayouts
;
181 std::vector
<CGUIListItemLayout
> m_focusedChannelLayouts
;
182 std::vector
<CGUIListItemLayout
> m_focusedProgrammeLayouts
;
183 std::vector
<CGUIListItemLayout
> m_programmeLayouts
;
184 std::vector
<CGUIListItemLayout
> m_rulerLayouts
;
185 std::vector
<CGUIListItemLayout
> m_rulerDateLayouts
;
187 CGUIListItemLayout
* m_channelLayout
= nullptr;
188 CGUIListItemLayout
* m_focusedChannelLayout
= nullptr;
189 CGUIListItemLayout
* m_programmeLayout
= nullptr;
190 CGUIListItemLayout
* m_focusedProgrammeLayout
= nullptr;
191 CGUIListItemLayout
* m_rulerLayout
= nullptr;
192 CGUIListItemLayout
* m_rulerDateLayout
= nullptr;
194 int m_pageControl
= 0;
196 void GetChannelCacheOffsets(int& cacheBefore
, int& cacheAfter
);
197 void GetProgrammeCacheOffsets(int& cacheBefore
, int& cacheAfter
);
200 bool OnMouseClick(int dwButton
, const CPoint
& point
);
201 bool OnMouseDoubleClick(int dwButton
, const CPoint
& point
);
202 bool OnMouseWheel(char wheel
, const CPoint
& point
);
204 void HandleChannels(bool bRender
, unsigned int currentTime
, CDirtyRegionList
& dirtyregions
);
205 void HandleRuler(bool bRender
, unsigned int currentTime
, CDirtyRegionList
& dirtyregions
);
206 void HandleRulerDate(bool bRender
, unsigned int currentTime
, CDirtyRegionList
& dirtyregions
);
207 void HandleProgrammeGrid(bool bRender
, unsigned int currentTime
, CDirtyRegionList
& dirtyregions
);
209 float GetCurrentTimePositionOnPage() const;
210 float GetProgressIndicatorWidth() const;
211 float GetProgressIndicatorHeight() const;
215 float GetChannelScrollOffsetPos() const;
216 float GetProgrammeScrollOffsetPos() const;
217 int GetChannelScrollOffset(CGUIListItemLayout
* layout
) const;
218 int GetProgrammeScrollOffset() const;
220 int m_rulerUnit
; //! number of blocks that makes up one element of the ruler
221 int m_channelsPerPage
= 0;
222 int m_programmesPerPage
= 0;
223 int m_channelCursor
= 0;
224 int m_channelOffset
= 0;
226 int m_blockCursor
= 0;
227 int m_blockOffset
= 0;
228 int m_blockTravelAxis
= 0;
229 int m_cacheChannelItems
;
230 int m_cacheProgrammeItems
;
231 int m_cacheRulerItems
;
233 float m_rulerDateHeight
= 0; //! height of ruler date item
234 float m_rulerDateWidth
= 0; //! width of ruler date item
235 float m_rulerPosX
= 0; //! X position of first ruler item
236 float m_rulerPosY
= 0; //! Y position of first ruler item
237 float m_rulerHeight
= 0; //! height of the scrolling timeline above the ruler items
238 float m_rulerWidth
= 0; //! width of each element of the ruler
239 float m_channelPosX
= 0; //! X position of first channel row
240 float m_channelPosY
= 0; //! Y position of first channel row
241 float m_channelHeight
= 0; //! height of the channel item
242 float m_channelWidth
= 0; //! width of the channel item
243 float m_gridPosX
= 0; //! X position of first grid item
244 float m_gridPosY
= 0; //! Y position of first grid item
245 float m_gridWidth
= 0; //! width of the epg grid control
246 float m_gridHeight
= 0; //! height of the epg grid control
247 float m_blockSize
= 0; //! a block's width in pixels
248 float m_analogScrollCount
= 0;
250 std::unique_ptr
<CGUITexture
> m_guiProgressIndicatorTexture
;
252 std::shared_ptr
<CFileItem
> m_lastItem
;
253 std::shared_ptr
<CFileItem
> m_lastChannel
;
255 bool m_bEnableProgrammeScrolling
= true;
256 bool m_bEnableChannelScrolling
= true;
260 int m_programmeScrollLastTime
= 0;
261 float m_programmeScrollSpeed
= 0;
262 float m_programmeScrollOffset
= 0;
264 int m_channelScrollLastTime
= 0;
265 float m_channelScrollSpeed
= 0;
266 float m_channelScrollOffset
= 0;
268 mutable CCriticalSection m_critSection
;
269 std::unique_ptr
<CGUIEPGGridContainerModel
> m_gridModel
;
270 std::unique_ptr
<CGUIEPGGridContainerModel
> m_updatedGridModel
;
272 int m_itemStartBlock
= 0;