Merge pull request #4314 from MartijnKaijser/beta1
[vuplus_xbmc] / xbmc / epg / GUIEPGGridContainer.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2012-2013 Team XBMC
5  *      http://xbmc.org
6  *
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)
10  *  any later version.
11  *
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.
16  *
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/>.
20  *
21  */
22
23 #include "XBDateTime.h"
24 #include "FileItem.h"
25 #include "guilib/GUIControl.h"
26 #include "guilib/GUIListItemLayout.h"
27 #include "guilib/IGUIContainer.h"
28
29 namespace PVR
30 {
31   class CGUIWindowPVRGuide;
32 }
33
34 namespace EPG
35 {
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)
38
39   struct GridItemsPtr
40   {
41     CGUIListItemPtr item;
42     float width;
43     float height;
44   };
45
46   class CGUIEPGGridContainer : public IGUIContainer
47   {
48   friend class PVR::CGUIWindowPVRGuide;
49
50   public:
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); };
56
57     virtual bool OnAction(const CAction &action);
58     virtual void OnDown();
59     virtual void OnUp();
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);
68
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);
74
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);
80
81     virtual CGUIListItemPtr GetListItem(int offset, unsigned int flag = 0) const;
82     virtual CStdString GetLabel(int info) const;
83
84     virtual int  CorrectOffset(int offset, int cursor) const;
85
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.
90      */
91     void SetRenderOffset(const CPoint &offset);
92
93     void GoToBegin();
94     void GoToEnd();
95     void GoToNow();
96     void SetStartEnd(CDateTime start, CDateTime end);
97     void SetChannel(const PVR::CPVRChannel &channel);
98     void SetChannel(const CStdString &channel);
99
100   protected:
101     bool OnClick(int actionID);
102     bool SelectItemFromPoint(const CPoint &point, bool justGrid = true);
103
104     void UpdateItems();
105
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();
113     void Reset();
114     void ClearGridIndex(void);
115
116     GridItemsPtr *GetItem(const int &channel);
117     GridItemsPtr *GetNextItem(const int &channel);
118     GridItemsPtr *GetPrevItem(const int &channel);
119     GridItemsPtr *GetClosestItem(const int &channel);
120
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);
127
128     CGUIListItemLayout *GetFocusedLayout() const;
129
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();
136
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();
142     void RenderRuler();
143     void RenderProgrammeGrid();
144     void RenderProgressIndicator();
145
146     CPoint m_renderOffset; ///< \brief render offset of the first item in the list \sa SetRenderOffset
147
148     ORIENTATION m_orientation;
149
150     struct ItemsPtr
151     {
152       long start;
153       long stop;
154     };
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;
160
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;
166
167     CGUIListItemLayout *m_channelLayout;
168     CGUIListItemLayout *m_focusedChannelLayout;
169     CGUIListItemLayout *m_programmeLayout;
170     CGUIListItemLayout *m_focusedProgrammeLayout;
171     CGUIListItemLayout *m_rulerLayout;
172
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
176                       // changing around)
177
178     void FreeChannelMemory(int keepStart, int keepEnd);
179     void FreeProgrammeMemory(int channel, int keepStart, int keepEnd);
180     void FreeRulerMemory(int keepStart, int keepEnd);
181
182     void GetChannelCacheOffsets(int &cacheBefore, int &cacheAfter);
183     void GetProgrammeCacheOffsets(int &cacheBefore, int &cacheAfter);
184
185   private:
186     int   m_rulerUnit; //! number of blocks that makes up one element of the ruler
187     int   m_channels;
188     int   m_channelsPerPage;
189     int   m_ProgrammesPerPage;
190     int   m_channelCursor;
191     int   m_channelOffset;
192     int   m_blocks;
193     int   m_blocksPerPage;
194     int   m_blockCursor;
195     int   m_blockOffset;
196     int   m_cacheChannelItems;
197     int   m_cacheProgrammeItems;
198     int   m_cacheRulerItems;
199
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
210     float m_gridWidth;
211     float m_gridHeight;
212     float m_blockSize;      //! a block's width in pixels
213     float m_analogScrollCount;
214
215     CDateTime m_gridStart;
216     CDateTime m_gridEnd;
217
218     CGUITexture m_guiProgressIndicatorTexture;
219
220     std::vector<std::vector<GridItemsPtr> > m_gridIndex;
221     GridItemsPtr *m_item;
222     CGUIListItem *m_lastItem;
223     CGUIListItem *m_lastChannel;
224
225     int   m_scrollTime;
226     bool  m_gridWrapAround; //! only when no more data available should this be true
227
228     int m_programmeScrollLastTime;
229     float m_programmeScrollSpeed;
230     float m_programmeScrollOffset;
231
232     int m_channelScrollLastTime;
233     float m_channelScrollSpeed;
234     float m_channelScrollOffset;
235
236     CStdString m_label;
237   };
238 }