Crazy Eddie's GUI System
0.8.4
|
00001 /*********************************************************************** 00002 created: 3/2/2005 00003 author: Paul D Turner 00004 *************************************************************************/ 00005 /*************************************************************************** 00006 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining 00009 * a copy of this software and associated documentation files (the 00010 * "Software"), to deal in the Software without restriction, including 00011 * without limitation the rights to use, copy, modify, merge, publish, 00012 * distribute, sublicense, and/or sell copies of the Software, and to 00013 * permit persons to whom the Software is furnished to do so, subject to 00014 * the following conditions: 00015 * 00016 * The above copyright notice and this permission notice shall be 00017 * included in all copies or substantial portions of the Software. 00018 * 00019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00020 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00021 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00022 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00023 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00024 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00025 * OTHER DEALINGS IN THE SOFTWARE. 00026 ***************************************************************************/ 00027 #ifndef _CEGUISpinner_h_ 00028 #define _CEGUISpinner_h_ 00029 00030 #include "../Base.h" 00031 #include "../Window.h" 00032 00033 #if defined(_MSC_VER) 00034 # pragma warning(push) 00035 # pragma warning(disable : 4251) 00036 #endif 00037 00038 00039 // Start of CEGUI namespace section 00040 namespace CEGUI 00041 { 00050 class CEGUIEXPORT Spinner : public Window 00051 { 00052 public: 00057 enum TextInputMode 00058 { 00059 FloatingPoint, 00060 Integer, 00061 Hexadecimal, 00062 Octal 00063 }; 00064 00065 /************************************************************************* 00066 Events system constants 00067 *************************************************************************/ 00068 static const String WidgetTypeName; 00069 static const String EventNamespace; 00070 00075 static const String EventValueChanged; 00081 static const String EventStepChanged; 00087 static const String EventMaximumValueChanged; 00093 static const String EventMinimumValueChanged; 00099 static const String EventTextInputModeChanged; 00100 00101 /************************************************************************* 00102 Component widget name strings 00103 *************************************************************************/ 00104 static const String EditboxName; 00105 static const String IncreaseButtonName; 00106 static const String DecreaseButtonName; 00107 00108 /************************************************************************* 00109 Object Construction and Destruction 00110 *************************************************************************/ 00115 Spinner(const String& type, const String& name); 00116 00121 virtual ~Spinner(void); 00122 00133 void initialiseComponents(void); 00134 00135 00136 /************************************************************************* 00137 Accessors 00138 *************************************************************************/ 00146 double getCurrentValue(void) const; 00147 00156 double getStepSize(void) const; 00157 00165 double getMaximumValue(void) const; 00166 00174 double getMinimumValue(void) const; 00175 00184 TextInputMode getTextInputMode(void) const; 00185 00186 /************************************************************************* 00187 Manipulators 00188 *************************************************************************/ 00199 void setCurrentValue(double value); 00200 00212 void setStepSize(double step); 00213 00224 void setMaximumValue(double maxValue); 00225 00236 void setMinimumValue(double minVaue); 00237 00249 void setTextInputMode(TextInputMode mode); 00250 00251 protected: 00252 /************************************************************************* 00253 Constants 00254 *************************************************************************/ 00255 static const String FloatValidator; 00256 static const String IntegerValidator; 00257 static const String HexValidator; 00258 static const String OctalValidator; 00259 00260 /************************************************************************* 00261 Protected Implementation Methods 00262 *************************************************************************/ 00272 virtual double getValueFromText(void) const; 00273 00281 virtual String getTextFromValue(void) const; 00282 00294 PushButton* getIncreaseButton() const; 00295 00307 PushButton* getDecreaseButton() const; 00308 00319 Editbox* getEditbox() const; 00320 00321 /************************************************************************* 00322 Overrides for Event handler methods 00323 *************************************************************************/ 00324 virtual void onFontChanged(WindowEventArgs& e); 00325 virtual void onTextChanged(WindowEventArgs& e); 00326 virtual void onActivated(ActivationEventArgs& e); 00327 00328 /************************************************************************* 00329 New Event handler methods 00330 *************************************************************************/ 00341 virtual void onValueChanged(WindowEventArgs& e); 00342 00353 virtual void onStepChanged(WindowEventArgs& e); 00354 00365 virtual void onMaximumValueChanged(WindowEventArgs& e); 00366 00377 virtual void onMinimumValueChanged(WindowEventArgs& e); 00378 00389 virtual void onTextInputModeChanged(WindowEventArgs& e); 00390 00391 /************************************************************************* 00392 Internal event listener methods 00393 *************************************************************************/ 00394 bool handleIncreaseButton(const EventArgs& e); 00395 bool handleDecreaseButton(const EventArgs& e); 00396 bool handleEditTextChange(const EventArgs& e); 00397 00398 00399 /************************************************************************* 00400 Data Fields 00401 *************************************************************************/ 00402 double d_stepSize; 00403 double d_currentValue; 00404 double d_maxValue; 00405 double d_minValue; 00406 TextInputMode d_inputMode; 00407 00408 private: 00409 /************************************************************************* 00410 Private Implementation Methods 00411 *************************************************************************/ 00419 void addSpinnerProperties(void); 00420 }; 00421 00422 00423 00424 template<> 00425 class PropertyHelper<Spinner::TextInputMode> 00426 { 00427 public: 00428 typedef Spinner::TextInputMode return_type; 00429 typedef return_type safe_method_return_type; 00430 typedef Spinner::TextInputMode pass_type; 00431 typedef String string_return_type; 00432 00433 static const String& getDataTypeName() 00434 { 00435 static String type("TextInputMode"); 00436 00437 return type; 00438 } 00439 00440 static return_type fromString(const String& str) 00441 { 00442 if (str == "FloatingPoint") 00443 { 00444 return Spinner::FloatingPoint; 00445 } 00446 else if (str == "Hexadecimal") 00447 { 00448 return Spinner::Hexadecimal; 00449 } 00450 else if (str == "Octal") 00451 { 00452 return Spinner::Octal; 00453 } 00454 else 00455 { 00456 return Spinner::Integer; 00457 } 00458 } 00459 00460 static string_return_type toString(pass_type val) 00461 { 00462 if (val == Spinner::Octal) 00463 { 00464 return "Octal"; 00465 } 00466 else if (val == Spinner::FloatingPoint) 00467 { 00468 return "FloatingPoint"; 00469 } 00470 else if (val == Spinner::Hexadecimal) 00471 { 00472 return "Hexadecimal"; 00473 } 00474 else if (val == Spinner::Integer) 00475 { 00476 return "Integer"; 00477 } 00478 else 00479 { 00480 assert(false && "Invalid Text Input Mode"); 00481 return "FloatingPoint"; 00482 } 00483 } 00484 }; 00485 00486 00487 00488 } // End of CEGUI namespace section 00489 00490 #if defined(_MSC_VER) 00491 # pragma warning(pop) 00492 #endif 00493 00494 #endif // end of guard _CEGUISpinner_h_