]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_slider.hpp
* modules/gui/skins/*:
[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.2 2004/01/11 17:12:17 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 class VarBool;
38
39
40 /// Cursor of a slider
41 class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>,
42     public Observer<VarBool>
43 {
44     public:
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 );
53
54         virtual ~CtrlSliderCursor();
55
56         /// Handle an event
57         virtual void handleEvent( EvtGeneric &rEvent );
58
59         /// Check whether coordinates are inside the control
60         virtual bool mouseOver( int x, int y ) const;
61
62         /// Draw the control on the given graphics
63         virtual void draw( OSGraphics &rImage, int xDest, int yDest );
64
65         /// Get the text of the tooltip
66         virtual UString getTooltipText() const { return m_tooltip; }
67
68     private:
69         /// Finite state machine of the control
70         FSM m_fsm;
71         /// Variable associated to the cursor
72         VarPercent &m_rVariable;
73         /// Visibility variable
74         VarBool *m_pVisible;
75         /// Tooltip text
76         const UString m_tooltip;
77         /// Initial size of the control
78         int m_width, m_height;
79         /// Callback objects
80         Callback m_cmdOverDown;
81         Callback m_cmdDownOver;
82         Callback m_cmdOverUp;
83         Callback m_cmdUpOver;
84         Callback m_cmdMove;
85         Callback m_cmdScroll;
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
93         EvtGeneric *m_pEvt;
94         /// Images of the cursor in the differents states
95         OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
96         /// Current image
97         OSGraphics *m_pImg;
98         /// Bezier curve of the slider
99         const Bezier m_curve;
100
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 );
108
109         /// Method called when the position variable is modified
110         virtual void onUpdate( Subject<VarPercent> &rVariable );
111
112         /// Method called when the visibility variable is modified
113         virtual void onUpdate( Subject<VarBool> &rVariable );
114
115         /// Methode to compute the resize factors
116         void getResizeFactors( float &rFactorX, float &rFactorY ) const;
117 };
118
119
120 /// Slider background
121 class CtrlSliderBg: public CtrlGeneric
122 {
123     public:
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() {}
129
130         /// Tell whether the mouse is over the control
131         virtual bool mouseOver( int x, int y ) const;
132
133         /// Handle an event
134         virtual void handleEvent( EvtGeneric &rEvent );
135
136     private:
137         /// Cursor of the slider
138         CtrlSliderCursor &m_rCursor;
139         /// Variable associated to the slider
140         VarPercent &m_rVariable;
141         /// Thickness of the curve
142         int m_thickness;
143         /// Visibility variable
144         VarBool *m_pVisible;
145         /// Bezier curve of the slider
146         const Bezier m_curve;
147         /// Initial size of the control
148         int m_width, m_height;
149
150         /// Methode to compute the resize factors
151         void getResizeFactors( float &rFactorX, float &rFactorY ) const;
152
153         /// Method called when the visibility variable is modified
154         virtual void onUpdate( Subject<VarBool> &rVariable );
155 };
156
157
158 #endif