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"
32 #include "../utils/position.hpp"
41 /// Cursor of a slider
42 class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>
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 /// 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"; }
81 /// Finite state machine of the control
83 /// Variable associated to the cursor
84 VarPercent &m_rVariable;
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;
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 position of the cursor (stored as a percentage)
99 float m_lastPercentage;
100 /// Last saved cursor placement
101 rect m_lastCursorRect;
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 );
122 /// getter for the current slider rectangle
123 rect getCurrentCursorRect();
127 /// Slider background
128 class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
131 CtrlSliderBg( intf_thread_t *pIntf,
132 const Bezier &rCurve, VarPercent &rVariable,
133 int thickness, GenericBitmap *pBackground, int nbHoriz,
134 int nbVert, int padHoriz, int padVert, VarBool *pVisible,
135 const UString &rHelp );
136 virtual ~CtrlSliderBg();
138 /// Return true if the control can be scrollable
139 virtual bool isScrollable() const { return true; }
141 /// Tell whether the mouse is over the control
142 virtual bool mouseOver( int x, int y ) const;
144 /// Draw the control on the given graphics
145 virtual void draw( OSGraphics &rImage, int xDest, int yDest, int w, int h );
148 virtual void handleEvent( EvtGeneric &rEvent );
150 /// Method called when the control is resized
151 virtual void onResize();
153 /// Get the type of control (custom RTTI)
154 virtual string getType() const { return "slider_bg"; }
156 /// Associate a cursor to this background
157 void associateCursor( CtrlSliderCursor &rCursor );
160 /// Cursor of the slider
161 CtrlSliderCursor *m_pCursor;
162 /// Variable associated to the slider
163 VarPercent &m_rVariable;
164 /// Thickness of the curve
166 /// Bezier curve of the slider
167 const Bezier &m_rCurve;
168 /// Initial size of the control
169 int m_width, m_height;
170 /// Background image sequence (optional)
171 GenericBitmap *m_pImgSeq;
172 /// Scaled bitmap if needed
173 ScaledBitmap *m_pScaledBmp;
174 /// Number of images in the background bitmap
175 int m_nbHoriz, m_nbVert;
176 /// Number of pixels between two images
177 int m_padHoriz, m_padVert;
178 /// Size of a background image
179 int m_bgWidth, m_bgHeight;
180 /// Index of the current background image
183 /// Method called when the observed variable is modified
184 virtual void onUpdate( Subject<VarPercent> &rVariable, void* );
186 /// Method to compute the resize factors
187 void getResizeFactors( float &rFactorX, float &rFactorY ) const;