kodi
GUIButtonControl.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 "GUIAction.h"
17 #include "GUIControl.h"
18 #include "GUILabel.h"
19 #include "GUITexture.h"
21 #include "utils/ColorUtils.h"
22 
28 {
29 public:
30  CGUIButtonControl(int parentID, int controlID,
31  float posX, float posY, float width, float height,
32  const CTextureInfo& textureFocus, const CTextureInfo& textureNoFocus,
33  const CLabelInfo &label, bool wrapMultiline = false);
34 
35  CGUIButtonControl(const CGUIButtonControl& control);
36 
37  ~CGUIButtonControl() override = default;
38  CGUIButtonControl* Clone() const override { return new CGUIButtonControl(*this); }
39 
40  void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions) override;
41  void Render() override;
42  bool OnAction(const CAction &action) override ;
43  bool OnMessage(CGUIMessage& message) override;
44  void AllocResources() override;
45  void FreeResources(bool immediately = false) override;
46  void DynamicResourceAlloc(bool bOnOff) override;
47  void SetInvalid() override;
48  void SetPosition(float posX, float posY) override;
49  virtual void SetLabel(const std::string & aLabel);
50  virtual void SetLabel2(const std::string & aLabel2);
51  void SetClickActions(const CGUIAction& clickActions) { m_clickActions = clickActions; }
52  const CGUIAction& GetClickActions() const { return m_clickActions; }
53  void SetFocusActions(const CGUIAction& focusActions) { m_focusActions = focusActions; }
54  void SetUnFocusActions(const CGUIAction& unfocusActions) { m_unfocusActions = unfocusActions; }
55  const CLabelInfo& GetLabelInfo() const { return m_label.GetLabelInfo(); }
56  virtual std::string GetLabel() const { return GetDescription(); }
57  virtual std::string GetLabel2() const;
58  void SetSelected(bool bSelected);
59  std::string GetDescription() const override;
60  float GetWidth() const override;
61  virtual void SetMinWidth(float minWidth);
62  void SetAlpha(unsigned char alpha);
63 
64  void PythonSetLabel(const std::string& strFont,
65  const std::string& strText,
66  UTILS::COLOR::Color textColor,
67  UTILS::COLOR::Color shadowColor,
68  UTILS::COLOR::Color focusedColor);
69  void PythonSetDisabledColor(UTILS::COLOR::Color disabledColor);
70 
71  virtual void OnClick();
72  bool HasClickActions() const { return m_clickActions.HasActionsMeetingCondition(); }
73 
74  bool UpdateColors(const CGUIListItem* item) override;
75 
76  CRect CalcRenderRegion() const override;
77 
78 protected:
79  friend class CGUISpinControlEx;
80  EVENT_RESULT OnMouseEvent(const CPoint& point, const KODI::MOUSE::CMouseEvent& event) override;
81  void OnFocus() override;
82  void OnUnFocus() override;
83  virtual void ProcessText(unsigned int currentTime);
84  virtual void RenderText();
85  virtual CGUILabel::COLOR GetTextColor() const;
86 
90  void SetMaxWidth(float labelMaxWidth) { m_labelMaxWidth = labelMaxWidth; }
91 
92  std::unique_ptr<CGUITexture> m_imgFocus;
93  std::unique_ptr<CGUITexture> m_imgNoFocus;
94  unsigned int m_focusCounter;
95  unsigned char m_alpha;
96 
97  float m_minWidth;
98  float m_maxWidth;
99  float m_labelMaxWidth{0};
100 
103  CGUILabel m_label;
104  CGUILabel m_label2;
105 
106  CGUIAction m_clickActions;
107  CGUIAction m_focusActions;
108  CGUIAction m_unfocusActions;
109 
110  bool m_bSelected;
111 };
112 
bool HasActionsMeetingCondition() const
Check if there is any action that meet its condition.
Definition: GUIAction.cpp:136
Class for rendering text labels. Handles alignment and rendering of text within a control...
Definition: GUILabel.h:69
Definition: GUIListItem.h:29
Definition: GUIButtonControl.h:27
Definition: GUIInfoLabel.h:31
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
CRect CalcRenderRegion() const override
calculate the render region in parentcontrol coordinates of this control Called during process to upd...
Definition: GUIButtonControl.cpp:334
Class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:21
Definition: GUITexture.h:51
Definition: GUIMessage.h:365
Definition: GUILabel.h:22
void SetMaxWidth(float labelMaxWidth)
Set the maximum width for the left label.
Definition: GUIButtonControl.h:90
Definition: GUISpinControlEx.h:23
COLOR
allowed color categories for labels, as defined by the skin
Definition: GUILabel.h:74
void RenderText(float posX, float posY, float width, float height) override
Render the spinner text.
Definition: GUISpinControlEx.cpp:136
EVENT_RESULT OnMouseEvent(const CPoint &point, const KODI::MOUSE::CMouseEvent &event) override
Perform a mouse action.
Definition: GUIButtonControl.cpp:342
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