Prechádzať zdrojové kódy

Fix TextBox properties initialization on MSVC

Marc Plano-Lesay 12 rokov pred
rodič
commit
947638d39e

+ 25 - 20
gameplay/src/TextBox.cpp

@@ -37,26 +37,7 @@ void TextBox::initialize(Theme::Style* style, Properties* properties)
     GP_ASSERT(properties);
 
     Label::initialize(style, properties);
-    const char* inputMode = properties->getString("inputMode");
-    if (inputMode)
-    {
-		if (strcasecmp(inputMode, "text") == 0)
-		{
-			_inputMode = TEXT;
-		}
-		else if (strcasecmp(inputMode, "password") == 0)
-		{
-			_inputMode = PASSWORD;
-		}
-		else
-		{
-			_inputMode = TEXT;
-		}
-    }
-	else
-	{
-		_inputMode = TEXT;
-	}
+	_inputMode = getInputMode(properties->getString("inputMode"));
 }
 
 int TextBox::getLastKeypress()
@@ -480,6 +461,30 @@ void TextBox::drawText(const Rectangle& clip)
     }
 }
 
+TextBox::InputMode TextBox::getInputMode(const char* inputMode)
+{
+    if (!inputMode)
+    {
+        return TextBox::TEXT;
+    }
+
+    if (strcmp(inputMode, "TEXT") == 0)
+    {
+        return TextBox::TEXT;
+    }
+    else if (strcmp(inputMode, "PASSWORD") == 0)
+    {
+        return TextBox::PASSWORD;
+    }
+    else
+    {
+        GP_ERROR("Failed to get corresponding textbox inputmode for unsupported value '%s'.", inputMode);
+    }
+
+    // Default.
+    return TextBox::TEXT;
+}
+
 std::string TextBox::getDisplayedText() const
 {
 	std::string displayedText;

+ 8 - 0
gameplay/src/TextBox.h

@@ -196,6 +196,14 @@ protected:
 	 **/
 	virtual void drawText(const Rectangle& clip);
 
+	/**
+	 * Gets an InputMode by string.
+	 *
+	 * @param inputMode The string representation of the InputMode type.
+	 * @return The InputMode enum value corresponding to the given string.
+	 */
+	static InputMode getInputMode(const char* inputMode);
+
 	/**
 	 * Get the text which should be displayed, depending on
 	 * _inputMode.

+ 1 - 1
samples/browser/res/common/forms/formBasicControls.form

@@ -67,7 +67,7 @@ form basicControls
         style = topLeftAlignedEntry
         position = 20, 540
         size = 250, 40
-        text = password
+        text = PASSWORD
         consumeInputEvents = true
         inputMode = PASSWORD
     }