差分発生行の前後
無視リスト:
コミット日時:
2009/04/10 12:08:14 (3 年前)
コミッタ:
alumican
ログメッセージ:

Eseclock:IEseclockTextFieldの仕様を変更

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/Eseclock/branches/alumican/src/org/libspark/eseclock/object/ClockSprite.as

    r2430 r2440  
    3535        import flash.text.TextFormat; 
    3636        import flash.utils.getDefinitionByName; 
    37         import org.libspark.eseclock.textfield.EseclockDefaultTextField; 
     37         
     38        import org.libspark.eseclock.textfield.EseclockDefaultClockTextField; 
     39        import org.libspark.eseclock.textfield.EseclockDefaultDescriptionTextField; 
    3840        import org.libspark.eseclock.textfield.IEseclockTextField; 
    3941         
     
    6264                private var _leading:Number; 
    6365                 
     66                //テキストが空文字列以外の場合はtrue 
     67                private var _hasDescription:Boolean; 
     68                 
     69                 
    6470                 
    6571                 
     
    6975                //------------------------------------- 
    7076                 
    71                 //時計の下に表示するテキスト 
    72                 public function get description():String { return _sub.description; } 
    73                 public function set description(value:String):void { updateDescription(value); } 
    74                  
    7577                //テキスト色 
    76                 public function get textColor():uint { return _field.defaultTextFormat.color as uint; } 
    7778                public function set textColor(value:uint):void { 
    7879                        _changeTextColor(_field, value); 
     
    8182                 
    8283                //背景色 
    83                 public function get backgroundColor():uint { return _backgroundColor; } 
    8484                public function set backgroundColor(value:uint):void { _drawBackground(value); } 
    8585                 
     
    128128                private function _createFields(color:uint, clockAsset:String = "", subAsset:String = ""):void 
    129129                { 
    130                         var fmt:TextFormat; 
    131                          
    132                         fmt = (clockAsset == "") ? new TextFormat("Arial Black", 96, color, true) : new TextFormat(null, null, color); 
    133                         _field = _createField(clockAsset, fmt); 
    134                         _field.update(99, 99, 99); 
    135                          
    136                         fmt = (subAsset == "") ? new TextFormat("Arial Black", 36, color, true) : new TextFormat(null, null, color); 
    137                         _sub = _createField(subAsset, fmt); 
    138                         description = "TOKYO / JAPAN"; 
     130                        _field = _createField(clockAsset, EseclockDefaultClockTextField); 
     131                        _field.setColor(color); 
     132                        _field.updateClock(99, 99, 99); 
     133                         
     134                        _masked.addChild(_field as DisplayObject); 
     135                         
     136                         
     137                        _sub = _createField(subAsset, EseclockDefaultDescriptionTextField); 
     138                        _sub.setColor(color); 
     139                        _sub.updateDescription("TOKYO / JAPAN"); 
     140                         
     141                        _masked.addChild(_sub as DisplayObject); 
     142                         
    139143                         
    140144                        //中央揃え 
     
    144148                /** 
    145149                 * 各テキストフィールドを生成する関数 
    146                  * @param       tf 
    147150                 * @param       asset 
    148                  * @param       fmt 
    149                  */ 
    150                 private function _createField(asset:String, fmt:TextFormat):IEseclockTextField { 
     151                 * @param       defaultClass 
     152                 */ 
     153                private function _createField(asset:String, defaultClass:Class):IEseclockTextField { 
    151154                        var tf:IEseclockTextField; 
    152155                         
    153156                        if (asset == "") { 
    154                                 tf = new EseclockDefaultTextField()
     157                                tf = new defaultClass() as IEseclockTextField
    155158                        } else { 
    156159                                var fieldClass:Class = getDefinitionByName(asset) as Class; 
     
    158161                        } 
    159162                         
    160                         tf.defaultTextFormat = fmt; 
    161                         tf.selectable = false; 
    162                         tf.autoSize = TextFieldAutoSize.LEFT; 
    163                         _masked.addChild(tf as DisplayObject); 
    164                          
    165163                        return tf; 
    166164                } 
     
    172170                public function updateDescription(description:String):void 
    173171                { 
    174                         _sub.description = description; 
     172                        _hasDescription = (description != "") ? true : false; 
     173                         
     174                        _sub.updateDescription(description); 
    175175                         
    176176                        //中央揃え 
     
    186186                public function updateField(h:uint, m:uint, s:uint):void 
    187187                { 
    188                         _field.update(h, m, s); 
     188                        _field.updateClock(h, m, s); 
    189189                } 
    190190                 
    191191                /** 
    192192                 * テキストフィールドの色を変更する関数 
    193                  * @param       textField     ターゲット 
     193                 * @param       tf    ターゲット 
    194194                 * @param       color           色 
    195195                 */ 
    196                 private function _changeTextColor(textField:IEseclockTextField, color:uint):void 
    197                 { 
    198                         var fmt:TextFormat = textField.defaultTextFormat; 
    199                         fmt.color = color; 
    200                         textField.defaultTextFormat = fmt; 
    201                         textField.setTextFormat(fmt); 
     196                private function _changeTextColor(tf:IEseclockTextField, color:uint):void 
     197                { 
     198                        tf.setColor(color); 
    202199                } 
    203200                 
     
    212209                         
    213210                        //テキストフィールドの中央揃え 
    214                         var margin:int = (description.length > 0) ? _leading : 0; 
    215                         var totalHeight:uint = _field.textHeight + _sub.textHeight; 
    216                          
    217                         _field.x = (_w - _field.textWidth) / 2; 
    218                         _field.y = (_h - totalHeight     ) / 2; 
    219                          
    220                         _sub.x = (_w - _sub.textWidth) / 2; 
    221                         _sub.y = (_h - totalHeight   ) / 2 + _field.textHeight + margin; 
     211                        var margin:int = (_hasDescription) ? _leading : 0; 
     212                        var totalHeight:uint = _field.objectHeight + _sub.objectHeight; 
     213                         
     214                        _field.x = (_w - _field.objectWidth) / 2; 
     215                        _field.y = (_h - totalHeight       ) / 2; 
     216                         
     217                        _sub.x = (_w - _sub.objectWidth) / 2; 
     218                        _sub.y = (_h - totalHeight     ) / 2 + _field.objectHeight + margin; 
    222219                } 
    223220        }