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 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"
40 /// Cursor of a slider
41 class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>
44 /// Create a cursor with 3 images (which are NOT copied, be careful)
45 /// If pVisible is NULL, the control is always visible
46 CtrlSliderCursor( intf_thread_t *pIntf, const GenericBitmap &rBmpUp,
47 const GenericBitmap &rBmpOver,
48 const GenericBitmap &rBmpDown,
49 const Bezier &rCurve, VarPercent &rVariable,
50 VarBool *pVisible, const UString &rTooltip,
51 const UString &rHelp );
53 virtual ~CtrlSliderCursor();
56 virtual void handleEvent( EvtGeneric &rEvent );
58 /// Check whether coordinates are inside the control
59 virtual bool mouseOver( int x, int y ) const;
61 /// Draw the control on the given graphics
62 virtual void draw( OSGraphics &rImage, int xDest, int yDest, int w, int h );
64 /// Called when the position is set
65 virtual void onPositionChange();
67 /// Method called when the control is resized
68 virtual void onResize();
70 /// Method called to notify are to be updated
71 virtual void notifyLayout( int witdh = -1, int height = -1,
72 int xOffSet = 0, int yOffSet = 0 );
75 /// Get the text of the tooltip
76 virtual UString getTooltipText() const { return m_tooltip; }
78 /// Get the type of control (custom RTTI)
79 virtual string getType() const { return "slider_cursor"; }
82 /// Finite state machine of the control
84 /// Variable associated to the cursor
85 VarPercent &m_rVariable;
87 const UString m_tooltip;
88 /// Initial size of the control
89 int m_width, m_height;
90 /// Position of the cursor
91 int m_xPosition, m_yPosition;
92 rect m_currentCursorRect;
94 DEFINE_CALLBACK( CtrlSliderCursor, OverDown )
95 DEFINE_CALLBACK( CtrlSliderCursor, DownOver )
96 DEFINE_CALLBACK( CtrlSliderCursor, OverUp )
97 DEFINE_CALLBACK( CtrlSliderCursor, UpOver )
98 DEFINE_CALLBACK( CtrlSliderCursor, Move )
99 DEFINE_CALLBACK( CtrlSliderCursor, Scroll )
100 /// Last saved position of the cursor (stored as a percentage)
101 float m_lastPercentage;
102 /// Offset between the mouse pointer and the center of the cursor
103 int m_xOffset, m_yOffset;
104 /// The last received event
106 /// Images of the cursor in the differents states
107 OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
110 /// Bezier curve of the slider
111 const Bezier &m_rCurve;
113 /// Method called when the position variable is modified
114 virtual void onUpdate( Subject<VarPercent> &rVariable, void * );
116 /// Method to compute the resize factors
117 void getResizeFactors( float &rFactorX, float &rFactorY ) const;
119 /// Call notifyLayout
120 void refreshLayout( bool force = true );
124 /// Slider background
125 class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
128 CtrlSliderBg( intf_thread_t *pIntf,
129 const Bezier &rCurve, VarPercent &rVariable,
130 int thickness, GenericBitmap *pBackground, int nbHoriz,
131 int nbVert, int padHoriz, int padVert, VarBool *pVisible,
132 const UString &rHelp );
133 virtual ~CtrlSliderBg();
135 /// Tell whether the mouse is over the control
136 virtual bool mouseOver( int x, int y ) const;
138 /// Draw the control on the given graphics
139 virtual void draw( OSGraphics &rImage, int xDest, int yDest, int w, int h );
142 virtual void handleEvent( EvtGeneric &rEvent );
144 /// Method called when the control is resized
145 virtual void onResize();
147 /// Get the type of control (custom RTTI)
148 virtual string getType() const { return "slider_bg"; }
150 /// Associate a cursor to this background
151 void associateCursor( CtrlSliderCursor &rCursor );
154 /// Cursor of the slider
155 CtrlSliderCursor *m_pCursor;
156 /// Variable associated to the slider
157 VarPercent &m_rVariable;
158 /// Thickness of the curve
160 /// Bezier curve of the slider
161 const Bezier &m_rCurve;
162 /// Initial size of the control
163 int m_width, m_height;
164 /// Background image sequence (optional)
165 GenericBitmap *m_pImgSeq;
166 /// Scaled bitmap if needed
167 ScaledBitmap *m_pScaledBmp;
168 /// Number of images in the background bitmap
169 int m_nbHoriz, m_nbVert;
170 /// Number of pixels between two images
171 int m_padHoriz, m_padVert;
172 /// Size of a background image
173 int m_bgWidth, m_bgHeight;
174 /// Index of the current background image
177 /// Method called when the observed variable is modified
178 virtual void onUpdate( Subject<VarPercent> &rVariable, void* );
180 /// Method to compute the resize factors
181 void getResizeFactors( float &rFactorX, float &rFactorY ) const;