source: OGRE/trunk/ogre_dependencies/Dependencies/include/CEGUI/elements/CEGUISpinner.h @ 692

Revision 692, 14.3 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/************************************************************************
2    filename:   CEGUISpinner.h
3    created:    3/2/2005
4    author:             Paul D Turner
5*************************************************************************/
6/*************************************************************************
7    Crazy Eddie's GUI System (http://www.cegui.org.uk)
8    Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
9
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Lesser General Public
12    License as published by the Free Software Foundation; either
13    version 2.1 of the License, or (at your option) any later version.
14
15    This library 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 GNU
18    Lesser General Public License for more details.
19
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23*************************************************************************/
24#ifndef _CEGUISpinner_h_
25#define _CEGUISpinner_h_
26
27#include "CEGUIBase.h"
28#include "CEGUIWindow.h"
29#include "elements/CEGUISpinnerProperties.h"
30
31#if defined(_MSC_VER)
32#       pragma warning(push)
33#       pragma warning(disable : 4251)
34#endif
35
36
37// Start of CEGUI namespace section
38namespace CEGUI
39{
40    /*!
41    \brief
42        Base class for the Spinner widget.
43
44        The spinner widget has a text area where numbers may be entered
45        and two buttons which may be used to increase or decrease the
46        value in the text area by a user specified amount.
47    */
48    class CEGUIEXPORT Spinner : public Window
49    {
50    public:
51        /*!
52        \brief
53            Enumerated type specifying possible input and/or display modes for the spinner.
54        */
55        enum TextInputMode
56        {
57            FloatingPoint,  //!< Floating point decimal.
58            Integer,        //!< Integer decimal.
59            Hexadecimal,    //!< Hexadecimal.
60            Octal           //!< Octal
61        };
62
63        /*************************************************************************
64            Events system constants
65        *************************************************************************/
66        static const String EventNamespace;                 //!< Namespace for global events
67        static const String EventValueChanged;              //!< Event fired when the spinner value changes.
68        static const String EventStepChanged;               //!< Event fired when the step value changes.
69        static const String EventMaximumValueChanged;       //!< Event fired when the maximum spinner value changes.
70        static const String EventMinimumValueChanged;       //!< Event fired when the minimum spinner value changes.
71        static const String EventTextInputModeChanged;      //!< Event fired when the input/display mode is changed.
72
73        /*************************************************************************
74            Object Construction and Destruction
75        *************************************************************************/
76        /*!
77        \brief
78            Constructor for Spinner objects
79        */
80        Spinner(const String& type, const String& name);
81
82        /*!
83        \brief
84            Destructor for Spinner objects
85        */
86        virtual ~Spinner(void);
87
88            /*!
89            \brief
90                    Initialises the Window based object ready for use.
91
92            \note
93                    This must be called for every window created.  Normally this is handled automatically by the WindowFactory for each Window type.
94
95            \return
96                    Nothing
97            */
98        void initialise(void);
99
100
101        /*************************************************************************
102                Accessors
103        *************************************************************************/
104        /*!
105        \brief
106            Return the current spinner value.
107
108        \return
109            current float value of the Spinner.
110        */
111        float getCurrentValue(void) const;
112
113        /*!
114        \brief
115            Return the current step value.
116
117        \return
118            float step value.  This is the value added to the spinner vaue when the
119            up / down buttons are clicked.
120        */
121        float getStepSize(void) const;
122
123        /*!
124        \brief
125            Return the current maximum limit value for the Spinner.
126
127        \return
128            Maximum value that is allowed for the spinner.
129        */
130        float getMaximumValue(void) const;
131
132        /*!
133        \brief
134            Return the current minimum limit value for the Spinner.
135
136        \return
137            Minimum value that is allowed for the spinner.
138        */
139        float getMinimumValue(void) const;
140
141        /*!
142        \brief
143            Return the current text input / display mode setting.
144
145        \return
146            One of the TextInputMode enumerated values indicating the current
147            text input and display mode.
148        */
149        TextInputMode getTextInputMode(void) const;
150
151        /*************************************************************************
152                Manipulators
153        *************************************************************************/
154        /*!
155        \brief
156            Set the current spinner value.
157
158        \param value
159            value to be assigned to the Spinner.
160
161        \return
162            Nothing.
163        */
164        void setCurrentValue(float value);
165
166        /*!
167        \brief
168            Set the current step value.
169
170        \param step
171            The value added to be the spinner value when the
172            up / down buttons are clicked.
173
174        \return
175            Nothing.
176        */
177        void setStepSize(float step);
178
179        /*!
180        \brief
181            Set the spinner maximum value.
182
183        \param maxValue
184            The maximum value to be allowed by the spinner.
185
186        \return
187            Nothing.
188        */
189        void setMaximumValue(float maxValue);
190
191        /*!
192        \brief
193            Set the spinner minimum value.
194
195        \param minVaue
196            The minimum value to be allowed by the spinner.
197
198        \return
199            Nothing.
200        */
201        void setMinimumValue(float minVaue);
202
203        /*!
204        \brief
205            Set the spinner input / display mode.
206
207        \param mode
208            One of the TextInputMode enumerated values indicating the text
209            input / display mode to be used by the spinner.
210
211        \return
212            Nothing.
213        */
214        void setTextInputMode(TextInputMode mode);
215
216    protected:
217        /*************************************************************************
218                Constants
219        *************************************************************************/
220        static const String FloatValidator;      //!< Validator regex used for floating point mode.
221        static const String IntegerValidator;    //!< Validator regex used for decimal integer mode.
222        static const String HexValidator;        //!< Validator regex used for hexadecimal mode.
223        static const String OctalValidator;      //!< Validator regex used for octal mode.
224
225        /*************************************************************************
226                Protected Implementation Methods
227        *************************************************************************/
228        /*!
229        \brief
230            Adds events specific to the Spinner base class.
231       
232        \return
233            Nothing.
234        */
235        void addSpinnerEvents(void);
236
237        /*!
238        \brief
239            Returns the numerical representation of the current editbox text.
240
241        \return
242            float value that is the numerical equivalent of the editbox text.
243
244        \exception InvalidRequestException  thrown if the text can not be converted.
245        */
246        virtual float getValueFromText(void) const;
247
248        /*!
249        \brief
250            Returns the textual representation of the current spinner value.
251
252        \return
253            String object that is equivalent to the the numerical value of the spinner.
254        */
255        virtual String getTextFromValue(void) const;
256
257
258                /*!
259                \brief
260                        Return whether this window was inherited from the given class name at some point in the inheritance heirarchy.
261
262                \param class_name
263                        The class name that is to be checked.
264
265                \return
266                        true if this window was inherited from \a class_name. false if not.
267                */
268                virtual bool    testClassName_impl(const String& class_name) const
269                {
270                        if (class_name==(const utf8*)"Spinner") return true;
271                        return Window::testClassName_impl(class_name);
272                }
273
274
275        /*************************************************************************
276                Abstract Implementation methods
277        *************************************************************************/
278        /*!
279        \brief
280            Creates a PushButton based widget that will be used for the increase
281            button component of the Spinner widget.
282
283        \return
284            Pointer to a valid PushButton based object.
285        */
286        virtual PushButton* createIncreaseButton(const String& name) const = 0;
287
288        /*!
289        \brief
290            Creates a PushButton based widget that will be used for the decrease
291            button component of the Spinner widget.
292
293        \return
294            Pointer to a valid PushButton based object.
295        */
296        virtual PushButton* createDecreaseButton(const String& name) const = 0;
297
298        /*!
299        \brief
300            Creates an Editbox based widget that will be used for the text input
301            area of the spinner widget.
302
303        \return
304            Pointer to a valid Editbox based object.
305        */
306        virtual Editbox* createEditbox(const String& name) const = 0;
307
308        /*************************************************************************
309                Overrides for Event handler methods
310        *************************************************************************/
311        virtual void onFontChanged(WindowEventArgs& e);
312        virtual void onTextChanged(WindowEventArgs& e);
313        virtual void onActivated(ActivationEventArgs& e);
314
315        /*************************************************************************
316                New Event handler methods
317        *************************************************************************/
318        /*!
319        \brief
320            Method called when the spinner value changes.
321
322        \param e
323            WindowEventArgs object containing any relevant data.
324
325        \return
326            Nothing.
327        */
328        virtual void onValueChanged(WindowEventArgs& e);
329
330        /*!
331        \brief
332            Method called when the step value changes.
333
334        \param e
335            WindowEventArgs object containing any relevant data.
336
337        \return
338            Nothing.
339        */
340        virtual void onStepChanged(WindowEventArgs& e);
341
342        /*!
343        \brief
344            Method called when the maximum value setting changes.
345
346        \param e
347            WindowEventArgs object containing any relevant data.
348
349        \return
350            Nothing.
351        */
352        virtual void onMaximumValueChanged(WindowEventArgs& e);
353
354        /*!
355        \brief
356            Method called when the minimum value setting changes.
357
358        \param e
359            WindowEventArgs object containing any relevant data.
360
361        \return
362            Nothing.
363        */
364        virtual void onMinimumValueChanged(WindowEventArgs& e);
365
366        /*!
367        \brief
368            Method called when the text input/display mode is changed.
369
370        \param e
371            WindowEventArgs object containing any relevant data.
372
373        \return
374            Nothing.
375        */
376        virtual void onTextInputModeChanged(WindowEventArgs& e);
377
378        /*************************************************************************
379                Internal event listener methods
380        *************************************************************************/
381        bool handleIncreaseButton(const EventArgs& e);
382        bool handleDecreaseButton(const EventArgs& e);
383        bool handleEditTextChange(const EventArgs& e);
384
385
386        /*************************************************************************
387                Data Fields
388        *************************************************************************/
389        PushButton* d_increaseButton;   //!< Pointer to the increase button widget.
390        PushButton* d_decreaseButton;   //!< Pointer to the decrease button widget.
391        Editbox*    d_editbox;          //!< Pointer to the editbox widget.
392
393        float   d_stepSize;     //!< Step size value used y the increase & decrease buttons.
394        float   d_currentValue; //!< Numerical copy of the text in d_editbox.
395        float   d_maxValue;     //!< Maximum value for spinner.
396        float   d_minValue;     //!< Minimum value for spinner.
397        TextInputMode   d_inputMode;    //!< Current text display/input mode.
398
399    private:
400        /*************************************************************************
401                Static properties for the Spinner widget
402        *************************************************************************/
403        static SpinnerProperties::CurrentValue  d_currentValueProperty;
404        static SpinnerProperties::StepSize      d_stepSizeProperty;
405        static SpinnerProperties::MaximumValue  d_maxValueProperty;
406        static SpinnerProperties::MinimumValue  d_minValueProperty;
407        static SpinnerProperties::TextInputMode d_textInputModeProperty;
408
409        /*************************************************************************
410                Private Implementation Methods
411        *************************************************************************/
412        /*!
413        \brief
414            Adds properties supported by the Spinner class.
415
416        \return
417            Nothing.
418        */
419        void    addSpinnerProperties(void);
420    };
421
422} // End of  CEGUI namespace section
423
424
425#endif  // end of guard _CEGUISpinner_h_
Note: See TracBrowser for help on using the repository browser.