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/GUIBaseContainer.h"
31 class CGUIWindowPVRGuide;
36 #define MAXCHANNELS 20
37 #define MAXBLOCKS 2304 //! !!_EIGHT_!! days of 5 minute blocks
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,
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);
95 void SetStartEnd(CDateTime start, CDateTime end);
96 void SetChannel(const PVR::CPVRChannel &channel);
97 void SetChannel(const CStdString &channel);
100 bool OnClick(int actionID);
101 bool SelectItemFromPoint(const CPoint &point);
105 void SetChannel(int channel);
106 void SetBlock(int block);
107 void ChannelScroll(int amount);
108 void ProgrammesScroll(int amount);
109 void ValidateOffset();
110 void UpdateLayout(bool refreshAllItems = false);
111 void CalculateLayout();
113 void ClearGridIndex(void);
115 GridItemsPtr *GetItem(const int &channel);
116 GridItemsPtr *GetNextItem(const int &channel);
117 GridItemsPtr *GetPrevItem(const int &channel);
118 GridItemsPtr *GetClosestItem(const int &channel);
120 int GetItemSize(GridItemsPtr *item);
121 int GetBlock(const CGUIListItemPtr &item, const int &channel);
122 int GetRealBlock(const CGUIListItemPtr &item, const int &channel);
123 void MoveToRow(int row);
124 bool MoveChannel(bool direction, bool wrapAround);
125 bool MoveProgrammes(bool direction);
127 CGUIListItemLayout *GetFocusedLayout() const;
129 void ScrollToBlockOffset(int offset);
130 void ScrollToChannelOffset(int offset);
131 void UpdateScrollOffset();
132 void RenderChannelItem(float posX, float posY, CGUIListItem *item, bool focused);
133 void RenderProgrammeItem(float posX, float posY, float width, float height, CGUIListItem *item, bool focused);
134 void GetCurrentLayouts();
136 CPoint m_renderOffset; ///< \brief render offset of the first item in the list \sa SetRenderOffset
138 ORIENTATION m_orientation;
145 std::vector< ItemsPtr > m_epgItemsPtr;
146 std::vector< CGUIListItemPtr > m_channelItems;
147 std::vector< CGUIListItemPtr > m_rulerItems;
148 std::vector< CGUIListItemPtr > m_programmeItems;
149 typedef std::vector<CGUIListItemPtr> ::iterator iItems;
151 std::vector<CGUIListItemLayout> m_channelLayouts;
152 std::vector<CGUIListItemLayout> m_focusedChannelLayouts;
153 std::vector<CGUIListItemLayout> m_focusedProgrammeLayouts;
154 std::vector<CGUIListItemLayout> m_programmeLayouts;
155 std::vector<CGUIListItemLayout> m_rulerLayouts;
157 CGUIListItemLayout *m_channelLayout;
158 CGUIListItemLayout *m_focusedChannelLayout;
159 CGUIListItemLayout *m_programmeLayout;
160 CGUIListItemLayout *m_focusedProgrammeLayout;
161 CGUIListItemLayout *m_rulerLayout;
163 bool m_wasReset; // true if we've received a Reset message until we've rendered once. Allows
164 // us to make sure we don't tell the infomanager that we've been moving when
165 // the "movement" was simply due to the list being repopulated (thus cursor position
168 void FreeChannelMemory(int keepStart, int keepEnd);
169 void FreeProgrammeMemory(int keepStart, int keepEnd);
170 void FreeRulerMemory(int keepStart, int keepEnd);
172 void GetChannelCacheOffsets(int &cacheBefore, int &cacheAfter);
173 void GetProgrammeCacheOffsets(int &cacheBefore, int &cacheAfter);
174 void GetRulerCacheOffsets(int &cacheBefore, int &cacheAfter);
177 int m_rulerUnit; //! number of blocks that makes up one element of the ruler
179 int m_channelsPerPage;
180 int m_ProgrammesPerPage;
187 int m_cacheChannelItems;
188 int m_cacheProgrammeItems;
189 int m_cacheRulerItems;
191 float m_rulerPosX; //! X position of first ruler item
192 float m_rulerPosY; //! Y position of first ruler item
193 float m_rulerHeight; //! height of the scrolling timeline above the ruler items
194 float m_rulerWidth; //! width of each element of the ruler
195 float m_channelPosX; //! Y position of first channel row
196 float m_channelPosY; //! Y position of first channel row
197 float m_channelHeight; //! height of each channel row (& every grid item)
198 float m_channelWidth; //! width of the channel item
199 float m_gridPosX; //! X position of first grid item
200 float m_gridPosY; //! Y position of first grid item
203 float m_blockSize; //! a block's width in pixels
204 float m_analogScrollCount;
206 CDateTime m_gridStart;
209 struct GridItemsPtr **m_gridIndex;
210 GridItemsPtr *m_item;
211 CGUIListItem *m_lastItem;
212 CGUIListItem *m_lastChannel;
214 unsigned int m_renderTime;
217 bool m_gridWrapAround; //! only when no more data available should this be true
219 int m_programmeScrollLastTime;
220 float m_programmeScrollSpeed;
221 float m_programmeScrollOffset;
223 int m_channelScrollLastTime;
224 float m_channelScrollSpeed;
225 float m_channelScrollOffset;