source: GTP/trunk/App/Demos/Geom/OgreStuff/include/CEGUI/elements/CEGUISlider.h @ 1812

Revision 1812, 9.2 KB checked in by gumbau, 18 years ago (diff)
Line 
1/************************************************************************
2        filename:       CEGUISlider.h
3        created:        13/4/2004
4        author:         Paul D Turner
5       
6        purpose:        Interface to base class for Slider widget
7*************************************************************************/
8/*************************************************************************
9    Crazy Eddie's GUI System (http://www.cegui.org.uk)
10    Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
11
12    This library is free software; you can redistribute it and/or
13    modify it under the terms of the GNU Lesser General Public
14    License as published by the Free Software Foundation; either
15    version 2.1 of the License, or (at your option) any later version.
16
17    This library is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20    Lesser General Public License for more details.
21
22    You should have received a copy of the GNU Lesser General Public
23    License along with this library; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25*************************************************************************/
26#ifndef _CEGUISlider_h_
27#define _CEGUISlider_h_
28
29#include "CEGUIBase.h"
30#include "CEGUIWindow.h"
31#include "elements/CEGUISliderProperties.h"
32
33
34#if defined(_MSC_VER)
35#       pragma warning(push)
36#       pragma warning(disable : 4251)
37#endif
38
39
40// Start of CEGUI namespace section
41namespace CEGUI
42{
43
44/*!
45\brief
46        Base class for Slider widgets.
47
48        The slider widget has a default range of 0.0f - 1.0f.  This enables use of the slider value to scale
49        any value needed by way of a simple multiplication.
50*/
51class CEGUIEXPORT Slider : public Window
52{
53public:
54        static const String EventNamespace;                             //!< Namespace for global events
55
56
57        /*************************************************************************
58                Event name constants
59        *************************************************************************/
60        static const String EventValueChanged;          //!< Event fired when the slider value changes.
61        static const String EventThumbTrackStarted;     //!< Name of the event fired when the user begins dragging the thumb.
62        static const String EventThumbTrackEnded;               //!< Name of the event fired when the user releases the thumb.
63
64
65        /*************************************************************************
66                Accessors
67        *************************************************************************/
68        /*!
69        \brief
70                return the current slider value.
71
72        \return
73                float value equal to the sliders current value.
74        */
75        float   getCurrentValue(void) const                     {return d_value;}
76
77
78        /*!
79        \brief
80                return the maximum value set for this widget
81
82        \return
83                float value equal to the currently set maximum value for this slider.
84        */
85        float   getMaxValue(void) const                         {return d_maxValue;}
86
87
88        /*!
89        \brief
90                return the current click step setting for the slider.
91
92                The click step size is the amount the slider value will be adjusted when the widget
93                is clicked wither side of the slider thumb.
94
95        \return
96                float value representing the current click step setting.
97        */
98        float   getClickStep(void) const                {return d_step;}
99
100
101        /*************************************************************************
102                Manipulators
103        *************************************************************************/
104        /*!
105        \brief
106                Initialises the Window based object ready for use.
107
108        \note
109                This must be called for every window created.  Normally this is handled automatically by the WindowFactory for each Window type.
110
111        \return
112                Nothing
113        */
114        virtual void    initialise(void);
115
116
117        /*!
118        \brief
119                set the maximum value for the slider.  Note that the minimum value is fixed at 0.
120
121        \param maxVal
122                float value specifying the maximum value for this slider widget.
123
124        \return
125                Nothing.
126        */
127        void    setMaxValue(float maxVal);
128
129
130        /*!
131        \brief
132                set the current slider value.
133
134        \param value
135                float value specifying the new value for this slider widget.
136
137        \return
138                Nothing.
139        */
140        void    setCurrentValue(float value);
141
142
143        /*!
144        \brief
145                set the current click step setting for the slider.
146
147                The click step size is the amount the slider value will be adjusted when the widget
148                is clicked wither side of the slider thumb.
149
150        \param step
151                float value representing the click step setting to use.
152
153        \return
154                Nothing.
155        */
156        void    setClickStep(float step)                {d_step = step;}
157
158
159        /*************************************************************************
160                Construction / Destruction
161        *************************************************************************/
162        /*!
163        \brief
164                Slider base class constructor
165        */
166        Slider(const String& type, const String& name);
167
168
169        /*!
170        \brief
171                Slider base class destructor
172        */
173        virtual ~Slider(void);
174
175
176protected:
177        /*************************************************************************
178                Implementation Functions
179        *************************************************************************/
180        /*!
181        \brief
182                Add slider specific events
183        */
184        void    addSliderEvents(void);
185
186
187        /*!
188        \brief
189                create a Thumb based widget to use as the thumb for this slider.
190
191    \param name
192        String containing the name to be assigned to the thumb upon creation.
193        */
194        virtual Thumb*  createThumb(const String& name) const           = 0;
195
196
197        /*!
198        \brief
199                update the size and location of the thumb to properly represent the current state of the slider
200        */
201        virtual void    updateThumb(void)       = 0;
202
203
204        /*!
205        \brief
206                return value that best represents current slider value given the current location of the thumb.
207
208        \return
209                float value that, given the thumb widget position, best represents the current value for the slider.
210        */
211        virtual float   getValueFromThumb(void) const   = 0;
212
213
214        /*!
215        \brief
216                Given window location \a pt, return a value indicating what change should be
217                made to the slider.
218
219        \param pt
220                Point object describing a pixel position in window space.
221
222        \return
223                - -1 to indicate slider should be moved to a lower setting.
224                -  0 to indicate slider should not be moved.
225                - +1 to indicate slider should be moved to a higher setting.
226        */
227        virtual float   getAdjustDirectionFromPoint(const Point& pt) const      = 0;
228
229
230        /*!
231        \brief
232                handler function for when thumb moves.
233        */
234        bool    handleThumbMoved(const EventArgs& e);
235
236
237        /*!
238        \brief
239                handler function for when thumb tracking begins
240        */
241        bool    handleThumbTrackStarted(const EventArgs& e);
242
243
244        /*!
245        \brief
246                handler function for when thumb tracking begins
247        */
248        bool    handleThumbTrackEnded(const EventArgs& e);
249
250
251        /*!
252        \brief
253                Return whether this window was inherited from the given class name at some point in the inheritance heirarchy.
254
255        \param class_name
256                The class name that is to be checked.
257
258        \return
259                true if this window was inherited from \a class_name. false if not.
260        */
261        virtual bool    testClassName_impl(const String& class_name) const
262        {
263                if (class_name==(const utf8*)"Slider")  return true;
264                return Window::testClassName_impl(class_name);
265        }
266
267
268        /*************************************************************************
269                New event handlers for slider widget
270        *************************************************************************/
271        /*!
272        \brief
273                Handler triggered when the slider value changes
274        */
275        virtual void    onValueChanged(WindowEventArgs& e);
276
277
278        /*!
279        \brief
280                Handler triggered when the user begins to drag the slider thumb.
281        */
282        virtual void    onThumbTrackStarted(WindowEventArgs& e);
283
284
285        /*!
286        \brief
287                Handler triggered when the slider thumb is released
288        */
289        virtual void    onThumbTrackEnded(WindowEventArgs& e);
290
291
292        /*************************************************************************
293                Overridden event handlers
294        *************************************************************************/
295        virtual void    onMouseButtonDown(MouseEventArgs& e);
296        virtual void    onMouseWheel(MouseEventArgs& e);
297
298
299        /*************************************************************************
300                Implementation Data
301        *************************************************************************/
302        float   d_value;                //!< current slider value
303        float   d_maxValue;             //!< slider maximum value (minimum is fixed at 0)
304        float   d_step;                 //!< amount to adjust slider by when clicked (and not dragged).
305
306        // Pointers to the controls that make up the slider
307        Thumb*  d_thumb;                //!< widget used to represent the 'thumb' of the slider.
308
309
310private:
311        /*************************************************************************
312                Static Properties for this class
313        *************************************************************************/
314        static SliderProperties::CurrentValue   d_currentValueProperty;
315        static SliderProperties::MaximumValue   d_maximumValueProperty;
316        static SliderProperties::ClickStepSize  d_clickStepSizeProperty;
317
318
319        /*************************************************************************
320                Private methods
321        *************************************************************************/
322        void    addSliderProperties(void);
323};
324
325} // End of  CEGUI namespace section
326
327#if defined(_MSC_VER)
328#       pragma warning(pop)
329#endif
330
331#endif  // end of guard _CEGUISlider_h_
Note: See TracBrowser for help on using the repository browser.