]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_slider.hpp
* all: the skin sliders can now have a background image, which
[vlc] / modules / gui / skins2 / controls / ctrl_slider.hpp
1 /*****************************************************************************
2  * ctrl_slider.hpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
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         /// Get the type of control (custom RTTI)
67         virtual string getType() const { return "slider_cursor"; }
68
69     private:
70         /// Finite state machine of the control
71         FSM m_fsm;
72         /// Variable associated to the cursor
73         VarPercent &m_rVariable;
74         /// Tooltip text
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;
80         /// Callback objects
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
92         EvtGeneric *m_pEvt;
93         /// Images of the cursor in the differents states
94         OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
95         /// Current image
96         OSGraphics *m_pImg;
97         /// Bezier curve of the slider
98         const Bezier &m_rCurve;
99
100         /// Method called when the position variable is modified
101         virtual void onUpdate( Subject<VarPercent> &rVariable );
102
103         /// Methode to compute the resize factors
104         void getResizeFactors( float &rFactorX, float &rFactorY ) const;
105 };
106
107
108 /// Slider background
109 class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
110 {
111     public:
112         CtrlSliderBg( intf_thread_t *pIntf, CtrlSliderCursor &rCursor,
113                       const Bezier &rCurve, VarPercent &rVariable,
114                       int thickness, GenericBitmap *pBackground, int nbImages,
115                       VarBool *pVisible, const UString &rHelp );
116         virtual ~CtrlSliderBg();
117
118         /// Tell whether the mouse is over the control
119         virtual bool mouseOver( int x, int y ) const;
120
121         /// Draw the control on the given graphics
122         virtual void draw( OSGraphics &rImage, int xDest, int yDest );
123
124         /// Handle an event
125         virtual void handleEvent( EvtGeneric &rEvent );
126
127         /// Get the type of control (custom RTTI)
128         virtual string getType() const { return "slider_bg"; }
129
130     private:
131         /// Cursor of the slider
132         CtrlSliderCursor &m_rCursor;
133         /// Variable associated to the slider
134         VarPercent &m_rVariable;
135         /// Thickness of the curve
136         int m_thickness;
137         /// Bezier curve of the slider
138         const Bezier &m_rCurve;
139         /// Initial size of the control
140         int m_width, m_height;
141         /// Background image sequence (optional)
142         OSGraphics *m_pImgSeq;
143         /// Number of images in the background bitmap
144         int m_nbImages;
145         /// Size of a background image
146         int m_bgWidth, m_bgHeight;
147         /// Index of the current background image
148         int m_position;
149
150         /// Method called when the observed variable is modified
151         virtual void onUpdate( Subject<VarPercent> &rVariable );
152
153         /// Methode to compute the resize factors
154         void getResizeFactors( float &rFactorX, float &rFactorY ) const;
155 };
156
157
158 #endif