summaryrefslogtreecommitdiffstats
path: root/xbmc/guilib/GUIControlGroup.h
blob: 5f4a7613741d147a5cdd1de9b99fca0972f29338 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

/*!
\file GUIControlGroup.h
\brief
*/

#include "GUIControlLookup.h"

#include <vector>

/*!
 \ingroup controls
 \brief group of controls, useful for remembering last control + animating/hiding together
 */
class CGUIControlGroup : public CGUIControlLookup
{
public:
  CGUIControlGroup();
  CGUIControlGroup(int parentID, int controlID, float posX, float posY, float width, float height);
  explicit CGUIControlGroup(const CGUIControlGroup& from);
  ~CGUIControlGroup(void) override;
  CGUIControlGroup* Clone() const override { return new CGUIControlGroup(*this); }

  void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions) override;
  void Render() override;
  void RenderEx() override;
  bool OnAction(const CAction &action) override;
  bool OnMessage(CGUIMessage& message) override;
  virtual bool SendControlMessage(CGUIMessage& message);
  bool HasFocus() const override;
  void AllocResources() override;
  void FreeResources(bool immediately = false) override;
  void DynamicResourceAlloc(bool bOnOff) override;
  bool CanFocus() const override;

  EVENT_RESULT SendMouseEvent(const CPoint &point, const CMouseEvent &event) override;
  void UnfocusFromPoint(const CPoint &point) override;

  void SetInitialVisibility() override;

  bool IsAnimating(ANIMATION_TYPE anim) override;
  bool HasAnimation(ANIMATION_TYPE anim) override;
  void QueueAnimation(ANIMATION_TYPE anim) override;
  void ResetAnimation(ANIMATION_TYPE anim) override;
  void ResetAnimations() override;

  int GetFocusedControlID() const;
  CGUIControl *GetFocusedControl() const;
  virtual CGUIControl *GetFirstFocusableControl(int id);

  virtual void AddControl(CGUIControl *control, int position = -1);
  bool InsertControl(CGUIControl *control, const CGUIControl *insertPoint);
  virtual bool RemoveControl(const CGUIControl *control);
  virtual void ClearAll();
  void SetDefaultControl(int id, bool always)
  {
    m_defaultControl = id;
    m_defaultAlways = always;
  }
  void SetRenderFocusedLast(bool renderLast) { m_renderFocusedLast = renderLast; }

  void SaveStates(std::vector<CControlState> &states) override;

  bool IsGroup() const override { return true; }

#ifdef _DEBUG
  void DumpTextureUse() override;
#endif
protected:
  // sub controls
  std::vector<CGUIControl *> m_children;

  typedef std::vector<CGUIControl *>::iterator iControls;
  typedef std::vector<CGUIControl *>::const_iterator ciControls;
  typedef std::vector<CGUIControl *>::reverse_iterator rControls;
  typedef std::vector<CGUIControl *>::const_reverse_iterator crControls;

  int  m_defaultControl;
  bool m_defaultAlways;
  int m_focusedControl;
  bool m_renderFocusedLast;
private:
  typedef std::vector< std::vector<CGUIControl *> * > COLLECTORTYPE;

  struct IDCollectorList
  {
    ~IDCollectorList()
    {
      for (auto item : m_items)
        delete item;
    }

    std::vector<CGUIControl *> *Get() {
      if (++m_stackDepth > m_items.size())
        m_items.push_back(new std::vector<CGUIControl *>());
      return m_items[m_stackDepth - 1];
    }

    void Release() { --m_stackDepth; }

    COLLECTORTYPE m_items;
    size_t m_stackDepth = 0;
  }m_idCollector;

  struct IDCollector
  {
    explicit IDCollector(IDCollectorList& list) : m_list(list), m_collector(list.Get()) {}

    ~IDCollector() { m_list.Release(); }

    IDCollectorList &m_list;
    std::vector<CGUIControl *> *m_collector;
  };
};