]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_slider.hpp
skins2: cosmetics (no functional change)
[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 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  *****************************************************************************/
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 #include "../utils/position.hpp"
33
34
35 class GenericBitmap;
36 class ScaledBitmap;
37 class OSGraphics;
38 class VarPercent;
39
40
41 /// Cursor of a slider
42 class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>
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     /// Return true if the control can be scrollable
60     virtual bool isScrollable() const { return true; }
61
62     /// Check whether coordinates are inside the control
63     virtual bool mouseOver( int x, int y ) const;
64
65     /// Draw the control on the given graphics
66     virtual void draw( OSGraphics &rImage, int xDest, int yDest, int w, int h );
67
68     /// Called when the position is set
69     virtual void onPositionChange();
70
71     /// Method called when the control is resized
72     virtual void onResize();
73
74     /// Get the text of the tooltip
75     virtual UString getTooltipText() const { return m_tooltip; }
76
77     /// Get the type of control (custom RTTI)
78     virtual string getType() const { return "slider_cursor"; }
79
80 private:
81     /// Finite state machine of the control
82     FSM m_fsm;
83     /// Variable associated to the cursor
84     VarPercent &m_rVariable;
85     /// Tooltip text
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;
91     /// Callback objects
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
105     EvtGeneric *m_pEvt;
106     /// Images of the cursor in the differents states
107     OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
108     /// Current image
109     OSGraphics *m_pImg;
110     /// Bezier curve of the slider
111     const Bezier &m_rCurve;
112
113     /// Method called when the position variable is modified
114     virtual void onUpdate( Subject<VarPercent> &rVariable, void * );
115
116     /// Method to compute the resize factors
117     void getResizeFactors( float &rFactorX, float &rFactorY ) const;
118
119     /// Call notifyLayout
120     void refreshLayout( bool force = true );
121
122     /// getter for the current slider rectangle
123     rect getCurrentCursorRect();
124 };
125
126
127 /// Slider background
128 class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
129 {
130 public:
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();
137
138     /// Return true if the control can be scrollable
139     virtual bool isScrollable() const { return true; }
140
141     /// Tell whether the mouse is over the control
142     virtual bool mouseOver( int x, int y ) const;
143
144     /// Draw the control on the given graphics
145     virtual void draw( OSGraphics &rImage, int xDest, int yDest, int w, int h );
146
147     /// Handle an event
148     virtual void handleEvent( EvtGeneric &rEvent );
149
150     /// Method called when the control is resized
151     virtual void onResize();
152
153     /// Get the type of control (custom RTTI)
154     virtual string getType() const { return "slider_bg"; }
155
156     /// Associate a cursor to this background
157     void associateCursor( CtrlSliderCursor &rCursor );
158
159 private:
160     /// Cursor of the slider
161     CtrlSliderCursor *m_pCursor;
162     /// Variable associated to the slider
163     VarPercent &m_rVariable;
164     /// Thickness of the curve
165     int m_thickness;
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
181     int m_position;
182
183     /// Method called when the observed variable is modified
184     virtual void onUpdate( Subject<VarPercent> &rVariable, void* );
185
186     /// Method to compute the resize factors
187     void getResizeFactors( float &rFactorX, float &rFactorY ) const;
188 };
189
190
191 #endif