kodi
GUIControl.h
Go to the documentation of this file.
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 "DirtyRegion.h"
17 #include "VisibleEffect.h" // needed for the CAnimation members
18 #include "guiinfo/GUIInfoBool.h"
19 #include "guiinfo/GUIInfoColor.h" // needed for CGUIInfoColor to handle infolabel'ed colors
20 #include "utils/ColorUtils.h"
21 #include "windowing/GraphicContext.h" // needed by any rendering operation (all controls)
22 
23 #include <vector>
24 
25 class CGUIListItem; // forward
26 class CAction;
27 
28 class CGUIMessage;
29 class CGUIAction;
30 
31 namespace KODI
32 {
33 namespace MOUSE
34 {
35 class CMouseEvent;
36 } // namespace MOUSE
37 } // namespace KODI
38 
39 enum ORIENTATION { HORIZONTAL = 0, VERTICAL };
40 
42 {
43 public:
44  CControlState(int id, int data)
45  {
46  m_id = id;
47  m_data = data;
48  }
49  int m_id;
50  int m_data;
51 };
52 
54 {
55  unsigned int nCountTotal;
56  unsigned int nCountVisible;
57 
58  void Reset()
59  {
60  nCountTotal = nCountVisible = 0;
61  };
62 };
63 
68 enum EVENT_RESULT { EVENT_RESULT_UNHANDLED = 0x00,
69  EVENT_RESULT_HANDLED = 0x01,
70  EVENT_RESULT_PAN_HORIZONTAL = 0x02,
71  EVENT_RESULT_PAN_VERTICAL = 0x04,
72  EVENT_RESULT_PAN_VERTICAL_WITHOUT_INERTIA = 0x08,
73  EVENT_RESULT_PAN_HORIZONTAL_WITHOUT_INERTIA = 0x10,
74  EVENT_RESULT_ROTATE = 0x20,
75  EVENT_RESULT_ZOOM = 0x40,
76  EVENT_RESULT_SWIPE = 0x80
77 };
78 
84 {
85 public:
86  CGUIControl();
87  CGUIControl(int parentID, int controlID, float posX, float posY, float width, float height);
88  CGUIControl(const CGUIControl &);
89  virtual ~CGUIControl(void);
90  virtual CGUIControl *Clone() const=0;
91 
92  virtual void DoProcess(unsigned int currentTime, CDirtyRegionList &dirtyregions);
93  virtual void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions);
94  virtual void DoRender();
95  virtual void Render() {}
96  // Called after the actual rendering is completed to trigger additional
97  // non GUI rendering operations
98  virtual void RenderEx() {}
99 
101  bool HasProcessed() const { return m_hasProcessed; }
102 
103  // OnAction() is called by our window when we are the focused control.
104  // We should process any control-specific actions in the derived classes,
105  // and return true if we have taken care of the action. Returning false
106  // indicates that the message may be handed down to the window or application
107  // levels. This base class implementation handles basic movement, and should
108  // be called from the derived classes when the action has not been handled.
109  // Return true to indicate that the action has been dealt with.
110  virtual bool OnAction(const CAction &action);
111 
112  // Common actions to make the code easier to read (no ugly switch statements in derived controls)
113  virtual void OnUp();
114  virtual void OnDown();
115  virtual void OnLeft();
116  virtual void OnRight();
117  virtual bool OnBack();
118  virtual bool OnInfo();
119  virtual void OnNextControl();
120  virtual void OnPrevControl();
121  virtual void OnFocus() {}
122  virtual void OnUnFocus() {}
123 
134  virtual EVENT_RESULT SendMouseEvent(const CPoint& point, const KODI::MOUSE::CMouseEvent& event);
135 
146  virtual EVENT_RESULT OnMouseEvent(const CPoint& point, const KODI::MOUSE::CMouseEvent& event)
147  {
148  return EVENT_RESULT_UNHANDLED;
149  }
150 
155  virtual void UnfocusFromPoint(const CPoint &point);
156 
162  virtual bool HitTest(const CPoint &point) const;
163 
164  virtual bool OnMessage(CGUIMessage& message);
165  virtual int GetID(void) const;
166  virtual void SetID(int id) { m_controlID = id; }
167  int GetParentID() const;
168  virtual bool HasFocus() const;
169  virtual void AllocResources();
170  virtual void FreeResources(bool immediately = false);
171  virtual void DynamicResourceAlloc(bool bOnOff);
172  virtual bool IsDynamicallyAllocated() { return false; }
173  virtual bool CanFocus() const;
174  virtual bool IsVisible() const;
175  bool IsVisibleFromSkin() const { return m_visibleFromSkinCondition; }
176  virtual bool IsDisabled() const;
177  virtual void SetPosition(float posX, float posY);
178  virtual void SetHitRect(const CRect& rect, const UTILS::COLOR::Color& color);
179  virtual void SetCamera(const CPoint &camera);
180  virtual void SetStereoFactor(const float &factor);
181  bool SetColorDiffuse(const KODI::GUILIB::GUIINFO::CGUIInfoColor &color);
182  CPoint GetRenderPosition() const;
183  virtual float GetXPosition() const;
184  virtual float GetYPosition() const;
185  virtual float GetWidth() const;
186  virtual float GetHeight() const;
187 
188  void MarkDirtyRegion(const unsigned int dirtyState = DIRTY_STATE_CONTROL);
189  bool IsControlDirty() const { return m_controlDirtyState != 0; }
190 
193  const CRect& GetRenderRegion() const { return m_renderRegion; }
197  virtual CRect CalcRenderRegion() const;
198 
203  typedef std::map<int, CGUIAction> ActionMap;
204  void SetActions(const ActionMap &actions);
205 
213  void SetAction(int actionID, const CGUIAction &action, bool replace = true);
214 
218  CGUIAction GetAction(int actionID) const;
219 
222  bool Navigate(int direction) const;
223  virtual void SetFocus(bool focus);
224  virtual void SetWidth(float width);
225  virtual void SetHeight(float height);
226  virtual void SetVisible(bool bVisible, bool setVisState = false);
227  void SetVisibleCondition(const std::string &expression, const std::string &allowHiddenFocus = "");
228  bool HasVisibleCondition() const { return m_visibleCondition != NULL; }
229  void SetEnableCondition(const std::string &expression);
230  virtual void UpdateVisibility(const CGUIListItem *item);
231  virtual void SetInitialVisibility();
232  virtual void SetEnabled(bool bEnable);
233  virtual void SetInvalid() { m_bInvalidated = true; }
234  virtual void SetPulseOnSelect(bool pulse) { m_pulseOnSelect = pulse; }
235  virtual std::string GetDescription() const { return ""; }
236  virtual std::string GetDescriptionByIndex(int index) const { return ""; }
237 
238  void SetAnimations(const std::vector<CAnimation> &animations);
239  const std::vector<CAnimation>& GetAnimations() const { return m_animations; }
240 
241  virtual void QueueAnimation(ANIMATION_TYPE anim);
242  virtual bool IsAnimating(ANIMATION_TYPE anim);
243  virtual bool HasAnimation(ANIMATION_TYPE anim);
244  CAnimation *GetAnimation(ANIMATION_TYPE type, bool checkConditions = true);
245  virtual void ResetAnimation(ANIMATION_TYPE type);
246  virtual void ResetAnimations();
247 
248  // push information updates
249  virtual void UpdateInfo(const CGUIListItem* item = NULL) {}
250  virtual void SetPushUpdates(bool pushUpdates) { m_pushedUpdates = pushUpdates; }
251 
252  virtual bool IsGroup() const { return false; }
253  virtual bool IsContainer() const { return false; }
254  virtual bool GetCondition(int condition, int data) const { return false; }
255 
256  void SetParentControl(CGUIControl* control) { m_parentControl = control; }
257  CGUIControl* GetParentControl(void) const { return m_parentControl; }
258  virtual void SaveStates(std::vector<CControlState> &states);
259  virtual CGUIControl *GetControl(int id, std::vector<CGUIControl*> *idCollector = nullptr);
260 
261 
262  void SetControlStats(GUICONTROLSTATS* controlStats) { m_controlStats = controlStats; }
263  virtual void UpdateControlStats();
264 
265  enum GUICONTROLTYPES
266  {
267  GUICONTROL_UNKNOWN,
268 
269  // Keep sorted
270  GUICONTAINER_EPGGRID,
271  GUICONTAINER_FIXEDLIST,
272  GUICONTAINER_LIST,
273  GUICONTAINER_PANEL,
274  GUICONTAINER_WRAPLIST,
275  GUICONTROL_BORDEREDIMAGE,
276  GUICONTROL_BUTTON,
277  GUICONTROL_COLORBUTTON,
278  GUICONTROL_EDIT,
279  GUICONTROL_FADELABEL,
280  GUICONTROL_GAME,
281  GUICONTROL_GAMECONTROLLER,
282  GUICONTROL_GAMECONTROLLERLIST,
283  GUICONTROL_GROUP,
284  GUICONTROL_GROUPLIST,
285  GUICONTROL_IMAGE,
286  GUICONTROL_LABEL,
287  GUICONTROL_LISTGROUP,
288  GUICONTROL_LISTLABEL,
289  GUICONTROL_MOVER,
290  GUICONTROL_MULTI_IMAGE,
291  GUICONTROL_PROGRESS,
292  GUICONTROL_RADIO,
293  GUICONTROL_RANGES,
294  GUICONTROL_RENDERADDON,
295  GUICONTROL_RESIZE,
296  GUICONTROL_RSS,
297  GUICONTROL_SCROLLBAR,
298  GUICONTROL_SETTINGS_SLIDER,
299  GUICONTROL_SLIDER,
300  GUICONTROL_SPIN,
301  GUICONTROL_SPINEX,
302  GUICONTROL_TEXTBOX,
303  GUICONTROL_TOGGLEBUTTON,
304  GUICONTROL_VIDEO,
305  GUICONTROL_VISUALISATION,
306  };
307  GUICONTROLTYPES GetControlType() const { return ControlType; }
308 
312  bool IsControlRenderable();
313 
314  enum GUIVISIBLE { HIDDEN = 0, DELAYED, VISIBLE };
315 
316  enum GUISCROLLVALUE { FOCUS = 0, NEVER, ALWAYS };
317 
318 #ifdef _DEBUG
319  virtual void DumpTextureUse() {}
320 #endif
321 protected:
326  virtual CPoint GetPosition() const { return CPoint(GetXPosition(), GetYPosition()); }
327 
333  virtual bool OnMouseOver(const CPoint &point);
334 
340  virtual bool CanFocusFromPoint(const CPoint &point) const;
341 
342  virtual bool UpdateColors(const CGUIListItem* item);
343  virtual bool Animate(unsigned int currentTime);
344  virtual bool CheckAnimation(ANIMATION_TYPE animType);
345  void UpdateStates(ANIMATION_TYPE type, ANIMATION_PROCESS currentProcess, ANIMATION_STATE currentState);
346  bool SendWindowMessage(CGUIMessage &message) const;
347 
348  // navigation and actions
349  ActionMap m_actions;
350 
351  float m_posX;
352  float m_posY;
353  float m_height;
354  float m_width;
355  CRect m_hitRect;
356  UTILS::COLOR::Color m_hitColor = 0xffffffff;
358  int m_controlID;
359  int m_parentID;
360  bool m_bHasFocus;
361  bool m_bInvalidated;
362  bool m_bAllocated;
363  bool m_pulseOnSelect;
364  GUICONTROLTYPES ControlType;
365  GUICONTROLSTATS *m_controlStats;
366 
367  CGUIControl *m_parentControl; // our parent control if we're part of a group
368 
369  // visibility condition/state
370  INFO::InfoPtr m_visibleCondition;
371  GUIVISIBLE m_visible;
372  bool m_visibleFromSkinCondition;
373  bool m_forceHidden; // set from the code when a hidden operation is given - overrides m_visible
374  KODI::GUILIB::GUIINFO::CGUIInfoBool m_allowHiddenFocus;
375  bool m_hasProcessed;
376  // enable/disable state
377  INFO::InfoPtr m_enableCondition;
378  bool m_enabled;
379 
380  bool m_pushedUpdates;
381 
382  // animation effects
383  std::vector<CAnimation> m_animations;
384  CPoint m_camera;
385  bool m_hasCamera;
386  float m_stereo;
387  TransformMatrix m_transform;
388  TransformMatrix m_cachedTransform; // Contains the absolute transform the control
389  bool m_isCulled{true};
390 
391  static const unsigned int DIRTY_STATE_CONTROL = 1; //This control is dirty
392  static const unsigned int DIRTY_STATE_CHILD = 2; //One / more children are dirty
393 
394  unsigned int m_controlDirtyState;
395  CRect m_renderRegion; // In screen coordinates
396 };
397 
Definition: GUIControl.h:53
Definition: GUIInfoBool.h:29
std::map< int, CGUIAction > ActionMap
Set actions to perform on navigation.
Definition: GUIControl.h:203
Definition: GUIListItem.h:29
virtual CPoint GetPosition() const
Return the coordinates of the top left of the control, in the control&#39;s parent coordinates.
Definition: GUIControl.h:326
bool HasProcessed() const
Returns whether or not we have processed.
Definition: GUIControl.h:101
Definition: VisibleEffect.h:151
const CRect & GetRenderRegion() const
return the render region in screen coordinates of this control
Definition: GUIControl.h:193
Base class for controls.
Definition: GUIControl.h:83
EVENT_RESULT
Results of OnMouseEvent() Any value not equal to EVENT_RESULT_UNHANDLED indicates that the event was ...
Definition: GUIControl.h:68
Class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:21
Definition: TransformMatrix.h:25
Definition: AudioDecoder.h:18
Definition: GUIMessage.h:365
virtual EVENT_RESULT OnMouseEvent(const CPoint &point, const KODI::MOUSE::CMouseEvent &event)
Perform a mouse action.
Definition: GUIControl.h:146
Definition: GUIControl.h:41
Definition: actions.py:1
Definition: GUIInfoColor.h:30
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