CCTextFieldTTF.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2013-2016 Chukong Technologies Inc.
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #include "2d/CCTextFieldTTF.h"
  23. #include "base/CCDirector.h"
  24. #include "platform/CCFileUtils.h"
  25. #include "base/ccUTF8.h"
  26. #include "2d/CCSprite.h"
  27. NS_CC_BEGIN
  28. #define CURSOR_TIME_SHOW_HIDE 0.5f
  29. #define CURSOR_DEFAULT_CHAR '|'
  30. #define PASSWORD_STYLE_TEXT_DEFAULT "\xe2\x80\xa2"
  31. static std::size_t _calcCharCount(const char * text)
  32. {
  33. int n = 0;
  34. char ch = 0;
  35. while ((ch = *text))
  36. {
  37. CC_BREAK_IF(! ch);
  38. if (0x80 != (0xC0 & ch))
  39. {
  40. ++n;
  41. }
  42. ++text;
  43. }
  44. return n;
  45. }
  46. bool TextFieldDelegate::onTextFieldAttachWithIME(TextFieldTTF* /*sender*/)
  47. {
  48. return false;
  49. }
  50. bool TextFieldDelegate::onTextFieldDetachWithIME(TextFieldTTF* /*sender*/)
  51. {
  52. return false;
  53. }
  54. bool TextFieldDelegate::onTextFieldInsertText(TextFieldTTF* /*sender*/, const char* /*text*/, size_t /*nLen*/)
  55. {
  56. return false;
  57. }
  58. bool TextFieldDelegate::onTextFieldDeleteBackward(TextFieldTTF* /*sender*/, const char* /*delText*/, size_t /*nLen*/)
  59. {
  60. return false;
  61. }
  62. bool TextFieldDelegate::onVisit(TextFieldTTF* /*sender*/, Renderer* /*renderer*/, const Mat4& /*transform*/, uint32_t /*flags*/)
  63. {
  64. return false;
  65. }
  66. //////////////////////////////////////////////////////////////////////////
  67. // constructor and destructor
  68. //////////////////////////////////////////////////////////////////////////
  69. TextFieldTTF::TextFieldTTF()
  70. : _delegate(0)
  71. , _charCount(0)
  72. , _inputText("")
  73. , _placeHolder("") // prevent Label initWithString assertion
  74. , _colorText(Color4B::WHITE)
  75. , _secureTextEntry(false)
  76. , _passwordStyleText(PASSWORD_STYLE_TEXT_DEFAULT)
  77. , _cursorEnabled(false)
  78. , _cursorPosition(0)
  79. , _cursorChar(CURSOR_DEFAULT_CHAR)
  80. , _cursorShowingTime(0.0f)
  81. , _isAttachWithIME(false)
  82. {
  83. _colorSpaceHolder.r = _colorSpaceHolder.g = _colorSpaceHolder.b = 127;
  84. _colorSpaceHolder.a = 255;
  85. }
  86. TextFieldTTF::~TextFieldTTF()
  87. {
  88. }
  89. //////////////////////////////////////////////////////////////////////////
  90. // static constructor
  91. //////////////////////////////////////////////////////////////////////////
  92. TextFieldTTF * TextFieldTTF::textFieldWithPlaceHolder(const std::string& placeholder, const Size& dimensions, TextHAlignment alignment, const std::string& fontName, float fontSize)
  93. {
  94. TextFieldTTF *ret = new (std::nothrow) TextFieldTTF();
  95. if(ret && ret->initWithPlaceHolder("", dimensions, alignment, fontName, fontSize))
  96. {
  97. ret->autorelease();
  98. if (placeholder.size()>0)
  99. {
  100. ret->setPlaceHolder(placeholder);
  101. }
  102. return ret;
  103. }
  104. CC_SAFE_DELETE(ret);
  105. return nullptr;
  106. }
  107. TextFieldTTF * TextFieldTTF::textFieldWithPlaceHolder(const std::string& placeholder, const std::string& fontName, float fontSize)
  108. {
  109. TextFieldTTF *ret = new (std::nothrow) TextFieldTTF();
  110. if(ret && ret->initWithPlaceHolder("", fontName, fontSize))
  111. {
  112. ret->autorelease();
  113. if (placeholder.size()>0)
  114. {
  115. ret->setPlaceHolder(placeholder);
  116. }
  117. return ret;
  118. }
  119. CC_SAFE_DELETE(ret);
  120. return nullptr;
  121. }
  122. //////////////////////////////////////////////////////////////////////////
  123. // initialize
  124. //////////////////////////////////////////////////////////////////////////
  125. bool TextFieldTTF::initWithPlaceHolder(const std::string& placeholder, const Size& dimensions, TextHAlignment alignment, const std::string& fontName, float fontSize)
  126. {
  127. setDimensions(dimensions.width, dimensions.height);
  128. setAlignment(alignment, TextVAlignment::CENTER);
  129. return initWithPlaceHolder(placeholder, fontName, fontSize);
  130. }
  131. bool TextFieldTTF::initWithPlaceHolder(const std::string& placeholder, const std::string& fontName, float fontSize)
  132. {
  133. _placeHolder = placeholder;
  134. do
  135. {
  136. // If fontName is ttf file and it corrected, use TTFConfig
  137. if (FileUtils::getInstance()->isFileExist(fontName))
  138. {
  139. TTFConfig ttfConfig(fontName, fontSize, GlyphCollection::DYNAMIC);
  140. if (setTTFConfig(ttfConfig))
  141. {
  142. break;
  143. }
  144. }
  145. setSystemFontName(fontName);
  146. setSystemFontSize(fontSize);
  147. } while (false);
  148. setTextColorInternally(_colorSpaceHolder);
  149. Label::setString(_placeHolder);
  150. #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
  151. // On desktop default enable cursor
  152. if (_currentLabelType == LabelType::TTF)
  153. {
  154. setCursorEnabled(true);
  155. }
  156. #endif
  157. return true;
  158. }
  159. //////////////////////////////////////////////////////////////////////////
  160. // IMEDelegate
  161. //////////////////////////////////////////////////////////////////////////
  162. bool TextFieldTTF::attachWithIME()
  163. {
  164. bool ret = IMEDelegate::attachWithIME();
  165. if (ret)
  166. {
  167. // open keyboard
  168. auto pGlView = Director::getInstance()->getOpenGLView();
  169. if (pGlView)
  170. {
  171. pGlView->setIMEKeyboardState(true);
  172. }
  173. }
  174. return ret;
  175. }
  176. bool TextFieldTTF::detachWithIME()
  177. {
  178. bool ret = IMEDelegate::detachWithIME();
  179. if (ret)
  180. {
  181. // close keyboard
  182. auto glView = Director::getInstance()->getOpenGLView();
  183. if (glView)
  184. {
  185. glView->setIMEKeyboardState(false);
  186. }
  187. }
  188. return ret;
  189. }
  190. void TextFieldTTF::didAttachWithIME()
  191. {
  192. setAttachWithIME(true);
  193. }
  194. void TextFieldTTF::didDetachWithIME()
  195. {
  196. setAttachWithIME(false);
  197. }
  198. bool TextFieldTTF::canAttachWithIME()
  199. {
  200. return (_delegate) ? (! _delegate->onTextFieldAttachWithIME(this)) : true;
  201. }
  202. bool TextFieldTTF::canDetachWithIME()
  203. {
  204. return (_delegate) ? (! _delegate->onTextFieldDetachWithIME(this)) : true;
  205. }
  206. void TextFieldTTF::insertText(const char * text, size_t len)
  207. {
  208. std::string insert(text, len);
  209. // insert \n means input end
  210. int pos = static_cast<int>(insert.find(StringUtils::AsciiCharacters::NewLine));
  211. if ((int)insert.npos != pos)
  212. {
  213. len = pos;
  214. insert.erase(pos);
  215. }
  216. if (len > 0)
  217. {
  218. if (_delegate && _delegate->onTextFieldInsertText(this, insert.c_str(), len))
  219. {
  220. // delegate doesn't want to insert text
  221. return;
  222. }
  223. std::size_t countInsertChar = _calcCharCount(insert.c_str());
  224. _charCount += countInsertChar;
  225. if (_cursorEnabled)
  226. {
  227. StringUtils::StringUTF8 stringUTF8;
  228. stringUTF8.replace(_inputText);
  229. stringUTF8.insert(_cursorPosition, insert);
  230. setCursorPosition(_cursorPosition + countInsertChar);
  231. setString(stringUTF8.getAsCharSequence());
  232. }
  233. else
  234. {
  235. std::string sText(_inputText);
  236. sText.append(insert);
  237. setString(sText);
  238. }
  239. }
  240. if ((int)insert.npos == pos) {
  241. return;
  242. }
  243. // '\n' inserted, let delegate process first
  244. if (_delegate && _delegate->onTextFieldInsertText(this, "\n", 1))
  245. {
  246. return;
  247. }
  248. // if delegate hasn't processed, detach from IME by default
  249. detachWithIME();
  250. }
  251. void TextFieldTTF::deleteBackward()
  252. {
  253. size_t len = _inputText.length();
  254. if (! len)
  255. {
  256. // there is no string
  257. return;
  258. }
  259. // get the delete byte number
  260. size_t deleteLen = 1; // default, erase 1 byte
  261. while(0x80 == (0xC0 & _inputText.at(len - deleteLen)))
  262. {
  263. ++deleteLen;
  264. }
  265. if (_delegate && _delegate->onTextFieldDeleteBackward(this, _inputText.c_str() + len - deleteLen, static_cast<int>(deleteLen)))
  266. {
  267. // delegate doesn't want to delete backwards
  268. return;
  269. }
  270. // if all text deleted, show placeholder string
  271. if (len <= deleteLen)
  272. {
  273. _inputText = "";
  274. _charCount = 0;
  275. setCursorPosition(0);
  276. setString(_inputText);
  277. return;
  278. }
  279. // set new input text
  280. if (_cursorEnabled)
  281. {
  282. if (_cursorPosition)
  283. {
  284. setCursorPosition(_cursorPosition - 1);
  285. StringUtils::StringUTF8 stringUTF8;
  286. stringUTF8.replace(_inputText);
  287. stringUTF8.deleteChar(_cursorPosition);
  288. _charCount = stringUTF8.length();
  289. setString(stringUTF8.getAsCharSequence());
  290. }
  291. }
  292. else
  293. {
  294. std::string text(_inputText.c_str(), len - deleteLen);
  295. setString(text);
  296. }
  297. }
  298. const std::string& TextFieldTTF::getContentText()
  299. {
  300. return _inputText;
  301. }
  302. void TextFieldTTF::setCursorPosition(std::size_t cursorPosition)
  303. {
  304. if (_cursorEnabled && cursorPosition <= (std::size_t)_charCount)
  305. {
  306. _cursorPosition = cursorPosition;
  307. _cursorShowingTime = CURSOR_TIME_SHOW_HIDE * 2.0f;
  308. }
  309. }
  310. void TextFieldTTF::setCursorFromPoint(const Vec2 &point, const Camera* camera)
  311. {
  312. if (_cursorEnabled)
  313. {
  314. // Reset Label, no cursor
  315. bool oldIsAttachWithIME = _isAttachWithIME;
  316. _isAttachWithIME = false;
  317. updateCursorDisplayText();
  318. Rect rect;
  319. rect.size = getContentSize();
  320. if (isScreenPointInRect(point, camera, getWorldToNodeTransform(), rect, nullptr))
  321. {
  322. int latterPosition = 0;
  323. for (; latterPosition < _lengthOfString; ++latterPosition)
  324. {
  325. if (_lettersInfo[latterPosition].valid && _lettersInfo[latterPosition].atlasIndex >= 0)
  326. {
  327. auto sprite = getLetter(latterPosition);
  328. if (sprite)
  329. {
  330. rect.size = sprite->getContentSize();
  331. if (isScreenPointInRect(point, camera, sprite->getWorldToNodeTransform(), rect, nullptr))
  332. {
  333. setCursorPosition(latterPosition);
  334. break;
  335. }
  336. }
  337. }
  338. }
  339. if (latterPosition == _lengthOfString)
  340. {
  341. setCursorPosition(latterPosition);
  342. }
  343. }
  344. // Set cursor
  345. _isAttachWithIME = oldIsAttachWithIME;
  346. updateCursorDisplayText();
  347. }
  348. }
  349. void TextFieldTTF::setAttachWithIME(bool isAttachWithIME)
  350. {
  351. if (isAttachWithIME != _isAttachWithIME)
  352. {
  353. _isAttachWithIME = isAttachWithIME;
  354. if (_isAttachWithIME)
  355. {
  356. setCursorPosition(_charCount);
  357. }
  358. updateCursorDisplayText();
  359. }
  360. }
  361. void TextFieldTTF::setTextColorInternally(const Color4B& color)
  362. {
  363. if (_currentLabelType == LabelType::BMFONT) {
  364. Label::setColor(Color3B(color));
  365. return;
  366. }
  367. Label::setTextColor(color);
  368. }
  369. void TextFieldTTF::setTextColor(const Color4B &color)
  370. {
  371. _colorText = color;
  372. if (!_inputText.empty())
  373. {
  374. setTextColorInternally(color);
  375. }
  376. }
  377. void TextFieldTTF::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
  378. {
  379. if (_delegate && _delegate->onVisit(this,renderer,parentTransform,parentFlags))
  380. {
  381. return;
  382. }
  383. Label::visit(renderer,parentTransform,parentFlags);
  384. }
  385. void TextFieldTTF::update(float delta)
  386. {
  387. if (_cursorEnabled && _isAttachWithIME)
  388. {
  389. _cursorShowingTime -= delta;
  390. if (_cursorShowingTime < -CURSOR_TIME_SHOW_HIDE)
  391. {
  392. _cursorShowingTime = CURSOR_TIME_SHOW_HIDE;
  393. }
  394. // before cursor inserted '\b', need next letter
  395. auto sprite = getLetter((int)_cursorPosition + 1);
  396. if (sprite)
  397. {
  398. if (_currentLabelType == LabelType::BMFONT) {
  399. sprite->setColor(getColor());
  400. }
  401. if (_cursorShowingTime >= 0.0f)
  402. {
  403. sprite->setOpacity(255);
  404. }
  405. else
  406. {
  407. sprite->setOpacity(0);
  408. }
  409. sprite->setDirty(true);
  410. }
  411. }
  412. }
  413. const Color4B& TextFieldTTF::getColorSpaceHolder()
  414. {
  415. return _colorSpaceHolder;
  416. }
  417. void TextFieldTTF::setColorSpaceHolder(const Color3B& color)
  418. {
  419. setColorSpaceHolder(Color4B(color));
  420. }
  421. void TextFieldTTF::setColorSpaceHolder(const Color4B& color)
  422. {
  423. _colorSpaceHolder = color;
  424. if (_inputText.empty())
  425. {
  426. setTextColorInternally(_colorSpaceHolder);
  427. }
  428. }
  429. //////////////////////////////////////////////////////////////////////////
  430. // properties
  431. //////////////////////////////////////////////////////////////////////////
  432. // input text property
  433. void TextFieldTTF::setString(const std::string &text)
  434. {
  435. std::string displayText;
  436. std::size_t charCount = 0;
  437. if (!text.empty())
  438. {
  439. _inputText = text;
  440. displayText = _inputText;
  441. charCount = _calcCharCount(_inputText.c_str());
  442. if (_secureTextEntry)
  443. {
  444. displayText = "";
  445. size_t length = charCount;
  446. while (length)
  447. {
  448. displayText.append(_passwordStyleText);
  449. --length;
  450. }
  451. }
  452. }
  453. else
  454. {
  455. _inputText = "";
  456. }
  457. if (_cursorEnabled && charCount != _charCount)
  458. {
  459. _cursorPosition = charCount;
  460. }
  461. if (_cursorEnabled)
  462. {
  463. // Need for recreate all letters in Label
  464. Label::removeAllChildrenWithCleanup(false);
  465. }
  466. // if there is no input text, display placeholder instead
  467. if (_inputText.empty() && (!_cursorEnabled || !_isAttachWithIME))
  468. {
  469. setTextColorInternally(_colorSpaceHolder);
  470. Label::setString(_placeHolder);
  471. }
  472. else
  473. {
  474. makeStringSupportCursor(displayText);
  475. setTextColorInternally(_colorText);
  476. Label::setString(displayText);
  477. }
  478. _charCount = charCount;
  479. }
  480. void TextFieldTTF::appendString(const std::string& text)
  481. {
  482. insertText(text.c_str(), text.length());
  483. }
  484. void TextFieldTTF::makeStringSupportCursor(std::string& displayText)
  485. {
  486. if (_cursorEnabled && _isAttachWithIME)
  487. {
  488. if (displayText.empty())
  489. {
  490. // \b - Next char not change x position
  491. if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT)
  492. displayText.push_back(StringUtils::AsciiCharacters::NextCharNoChangeX);
  493. displayText.push_back(_cursorChar);
  494. }
  495. else
  496. {
  497. StringUtils::StringUTF8 stringUTF8;
  498. stringUTF8.replace(displayText);
  499. if (_cursorPosition > stringUTF8.length())
  500. {
  501. _cursorPosition = stringUTF8.length();
  502. }
  503. std::string cursorChar;
  504. // \b - Next char not change x position
  505. if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT)
  506. cursorChar.push_back(StringUtils::AsciiCharacters::NextCharNoChangeX);
  507. cursorChar.push_back(_cursorChar);
  508. stringUTF8.insert(_cursorPosition, cursorChar);
  509. displayText = stringUTF8.getAsCharSequence();
  510. }
  511. }
  512. }
  513. void TextFieldTTF::updateCursorDisplayText()
  514. {
  515. // Update Label content
  516. setString(_inputText);
  517. }
  518. void TextFieldTTF::setCursorChar(char cursor)
  519. {
  520. if (_cursorChar != cursor)
  521. {
  522. _cursorChar = cursor;
  523. updateCursorDisplayText();
  524. }
  525. }
  526. void TextFieldTTF::controlKey(EventKeyboard::KeyCode keyCode)
  527. {
  528. if (_cursorEnabled)
  529. {
  530. switch (keyCode)
  531. {
  532. case EventKeyboard::KeyCode::KEY_HOME:
  533. case EventKeyboard::KeyCode::KEY_KP_HOME:
  534. setCursorPosition(0);
  535. updateCursorDisplayText();
  536. break;
  537. case EventKeyboard::KeyCode::KEY_END:
  538. setCursorPosition(_charCount);
  539. updateCursorDisplayText();
  540. break;
  541. case EventKeyboard::KeyCode::KEY_DELETE:
  542. case EventKeyboard::KeyCode::KEY_KP_DELETE:
  543. if (_cursorPosition < (std::size_t)_charCount)
  544. {
  545. StringUtils::StringUTF8 stringUTF8;
  546. stringUTF8.replace(_inputText);
  547. stringUTF8.deleteChar(_cursorPosition);
  548. setCursorPosition(_cursorPosition);
  549. _charCount = stringUTF8.length();
  550. setString(stringUTF8.getAsCharSequence());
  551. }
  552. break;
  553. case EventKeyboard::KeyCode::KEY_LEFT_ARROW:
  554. if (_cursorPosition)
  555. {
  556. setCursorPosition(_cursorPosition - 1);
  557. updateCursorDisplayText();
  558. }
  559. break;
  560. case EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
  561. if (_cursorPosition < (std::size_t)_charCount)
  562. {
  563. setCursorPosition(_cursorPosition + 1);
  564. updateCursorDisplayText();
  565. }
  566. break;
  567. case EventKeyboard::KeyCode::KEY_ESCAPE:
  568. detachWithIME();
  569. break;
  570. default:
  571. break;
  572. }
  573. }
  574. }
  575. const std::string& TextFieldTTF::getString() const
  576. {
  577. return _inputText;
  578. }
  579. // place holder text property
  580. void TextFieldTTF::setPlaceHolder(const std::string& text)
  581. {
  582. _placeHolder = text;
  583. if (_inputText.empty() && !_isAttachWithIME)
  584. {
  585. setTextColorInternally(_colorSpaceHolder);
  586. Label::setString(_placeHolder);
  587. }
  588. }
  589. const std::string& TextFieldTTF::getPlaceHolder() const
  590. {
  591. return _placeHolder;
  592. }
  593. void TextFieldTTF::setCursorEnabled(bool enabled)
  594. {
  595. if (_cursorEnabled == enabled)
  596. {
  597. return;
  598. }
  599. _cursorEnabled = enabled;
  600. if (_cursorEnabled)
  601. {
  602. _cursorPosition = _charCount;
  603. if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT) {
  604. scheduleUpdate();
  605. }
  606. return;
  607. }
  608. _cursorPosition = 0;
  609. if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT) {
  610. unscheduleUpdate();
  611. }
  612. }
  613. // secureTextEntry
  614. void TextFieldTTF::setSecureTextEntry(bool value)
  615. {
  616. if (_secureTextEntry != value)
  617. {
  618. _secureTextEntry = value;
  619. setString(_inputText);
  620. }
  621. }
  622. void TextFieldTTF::setPasswordTextStyle(const std::string &text)
  623. {
  624. if (text.length() < 1)
  625. {
  626. return;
  627. }
  628. if (text != _passwordStyleText) {
  629. _passwordStyleText = text;
  630. setString(_inputText);
  631. }
  632. }
  633. const std::string& TextFieldTTF::getPasswordTextStyle() const
  634. {
  635. return _passwordStyleText;
  636. }
  637. bool TextFieldTTF::isSecureTextEntry() const
  638. {
  639. return _secureTextEntry;
  640. }
  641. NS_CC_END