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