1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: ctrl_slider.hpp,v 1.2 2004/01/11 17:12:17 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"
40 /// Cursor of a slider
41 class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>,
42 public Observer<VarBool>
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();
57 virtual void handleEvent( EvtGeneric &rEvent );
59 /// Check whether coordinates are inside the control
60 virtual bool mouseOver( int x, int y ) const;
62 /// Draw the control on the given graphics
63 virtual void draw( OSGraphics &rImage, int xDest, int yDest );
65 /// Get the text of the tooltip
66 virtual UString getTooltipText() const { return m_tooltip; }
69 /// Finite state machine of the control
71 /// Variable associated to the cursor
72 VarPercent &m_rVariable;
73 /// Visibility variable
76 const UString m_tooltip;
77 /// Initial size of the control
78 int m_width, m_height;
80 Callback m_cmdOverDown;
81 Callback m_cmdDownOver;
86 /// Position of the cursor
87 int m_xPosition, m_yPosition;
88 /// Last saved position of the cursor (stored as a percentage)
89 float m_lastPercentage;
90 /// Offset between the mouse pointer and the center of the cursor
91 int m_xOffset, m_yOffset;
92 /// The last received event
94 /// Images of the cursor in the differents states
95 OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
98 /// Bezier curve of the slider
101 /// Callback functions
102 static void transOverDown( SkinObject *pCtrl );
103 static void transDownOver( SkinObject *pCtrl );
104 static void transOverUp( SkinObject *pCtrl );
105 static void transUpOver( SkinObject *pCtrl );
106 static void transMove( SkinObject *pCtrl );
107 static void transScroll( SkinObject *pCtrl );
109 /// Method called when the position variable is modified
110 virtual void onUpdate( Subject<VarPercent> &rVariable );
112 /// Method called when the visibility variable is modified
113 virtual void onUpdate( Subject<VarBool> &rVariable );
115 /// Methode to compute the resize factors
116 void getResizeFactors( float &rFactorX, float &rFactorY ) const;
120 /// Slider background
121 class CtrlSliderBg: public CtrlGeneric
124 /// If pVisible is NULL, the control is always visible
125 CtrlSliderBg( intf_thread_t *pIntf, CtrlSliderCursor &rCursor,
126 const Bezier &rCurve, VarPercent &rVariable,
127 int thickness, VarBool *pVisible, const UString &rHelp );
128 virtual ~CtrlSliderBg() {}
130 /// Tell whether the mouse is over the control
131 virtual bool mouseOver( int x, int y ) const;
134 virtual void handleEvent( EvtGeneric &rEvent );
137 /// Cursor of the slider
138 CtrlSliderCursor &m_rCursor;
139 /// Variable associated to the slider
140 VarPercent &m_rVariable;
141 /// Thickness of the curve
143 /// Visibility variable
145 /// Bezier curve of the slider
146 const Bezier m_curve;
147 /// Initial size of the control
148 int m_width, m_height;
150 /// Methode to compute the resize factors
151 void getResizeFactors( float &rFactorX, float &rFactorY ) const;
153 /// Method called when the visibility variable is modified
154 virtual void onUpdate( Subject<VarBool> &rVariable );