Crazy Eddie's GUI System  0.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Spinner.h
1 /***********************************************************************
2  filename: CEGUISpinner.h
3  created: 3/2/2005
4  author: Paul D Turner
5 *************************************************************************/
6 /***************************************************************************
7  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  ***************************************************************************/
28 #ifndef _CEGUISpinner_h_
29 #define _CEGUISpinner_h_
30 
31 #include "../Base.h"
32 #include "../Window.h"
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
41 namespace CEGUI
42 {
51  class CEGUIEXPORT Spinner : public Window
52  {
53  public:
59  {
63  Octal
64  };
65 
66  /*************************************************************************
67  Events system constants
68  *************************************************************************/
69  static const String WidgetTypeName;
70  static const String EventNamespace;
71 
76  static const String EventValueChanged;
82  static const String EventStepChanged;
101 
102  /*************************************************************************
103  Component widget name strings
104  *************************************************************************/
105  static const String EditboxName;
106  static const String IncreaseButtonName;
107  static const String DecreaseButtonName;
108 
109  /*************************************************************************
110  Object Construction and Destruction
111  *************************************************************************/
116  Spinner(const String& type, const String& name);
117 
122  virtual ~Spinner(void);
123 
134  void initialiseComponents(void);
135 
136 
137  /*************************************************************************
138  Accessors
139  *************************************************************************/
147  double getCurrentValue(void) const;
148 
157  double getStepSize(void) const;
158 
166  double getMaximumValue(void) const;
167 
175  double getMinimumValue(void) const;
176 
185  TextInputMode getTextInputMode(void) const;
186 
187  /*************************************************************************
188  Manipulators
189  *************************************************************************/
200  void setCurrentValue(double value);
201 
213  void setStepSize(double step);
214 
225  void setMaximumValue(double maxValue);
226 
237  void setMinimumValue(double minVaue);
238 
250  void setTextInputMode(TextInputMode mode);
251 
252  protected:
253  /*************************************************************************
254  Constants
255  *************************************************************************/
256  static const String FloatValidator;
257  static const String IntegerValidator;
258  static const String HexValidator;
259  static const String OctalValidator;
260 
261  /*************************************************************************
262  Protected Implementation Methods
263  *************************************************************************/
273  virtual double getValueFromText(void) const;
274 
282  virtual String getTextFromValue(void) const;
283 
295  PushButton* getIncreaseButton() const;
296 
308  PushButton* getDecreaseButton() const;
309 
320  Editbox* getEditbox() const;
321 
322  /*************************************************************************
323  Overrides for Event handler methods
324  *************************************************************************/
325  virtual void onFontChanged(WindowEventArgs& e);
326  virtual void onTextChanged(WindowEventArgs& e);
327  virtual void onActivated(ActivationEventArgs& e);
328 
329  /*************************************************************************
330  New Event handler methods
331  *************************************************************************/
342  virtual void onValueChanged(WindowEventArgs& e);
343 
354  virtual void onStepChanged(WindowEventArgs& e);
355 
366  virtual void onMaximumValueChanged(WindowEventArgs& e);
367 
378  virtual void onMinimumValueChanged(WindowEventArgs& e);
379 
390  virtual void onTextInputModeChanged(WindowEventArgs& e);
391 
392  /*************************************************************************
393  Internal event listener methods
394  *************************************************************************/
395  bool handleIncreaseButton(const EventArgs& e);
396  bool handleDecreaseButton(const EventArgs& e);
397  bool handleEditTextChange(const EventArgs& e);
398 
399 
400  /*************************************************************************
401  Data Fields
402  *************************************************************************/
403  double d_stepSize;
404  double d_currentValue;
405  double d_maxValue;
406  double d_minValue;
408 
409  private:
410  /*************************************************************************
411  Private Implementation Methods
412  *************************************************************************/
420  void addSpinnerProperties(void);
421  };
422 
423 
424 
425 template<>
426 class PropertyHelper<Spinner::TextInputMode>
427 {
428 public:
432  typedef String string_return_type;
433 
434  static const String& getDataTypeName()
435  {
436  static String type("TextInputMode");
437 
438  return type;
439  }
440 
441  static return_type fromString(const String& str)
442  {
443  if (str == "FloatingPoint")
444  {
445  return Spinner::FloatingPoint;
446  }
447  else if (str == "Hexadecimal")
448  {
449  return Spinner::Hexadecimal;
450  }
451  else if (str == "Octal")
452  {
453  return Spinner::Octal;
454  }
455  else
456  {
457  return Spinner::Integer;
458  }
459  }
460 
461  static string_return_type toString(pass_type val)
462  {
463  if (val == Spinner::Octal)
464  {
465  return "Octal";
466  }
467  else if (val == Spinner::FloatingPoint)
468  {
469  return "FloatingPoint";
470  }
471  else if (val == Spinner::Hexadecimal)
472  {
473  return "Hexadecimal";
474  }
475  else if (val == Spinner::Integer)
476  {
477  return "Integer";
478  }
479  else
480  {
481  assert(false && "Invalid Text Input Mode");
482  return "FloatingPoint";
483  }
484  }
485 };
486 
487 
488 
489 } // End of CEGUI namespace section
490 
491 #if defined(_MSC_VER)
492 # pragma warning(pop)
493 #endif
494 
495 #endif // end of guard _CEGUISpinner_h_