1 /**************************************************************************** 2 Copyright (c) 2011-2012 cocos2d-x.org 3 Copyright (c) 2013-2014 Chukong Technologies Inc. 4 5 http://www.cocos2d-x.org 6 7 Permission is hereby granted, free of charge, to any person obtaining a copy 8 of this software and associated documentation files (the "Software"), to deal 9 in the Software without restriction, including without limitation the rights 10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 copies of the Software, and to permit persons to whom the Software is 12 furnished to do so, subject to the following conditions: 13 14 The above copyright notice and this permission notice shall be included in 15 all copies or substantial portions of the Software. 16 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 THE SOFTWARE. 24 ****************************************************************************/ 25 26 /** 27 * @ignore 28 */ 29 //it's a private class, it's a renderer of ccui.TextField. 30 ccui._TextFieldRenderer = cc.TextFieldTTF.extend({ 31 _maxLengthEnabled: false, 32 _maxLength: 0, 33 _passwordEnabled: false, 34 _passwordStyleText: "", 35 _attachWithIME: false, 36 _detachWithIME: false, 37 _insertText: false, 38 _deleteBackward: false, 39 _className: "_TextFieldRenderer", 40 _textFieldRendererAdaptDirty: true, 41 42 ctor: function () { 43 cc.TextFieldTTF.prototype.ctor.call(this); 44 this._maxLengthEnabled = false; 45 this._maxLength = 0; 46 this._passwordEnabled = false; 47 this._passwordStyleText = "*"; 48 this._attachWithIME = false; 49 this._detachWithIME = false; 50 this._insertText = false; 51 this._deleteBackward = false; 52 }, 53 54 onEnter: function () { 55 cc.TextFieldTTF.prototype.onEnter.call(this); 56 cc.TextFieldTTF.prototype.setDelegate.call(this, this); 57 }, 58 59 onTextFieldAttachWithIME: function (sender) { 60 this.setAttachWithIME(true); 61 return false; 62 }, 63 64 onTextFieldInsertText: function (sender, text, len) { 65 if (len == 1 && text == "\n") 66 return false; 67 68 this.setInsertText(true); 69 return (this._maxLengthEnabled) && (cc.TextFieldTTF.prototype.getCharCount.call(this) >= this._maxLength); 70 }, 71 72 onTextFieldDeleteBackward: function (sender, delText, nLen) { 73 this.setDeleteBackward(true); 74 return false; 75 }, 76 77 onTextFieldDetachWithIME: function (sender) { 78 this.setDetachWithIME(true); 79 return false; 80 }, 81 82 insertText: function (text, len) { 83 var input_text = text; 84 85 if (text != "\n"){ 86 if (this._maxLengthEnabled){ 87 var text_count = this.getString().length; 88 if (text_count >= this._maxLength){ 89 // password 90 if (this._passwordEnabled) 91 this.setPasswordText(this.getString()); 92 return; 93 } 94 } 95 } 96 cc.TextFieldTTF.prototype.insertText.call(this, input_text, len); 97 98 // password 99 if (this._passwordEnabled && cc.TextFieldTTF.prototype.getCharCount.call(this) > 0) 100 this.setPasswordText(this.getString()); 101 }, 102 103 deleteBackward: function () { 104 cc.TextFieldTTF.prototype.deleteBackward.call(this); 105 106 if (cc.TextFieldTTF.prototype.getCharCount.call(this) > 0 && this._passwordEnabled) 107 this.setPasswordText(this._inputText); 108 }, 109 110 openIME: function () { 111 cc.TextFieldTTF.prototype.attachWithIME.call(this); 112 }, 113 114 closeIME: function () { 115 cc.TextFieldTTF.prototype.detachWithIME.call(this); 116 }, 117 118 setMaxLengthEnabled: function (enable) { 119 this._maxLengthEnabled = enable; 120 }, 121 122 isMaxLengthEnabled: function () { 123 return this._maxLengthEnabled; 124 }, 125 126 setMaxLength: function (length) { 127 this._maxLength = length; 128 }, 129 130 getMaxLength: function () { 131 return this._maxLength; 132 }, 133 134 getCharCount: function () { 135 return cc.TextFieldTTF.prototype.getCharCount.call(this); 136 }, 137 138 setPasswordEnabled: function (enable) { 139 this._passwordEnabled = enable; 140 }, 141 142 isPasswordEnabled: function () { 143 return this._passwordEnabled; 144 }, 145 146 setPasswordStyleText: function (styleText) { 147 if (styleText.length > 1) 148 return; 149 var header = styleText.charCodeAt(0); 150 if (header < 33 || header > 126) 151 return; 152 this._passwordStyleText = styleText; 153 }, 154 155 setPasswordText: function (text) { 156 var tempStr = ""; 157 var text_count = text.length; 158 var max = text_count; 159 160 if (this._maxLengthEnabled && text_count > this._maxLength) 161 max = this._maxLength; 162 163 for (var i = 0; i < max; ++i) 164 tempStr += this._passwordStyleText; 165 166 cc.LabelTTF.prototype.setString.call(this, tempStr); 167 }, 168 169 setAttachWithIME: function (attach) { 170 this._attachWithIME = attach; 171 }, 172 173 getAttachWithIME: function () { 174 return this._attachWithIME; 175 }, 176 177 setDetachWithIME: function (detach) { 178 this._detachWithIME = detach; 179 }, 180 181 getDetachWithIME: function () { 182 return this._detachWithIME; 183 }, 184 185 setInsertText: function (insert) { 186 this._insertText = insert; 187 }, 188 189 getInsertText: function () { 190 return this._insertText; 191 }, 192 193 setDeleteBackward: function (deleteBackward) { 194 this._deleteBackward = deleteBackward; 195 }, 196 197 getDeleteBackward: function () { 198 return this._deleteBackward; 199 }, 200 201 onDraw: function (sender) { 202 return false; 203 } 204 }); 205 206 ccui._TextFieldRenderer.create = function (placeholder, fontName, fontSize) { 207 var ret = new ccui._TextFieldRenderer(); 208 if (ret && ret.initWithString("", fontName, fontSize)) { 209 if (placeholder) 210 ret.setPlaceHolder(placeholder); 211 return ret; 212 } 213 return null; 214 }; 215 216 /** 217 * 218 * @class 219 * @extends ccui.Widget 220 * 221 * @property {String} string - The content string of the label 222 * @property {Number} placeHolder - The place holder of the text field 223 * @property {String} font - The text field font with a style string: e.g. "18px Verdana" 224 * @property {String} fontName - The text field font name 225 * @property {Number} fontSize - The text field font size 226 * @property {Boolean} maxLengthEnabled - Indicate whether max length limit is enabled 227 * @property {Number} maxLength - The max length of the text field 228 * @property {Boolean} passwordEnabled - Indicate whether the text field is for entering password 229 */ 230 ccui.TextField = ccui.Widget.extend(/** @lends ccui.TextField# */{ 231 _textFieldRenderer: null, 232 _touchWidth: 0, 233 _touchHeight: 0, 234 _useTouchArea: false, 235 _textFieldEventListener: null, 236 _textFieldEventSelector: null, 237 _passwordStyleText: "", 238 _textFieldRendererAdaptDirty: true, 239 _fontName: "", 240 _fontSize: 12, 241 242 /** 243 * allocates and initializes a UITextField. 244 * Constructor of ccui.TextField. override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. 245 * @param {string} placeholder 246 * @param {string} fontName 247 * @param {Number} fontSize 248 * @example 249 * // example 250 * var uiTextField = new ccui.TextField(); 251 */ 252 ctor: function (placeholder, fontName, fontSize) { 253 ccui.Widget.prototype.ctor.call(this); 254 if (placeholder) 255 this.setPlaceHolder(placeholder); 256 if (fontName) 257 this.setFontName(fontName); 258 if (fontSize) 259 this.setFontSize(fontSize); 260 }, 261 262 /** 263 * Initializes a ccui.TextField. Please do not call this function by yourself, you should pass the parameters to constructor to initialize it. 264 * @returns {boolean} 265 * @override 266 */ 267 init: function(){ 268 if(ccui.Widget.prototype.init.call(this)){ 269 this.setTouchEnabled(true); 270 return true; 271 } 272 return false; 273 }, 274 275 /** 276 * Calls parent class' onEnter and schedules update function. 277 * @override 278 */ 279 onEnter: function () { 280 ccui.Widget.prototype.onEnter.call(this); 281 this.scheduleUpdate(); 282 }, 283 284 _initRenderer: function () { 285 this._textFieldRenderer = ccui._TextFieldRenderer.create("input words here", "Thonburi", 20); 286 this.addProtectedChild(this._textFieldRenderer, ccui.TextField.RENDERER_ZORDER, -1); 287 }, 288 289 /** 290 * Sets touch size of ccui.TextField. 291 * @param {cc.Size} size 292 */ 293 setTouchSize: function (size) { 294 this._touchWidth = size.width; 295 this._touchHeight = size.height; 296 }, 297 298 /** 299 * Sets whether use touch area. 300 * @param enable 301 */ 302 setTouchAreaEnabled: function(enable){ 303 this._useTouchArea = enable; 304 }, 305 306 /** 307 * Checks a point if is in ccui.TextField's space 308 * @param {cc.Point} pt 309 * @returns {boolean} 310 */ 311 hitTest: function(pt){ 312 if (this._useTouchArea) { 313 var nsp = this.convertToNodeSpace(pt); 314 var bb = cc.rect( 315 -this._touchWidth * this._anchorPoint.x, 316 -this._touchHeight * this._anchorPoint.y, 317 this._touchWidth, this._touchHeight 318 ); 319 320 return ( nsp.x >= bb.x && nsp.x <= bb.x + bb.width && 321 nsp.y >= bb.y && nsp.y <= bb.y + bb.height ); 322 } else 323 return ccui.Widget.prototype.hitTest.call(this, pt); 324 }, 325 326 /** 327 * Returns touch size of ccui.TextField. 328 * @returns {cc.Size} 329 */ 330 getTouchSize: function () { 331 return cc.size(this._touchWidth, this._touchHeight); 332 }, 333 334 /** 335 * Changes the string value of textField. 336 * @deprecated since v3.0, please use setString instead. 337 * @param {String} text 338 */ 339 setText: function (text) { 340 cc.log("Please use the setString"); 341 this.setString(text); 342 }, 343 344 /** 345 * Changes the string value of textField. 346 * @param {String} text 347 */ 348 setString: function (text) { 349 if (text == null) 350 return; 351 352 text = String(text); 353 if (this.isMaxLengthEnabled()) 354 text = text.substr(0, this.getMaxLength()); 355 if (this.isPasswordEnabled()) { 356 this._textFieldRenderer.setPasswordText(text); 357 this._textFieldRenderer.setString(""); 358 this._textFieldRenderer.insertText(text, text.length); 359 } else 360 this._textFieldRenderer.setString(text); 361 this._textFieldRendererAdaptDirty = true; 362 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 363 }, 364 365 /** 366 * Sets the placeholder string. <br /> 367 * display this string if string equal "". 368 * @param {String} value 369 */ 370 setPlaceHolder: function (value) { 371 this._textFieldRenderer.setPlaceHolder(value); 372 this._textFieldRendererAdaptDirty = true; 373 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 374 }, 375 376 /** 377 * Returns the placeholder string. 378 * @returns {String} 379 */ 380 getPlaceHolder: function () { 381 return this._textFieldRenderer.getPlaceHolder(); 382 }, 383 384 /** 385 * Returns the color of ccui.TextField's place holder. 386 * @returns {cc.Color} 387 */ 388 getPlaceHolderColor: function(){ 389 return this._textFieldRenderer.getPlaceHolderColor(); 390 }, 391 392 /** 393 * Sets the place holder color to ccui.TextField. 394 * @param color 395 */ 396 setPlaceHolderColor: function(color){ 397 this._textFieldRenderer.setColorSpaceHolder(color); 398 }, 399 400 /** 401 * Sets the text color to ccui.TextField 402 * @param textColor 403 */ 404 setTextColor: function(textColor){ 405 this._textFieldRenderer.setTextColor(textColor); 406 }, 407 408 /** 409 * Sets font size for ccui.TextField. 410 * @param {Number} size 411 */ 412 setFontSize: function (size) { 413 this._textFieldRenderer.setFontSize(size); 414 this._fontSize = size; 415 this._textFieldRendererAdaptDirty = true; 416 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 417 }, 418 419 /** 420 * Gets font size of ccui.TextField. 421 * @return {Number} size 422 */ 423 getFontSize: function () { 424 return this._fontSize; 425 }, 426 427 /** 428 * Sets font name for ccui.TextField 429 * @param {String} name 430 */ 431 setFontName: function (name) { 432 this._textFieldRenderer.setFontName(name); 433 this._fontName = name; 434 this._textFieldRendererAdaptDirty = true; 435 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 436 }, 437 438 /** 439 * Returns font name of ccui.TextField. 440 * @return {String} font name 441 */ 442 getFontName: function () { 443 return this._fontName; 444 }, 445 446 /** 447 * detach with IME 448 */ 449 didNotSelectSelf: function () { 450 this._textFieldRenderer.detachWithIME(); 451 }, 452 453 /** 454 * Returns textField string value 455 * @deprecated since v3.0, please use getString instead. 456 * @returns {String} 457 */ 458 getStringValue: function () { 459 cc.log("Please use the getString"); 460 return this.getString(); 461 }, 462 463 /** 464 * Returns string value of ccui.TextField. 465 * @returns {String} 466 */ 467 getString: function () { 468 return this._textFieldRenderer.getString(); 469 }, 470 471 /** 472 * Returns the length of ccui.TextField. 473 * @returns {Number} 474 */ 475 getStringLength: function(){ 476 return this._textFieldRenderer.getStringLength(); 477 }, 478 479 /** 480 * The touch began event callback handler. 481 * @param {cc.Point} touchPoint 482 */ 483 onTouchBegan: function (touchPoint, unusedEvent) { 484 var self = this; 485 var pass = ccui.Widget.prototype.onTouchBegan.call(self, touchPoint, unusedEvent); 486 if (self._hit) { 487 setTimeout(function(){ 488 self._textFieldRenderer.attachWithIME(); 489 }, 0); 490 } 491 return pass; 492 }, 493 494 /** 495 * Sets Whether to open string length limit for ccui.TextField. 496 * @param {Boolean} enable 497 */ 498 setMaxLengthEnabled: function (enable) { 499 this._textFieldRenderer.setMaxLengthEnabled(enable); 500 }, 501 502 /** 503 * Returns Whether to open string length limit. 504 * @returns {Boolean} 505 */ 506 isMaxLengthEnabled: function () { 507 return this._textFieldRenderer.isMaxLengthEnabled(); 508 }, 509 510 /** 511 * Sets the max length of ccui.TextField. Only when you turn on the string length limit, it is valid. 512 * @param {number} length 513 */ 514 setMaxLength: function (length) { 515 this._textFieldRenderer.setMaxLength(length); 516 this.setString(this.getString()); 517 }, 518 519 /** 520 * Returns the max length of ccui.TextField. 521 * @returns {number} length 522 */ 523 getMaxLength: function () { 524 return this._textFieldRenderer.getMaxLength(); 525 }, 526 527 /** 528 * Sets whether to open setting string as password character. 529 * @param {Boolean} enable 530 */ 531 setPasswordEnabled: function (enable) { 532 this._textFieldRenderer.setPasswordEnabled(enable); 533 }, 534 535 /** 536 * Returns whether to open setting string as password character. 537 * @returns {Boolean} 538 */ 539 isPasswordEnabled: function () { 540 return this._textFieldRenderer.isPasswordEnabled(); 541 }, 542 543 /** 544 * Sets the password style character, Only when you turn on setting string as password character, it is valid. 545 * @param styleText 546 */ 547 setPasswordStyleText: function(styleText){ 548 this._textFieldRenderer.setPasswordStyleText(styleText); 549 this._passwordStyleText = styleText; 550 551 this.setString(this.getString()); 552 }, 553 554 /** 555 * Returns the password style character. 556 * @returns {String} 557 */ 558 getPasswordStyleText: function () { 559 return this._passwordStyleText; 560 }, 561 562 update: function (dt) { 563 if (this.getAttachWithIME()) { 564 this._attachWithIMEEvent(); 565 this.setAttachWithIME(false); 566 } 567 if (this.getDetachWithIME()) { 568 this._detachWithIMEEvent(); 569 this.setDetachWithIME(false); 570 } 571 if (this.getInsertText()) { 572 this._insertTextEvent(); 573 this.setInsertText(false); 574 this._textFieldRendererAdaptDirty = true; 575 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 576 } 577 if (this.getDeleteBackward()) { 578 this._deleteBackwardEvent(); 579 this.setDeleteBackward(false); 580 this._textFieldRendererAdaptDirty = true; 581 this._updateContentSizeWithTextureSize(this._textFieldRenderer.getContentSize()); 582 } 583 }, 584 585 /** 586 * Returns whether attach with IME. 587 * @returns {Boolean} 588 */ 589 getAttachWithIME: function () { 590 return this._textFieldRenderer.getAttachWithIME(); 591 }, 592 593 /** 594 * Sets attach with IME. 595 * @param {Boolean} attach 596 */ 597 setAttachWithIME: function (attach) { 598 this._textFieldRenderer.setAttachWithIME(attach); 599 }, 600 601 /** 602 * Returns whether detach with IME. 603 * @returns {Boolean} 604 */ 605 getDetachWithIME: function () { 606 return this._textFieldRenderer.getDetachWithIME(); 607 }, 608 609 /** 610 * Sets detach with IME. 611 * @param {Boolean} detach 612 */ 613 setDetachWithIME: function (detach) { 614 this._textFieldRenderer.setDetachWithIME(detach); 615 }, 616 617 /** 618 * Returns insertText string of ccui.TextField. 619 * @returns {String} 620 */ 621 getInsertText: function () { 622 return this._textFieldRenderer.getInsertText(); 623 }, 624 625 /** 626 * Sets insertText string to ccui.TextField. 627 * @param {String} insertText 628 */ 629 setInsertText: function (insertText) { 630 this._textFieldRenderer.setInsertText(insertText); 631 }, 632 633 /** 634 * Returns the delete backward of ccui.TextField. 635 * @returns {Boolean} 636 */ 637 getDeleteBackward: function () { 638 return this._textFieldRenderer.getDeleteBackward(); 639 }, 640 641 /** 642 * Sets the delete backward of ccui.TextField. 643 * @param {Boolean} deleteBackward 644 */ 645 setDeleteBackward: function (deleteBackward) { 646 this._textFieldRenderer.setDeleteBackward(deleteBackward); 647 }, 648 649 _attachWithIMEEvent: function () { 650 if(this._textFieldEventSelector){ 651 if (this._textFieldEventListener) 652 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_ATTACH_WITH_IME); 653 else 654 this._textFieldEventSelector(this, ccui.TextField.EVENT_ATTACH_WITH_IME); 655 } 656 }, 657 658 _detachWithIMEEvent: function () { 659 if(this._textFieldEventSelector){ 660 if (this._textFieldEventListener) 661 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_DETACH_WITH_IME); 662 else 663 this._textFieldEventSelector(this, ccui.TextField.EVENT_DETACH_WITH_IME); 664 } 665 }, 666 667 _insertTextEvent: function () { 668 if(this._textFieldEventSelector){ 669 if (this._textFieldEventListener) 670 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_INSERT_TEXT); 671 else 672 this._textFieldEventSelector(this, ccui.TextField.EVENT_INSERT_TEXT); 673 } 674 }, 675 676 _deleteBackwardEvent: function () { 677 if(this._textFieldEventSelector){ 678 if (this._textFieldEventListener) 679 this._textFieldEventSelector.call(this._textFieldEventListener, this, ccui.TextField.EVENT_DELETE_BACKWARD); 680 else 681 this._textFieldEventSelector(this, ccui.TextField.EVENT_DELETE_BACKWARD); 682 } 683 }, 684 685 /** 686 * Adds event listener to cuci.TextField. 687 * @param {Object} [target=] 688 * @param {Function} selector 689 * @deprecated since v3.0, please use addEventListener instead. 690 */ 691 addEventListenerTextField: function (selector, target) { 692 this.addEventListener(selector, target); 693 }, 694 695 /** 696 * Adds event listener callback. 697 * @param {Object} [target=] 698 * @param {Function} selector 699 */ 700 addEventListener: function(selector, target){ 701 this._textFieldEventSelector = selector; 702 this._textFieldEventListener = target; 703 }, 704 705 _onSizeChanged: function () { 706 ccui.Widget.prototype._onSizeChanged.call(this); 707 this._textFieldRendererAdaptDirty = true; 708 }, 709 710 _adaptRenderers: function(){ 711 if (this._textFieldRendererAdaptDirty) { 712 this._textfieldRendererScaleChangedWithSize(); 713 this._textFieldRendererAdaptDirty = false; 714 } 715 }, 716 717 _textfieldRendererScaleChangedWithSize: function () { 718 if (!this._ignoreSize) 719 this._textFieldRenderer.setDimensions(this._contentSize); 720 this._textFieldRenderer.setPosition(this._contentSize.width / 2, this._contentSize.height / 2); 721 }, 722 723 /** 724 * Returns the ccui.TextField's content size. 725 * @returns {cc.Size} 726 */ 727 getVirtualRendererSize: function(){ 728 return this._textFieldRenderer.getContentSize(); 729 }, 730 731 /** 732 * Returns the renderer of ccui.TextField. 733 * @returns {cc.Node} 734 */ 735 getVirtualRenderer: function () { 736 return this._textFieldRenderer; 737 }, 738 739 /** 740 * Returns the "class name" of ccui.TextField. 741 * @returns {string} 742 */ 743 getDescription: function () { 744 return "TextField"; 745 }, 746 747 /** 748 * Open keyboard and receive input text. 749 * @return {Boolean} 750 */ 751 attachWithIME: function () { 752 this._textFieldRenderer.attachWithIME(); 753 }, 754 755 _createCloneInstance: function () { 756 return ccui.TextField.create(); 757 }, 758 759 _copySpecialProperties: function (textField) { 760 this.setString(textField._textFieldRenderer.getString()); 761 this.setPlaceHolder(textField.getString()); 762 this.setFontSize(textField._textFieldRenderer.getFontSize()); 763 this.setFontName(textField._textFieldRenderer.getFontName()); 764 this.setMaxLengthEnabled(textField.isMaxLengthEnabled()); 765 this.setMaxLength(textField.getMaxLength()); 766 this.setPasswordEnabled(textField.isPasswordEnabled()); 767 this.setPasswordStyleText(textField._passwordStyleText); 768 this.setAttachWithIME(textField.getAttachWithIME()); 769 this.setDetachWithIME(textField.getDetachWithIME()); 770 this.setInsertText(textField.getInsertText()); 771 this.setDeleteBackward(textField.getDeleteBackward()); 772 }, 773 774 /** 775 * Sets the text area size to ccui.TextField. 776 * @param {cc.Size} size 777 */ 778 setTextAreaSize: function(size){ 779 this.setContentSize(size); 780 }, 781 782 /** 783 * Sets the text horizontal alignment of ccui.TextField. 784 * @param alignment 785 */ 786 setTextHorizontalAlignment: function(alignment){ 787 this._textFieldRenderer.setHorizontalAlignment(alignment); 788 }, 789 790 /** 791 * Sets the text vertical alignment of ccui.TextField. 792 * @param alignment 793 */ 794 setTextVerticalAlignment: function(alignment){ 795 this._textFieldRenderer.setVerticalAlignment(alignment); 796 }, 797 _setFont: function (font) { 798 this._textFieldRenderer._setFont(font); 799 this._textFieldRendererAdaptDirty = true; 800 }, 801 802 _getFont: function () { 803 return this._textFieldRenderer._getFont(); 804 } 805 }); 806 807 /** 808 * Creates a ccui.TextField. 809 * @deprecated since v3.0, please use new ccui.TextField() instead. 810 * @param {String} placeholder 811 * @param {String} fontName 812 * @param {Number} fontSize 813 * @returns {ccui.TextField} 814 * @example 815 * // example 816 * var uiTextField = ccui.TextField.create(); 817 */ 818 ccui.TextField.create = function(placeholder, fontName, fontSize){ 819 return new ccui.TextField(placeholder, fontName, fontSize); 820 }; 821 822 var _p = ccui.TextField.prototype; 823 824 // Extended properties 825 /** @expose */ 826 _p.string; 827 cc.defineGetterSetter(_p, "string", _p.getString, _p.setString); 828 /** @expose */ 829 _p.placeHolder; 830 cc.defineGetterSetter(_p, "placeHolder", _p.getPlaceHolder, _p.setPlaceHolder); 831 /** @expose */ 832 _p.font; 833 cc.defineGetterSetter(_p, "font", _p._getFont, _p._setFont); 834 /** @expose */ 835 _p.fontSize; 836 cc.defineGetterSetter(_p, "fontSize", _p.getFontSize, _p.setFontSize); 837 /** @expose */ 838 _p.fontName; 839 cc.defineGetterSetter(_p, "fontName", _p.getFontName, _p.setFontName); 840 /** @expose */ 841 _p.maxLengthEnabled; 842 cc.defineGetterSetter(_p, "maxLengthEnabled", _p.isMaxLengthEnabled, _p.setMaxLengthEnabled); 843 /** @expose */ 844 _p.maxLength; 845 cc.defineGetterSetter(_p, "maxLength", _p.getMaxLength, _p.setMaxLength); 846 /** @expose */ 847 _p.passwordEnabled; 848 cc.defineGetterSetter(_p, "passwordEnabled", _p.isPasswordEnabled, _p.setPasswordEnabled); 849 850 _p = null; 851 852 // Constants 853 //TextField event 854 /** 855 * The attach with IME event flag of ccui.TextField 856 * @constant 857 * @type {number} 858 */ 859 ccui.TextField.EVENT_ATTACH_WITH_IME = 0; 860 /** 861 * The detach with IME event flag of ccui.TextField 862 * @constant 863 * @type {number} 864 */ 865 ccui.TextField.EVENT_DETACH_WITH_IME = 1; 866 /** 867 * The insert text event flag of ccui.TextField 868 * @constant 869 * @type {number} 870 */ 871 ccui.TextField.EVENT_INSERT_TEXT = 2; 872 /** 873 * The delete backward event flag of ccui.TextField 874 * @constant 875 * @type {number} 876 */ 877 ccui.TextField.EVENT_DELETE_BACKWARD = 3; 878 879 /** 880 * The zOrder value of ccui.TextField's renderer. 881 * @constant 882 * @type {number} 883 */ 884 ccui.TextField.RENDERER_ZORDER = -1;