mirror of https://github.com/axmolengine/axmol.git
Added support for secureTextEntry (passwords)
Added a secureTextEntry property. Enabling this property causes the TextField to display the entered text as bullets.
This commit is contained in:
parent
696ea07495
commit
6d6a0f23eb
|
@ -55,6 +55,7 @@ CCTextFieldTTF::CCTextFieldTTF()
|
|||
, m_nCharCount(0)
|
||||
, m_pInputText(new std::string)
|
||||
, m_pPlaceHolder(new std::string) // prevent CCLabelTTF initWithString assertion
|
||||
, m_pSecureTextEntry(false)
|
||||
{
|
||||
m_ColorSpaceHolder.r = m_ColorSpaceHolder.g = m_ColorSpaceHolder.b = 127;
|
||||
}
|
||||
|
@ -287,11 +288,25 @@ void CCTextFieldTTF::setColorSpaceHolder(const ccColor3B& color)
|
|||
// input text property
|
||||
void CCTextFieldTTF::setString(const char *text)
|
||||
{
|
||||
std::string displayText;
|
||||
int length;
|
||||
|
||||
CC_SAFE_DELETE(m_pInputText);
|
||||
|
||||
if (text)
|
||||
{
|
||||
m_pInputText = new std::string(text);
|
||||
displayText = *m_pInputText;
|
||||
if (m_pSecureTextEntry)
|
||||
{
|
||||
displayText = "";
|
||||
length = m_pInputText->length();
|
||||
while (length)
|
||||
{
|
||||
displayText.append("•");
|
||||
--length;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -305,7 +320,7 @@ void CCTextFieldTTF::setString(const char *text)
|
|||
}
|
||||
else
|
||||
{
|
||||
CCLabelTTF::setString(m_pInputText->c_str());
|
||||
CCLabelTTF::setString(displayText.c_str());
|
||||
}
|
||||
m_nCharCount = _calcCharCount(m_pInputText->c_str());
|
||||
}
|
||||
|
@ -331,4 +346,19 @@ const char * CCTextFieldTTF::getPlaceHolder(void)
|
|||
return m_pPlaceHolder->c_str();
|
||||
}
|
||||
|
||||
// secureTextEntry
|
||||
void CCTextFieldTTF::setSecureTextEntry(bool value)
|
||||
{
|
||||
if (m_pSecureTextEntry != value)
|
||||
{
|
||||
m_pSecureTextEntry = value;
|
||||
setString(getString());
|
||||
}
|
||||
}
|
||||
|
||||
bool CCTextFieldTTF::getSecureTextEntry()
|
||||
{
|
||||
return m_pSecureTextEntry;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -145,6 +145,11 @@ public:
|
|||
protected:
|
||||
std::string * m_pPlaceHolder;
|
||||
ccColor3B m_ColorSpaceHolder;
|
||||
public:
|
||||
virtual void setSecureTextEntry(bool value);
|
||||
virtual bool getSecureTextEntry();
|
||||
protected:
|
||||
bool m_pSecureTextEntry;
|
||||
protected:
|
||||
|
||||
virtual void draw();
|
||||
|
|
Loading…
Reference in New Issue