1 
2 namespace Upp {
3 
4 class SliderCtrlX : public Ctrl {
5 	static const int BORDER_SIZE = 2;
6 	static const int BORDER1 = BORDER_SIZE;
7 	static const int BORDER2 = 2 * BORDER_SIZE;
8 
9 	typedef enum { HORZ, VERT } HOVE;
10 
11 	typedef enum { MAJOR, MINOR } MAJORMINOR;
12 
13 public:
14 	typedef enum { TOP, MIDDLE_TOP, MIDDLE_BOTTOM, BOTTOM,
15 		RIGHT = TOP, LEFT = BOTTOM, MIDDLE_LEFT = MIDDLE_BOTTOM, MIDDLE_RIGHT = MIDDLE_TOP } TICK_ALIGNMENT;
16 
17 	typedef enum {CONTROL, INDICATOR} SLIDERTYPES;
18 
19 	typedef enum {TYPE_0, TYPE_1, TYPE_2, TYPE_3, TYPE_4} THUMB_TYPES;
20 
21 private:
22 	int				border2;			//
23 	Color			m_FillColor;		// what color to use for filling the slider
24 	int           	m_nMin;
25 	int           	m_nMax;
26 	bool			m_bInverted;		// True if origin is right or down
27 	int           	m_nStep;			// Value of steps to inc/dec
28 	bool          	m_bRound_step;		// Uses the defined Step
29 	bool		  	m_bJump;			// Jumps directly to mouse pos if click on the scale
30 	bool			m_bUseCustomThumbs;
31 	// eg a slider from -180 to 180, setting MajorTix to 30 would put Major tix
32 	// on the endpoints, as well as every 30, so: -180, -150, -120, -90, -60, -30, 0, 30...
33 	// Text Labels are drawn on all Major Tick points.
34 	// Setting MinorTix	to 5 would draw minor tix every 5, eg: -175, -170, -165...
35 	int				m_nMajorTicks;		// This is the "increment" for major tix
36 	int				m_nMinorTicks;		// This is the "increment" for minor tix
37 	int				m_nMajorTickSize; 	// Percent of the space from the line to the edge, eg 30
38 	int				m_nMinorTickSize; 	// Percent of the space from the line to the edge, eg 20
39 	//int				m_nTextAlign;
40 	int				m_nTickPosition;
41 	int				m_nThickness;		// Thickness of the thumb guide
42 	int				m_nSliderType;		// either a CONTROL / INDICATOR
43 	int				m_nThumbNumber;		// Number of the thumb
44 	int				m_nThumbType;		// Index of thumb in Image list
45 	Image			m_ThumbImg;			// Image of the thumb
46 	Image			m_ThumbFImg;		// Image of the focused thumb
47 	Size			m_ThumbSize;		// Size of the thumb;
48 
49 	Vector<Ctrl*>	m_vctrlOutput;
50 	Vector<int>		m_vValues;
51 	Vector<Image>	m_vThumbImgs;
52 	Vector<Image>	m_vThumbImgsFocus;
53 	int				nHalfThumb;
54 
55 	int				ClientToSlider(int x) const;
56 	int				HoVe(int  x, int  y) const;
57 	int&			HoVeR(int& x, int& y) const;
Max()58 	int				Max()	const	{ return Upp::max( m_nMin, m_nMax ); };
Min()59 	int				Min()	const	{ return Upp::min( m_nMin, m_nMax ); };
60 	int				SliderToClient(int value) const;
61 
62 protected:
63 
64 	void			DrawTick( Draw &w, MAJORMINOR Type, HOVE Orientation, int nPos, int nVal );
65 
66 public:
67 	typedef SliderCtrl CLASSNAME;
68 
69 	Callback		WhenSlideFinish;
70 	Callback2<String&, int> LabelFormat;
71 
72 					SliderCtrlX();
73 	virtual 		~SliderCtrlX();
74 
75 	SliderCtrlX&	AddOutCtrl( Ctrl* c );
76 	void			Dec();
FillColor(Color c)77 	SliderCtrlX&	FillColor( Color c )				{ m_FillColor = c; return *this; };
78 	virtual Value	GetData() const;
79 	virtual Value	GetData( int nIndex ) const;
GetMax()80 	int				GetMax() const                  	{ return m_nMax; }
GetMin()81 	int				GetMin() const                  	{ return m_nMin; }
GetStep()82 	int				GetStep() const                 	{ return m_nStep; }
83 	virtual void	GotFocus();
84 	void			Inc();
IsInverted()85 	bool			IsInverted() const					{ return m_bInverted; };
IsRoundStep()86 	bool			IsRoundStep() const             	{ return m_bRound_step; }
87 	bool			IsVert() const;
88 	SliderCtrlX&	Jump(bool v = false)		  		{ m_bJump = v; return *this; }
89 	virtual bool	Key(dword key, int repcnt);
90 	virtual void	LeftDown(Point pos, dword keyflags);
91 	virtual void	LeftRepeat(Point pos, dword keyflags);
92 	virtual void	LeftUp(Point pos, dword keyflags);
93 	virtual void	LostFocus();
94 	virtual void	MouseMove(Point pos, dword keyflags);
95 	SliderCtrlX&	MinMax(int _min, int _max);
96 	virtual void	Paint(Draw& draw);
Range(int max)97 	SliderCtrlX&	Range(int max)                  	{ return MinMax(0, max); }
98 	SliderCtrlX&	SetCustomThumb( Image i, int nIndex = 0 ) { m_vThumbImgs.At( nIndex ) = i; m_vThumbImgsFocus.At( nIndex ) = i; return *this; };
99 	virtual void	SetData(const Value& value);
SetInverted(bool b)100 	SliderCtrlX&	SetInverted(bool b)					{ m_bInverted = b; return *this; };
SetMajorTicks(int n)101 	SliderCtrlX&	SetMajorTicks( int n )				{ m_nMajorTicks = n; return *this; };
SetMajorTicksSize(int n)102 	SliderCtrlX&	SetMajorTicksSize( int n )			{ m_nMajorTickSize = n; return *this; };
103 	SliderCtrlX&	SetMaxi( int n=100 )				{ m_nMax = n; return *this; };
104 	SliderCtrlX&	SetMini( int n=0 )					{ m_nMin = n; return *this; };
SetMinorTicks(int n)105 	SliderCtrlX&	SetMinorTicks( int n )				{ m_nMinorTicks = n; return *this; };
SetMinorTicksSize(int n)106 	SliderCtrlX&	SetMinorTicksSize( int n )			{ m_nMinorTickSize = n; return *this; };
107 	SliderCtrlX&	SetSliderType(int n=0)				{ m_nSliderType = n; return *this;};
108 	SliderCtrlX&	SetThickness( int n = 2 )			{ m_nThickness = n; border2 = m_nThickness * BORDER_SIZE; return *this; };
SetTickPosition(int n)109 	SliderCtrlX&	SetTickPosition(int n )				{ m_nTickPosition = n; return *this; };
110 	Value			SetValue( const Value& v, int nIndex = 0 );
111 	SliderCtrlX&	Step(int _step, bool _r = true) 	{ m_nStep = _step; m_bRound_step = _r; return *this; }
112 	SliderCtrlX&	SetThumbType(int n=0);
113 	SliderCtrlX&	UseCustomThumbs( bool b = true )	{ m_bUseCustomThumbs = b; return *this; };
114 };
115 
116 }