xbmc
GUIEPGGridContainer.h
1 /*
2  * Copyright (C) 2012-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
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"
18 
19 #include <memory>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 class CDateTime;
25 class CFileItem;
26 class CFileItemList;
27 class CGUIListItem;
28 class CGUIListItemLayout;
29 
30 namespace PVR
31 {
32  class CPVRChannel;
33  class CPVRChannelGroupMember;
34  class CPVRChannelNumber;
35 
36  class CGUIEPGGridContainerModel;
37 
39  {
40  public:
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);
45 
46  CGUIEPGGridContainer* Clone() const override { return new CGUIEPGGridContainer(*this); }
47 
52  bool HasData() const;
53 
54  void AllocResources() override;
55  void FreeResources(bool immediately) override;
56 
57  bool OnAction(const CAction& action) override;
58  void OnDown() override;
59  void OnUp() 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 CMouseEvent& event) override;
67 
68  void Process(unsigned int currentTime, CDirtyRegionList& dirtyregions) override;
69  void Render() override;
70 
71  CGUIListItemPtr GetListItem(int offset, unsigned int flag = 0) const override;
72  std::string GetLabel(int info) const override;
73 
74  std::shared_ptr<CFileItem> GetSelectedGridItem(int offset = 0) const;
75  std::shared_ptr<CPVRChannelGroupMember> GetSelectedChannelGroupMember() const;
76  CDateTime GetSelectedDate() const;
77 
78  void LoadLayout(TiXmlElement* layout);
79  void SetPageControl(int id);
80 
86  void SetRenderOffset(const CPoint& offset);
87 
88  void JumpToNow();
89  void JumpToDate(const CDateTime& date);
90 
91  void GoToBegin();
92  void GoToEnd();
93  void GoToNow();
94  void GoToDate(const CDateTime& date);
95 
96  void GoToFirstChannel();
97  void GoToLastChannel();
98 
99  void GoToTop();
100  void GoToBottom();
101  void GoToMostLeft();
102  void GoToMostRight();
103 
104  void SetTimelineItems(const std::unique_ptr<CFileItemList>& items,
105  const CDateTime& gridStart,
106  const CDateTime& gridEnd);
107 
108  std::unique_ptr<CFileItemList> GetCurrentTimeLineItems() const;
109 
115  bool SetChannel(const std::shared_ptr<CPVRChannel>& channel);
116 
122  bool SetChannel(const std::string& channel);
123 
129  bool SetChannel(const CPVRChannelNumber& channelNumber);
130 
131  private:
132  bool OnClick(int actionID);
133  bool SelectItemFromPoint(const CPoint& point, bool justGrid = true);
134 
135  void SetChannel(int channel);
136 
137  void SetBlock(int block, bool bUpdateBlockTravelAxis = true);
138  void UpdateBlock(bool bUpdateBlockTravelAxis = true);
139 
140  void ChannelScroll(int amount);
141  void ProgrammesScroll(int amount);
142  void ValidateOffset();
143  void UpdateLayout();
144 
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;
150  void UpdateItem();
151 
152  void MoveToRow(int row);
153 
154  CGUIListItemLayout* GetFocusedLayout() const;
155 
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();
164 
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();
172  void RenderRuler();
173  void RenderProgrammeGrid();
174  void RenderProgressIndicator();
175 
176  CPoint m_renderOffset;
177 
178  ORIENTATION m_orientation;
179 
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;
186 
187  CGUIListItemLayout* m_channelLayout;
188  CGUIListItemLayout* m_focusedChannelLayout;
189  CGUIListItemLayout* m_programmeLayout;
190  CGUIListItemLayout* m_focusedProgrammeLayout;
191  CGUIListItemLayout* m_rulerLayout;
192  CGUIListItemLayout* m_rulerDateLayout;
193 
194  int m_pageControl;
195 
196  void GetChannelCacheOffsets(int& cacheBefore, int& cacheAfter);
197  void GetProgrammeCacheOffsets(int& cacheBefore, int& cacheAfter);
198 
199  private:
200  bool OnMouseClick(int dwButton, const CPoint& point);
201  bool OnMouseDoubleClick(int dwButton, const CPoint& point);
202  bool OnMouseWheel(char wheel, const CPoint& point);
203 
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);
208 
209  float GetCurrentTimePositionOnPage() const;
210  float GetProgressIndicatorWidth() const;
211  float GetProgressIndicatorHeight() const;
212 
213  void UpdateItems();
214 
215  float GetChannelScrollOffsetPos() const;
216  float GetProgrammeScrollOffsetPos() const;
217  int GetChannelScrollOffset(CGUIListItemLayout* layout) const;
218  int GetProgrammeScrollOffset() const;
219 
220  int m_rulerUnit;
221  int m_channelsPerPage;
222  int m_programmesPerPage;
223  int m_channelCursor;
224  int m_channelOffset;
225  int m_blocksPerPage;
226  int m_blockCursor;
227  int m_blockOffset;
228  int m_blockTravelAxis;
229  int m_cacheChannelItems;
230  int m_cacheProgrammeItems;
231  int m_cacheRulerItems;
232 
233  float m_rulerDateHeight;
234  float m_rulerDateWidth;
235  float m_rulerPosX;
236  float m_rulerPosY;
237  float m_rulerHeight;
238  float m_rulerWidth;
239  float m_channelPosX;
240  float m_channelPosY;
241  float m_channelHeight;
242  float m_channelWidth;
243  float m_gridPosX;
244  float m_gridPosY;
245  float m_gridWidth;
246  float m_gridHeight;
247  float m_blockSize;
248  float m_analogScrollCount;
249 
250  std::unique_ptr<CGUITexture> m_guiProgressIndicatorTexture;
251 
252  std::shared_ptr<CFileItem> m_lastItem;
253  std::shared_ptr<CFileItem> m_lastChannel;
254 
255  bool m_bEnableProgrammeScrolling = true;
256  bool m_bEnableChannelScrolling = true;
257 
258  int m_scrollTime;
259 
260  int m_programmeScrollLastTime;
261  float m_programmeScrollSpeed;
262  float m_programmeScrollOffset;
263 
264  int m_channelScrollLastTime;
265  float m_channelScrollSpeed;
266  float m_channelScrollOffset;
267 
268  mutable CCriticalSection m_critSection;
269  std::unique_ptr<CGUIEPGGridContainerModel> m_gridModel;
270  std::unique_ptr<CGUIEPGGridContainerModel> m_updatedGridModel;
271 
272  int m_itemStartBlock = 0;
273  };
274 }
bool HasData() const
Check whether the control currently holds data.
Definition: GUIEPGGridContainer.cpp:169
Definition: GUIListItem.h:30
Definition: ContextMenuManager.h:24
bool SetChannel(const std::shared_ptr< CPVRChannel > &channel)
Set the control&#39;s selection to the given channel and set the control&#39;s view port to show the channel...
Definition: GUIEPGGridContainer.cpp:1123
void SetRenderOffset(const CPoint &offset)
Set the offset of the first item in the container from the container&#39;s position Useful for lists/pane...
Definition: GUIEPGGridContainer.cpp:2084
Represents a list of files.
Definition: FileItem.h:713
Definition: GUIListItemLayout.h:20
Definition: IGUIContainer.h:22
EVENT_RESULT
Results of OnMouseEvent() Any value not equal to EVENT_RESULT_UNHANDLED indicates that the event was ...
Definition: GUIControl.h:60
Definition: GUIEPGGridContainer.h:38
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
bool OnMouseOver(const CPoint &point) override
Called when the mouse is over the control. Default implementation selects the control.
Definition: GUIEPGGridContainer.cpp:1315
Definition: GUITexture.h:51
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
Definition: GUIMessage.h:365
Definition: PVRChannelNumber.h:15
EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event) override
Perform a mouse action.
Definition: GUIEPGGridContainer.cpp:1254
Represents a file on a share.
Definition: FileItem.h:102
Simple class for mouse events.
Definition: Key.h:114