Merge pull request #4687 from ruuk/textboxgettext
[vuplus_xbmc] / xbmc / guilib / GUISliderControl.h
1 /*!
2 \file GUISliderControl.h
3 \brief
4 */
5
6 #ifndef GUILIB_GUISLIDERCONTROL_H
7 #define GUILIB_GUISLIDERCONTROL_H
8
9 #pragma once
10
11 /*
12  *      Copyright (C) 2005-2013 Team XBMC
13  *      http://xbmc.org
14  *
15  *  This Program is free software; you can redistribute it and/or modify
16  *  it under the terms of the GNU General Public License as published by
17  *  the Free Software Foundation; either version 2, or (at your option)
18  *  any later version.
19  *
20  *  This Program is distributed in the hope that it will be useful,
21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  *  GNU General Public License for more details.
24  *
25  *  You should have received a copy of the GNU General Public License
26  *  along with XBMC; see the file COPYING.  If not, see
27  *  <http://www.gnu.org/licenses/>.
28  *
29  */
30
31 #include "GUIControl.h"
32 #include "GUITexture.h"
33
34 #define SPIN_CONTROL_TYPE_INT       1
35 #define SPIN_CONTROL_TYPE_FLOAT     2
36 #define SPIN_CONTROL_TYPE_TEXT      3
37
38 typedef struct
39 {
40   const char *action;
41   const char *formatString;
42   int         infoCode;
43   bool        fireOnDrag;
44 } SliderAction;
45
46 /*!
47  \ingroup controls
48  \brief
49  */
50 class CGUISliderControl :
51       public CGUIControl
52 {
53 public:
54   typedef enum {
55     RangeSelectorLower = 0,
56     RangeSelectorUpper = 1
57   } RangeSelector;
58
59   CGUISliderControl(int parentID, int controlID, float posX, float posY, float width, float height, const CTextureInfo& backGroundTexture, const CTextureInfo& mibTexture, const CTextureInfo& nibTextureFocus, int iType);
60   virtual ~CGUISliderControl(void);
61   virtual CGUISliderControl *Clone() const { return new CGUISliderControl(*this); };
62
63   virtual void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions);
64   virtual void Render();
65   virtual bool OnAction(const CAction &action);
66   virtual void AllocResources();
67   virtual void FreeResources(bool immediately = false);
68   virtual void DynamicResourceAlloc(bool bOnOff);
69   virtual void SetInvalid();
70   virtual void SetRange(int iStart, int iEnd);
71   virtual void SetFloatRange(float fStart, float fEnd);
72   virtual bool OnMessage(CGUIMessage& message);
73   bool ProcessSelector(CGUITexture &nib, unsigned int currentTime, float fScaleY, RangeSelector selector);
74   void SetRangeSelection(bool rangeSelection);
75   bool GetRangeSelection() const { return m_rangeSelection; }
76   void SetRangeSelector(RangeSelector selector);
77   void SwitchRangeSelector();
78   void SetInfo(int iInfo);
79   void SetPercentage(float iPercent, RangeSelector selector = RangeSelectorLower, bool updateCurrent = false);
80   float GetPercentage(RangeSelector selector = RangeSelectorLower) const;
81   void SetIntValue(int iValue, RangeSelector selector = RangeSelectorLower, bool updateCurrent = false);
82   int GetIntValue(RangeSelector selector = RangeSelectorLower) const;
83   void SetFloatValue(float fValue, RangeSelector selector = RangeSelectorLower, bool updateCurrent = false);
84   float GetFloatValue(RangeSelector selector = RangeSelectorLower) const;
85   void SetIntInterval(int iInterval);
86   void SetFloatInterval(float fInterval);
87   void SetType(int iType) { m_iType = iType; };
88   virtual CStdString GetDescription() const;
89   void SetTextValue(const CStdString &textValue) { m_textValue = textValue; };
90   void SetAction(const CStdString &action);
91 protected:
92   virtual bool HitTest(const CPoint &point) const;
93   virtual EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event);
94   virtual bool UpdateColors();
95   virtual void Move(int iNumSteps);
96   virtual void SetFromPosition(const CPoint &point, bool guessSelector = false);
97   /*! \brief Get the current position of the slider as a proportion
98    \return slider position in the range [0,1]
99    */
100   float GetProportion(RangeSelector selector = RangeSelectorLower) const;
101   
102   /*! \brief Send a click message (and/or action) to the app in response to a slider move
103    */
104   void SendClick();
105
106   CGUITexture m_guiBackground;
107   CGUITexture m_guiSelectorLower;
108   CGUITexture m_guiSelectorUpper;
109   CGUITexture m_guiSelectorLowerFocus;
110   CGUITexture m_guiSelectorUpperFocus;
111   int m_iType;
112
113   bool m_rangeSelection;
114   RangeSelector m_currentSelector;
115
116   float m_percentValues[2];
117
118   int m_intValues[2];
119   int m_iStart;
120   int m_iInterval;
121   int m_iEnd;
122
123   float m_floatValues[2];
124   float m_fStart;
125   float m_fInterval;
126   float m_fEnd;
127
128   int m_iInfoCode;
129   CStdString m_textValue; ///< Allows overriding of the text value to be displayed (parent must update when the slider updates)
130   const SliderAction *m_action; ///< Allows the skin to configure the action of a click on the slider \sa SendClick
131   bool m_dragging; ///< Whether we're in a (mouse/touch) drag operation or not - some actions are sent only on release.
132 };
133 #endif