Validation function for floating point values.

1
2.3
-4.5
-8.2e-10
are all valid.
This commit is contained in:
Steve Checkoway
2006-09-02 23:27:27 +00:00
parent dc98ba4190
commit dd71daeee4
2 changed files with 14 additions and 1 deletions
+12 -1
View File
@@ -11,6 +11,7 @@
#include "ActorUtil.h"
#include "InputEventPlus.h"
#include "RageInput.h"
#include "LocalizedString.h"
static const char* g_szKeys[NUM_KEYBOARD_ROWS][KEYS_PER_ROW] =
{
@@ -88,6 +89,16 @@ void ScreenTextEntry::TextEntry(
SCREENMAN->AddNewScreenToTop( "ScreenTextEntry", smSendOnPop );
}
static LocalizedString INVALID_FLOAT( "ScreenTextEntry", "\"%s\" is an invalid floating point value." );
bool ScreenTextEntry::FloatValidate( const RString &sAnswer, RString &sErrorOut )
{
float f;
if( StringToFloat(sAnswer, f) )
return true;
sErrorOut = ssprintf( INVALID_FLOAT.GetValue(), sAnswer.c_str() );
return false;
}
bool ScreenTextEntry::s_bCancelledLast = false;
/*
@@ -313,7 +324,7 @@ void ScreenTextEntryVisual::Init()
for( int x=0; x<KEYS_PER_ROW; ++x )
{
BitmapText *&pbt = m_ptextKeys[r][x];
pbt = static_cast<BitmapText *>( text.Copy() ); // XXX: Copy() should be covariant
pbt = dynamic_cast<BitmapText *>( text.Copy() ); // XXX: Copy() should be covariant
this->AddChild( pbt );
RString s = g_szKeys[r][x];
+2
View File
@@ -55,6 +55,8 @@ public:
{
TextEntry( smSendOnPop, sQuestion, "", 255, NULL, OnOK, OnCanel, true );
}
static bool FloatValidate( const RString &sAnswer, RString &sErrorOut );
virtual void Init();
virtual void BeginScreen();