4 * Copyright (C) 2012-2013 Team XBMC
7 * This Program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This Program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with XBMC; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
23 #include "XBDateTime.h"
25 #include "guilib/GUIControl.h"
26 #include "guilib/GUIListItemLayout.h"
27 #include "guilib/IGUIContainer.h"
31 class CGUIWindowPVRGuide;
36 #define MAXCHANNELS 20
37 #define MAXBLOCKS (16 * 24 * 60 / 5) //! 16 days of 5 minute blocks (14 days for upcoming data + 1 day for past data + 1 day for fillers)
46 class CGUIEPGGridContainer : public IGUIContainer
48 friend class PVR::CGUIWindowPVRGuide;
51 CGUIEPGGridContainer(int parentID, int controlID, float posX, float posY, float width, float height,
52 ORIENTATION orientation, int scrollTime, int preloadItems, int minutesPerPage,
53 int rulerUnit, const CTextureInfo& progressIndicatorTexture);
54 virtual ~CGUIEPGGridContainer(void);
55 virtual CGUIEPGGridContainer *Clone() const { return new CGUIEPGGridContainer(*this); };
57 virtual bool OnAction(const CAction &action);
58 virtual void OnDown();
60 virtual void OnLeft();
61 virtual void OnRight();
62 virtual bool OnMouseOver(const CPoint &point);
63 virtual bool OnMouseClick(int dwButton, const CPoint &point);
64 virtual bool OnMouseDoubleClick(int dwButton, const CPoint &point);
65 virtual bool OnMouseWheel(char wheel, const CPoint &point);
66 virtual bool OnMessage(CGUIMessage& message);
67 virtual void SetFocus(bool bOnOff);
69 virtual CStdString GetDescription() const;
70 const int GetNumChannels() { return m_channels; };
71 virtual int GetSelectedItem() const;
72 const int GetSelectedChannel() { return m_channelCursor + m_channelOffset; }
73 virtual EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event);
75 virtual void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions);
76 virtual void DoRender();
77 virtual void Render();
78 void LoadLayout(TiXmlElement *layout);
79 void LoadContent(TiXmlElement *content);
81 virtual CGUIListItemPtr GetListItem(int offset, unsigned int flag = 0) const;
82 virtual CStdString GetLabel(int info) const;
84 virtual int CorrectOffset(int offset, int cursor) const;
86 /*! \brief Set the offset of the first item in the container from the container's position
87 Useful for lists/panels where the focused item may be larger than the non-focused items and thus
88 normally cut off from the clipping window defined by the container's position + size.
89 \param offset CPoint holding the offset in skin coordinates.
91 void SetRenderOffset(const CPoint &offset);
96 void SetStartEnd(CDateTime start, CDateTime end);
97 void SetChannel(const PVR::CPVRChannel &channel);
98 void SetChannel(const CStdString &channel);
101 bool OnClick(int actionID);
102 bool SelectItemFromPoint(const CPoint &point, bool justGrid = true);
106 void SetChannel(int channel);
107 void SetBlock(int block);
108 void ChannelScroll(int amount);
109 void ProgrammesScroll(int amount);
110 void ValidateOffset();
111 void UpdateLayout(bool refreshAllItems = false);
112 void CalculateLayout();
114 void ClearGridIndex(void);
116 GridItemsPtr *GetItem(const int &channel);
117 GridItemsPtr *GetNextItem(const int &channel);
118 GridItemsPtr *GetPrevItem(const int &channel);
119 GridItemsPtr *GetClosestItem(const int &channel);
121 int GetItemSize(GridItemsPtr *item);
122 int GetBlock(const CGUIListItemPtr &item, const int &channel);
123 int GetRealBlock(const CGUIListItemPtr &item, const int &channel);
124 void MoveToRow(int row);
125 bool MoveChannel(bool direction, bool wrapAround);
126 bool MoveProgrammes(bool direction);
128 CGUIListItemLayout *GetFocusedLayout() const;
130 void ScrollToBlockOffset(int offset);
131 void ScrollToChannelOffset(int offset);
132 void UpdateScrollOffset(unsigned int currentTime);
133 void ProcessItem(float posX, float posY, CGUIListItem *item, CGUIListItem *&lastitem, bool focused, CGUIListItemLayout* normallayout, CGUIListItemLayout* focusedlayout, unsigned int currentTime, CDirtyRegionList &dirtyregions, float resize = -1.0f);
134 void RenderItem(float posX, float posY, CGUIListItem *item, bool focused);
135 void GetCurrentLayouts();
137 void ProcessChannels(unsigned int currentTime, CDirtyRegionList &dirtyregions);
138 void ProcessRuler(unsigned int currentTime, CDirtyRegionList &dirtyregions);
139 void ProcessProgrammeGrid(unsigned int currentTime, CDirtyRegionList &dirtyregions);
140 void ProcessProgressIndicator(unsigned int currentTime, CDirtyRegionList &dirtyregions);
141 void RenderChannels();
143 void RenderProgrammeGrid();
144 void RenderProgressIndicator();
146 CPoint m_renderOffset; ///< \brief render offset of the first item in the list \sa SetRenderOffset
148 ORIENTATION m_orientation;
155 std::vector< ItemsPtr > m_epgItemsPtr;
156 std::vector< CGUIListItemPtr > m_channelItems;
157 std::vector< CGUIListItemPtr > m_rulerItems;
158 std::vector< CGUIListItemPtr > m_programmeItems;
159 typedef std::vector<CGUIListItemPtr> ::iterator iItems;
161 std::vector<CGUIListItemLayout> m_channelLayouts;
162 std::vector<CGUIListItemLayout> m_focusedChannelLayouts;
163 std::vector<CGUIListItemLayout> m_focusedProgrammeLayouts;
164 std::vector<CGUIListItemLayout> m_programmeLayouts;
165 std::vector<CGUIListItemLayout> m_rulerLayouts;
167 CGUIListItemLayout *m_channelLayout;
168 CGUIListItemLayout *m_focusedChannelLayout;
169 CGUIListItemLayout *m_programmeLayout;
170 CGUIListItemLayout *m_focusedProgrammeLayout;
171 CGUIListItemLayout *m_rulerLayout;
173 bool m_wasReset; // true if we've received a Reset message until we've rendered once. Allows
174 // us to make sure we don't tell the infomanager that we've been moving when
175 // the "movement" was simply due to the list being repopulated (thus cursor position
178 void FreeChannelMemory(int keepStart, int keepEnd);
179 void FreeProgrammeMemory(int channel, int keepStart, int keepEnd);
180 void FreeRulerMemory(int keepStart, int keepEnd);
182 void GetChannelCacheOffsets(int &cacheBefore, int &cacheAfter);
183 void GetProgrammeCacheOffsets(int &cacheBefore, int &cacheAfter);
186 int m_rulerUnit; //! number of blocks that makes up one element of the ruler
188 int m_channelsPerPage;
189 int m_ProgrammesPerPage;
196 int m_cacheChannelItems;
197 int m_cacheProgrammeItems;
198 int m_cacheRulerItems;
200 float m_rulerPosX; //! X position of first ruler item
201 float m_rulerPosY; //! Y position of first ruler item
202 float m_rulerHeight; //! height of the scrolling timeline above the ruler items
203 float m_rulerWidth; //! width of each element of the ruler
204 float m_channelPosX; //! Y position of first channel row
205 float m_channelPosY; //! Y position of first channel row
206 float m_channelHeight; //! height of each channel row (& every grid item)
207 float m_channelWidth; //! width of the channel item
208 float m_gridPosX; //! X position of first grid item
209 float m_gridPosY; //! Y position of first grid item
212 float m_blockSize; //! a block's width in pixels
213 float m_analogScrollCount;
215 CDateTime m_gridStart;
218 CGUITexture m_guiProgressIndicatorTexture;
220 std::vector<std::vector<GridItemsPtr> > m_gridIndex;
221 GridItemsPtr *m_item;
222 CGUIListItem *m_lastItem;
223 CGUIListItem *m_lastChannel;
226 bool m_gridWrapAround; //! only when no more data available should this be true
228 int m_programmeScrollLastTime;
229 float m_programmeScrollSpeed;
230 float m_programmeScrollOffset;
232 int m_channelScrollLastTime;
233 float m_channelScrollSpeed;
234 float m_channelScrollOffset;