kodi
GUIBaseContainer.h
1 /*
2  * Copyright (C) 2005-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 
16 #include "GUIAction.h"
17 #include "IGUIContainer.h"
18 #include "utils/Stopwatch.h"
19 
20 #include <list>
21 #include <memory>
22 #include <utility>
23 #include <vector>
24 
30 class IListProvider;
31 class TiXmlNode;
32 class CGUIListItemLayout;
33 
35 {
36 public:
37  CGUIBaseContainer(int parentID, int controlID, float posX, float posY, float width, float height, ORIENTATION orientation, const CScroller& scroller, int preloadItems);
38  explicit CGUIBaseContainer(const CGUIBaseContainer& other);
39  ~CGUIBaseContainer(void) override;
40 
41  bool OnAction(const CAction &action) override;
42  void OnDown() override;
43  void OnUp() override;
44  void OnLeft() override;
45  void OnRight() override;
46  bool OnMouseOver(const CPoint &point) override;
47  bool CanFocus() const override;
48  bool OnMessage(CGUIMessage& message) override;
49  void SetFocus(bool bOnOff) override;
50  void AllocResources() override;
51  void FreeResources(bool immediately = false) override;
52  void UpdateVisibility(const CGUIListItem *item = NULL) override;
53 
54  virtual unsigned int GetRows() const;
55 
56  virtual bool HasNextPage() const;
57  virtual bool HasPreviousPage() const;
58 
59  void SetPageControl(int id);
60 
61  std::string GetDescription() const override;
62  void SaveStates(std::vector<CControlState> &states) override;
63  virtual int GetSelectedItem() const;
64 
65  void DoProcess(unsigned int currentTime, CDirtyRegionList &dirtyregions) override;
66  void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions) override;
67 
68  void LoadLayout(TiXmlElement *layout);
69  void LoadListProvider(TiXmlElement *content, int defaultItem, bool defaultAlways);
70 
71  std::shared_ptr<CGUIListItem> GetListItem(int offset, unsigned int flag = 0) const override;
72 
73  bool GetCondition(int condition, int data) const override;
74  std::string GetLabel(int info) const override;
75 
79  void SetListProvider(std::unique_ptr<IListProvider> provider);
80 
86  void SetRenderOffset(const CPoint &offset);
87 
88  void SetClickActions(const CGUIAction& clickActions) { m_clickActions = clickActions; }
89  void SetFocusActions(const CGUIAction& focusActions) { m_focusActions = focusActions; }
90  void SetUnFocusActions(const CGUIAction& unfocusActions) { m_unfocusActions = unfocusActions; }
91 
92  void SetAutoScrolling(const TiXmlNode *node);
93  void ResetAutoScrolling();
94  void UpdateAutoScrolling(unsigned int currentTime);
95 
96 #ifdef _DEBUG
97  void DumpTextureUse() override;
98 #endif
99 protected:
100  EVENT_RESULT OnMouseEvent(const CPoint& point, const KODI::MOUSE::CMouseEvent& event) override;
101  bool OnClick(int actionID);
102 
103  virtual void ProcessItem(float posX,
104  float posY,
105  std::shared_ptr<CGUIListItem>& item,
106  bool focused,
107  unsigned int currentTime,
108  CDirtyRegionList& dirtyregions);
109 
110  void Render() override;
111  virtual void RenderItem(float posX, float posY, CGUIListItem *item, bool focused);
112  virtual void Scroll(int amount);
113  virtual bool MoveDown(bool wrapAround);
114  virtual bool MoveUp(bool wrapAround);
115  virtual bool GetOffsetRange(int &minOffset, int &maxOffset) const;
116  virtual void ValidateOffset();
117  virtual int CorrectOffset(int offset, int cursor) const;
118  virtual void UpdateLayout(bool refreshAllItems = false);
119  virtual void SetPageControlRange();
120  virtual void UpdatePageControl(int offset);
121  virtual void CalculateLayout();
122  virtual void SelectItem(int item) {}
123  virtual bool SelectItemFromPoint(const CPoint& point) { return false; }
124  virtual int GetCursorFromPoint(const CPoint& point, CPoint* itemPoint = NULL) const { return -1; }
125  virtual void Reset();
126  virtual size_t GetNumItems() const { return m_items.size(); }
127  virtual int GetCurrentPage() const;
128  bool InsideLayout(const CGUIListItemLayout *layout, const CPoint &point) const;
129  void OnFocus() override;
130  void OnUnFocus() override;
131  void UpdateListProvider(bool forceRefresh = false);
132 
133  int ScrollCorrectionRange() const;
134  inline float Size() const;
135  void FreeMemory(int keepStart, int keepEnd);
136  void GetCurrentLayouts();
137  CGUIListItemLayout *GetFocusedLayout() const;
138 
140 
141  float m_analogScrollCount;
142  unsigned int m_lastHoldTime;
143 
144  ORIENTATION m_orientation;
145  int m_itemsPerPage;
146 
147  std::vector<std::shared_ptr<CGUIListItem>> m_items;
148  typedef std::vector<std::shared_ptr<CGUIListItem>>::iterator iItems;
149  std::shared_ptr<CGUIListItem> m_lastItem;
150 
151  int m_pageControl;
152 
153  std::list<CGUIListItemLayout> m_layouts;
154  std::list<CGUIListItemLayout> m_focusedLayouts;
155 
156  CGUIListItemLayout* m_layout{nullptr};
157  CGUIListItemLayout* m_focusedLayout{nullptr};
158  bool m_layoutCondition = false;
159  bool m_focusedLayoutCondition = false;
160 
161  virtual void ScrollToOffset(int offset);
162  void SetContainerMoving(int direction);
163  void UpdateScrollOffset(unsigned int currentTime);
164 
165  CScroller m_scroller;
166 
167  std::unique_ptr<IListProvider> m_listProvider;
168 
169  bool m_wasReset; // true if we've received a Reset message until we've rendered once. Allows
170  // us to make sure we don't tell the infomanager that we've been moving when
171  // the "movement" was simply due to the list being repopulated (thus cursor position
172  // changing around)
173 
174  void UpdateScrollByLetter();
175  void GetCacheOffsets(int &cacheBefore, int &cacheAfter) const;
176  int GetCacheCount() const { return m_cacheItems; }
177  bool ScrollingDown() const { return m_scroller.IsScrollingDown(); }
178  bool ScrollingUp() const { return m_scroller.IsScrollingUp(); }
179  void OnNextLetter();
180  void OnPrevLetter();
181  void OnJumpLetter(const std::string& letter, bool skip = false);
182  void OnJumpSMS(int letter);
183  std::vector< std::pair<int, std::string> > m_letterOffsets;
184 
189  virtual void SetCursor(int cursor);
190  inline int GetCursor() const { return m_cursor; }
191 
196  void SetOffset(int offset);
201  inline int GetOffset() const { return m_offset; }
206  inline int GetItemOffset() const { return CorrectOffset(GetOffset(), 0); }
207 
208  // autoscrolling
209  INFO::InfoPtr m_autoScrollCondition;
210  int m_autoScrollMoveTime; // time between to moves
211  unsigned int m_autoScrollDelayTime; // current offset into the delay
212  bool m_autoScrollIsReversed; // scroll backwards
213 
214  unsigned int m_lastRenderTime;
215 
216 private:
217  bool OnContextMenu();
218 
219  int m_cursor;
220  int m_offset;
221  int m_cacheItems;
222  CStopWatch m_scrollTimer;
223  CStopWatch m_lastScrollStartTimer;
224  CStopWatch m_pageChangeTimer;
225 
226  CGUIAction m_clickActions;
227  CGUIAction m_focusActions;
228  CGUIAction m_unfocusActions;
229 
230  // letter match searching
231  CStopWatch m_matchTimer;
232  std::string m_match;
233  float m_scrollItemsPerFrame;
234  static const int letter_match_timeout = 1000;
235 
236  bool m_gestureActive = false;
237 
238  // early inertial scroll cancellation
239  bool m_waitForScrollEnd = false;
240  float m_lastScrollValue = 0.0f;
241 };
242 
243 
bool OnMouseOver(const CPoint &point) override
Called when the mouse is over the control. Default implementation selects the control.
Definition: GUIBaseContainer.cpp:771
Definition: Stopwatch.h:14
An interface for providing lists to UI containers.
Definition: IListProvider.h:21
virtual void SetCursor(int cursor)
Set the cursor position Should be used by all base classes rather than directly setting it...
Definition: GUIBaseContainer.cpp:1485
Definition: GUIListItem.h:29
int GetOffset() const
Returns the index of the first visible row returns the first row. This may be outside of the range of...
Definition: GUIBaseContainer.h:201
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: GUIBaseContainer.cpp:1300
void SetOffset(int offset)
Set the container offset Should be used by all base classes rather than directly setting it...
Definition: GUIBaseContainer.cpp:1492
Definition: GUIBaseContainer.h:34
Definition: GUIListItemLayout.h:20
Definition: IGUIContainer.h:20
CPoint m_renderOffset
render offset of the first item in the list
Definition: GUIBaseContainer.h:139
Class used to handle scrolling, allow using tweeners.
Definition: VisibleEffect.h:221
EVENT_RESULT
Results of OnMouseEvent() Any value not equal to EVENT_RESULT_UNHANDLED indicates that the event was ...
Definition: GUIControl.h:68
EVENT_RESULT OnMouseEvent(const CPoint &point, const KODI::MOUSE::CMouseEvent &event) override
Perform a mouse action.
Definition: GUIBaseContainer.cpp:779
Class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:21
int GetItemOffset() const
Returns the index of the first visible item returns the first visible item. This will always be in th...
Definition: GUIBaseContainer.h:206
Definition: GUIMessage.h:365
void SetListProvider(std::unique_ptr< IListProvider > provider)
Set the list provider for this container (for python).
Definition: GUIBaseContainer.cpp:1294
Simple class for mouse events.
Definition: MouseEvent.h:20
Class containing vector of condition->(action/navigation route) and handling its execution.
Definition: GUIAction.h:21