]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_slider.hpp
* controls/*, src/generic_window.cpp, src/generic_layout.cpp: a visibiliy
[vlc] / modules / gui / skins2 / controls / ctrl_slider.hpp
1 /*****************************************************************************
2  * ctrl_slider.hpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: ctrl_slider.hpp,v 1.3 2004/02/29 16:49:55 asmax Exp $
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifndef CTRL_SLIDER_HPP
26 #define CTRL_SLIDER_HPP
27
28 #include "ctrl_generic.hpp"
29 #include "../utils/bezier.hpp"
30 #include "../utils/fsm.hpp"
31 #include "../utils/observer.hpp"
32
33
34 class GenericBitmap;
35 class OSGraphics;
36 class VarPercent;
37
38
39 /// Cursor of a slider
40 class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>
41 {
42     public:
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 );
51
52         virtual ~CtrlSliderCursor();
53
54         /// Handle an event
55         virtual void handleEvent( EvtGeneric &rEvent );
56
57         /// Check whether coordinates are inside the control
58         virtual bool mouseOver( int x, int y ) const;
59
60         /// Draw the control on the given graphics
61         virtual void draw( OSGraphics &rImage, int xDest, int yDest );
62
63         /// Get the text of the tooltip
64         virtual UString getTooltipText() const { return m_tooltip; }
65
66     private:
67         /// Finite state machine of the control
68         FSM m_fsm;
69         /// Variable associated to the cursor
70         VarPercent &m_rVariable;
71         /// Tooltip text
72         const UString m_tooltip;
73         /// Initial size of the control
74         int m_width, m_height;
75         /// Callback objects
76         Callback m_cmdOverDown;
77         Callback m_cmdDownOver;
78         Callback m_cmdOverUp;
79         Callback m_cmdUpOver;
80         Callback m_cmdMove;
81         Callback m_cmdScroll;
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
89         EvtGeneric *m_pEvt;
90         /// Images of the cursor in the differents states
91         OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
92         /// Current image
93         OSGraphics *m_pImg;
94         /// Bezier curve of the slider
95         const Bezier m_curve;
96
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 );
104
105         /// Method called when the position variable is modified
106         virtual void onUpdate( Subject<VarPercent> &rVariable );
107
108         /// Methode to compute the resize factors
109         void getResizeFactors( float &rFactorX, float &rFactorY ) const;
110 };
111
112
113 /// Slider background
114 class CtrlSliderBg: public CtrlGeneric
115 {
116     public:
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() {}
121
122         /// Tell whether the mouse is over the control
123         virtual bool mouseOver( int x, int y ) const;
124
125         /// Handle an event
126         virtual void handleEvent( EvtGeneric &rEvent );
127
128     private:
129         /// Cursor of the slider
130         CtrlSliderCursor &m_rCursor;
131         /// Variable associated to the slider
132         VarPercent &m_rVariable;
133         /// Thickness of the curve
134         int m_thickness;
135         /// Bezier curve of the slider
136         const Bezier m_curve;
137         /// Initial size of the control
138         int m_width, m_height;
139
140         /// Methode to compute the resize factors
141         void getResizeFactors( float &rFactorX, float &rFactorY ) const;
142 };
143
144
145 #endif