]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_slider.hpp
skins2: fix RadialSlider (overflow)
[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
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, void * );
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     /// Method called when the control is resized
132     virtual void onResize();
133
134     /// Get the type of control (custom RTTI)
135     virtual string getType() const { return "slider_bg"; }
136
137     /// Associate a cursor to this background
138     void associateCursor( CtrlSliderCursor &rCursor );
139
140 private:
141     /// Cursor of the slider
142     CtrlSliderCursor *m_pCursor;
143     /// Variable associated to the slider
144     VarPercent &m_rVariable;
145     /// Thickness of the curve
146     int m_thickness;
147     /// Bezier curve of the slider
148     const Bezier &m_rCurve;
149     /// Initial size of the control
150     int m_width, m_height;
151     /// Background image sequence (optional)
152     GenericBitmap *m_pImgSeq;
153     /// Number of images in the background bitmap
154     int m_nbHoriz, m_nbVert;
155     /// Number of pixels between two images
156     int m_padHoriz, m_padVert;
157     /// Size of a background image
158     int m_bgWidth, m_bgHeight;
159     /// Index of the current background image
160     int m_position;
161
162     /// Method called when the observed variable is modified
163     virtual void onUpdate( Subject<VarPercent> &rVariable, void* );
164
165     /// Method to compute the resize factors
166     void getResizeFactors( float &rFactorX, float &rFactorY ) const;
167 };
168
169
170 #endif