| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
class IListProvider; |
| 31 |
class TiXmlNode; |
| 32 |
class CGUIListItemLayout; |
| 33 |
|
| 34 |
class CGUIBaseContainer : public IGUIContainer |
| 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 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
void SetListProvider(std::unique_ptr<IListProvider> provider); |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 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 |
|
| 139 |
CPoint m_renderOffset; |
| 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; |
| 170 |
|
| 171 |
|
| 172 |
|
| 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 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
virtual void SetCursor(int cursor); |
| 190 |
inline int GetCursor() const { return m_cursor; } |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
void SetOffset(int offset); |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
inline int GetOffset() const { return m_offset; } |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
inline int GetItemOffset() const { return CorrectOffset(GetOffset(), 0); } |
| 207 |
|
| 208 |
|
| 209 |
INFO::InfoPtr m_autoScrollCondition; |
| 210 |
int m_autoScrollMoveTime; |
| 211 |
unsigned int m_autoScrollDelayTime; |
| 212 |
bool m_autoScrollIsReversed; |
| 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 |
|
| 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 |
|
| 239 |
bool m_waitForScrollEnd = false; |
| 240 |
float m_lastScrollValue = 0.0f; |
| 241 |
}; |
| 242 |
|
| 243 |
|