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  GUICONTROL_BUTTON,
261  GUICONTROL_FADELABEL,
262  GUICONTROL_IMAGE,
263  GUICONTROL_BORDEREDIMAGE,
264  GUICONTROL_LABEL,
265  GUICONTROL_LISTGROUP,
266  GUICONTROL_PROGRESS,
267  GUICONTROL_RADIO,
268  GUICONTROL_RSS,
269  GUICONTROL_SLIDER,
270  GUICONTROL_SETTINGS_SLIDER,
271  GUICONTROL_SPIN,
272  GUICONTROL_SPINEX,
273  GUICONTROL_TEXTBOX,
274  GUICONTROL_TOGGLEBUTTON,
275  GUICONTROL_VIDEO,
276  GUICONTROL_GAME,
277  GUICONTROL_MOVER,
278  GUICONTROL_RESIZE,
279  GUICONTROL_EDIT,
280  GUICONTROL_VISUALISATION,
281  GUICONTROL_RENDERADDON,
282  GUICONTROL_MULTI_IMAGE,
283  GUICONTROL_GROUP,
284  GUICONTROL_GROUPLIST,
285  GUICONTROL_SCROLLBAR,
286  GUICONTROL_LISTLABEL,
287  GUICONTROL_GAMECONTROLLER,
288  GUICONTAINER_LIST,
289  GUICONTAINER_WRAPLIST,
290  GUICONTAINER_FIXEDLIST,
291  GUICONTAINER_EPGGRID,
292  GUICONTAINER_PANEL,
293  GUICONTROL_RANGES,
294  GUICONTROL_COLORBUTTON
295  };
296  GUICONTROLTYPES GetControlType() const { return ControlType; }
297 
298  enum GUIVISIBLE { HIDDEN = 0, DELAYED, VISIBLE };
299 
300  enum GUISCROLLVALUE { FOCUS = 0, NEVER, ALWAYS };
301 
302 #ifdef _DEBUG
303  virtual void DumpTextureUse() {}
304 #endif
305 protected:
310  virtual CPoint GetPosition() const { return CPoint(GetXPosition(), GetYPosition()); }
311 
317  virtual bool OnMouseOver(const CPoint &point);
318 
324  virtual bool CanFocusFromPoint(const CPoint &point) const;
325 
326  virtual bool UpdateColors(const CGUIListItem* item);
327  virtual bool Animate(unsigned int currentTime);
328  virtual bool CheckAnimation(ANIMATION_TYPE animType);
329  void UpdateStates(ANIMATION_TYPE type, ANIMATION_PROCESS currentProcess, ANIMATION_STATE currentState);
330  bool SendWindowMessage(CGUIMessage &message) const;
331 
332  // navigation and actions
333  ActionMap m_actions;
334 
335  float m_posX;
336  float m_posY;
337  float m_height;
338  float m_width;
339  CRect m_hitRect;
340  UTILS::COLOR::Color m_hitColor = 0xffffffff;
342  int m_controlID;
343  int m_parentID;
344  bool m_bHasFocus;
345  bool m_bInvalidated;
346  bool m_bAllocated;
347  bool m_pulseOnSelect;
348  GUICONTROLTYPES ControlType;
349  GUICONTROLSTATS *m_controlStats;
350 
351  CGUIControl *m_parentControl; // our parent control if we're part of a group
352 
353  // visibility condition/state
354  INFO::InfoPtr m_visibleCondition;
355  GUIVISIBLE m_visible;
356  bool m_visibleFromSkinCondition;
357  bool m_forceHidden; // set from the code when a hidden operation is given - overrides m_visible
358  KODI::GUILIB::GUIINFO::CGUIInfoBool m_allowHiddenFocus;
359  bool m_hasProcessed;
360  // enable/disable state
361  INFO::InfoPtr m_enableCondition;
362  bool m_enabled;
363 
364  bool m_pushedUpdates;
365 
366  // animation effects
367  std::vector<CAnimation> m_animations;
368  CPoint m_camera;
369  bool m_hasCamera;
370  float m_stereo;
371  TransformMatrix m_transform;
372  TransformMatrix m_cachedTransform; // Contains the absolute transform the control
373  bool m_isCulled{true};
374 
375  static const unsigned int DIRTY_STATE_CONTROL = 1; //This control is dirty
376  static const unsigned int DIRTY_STATE_CHILD = 2; //One / more children are dirty
377 
378  unsigned int m_controlDirtyState;
379  CRect m_renderRegion; // In screen coordinates
380 };
381 
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:310
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