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