skins2: remove range constraint for slider
[vlc.git] / modules / gui / skins2 / controls / ctrl_slider.hpp
blobcddc1683d64ef746f1ab237a9c915ee51baf3470
1 /*****************************************************************************
2 * ctrl_slider.hpp
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
5 * $Id$
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifndef CTRL_SLIDER_HPP
26 #define CTRL_SLIDER_HPP
28 #include "ctrl_generic.hpp"
29 #include "../utils/bezier.hpp"
30 #include "../utils/fsm.hpp"
31 #include "../utils/observer.hpp"
32 #include "../utils/position.hpp"
35 class GenericBitmap;
36 class ScaledBitmap;
37 class OSGraphics;
38 class VarPercent;
41 /// Cursor of a slider
42 class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>
44 public:
45 /// Create a cursor with 3 images (which are NOT copied, be careful)
46 /// If pVisible is NULL, the control is always visible
47 CtrlSliderCursor( intf_thread_t *pIntf, const GenericBitmap &rBmpUp,
48 const GenericBitmap &rBmpOver,
49 const GenericBitmap &rBmpDown,
50 const Bezier &rCurve, VarPercent &rVariable,
51 VarBool *pVisible, const UString &rTooltip,
52 const UString &rHelp );
54 virtual ~CtrlSliderCursor();
56 /// Handle an event
57 virtual void handleEvent( EvtGeneric &rEvent );
59 /// Return true if the control can be scrollable
60 virtual bool isScrollable() const { return true; }
62 /// Check whether coordinates are inside the control
63 virtual bool mouseOver( int x, int y ) const;
65 /// Draw the control on the given graphics
66 virtual void draw( OSGraphics &rImage, int xDest, int yDest, int w, int h );
68 /// Called when the position is set
69 virtual void onPositionChange();
71 /// Method called when the control is resized
72 virtual void onResize();
74 /// Get the text of the tooltip
75 virtual UString getTooltipText() const { return m_tooltip; }
77 /// Get the type of control (custom RTTI)
78 virtual string getType() const { return "slider_cursor"; }
80 private:
81 /// Finite state machine of the control
82 FSM m_fsm;
83 /// Variable associated to the cursor
84 VarPercent &m_rVariable;
85 /// Tooltip text
86 const UString m_tooltip;
87 /// Initial size of the control
88 int m_width, m_height;
89 /// Position of the cursor
90 int m_xPosition, m_yPosition;
91 /// Callback objects
92 DEFINE_CALLBACK( CtrlSliderCursor, OverDown )
93 DEFINE_CALLBACK( CtrlSliderCursor, DownOver )
94 DEFINE_CALLBACK( CtrlSliderCursor, OverUp )
95 DEFINE_CALLBACK( CtrlSliderCursor, UpOver )
96 DEFINE_CALLBACK( CtrlSliderCursor, Move )
97 DEFINE_CALLBACK( CtrlSliderCursor, Scroll )
98 /// Last saved cursor placement
99 rect m_lastCursorRect;
100 /// Offset between the mouse pointer and the center of the cursor
101 int m_xOffset, m_yOffset;
102 /// The last received event
103 EvtGeneric *m_pEvt;
104 /// Images of the cursor in the differents states
105 OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
106 /// Current image
107 OSGraphics *m_pImg;
108 /// Bezier curve of the slider
109 const Bezier &m_rCurve;
111 /// Method called when the position variable is modified
112 virtual void onUpdate( Subject<VarPercent> &rVariable, void * );
114 /// Method to compute the resize factors
115 void getResizeFactors( float &rFactorX, float &rFactorY ) const;
117 /// Call notifyLayout
118 void refreshLayout( bool force = true );
120 /// getter for the current slider rectangle
121 rect getCurrentCursorRect();
125 /// Slider background
126 class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
128 public:
129 CtrlSliderBg( intf_thread_t *pIntf,
130 const Bezier &rCurve, VarPercent &rVariable,
131 int thickness, GenericBitmap *pBackground, int nbHoriz,
132 int nbVert, int padHoriz, int padVert, VarBool *pVisible,
133 const UString &rHelp );
134 virtual ~CtrlSliderBg();
136 /// Return true if the control can be scrollable
137 virtual bool isScrollable() const { return true; }
139 /// Tell whether the mouse is over the control
140 virtual bool mouseOver( int x, int y ) const;
142 /// Draw the control on the given graphics
143 virtual void draw( OSGraphics &rImage, int xDest, int yDest, int w, int h );
145 /// Handle an event
146 virtual void handleEvent( EvtGeneric &rEvent );
148 /// Method called when the control is resized
149 virtual void onResize();
151 /// Get the type of control (custom RTTI)
152 virtual string getType() const { return "slider_bg"; }
154 /// Associate a cursor to this background
155 void associateCursor( CtrlSliderCursor &rCursor );
157 private:
158 /// Cursor of the slider
159 CtrlSliderCursor *m_pCursor;
160 /// Variable associated to the slider
161 VarPercent &m_rVariable;
162 /// Thickness of the curve
163 int m_thickness;
164 /// Bezier curve of the slider
165 const Bezier &m_rCurve;
166 /// Initial size of the control
167 int m_width, m_height;
168 /// Background image sequence (optional)
169 GenericBitmap *m_pImgSeq;
170 /// Scaled bitmap if needed
171 ScaledBitmap *m_pScaledBmp;
172 /// Number of images in the background bitmap
173 int m_nbHoriz, m_nbVert;
174 /// Number of pixels between two images
175 int m_padHoriz, m_padVert;
176 /// Size of a background image
177 int m_bgWidth, m_bgHeight;
178 /// Index of the current background image
179 int m_position;
181 /// Method called when the observed variable is modified
182 virtual void onUpdate( Subject<VarPercent> &rVariable, void* );
184 /// Method to compute the resize factors
185 void getResizeFactors( float &rFactorX, float &rFactorY ) const;
189 #endif