unsigned short* cc_utf8_to_utf16(const char* str_old) { int len = cc_utf8_strlen(str_old, -1); unsigned short* str_new = new unsigned short[len + 1]; str_new[len] = 0; for (int i = 0; i < len; ++i) { str_new[i] = cc_utf8_get_char(str_old); str_old = cc_utf8_next_char(str_old); } return str_new; }
void EditBoxImplAndroid::setText(const char* pText) { if (pText != NULL) { _text = pText; if (_text.length() > 0) { _labelPlaceHolder->setVisible(false); std::string strToShow; if (EditBox::InputFlag::PASSWORD == _editBoxInputFlag) { long length = cc_utf8_strlen(_text.c_str(), -1); for (long i = 0; i < length; i++) { strToShow.append("\u25CF"); } } else { strToShow = _text; } _label->setString(strToShow.c_str()); // Clip the text width to fit to the text box // FIXME: After re-implement LabelTTF by Label, '(g|s)etTextureRect' will not work, it's because LabelTTF is inherited from Node rather than Sprite now. // float fMaxWidth = _editSize.width - CC_EDIT_BOX_PADDING * 2; // Rect clippingRect = _label->getTextureRect(); // if(clippingRect.size.width > fMaxWidth) { // clippingRect.size.width = fMaxWidth; // _label->setTextureRect(clippingRect); // } } else { _labelPlaceHolder->setVisible(true); _label->setString(""); } } }
unsigned short* cc_utf8_to_utf16(const char* str_old, int length/* = -1 */, int* rUtf16Size/* = nullptr */) { unsigned short len = cc_utf8_strlen(str_old, length); if (rUtf16Size != nullptr) { *rUtf16Size = len; } unsigned short* str_new = new unsigned short[len + 1]; str_new[len] = 0; for (int i = 0; i < len; ++i) { str_new[i] = cc_utf8_get_char(str_old); str_old = cc_utf8_next_char(str_old); } return str_new; }
void EditBoxImplAndroid::setText(const char* pText) { if (pText != NULL) { _text = pText; if (_text.length() > 0) { _labelPlaceHolder->setVisible(false); std::string strToShow; if (kEditBoxInputFlagPassword == _editBoxInputFlag) { long length = cc_utf8_strlen(_text.c_str(), -1); for (long i = 0; i < length; i++) { strToShow.append("\u25CF"); } } else { strToShow = _text; } _label->setString(strToShow.c_str()); // Clip the text width to fit to the text box float fMaxWidth = _editSize.width - CC_EDIT_BOX_PADDING * 2; Rect clippingRect = _label->getTextureRect(); if(clippingRect.size.width > fMaxWidth) { clippingRect.size.width = fMaxWidth; _label->setTextureRect(clippingRect); } } else { _labelPlaceHolder->setVisible(true); _label->setString(""); } } }
void EditBoxImplAndroid::setText(const char* pText) { if (pText != NULL) { _text = pText; if (_text.length() > 0) { _labelPlaceHolder->setVisible(false); std::string strToShow; if (EditBox::InputFlag::PASSWORD == _editBoxInputFlag) { long length = cc_utf8_strlen(_text.c_str(), -1); for (long i = 0; i < length; i++) { strToShow.append("*"); } } else { strToShow = _text; } _label->setString(strToShow.c_str()); // Clip the text width to fit to the text box float fMaxWidth = _editSize.width - CC_EDIT_BOX_PADDING * 2; auto labelSize = _label->getContentSize(); if(labelSize.width > fMaxWidth) { _label->setDimensions(fMaxWidth,labelSize.height); } } else { _labelPlaceHolder->setVisible(true); _label->setString(""); } } }
void EditBoxImplWin::setText(const char* pText) { if (pText != NULL) { _text = pText; if (_text.length() > 0) { _labelPlaceHolder->setVisible(false); std::string strToShow; if (EditBox::InputFlag::PASSWORD == _editBoxInputFlag) { long length = cc_utf8_strlen(_text.c_str(), -1); for (long i = 0; i < length; i++) { strToShow.append("*"); } } else { strToShow = _text; } //! std::string strWithEllipsis = getStringWithEllipsisJni(strToShow.c_str(), _editSize.width, _editSize.height-12); //! _label->setString(strWithEllipsis.c_str()); _label->setString(strToShow.c_str()); } else { _labelPlaceHolder->setVisible(true); _label->setString(""); } } }
void CCEditBoxImplWin::setText(const char* pText) { if (pText != NULL) { m_strText = pText; if (m_strText.length() > 0) { m_pLabelPlaceHolder->setVisible(false); std::string strToShow; if (kEditBoxInputFlagPassword == m_eEditBoxInputFlag) { long length = cc_utf8_strlen(m_strText.c_str(), -1); for (long i = 0; i < length; i++) { strToShow.append("*"); } } else { strToShow = m_strText; } //! std::string strWithEllipsis = getStringWithEllipsisJni(strToShow.c_str(), m_EditSize.width, m_EditSize.height-12); //! m_pLabel->setString(strWithEllipsis.c_str()); m_pLabel->setString(strToShow.c_str()); } else { m_pLabelPlaceHolder->setVisible(true); m_pLabel->setString(""); } } }