]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_slider.hpp
* skins2: The Image control now supports the "action2" attribute (feel free to
[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         /// Method to compute the resize factors
104         void getResizeFactors( float &rFactorX, float &rFactorY ) const;
105
106         /// Call notifyLayout
107         void refreshLayout();
108 };
109
110
111 /// Slider background
112 class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
113 {
114     public:
115         CtrlSliderBg( intf_thread_t *pIntf,
116                       const Bezier &rCurve, VarPercent &rVariable,
117                       int thickness, GenericBitmap *pBackground, int nbHoriz,
118                       int nbVert, int padHoriz, int padVert, VarBool *pVisible,
119                       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         /// Draw the control on the given graphics
126         virtual void draw( OSGraphics &rImage, int xDest, int yDest );
127
128         /// Handle an event
129         virtual void handleEvent( EvtGeneric &rEvent );
130
131         /// Get the type of control (custom RTTI)
132         virtual string getType() const { return "slider_bg"; }
133
134         /// Associate a cursor to this background
135         void associateCursor( CtrlSliderCursor &rCursor );
136
137     private:
138         /// Cursor of the slider
139         CtrlSliderCursor *m_pCursor;
140         /// Variable associated to the slider
141         VarPercent &m_rVariable;
142         /// Thickness of the curve
143         int m_thickness;
144         /// Bezier curve of the slider
145         const Bezier &m_rCurve;
146         /// Initial size of the control
147         int m_width, m_height;
148         /// Background image sequence (optional)
149         OSGraphics *m_pImgSeq;
150         /// Number of images in the background bitmap
151         int m_nbHoriz, m_nbVert;
152         /// Number of pixels between two images
153         int m_padHoriz, m_padVert;
154         /// Size of a background image
155         int m_bgWidth, m_bgHeight;
156         /// Index of the current background image
157         int m_position;
158
159         /// Method called when the observed variable is modified
160         virtual void onUpdate( Subject<VarPercent> &rVariable );
161
162         /// Method to compute the resize factors
163         void getResizeFactors( float &rFactorX, float &rFactorY ) const;
164 };
165
166
167 #endif