[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / epg / GUIEPGGridContainer.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2012-2013 Team XBMC
5  *      http://www.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/GUIBaseContainer.h"
28
29 namespace PVR
30 {
31   class CGUIWindowPVRGuide;
32 }
33
34 namespace EPG
35 {
36   #define MAXCHANNELS 20
37   #define MAXBLOCKS   2304 //! !!_EIGHT_!! days of 5 minute blocks
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);
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 SetStartEnd(CDateTime start, CDateTime end);
96     void SetChannel(const PVR::CPVRChannel &channel);
97     void SetChannel(const CStdString &channel);
98
99   protected:
100     bool OnClick(int actionID);
101     bool SelectItemFromPoint(const CPoint &point);
102
103     void UpdateItems();
104
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();
112     void Reset();
113     void ClearGridIndex(void);
114
115     GridItemsPtr *GetItem(const int &channel);
116     GridItemsPtr *GetNextItem(const int &channel);
117     GridItemsPtr *GetPrevItem(const int &channel);
118     GridItemsPtr *GetClosestItem(const int &channel);
119
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);
126
127     CGUIListItemLayout *GetFocusedLayout() const;
128
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();
135
136     CPoint m_renderOffset; ///< \brief render offset of the first item in the list \sa SetRenderOffset
137
138     ORIENTATION m_orientation;
139
140     struct ItemsPtr
141     {
142       long start;
143       long stop;
144     };
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;
150
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;
156
157     CGUIListItemLayout *m_channelLayout;
158     CGUIListItemLayout *m_focusedChannelLayout;
159     CGUIListItemLayout *m_programmeLayout;
160     CGUIListItemLayout *m_focusedProgrammeLayout;
161     CGUIListItemLayout *m_rulerLayout;
162
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
166                       // changing around)
167
168     void FreeChannelMemory(int keepStart, int keepEnd);
169     void FreeProgrammeMemory(int keepStart, int keepEnd);
170     void FreeRulerMemory(int keepStart, int keepEnd);
171
172     void GetChannelCacheOffsets(int &cacheBefore, int &cacheAfter);
173     void GetProgrammeCacheOffsets(int &cacheBefore, int &cacheAfter);
174     void GetRulerCacheOffsets(int &cacheBefore, int &cacheAfter);
175
176   private:
177     int   m_rulerUnit; //! number of blocks that makes up one element of the ruler
178     int   m_channels;
179     int   m_channelsPerPage;
180     int   m_ProgrammesPerPage;
181     int   m_channelCursor;
182     int   m_channelOffset;
183     int   m_blocks;
184     int   m_blocksPerPage;
185     int   m_blockCursor;
186     int   m_blockOffset;
187     int   m_cacheChannelItems;
188     int   m_cacheProgrammeItems;
189     int   m_cacheRulerItems;
190
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
201     float m_gridWidth;
202     float m_gridHeight;
203     float m_blockSize;      //! a block's width in pixels
204     float m_analogScrollCount;
205
206     CDateTime m_gridStart;
207     CDateTime m_gridEnd;
208
209     struct GridItemsPtr **m_gridIndex;
210     GridItemsPtr *m_item;
211     CGUIListItem *m_lastItem;
212     CGUIListItem *m_lastChannel;
213
214     unsigned int m_renderTime;
215
216     int   m_scrollTime;
217     bool  m_gridWrapAround; //! only when no more data available should this be true
218
219     int m_programmeScrollLastTime;
220     float m_programmeScrollSpeed;
221     float m_programmeScrollOffset;
222
223     int m_channelScrollLastTime;
224     float m_channelScrollSpeed;
225     float m_channelScrollOffset;
226
227     CStdString m_label;
228   };
229 }