xbmc
GUISpinControl.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 "GUIControl.h"
17 #include "GUILabel.h"
18 #include "GUITexture.h"
19 
20 #include <vector>
21 
22 #define SPIN_CONTROL_TYPE_INT 1
23 #define SPIN_CONTROL_TYPE_FLOAT 2
24 #define SPIN_CONTROL_TYPE_TEXT 3
25 #define SPIN_CONTROL_TYPE_PAGE 4
26 
32 {
33 public:
34  CGUISpinControl(int parentID, int controlID, float posX, float posY, float width, float height, const CTextureInfo& textureUp, const CTextureInfo& textureDown, const CTextureInfo& textureUpFocus, const CTextureInfo& textureDownFocus, const CTextureInfo& textureUpDisabled, const CTextureInfo& textureDownDisabled, const CLabelInfo& labelInfo, int iType);
35  ~CGUISpinControl() override = default;
36  CGUISpinControl* Clone() const override { return new CGUISpinControl(*this); }
37 
38  void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions) override;
39  void Render() override;
40  bool OnAction(const CAction &action) override;
41  void OnLeft() override;
42  void OnRight() override;
43  bool HitTest(const CPoint &point) const override;
44  bool OnMouseOver(const CPoint &point) override;
45  bool OnMessage(CGUIMessage& message) override;
46  void AllocResources() override;
47  void FreeResources(bool immediately = false) override;
48  void DynamicResourceAlloc(bool bOnOff) override;
49  void SetInvalid() override;
50  void SetPosition(float posX, float posY) override;
51  float GetWidth() const override;
52  void SetRange(int iStart, int iEnd);
53  void SetFloatRange(float fStart, float fEnd);
54  void SetValue(int iValue);
55  void SetValueFromLabel(const std::string &label);
56  void SetFloatValue(float fValue);
57  void SetStringValue(const std::string& strValue);
58  int GetValue() const;
59  float GetFloatValue() const;
60  std::string GetStringValue() const;
61  void AddLabel(const std::string& strLabel, int iValue);
62  void AddLabel(const std::string& strLabel, const std::string& strValue);
63  const std::string GetLabel() const;
64  void SetReverse(bool bOnOff);
65  int GetMaximum() const;
66  int GetMinimum() const;
67  void SetSpinAlign(uint32_t align, float offsetX)
68  {
69  m_label.GetLabelInfo().align = align;
70  m_label.GetLabelInfo().offsetX = offsetX;
71  }
72  void SetType(int iType) { m_iType = iType; }
73  float GetSpinWidth() const { return m_imgspinUp->GetWidth(); }
74  float GetSpinHeight() const { return m_imgspinUp->GetHeight(); }
75  void SetFloatInterval(float fInterval);
76  void SetShowRange(bool bOnoff) ;
77  void SetShowOnePage(bool showOnePage) { m_showOnePage = showOnePage; }
78  void Clear();
79  std::string GetDescription() const override;
80  bool IsFocusedOnUp() const;
81 
82  bool IsVisible() const override;
83 
84 protected:
85  CGUISpinControl(const CGUISpinControl& control);
86 
87  EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event) override;
88  bool UpdateColors(const CGUIListItem* item) override;
95  virtual void RenderText(float posX, float posY, float width, float height);
96  CGUILabel::COLOR GetTextColor() const;
97  void PageUp();
98  void PageDown();
99  bool CanMoveDown(bool bTestReverse = true);
100  bool CanMoveUp(bool bTestReverse = true);
101  void MoveUp(bool bTestReverse = true);
102  void MoveDown(bool bTestReverse = true);
103  void ChangePage(int amount);
104  int m_iStart;
105  int m_iEnd;
106  float m_fStart;
107  float m_fEnd;
108  int m_iValue;
109  float m_fValue;
110  int m_iType;
111  int m_iSelect;
112  bool m_bReverse;
113  float m_fInterval;
114  std::vector<std::string> m_vecLabels;
115  std::vector<int> m_vecValues;
116  std::vector<std::string> m_vecStrValues;
117  std::unique_ptr<CGUITexture> m_imgspinUp;
118  std::unique_ptr<CGUITexture> m_imgspinDown;
119  std::unique_ptr<CGUITexture> m_imgspinUpFocus;
120  std::unique_ptr<CGUITexture> m_imgspinDownFocus;
121  std::unique_ptr<CGUITexture> m_imgspinUpDisabled;
122  std::unique_ptr<CGUITexture> m_imgspinDownDisabled;
123  CGUILabel m_label;
124  bool m_bShowRange;
125  char m_szTyped[10];
126  int m_iTypedPos;
127 
128  int m_currentItem;
129  int m_itemsPerPage;
130  int m_numItems;
131  bool m_showOnePage;
132 };
133 
Class for rendering text labels. Handles alignment and rendering of text within a control...
Definition: GUILabel.h:69
Definition: GUIListItem.h:30
Definition: GUISpinControl.h:31
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
virtual void RenderText(float posX, float posY, float width, float height)
Render the spinner text.
Definition: GUISpinControl.cpp:552
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
Definition: GUITexture.h:51
bool HitTest(const CPoint &point) const override
Used to test whether the point is inside a control.
Definition: GUISpinControl.cpp:987
Definition: GUIMessage.h:365
Definition: GUILabel.h:22
COLOR
allowed color categories for labels, as defined by the skin
Definition: GUILabel.h:74
EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event) override
Perform a mouse action.
Definition: GUISpinControl.cpp:1008
bool OnMouseOver(const CPoint &point) override
Called when the mouse is over the control. Default implementation selects the control.
Definition: GUISpinControl.cpp:994
Simple class for mouse events.
Definition: Key.h:114