1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: ctrl_slider.hpp,v 1.3 2004/02/29 16:49:55 asmax Exp $
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
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, 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"
39 /// Cursor of a slider
40 class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>
43 /// Create a cursor with 3 images (which are NOT copied, be careful)
44 /// If pVisible is NULL, the control is always visible
45 CtrlSliderCursor( intf_thread_t *pIntf, const GenericBitmap &rBmpUp,
46 const GenericBitmap &rBmpOver,
47 const GenericBitmap &rBmpDown,
48 const Bezier &rCurve, VarPercent &rVariable,
49 VarBool *pVisible, const UString &rTooltip,
50 const UString &rHelp );
52 virtual ~CtrlSliderCursor();
55 virtual void handleEvent( EvtGeneric &rEvent );
57 /// Check whether coordinates are inside the control
58 virtual bool mouseOver( int x, int y ) const;
60 /// Draw the control on the given graphics
61 virtual void draw( OSGraphics &rImage, int xDest, int yDest );
63 /// Get the text of the tooltip
64 virtual UString getTooltipText() const { return m_tooltip; }
67 /// Finite state machine of the control
69 /// Variable associated to the cursor
70 VarPercent &m_rVariable;
72 const UString m_tooltip;
73 /// Initial size of the control
74 int m_width, m_height;
76 Callback m_cmdOverDown;
77 Callback m_cmdDownOver;
82 /// Position of the cursor
83 int m_xPosition, m_yPosition;
84 /// Last saved position of the cursor (stored as a percentage)
85 float m_lastPercentage;
86 /// Offset between the mouse pointer and the center of the cursor
87 int m_xOffset, m_yOffset;
88 /// The last received event
90 /// Images of the cursor in the differents states
91 OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
94 /// Bezier curve of the slider
97 /// Callback functions
98 static void transOverDown( SkinObject *pCtrl );
99 static void transDownOver( SkinObject *pCtrl );
100 static void transOverUp( SkinObject *pCtrl );
101 static void transUpOver( SkinObject *pCtrl );
102 static void transMove( SkinObject *pCtrl );
103 static void transScroll( SkinObject *pCtrl );
105 /// Method called when the position variable is modified
106 virtual void onUpdate( Subject<VarPercent> &rVariable );
108 /// Methode to compute the resize factors
109 void getResizeFactors( float &rFactorX, float &rFactorY ) const;
113 /// Slider background
114 class CtrlSliderBg: public CtrlGeneric
117 CtrlSliderBg( intf_thread_t *pIntf, CtrlSliderCursor &rCursor,
118 const Bezier &rCurve, VarPercent &rVariable,
119 int thickness, VarBool *pVisible, const UString &rHelp );
120 virtual ~CtrlSliderBg() {}
122 /// Tell whether the mouse is over the control
123 virtual bool mouseOver( int x, int y ) const;
126 virtual void handleEvent( EvtGeneric &rEvent );
129 /// Cursor of the slider
130 CtrlSliderCursor &m_rCursor;
131 /// Variable associated to the slider
132 VarPercent &m_rVariable;
133 /// Thickness of the curve
135 /// Bezier curve of the slider
136 const Bezier m_curve;
137 /// Initial size of the control
138 int m_width, m_height;
140 /// Methode to compute the resize factors
141 void getResizeFactors( float &rFactorX, float &rFactorY ) const;