| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- CTLText.prototype = {
-
- constructor : CTLText,
-
- __autofit : function(){
- if(this._bFitText){
-
- var iFontSize = this._iFontSize;
- while(
- this._oText.getBounds().height > (this._iHeight -this._iPaddingV*2) ||
- this._oText.getBounds().width > (this._iWidth-this._iPaddingH*2)
- ){
- iFontSize--;
-
- this._oText.font = iFontSize+"px "+this._szFont;
- this._oText.lineHeight = Math.round(iFontSize*this._fLineHeightFactor);
-
- this.__updateY();
- this.__verticalAlign();
-
- if ( iFontSize < 8 ){
- break;
- }
- };
-
- this._iFontSize = iFontSize;
- }
- },
-
- __verticalAlign : function(){
- if(this._bVerticalAlign){
- var iCurHeight = this._oText.getBounds().height;
- this._oText.y -= (iCurHeight-this._iHeight)/2 + (this._iPaddingV);
- }
- },
- __updateY : function(){
- this._oText.y = this._y + this._iPaddingV;
- switch(this._oText.textBaseline){
- case "middle":{
- this._oText.y += (this._oText.lineHeight/2) +
- (this._iFontSize*this._fLineHeightFactor-this._iFontSize);
- }break;
- }
- },
- __createText : function(szMsg){
-
- if (this._bDebug){
- this._oDebugShape = new createjs.Shape();
- this._oDebugShape.graphics.beginFill("rgba(255,0,0,0.5)").drawRect(
- this._x, this._y, this._iWidth, this._iHeight);
- this._oContainer.addChild(this._oDebugShape);
- }
- this._oText = new createjs.Text(szMsg, this._iFontSize+"px "+this._szFont, this._szColor);
- this._oText.textBaseline = "middle";
- this._oText.lineHeight = Math.round(this._iFontSize*this._fLineHeightFactor);
- this._oText.textAlign = this._szAlign;
-
-
- if ( this._bMultiline ){
- this._oText.lineWidth = this._iWidth - (this._iPaddingH*2);
- }else{
- this._oText.lineWidth = null;
- }
-
- switch(this._szAlign){
- case "center":{
- this._oText.x = this._x+(this._iWidth/2);
- }break;
- case "left":{
- this._oText.x = this._x+this._iPaddingH;
- }break;
- case "right":{
- this._oText.x = this._x+this._iWidth-this._iPaddingH;
- }break;
- }
- this._oContainer.addChild(this._oText);
-
- this.refreshText(szMsg);
- },
-
- setVerticalAlign : function( bVerticalAlign ){
- this._bVerticalAlign = bVerticalAlign;
- },
-
- setOutline : function(iSize){
- if ( this._oText !== null ){
- this._oText.outline = iSize;
- }
- },
-
- setShadow : function(szColor,iOffsetX,iOffsetY,iBlur){
- if ( this._oText !== null ){
- this._oText.shadow = new createjs.Shadow(szColor, iOffsetX,iOffsetY,iBlur);
- }
- },
-
- setColor : function(szColor){
- this._oText.color = szColor;
- },
-
- setAlpha : function(iAlpha){
- this._oText.alpha = iAlpha;
- },
-
- removeTweens : function(){
- createjs.Tween.removeTweens(this._oText);
- },
-
- getText : function(){
- return this._oText;
- },
-
- getY : function(){
- return this._y;
- },
-
- getFontSize : function(){
- return this._iFontSize;
- },
-
- refreshText : function(szMsg){
- if(szMsg === ""){
- szMsg = " ";
- }
- if ( this._oText === null ){
- this.__createText(szMsg);
- }
-
- this._oText.text = szMsg;
- this._oText.font = this._iFontSize+"px "+this._szFont;
- this._oText.lineHeight = Math.round(this._iFontSize*this._fLineHeightFactor);
-
- this.__autofit();
- this.__updateY();
- this.__verticalAlign();
- },
-
- unload : function(){
- this._oContainer.removeChild(this._oText);
- if(this._oDebugShape){
- this._oContainer.removeChild(this._oDebugShape);
- }
- }
- };
- function CTLText( oContainer,
- x, y, iWidth, iHeight,
- iFontSize, szAlign, szColor, szFont,iLineHeightFactor,
- iPaddingH, iPaddingV,
- szMsg,
- bFitText, bVerticalAlign, bMultiline,
- bDebug ){
- this._oContainer = oContainer;
- this._x = x;
- this._y = y;
- this._iWidth = iWidth;
- this._iHeight = iHeight;
-
- this._bMultiline = bMultiline;
- this._iFontSize = iFontSize;
- this._szAlign = szAlign;
- this._szColor = szColor;
- this._szFont = szFont;
- this._iPaddingH = iPaddingH;
- this._iPaddingV = iPaddingV;
- this._bVerticalAlign = bVerticalAlign;
- this._bFitText = bFitText;
- this._bDebug = bDebug;
- // RESERVED
- this._oDebugShape = null;
- this._fLineHeightFactor = iLineHeightFactor;
-
- this._oText = null;
- if ( szMsg ){
- this.__createText(szMsg);
-
- }
- }
|