xbmc
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  CGUIListItemPtr 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 CMouseEvent &event) override;
101  bool OnClick(int actionID);
102 
103  virtual void ProcessItem(float posX, float posY, CGUIListItemPtr& item, bool focused, unsigned int currentTime, CDirtyRegionList &dirtyregions);
104 
105  void Render() override;
106  virtual void RenderItem(float posX, float posY, CGUIListItem *item, bool focused);
107  virtual void Scroll(int amount);
108  virtual bool MoveDown(bool wrapAround);
109  virtual bool MoveUp(bool wrapAround);
110  virtual bool GetOffsetRange(int &minOffset, int &maxOffset) const;
111  virtual void ValidateOffset();
112  virtual int CorrectOffset(int offset, int cursor) const;
113  virtual void UpdateLayout(bool refreshAllItems = false);
114  virtual void SetPageControlRange();
115  virtual void UpdatePageControl(int offset);
116  virtual void CalculateLayout();
117  virtual void SelectItem(int item) {}
118  virtual bool SelectItemFromPoint(const CPoint& point) { return false; }
119  virtual int GetCursorFromPoint(const CPoint& point, CPoint* itemPoint = NULL) const { return -1; }
120  virtual void Reset();
121  virtual size_t GetNumItems() const { return m_items.size(); }
122  virtual int GetCurrentPage() const;
123  bool InsideLayout(const CGUIListItemLayout *layout, const CPoint &point) const;
124  void OnFocus() override;
125  void OnUnFocus() override;
126  void UpdateListProvider(bool forceRefresh = false);
127 
128  int ScrollCorrectionRange() const;
129  inline float Size() const;
130  void FreeMemory(int keepStart, int keepEnd);
131  void GetCurrentLayouts();
132  CGUIListItemLayout *GetFocusedLayout() const;
133 
135 
136  float m_analogScrollCount;
137  unsigned int m_lastHoldTime;
138 
139  ORIENTATION m_orientation;
140  int m_itemsPerPage;
141 
142  std::vector< CGUIListItemPtr > m_items;
143  typedef std::vector<CGUIListItemPtr> ::iterator iItems;
144  CGUIListItemPtr m_lastItem;
145 
146  int m_pageControl;
147 
148  std::list<CGUIListItemLayout> m_layouts;
149  std::list<CGUIListItemLayout> m_focusedLayouts;
150 
151  CGUIListItemLayout* m_layout{nullptr};
152  CGUIListItemLayout* m_focusedLayout{nullptr};
153  bool m_layoutCondition = false;
154  bool m_focusedLayoutCondition = false;
155 
156  void ScrollToOffset(int offset);
157  void SetContainerMoving(int direction);
158  void UpdateScrollOffset(unsigned int currentTime);
159 
160  CScroller m_scroller;
161 
162  std::unique_ptr<IListProvider> m_listProvider;
163 
164  bool m_wasReset; // true if we've received a Reset message until we've rendered once. Allows
165  // us to make sure we don't tell the infomanager that we've been moving when
166  // the "movement" was simply due to the list being repopulated (thus cursor position
167  // changing around)
168 
169  void UpdateScrollByLetter();
170  void GetCacheOffsets(int &cacheBefore, int &cacheAfter) const;
171  int GetCacheCount() const { return m_cacheItems; }
172  bool ScrollingDown() const { return m_scroller.IsScrollingDown(); }
173  bool ScrollingUp() const { return m_scroller.IsScrollingUp(); }
174  void OnNextLetter();
175  void OnPrevLetter();
176  void OnJumpLetter(const std::string& letter, bool skip = false);
177  void OnJumpSMS(int letter);
178  std::vector< std::pair<int, std::string> > m_letterOffsets;
179 
184  virtual void SetCursor(int cursor);
185  inline int GetCursor() const { return m_cursor; }
186 
191  void SetOffset(int offset);
196  inline int GetOffset() const { return m_offset; }
201  inline int GetItemOffset() const { return CorrectOffset(GetOffset(), 0); }
202 
203  // autoscrolling
204  INFO::InfoPtr m_autoScrollCondition;
205  int m_autoScrollMoveTime; // time between to moves
206  unsigned int m_autoScrollDelayTime; // current offset into the delay
207  bool m_autoScrollIsReversed; // scroll backwards
208 
209  unsigned int m_lastRenderTime;
210 
211 private:
212  bool OnContextMenu();
213 
214  int m_cursor;
215  int m_offset;
216  int m_cacheItems;
217  CStopWatch m_scrollTimer;
218  CStopWatch m_lastScrollStartTimer;
219  CStopWatch m_pageChangeTimer;
220 
221  CGUIAction m_clickActions;
222  CGUIAction m_focusActions;
223  CGUIAction m_unfocusActions;
224 
225  // letter match searching
226  CStopWatch m_matchTimer;
227  std::string m_match;
228  float m_scrollItemsPerFrame;
229  static const int letter_match_timeout = 1000;
230 
231  bool m_gestureActive = false;
232 
233  // early inertial scroll cancellation
234  bool m_waitForScrollEnd = false;
235  float m_lastScrollValue = 0.0f;
236 };
237 
238 
bool OnMouseOver(const CPoint &point) override
Called when the mouse is over the control. Default implementation selects the control.
Definition: GUIBaseContainer.cpp:758
Definition: Stopwatch.h:14
An interface for providing lists to UI containers.
Definition: IListProvider.h:22
virtual void SetCursor(int cursor)
Set the cursor position Should be used by all base classes rather than directly setting it...
Definition: GUIBaseContainer.cpp:1466
Definition: GUIListItem.h:30
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:196
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:1281
void SetOffset(int offset)
Set the container offset Should be used by all base classes rather than directly setting it...
Definition: GUIBaseContainer.cpp:1473
Definition: GUIBaseContainer.h:34
EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event) override
Perform a mouse action.
Definition: GUIBaseContainer.cpp:766
Definition: GUIListItemLayout.h:20
Definition: IGUIContainer.h:22
CPoint m_renderOffset
render offset of the first item in the list
Definition: GUIBaseContainer.h:134
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:60
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
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:201
Definition: GUIMessage.h:365
void SetListProvider(std::unique_ptr< IListProvider > provider)
Set the list provider for this container (for python).
Definition: GUIBaseContainer.cpp:1275
Simple class for mouse events.
Definition: Key.h:114
Class containing vector of condition->(action/navigation route) and handling its execution.
Definition: GUIAction.h:21