1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
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; }
66 /// Get the type of control (custom RTTI)
67 virtual string getType() const { return "slider_cursor"; }
70 /// Finite state machine of the control
72 /// Variable associated to the cursor
73 VarPercent &m_rVariable;
75 const UString m_tooltip;
76 /// Initial size of the control
77 int m_width, m_height;
78 /// Position of the cursor
79 int m_xPosition, m_yPosition;
81 DEFINE_CALLBACK( CtrlSliderCursor, OverDown )
82 DEFINE_CALLBACK( CtrlSliderCursor, DownOver )
83 DEFINE_CALLBACK( CtrlSliderCursor, OverUp )
84 DEFINE_CALLBACK( CtrlSliderCursor, UpOver )
85 DEFINE_CALLBACK( CtrlSliderCursor, Move )
86 DEFINE_CALLBACK( CtrlSliderCursor, Scroll )
87 /// Last saved position of the cursor (stored as a percentage)
88 float m_lastPercentage;
89 /// Offset between the mouse pointer and the center of the cursor
90 int m_xOffset, m_yOffset;
91 /// The last received event
93 /// Images of the cursor in the differents states
94 OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
97 /// Bezier curve of the slider
98 const Bezier &m_rCurve;
100 /// Method called when the position variable is modified
101 virtual void onUpdate( Subject<VarPercent> &rVariable );
103 /// Method to compute the resize factors
104 void getResizeFactors( float &rFactorX, float &rFactorY ) const;
106 /// Call notifyLayout
107 void refreshLayout();
111 /// Slider background
112 class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
115 CtrlSliderBg( intf_thread_t *pIntf,
116 const Bezier &rCurve, VarPercent &rVariable,
117 int thickness, GenericBitmap *pBackground, int nbHoriz,
118 int nbVert, int padHoriz, int padVert, VarBool *pVisible,
119 const UString &rHelp );
120 virtual ~CtrlSliderBg();
122 /// Tell whether the mouse is over the control
123 virtual bool mouseOver( int x, int y ) const;
125 /// Draw the control on the given graphics
126 virtual void draw( OSGraphics &rImage, int xDest, int yDest );
129 virtual void handleEvent( EvtGeneric &rEvent );
131 /// Get the type of control (custom RTTI)
132 virtual string getType() const { return "slider_bg"; }
134 /// Associate a cursor to this background
135 void associateCursor( CtrlSliderCursor &rCursor );
138 /// Cursor of the slider
139 CtrlSliderCursor *m_pCursor;
140 /// Variable associated to the slider
141 VarPercent &m_rVariable;
142 /// Thickness of the curve
144 /// Bezier curve of the slider
145 const Bezier &m_rCurve;
146 /// Initial size of the control
147 int m_width, m_height;
148 /// Background image sequence (optional)
149 OSGraphics *m_pImgSeq;
150 /// Number of images in the background bitmap
151 int m_nbHoriz, m_nbVert;
152 /// Number of pixels between two images
153 int m_padHoriz, m_padVert;
154 /// Size of a background image
155 int m_bgWidth, m_bgHeight;
156 /// Index of the current background image
159 /// Method called when the observed variable is modified
160 virtual void onUpdate( Subject<VarPercent> &rVariable );
162 /// Method to compute the resize factors
163 void getResizeFactors( float &rFactorX, float &rFactorY ) const;