1
+ /*global cc */
2
+
1
3
/****************************************************************************
2
4
Copyright (c) 2015 Chukong Technologies Inc.
3
5
22
24
THE SOFTWARE.
23
25
****************************************************************************/
24
26
25
- EventTarget = require ( "../cocos2d/core/event/event-target" ) ;
27
+ var EventTarget = require ( "../cocos2d/core/event/event-target" ) ;
26
28
27
29
cc . Label = cc . Node . extend ( {
28
30
_hAlign : 0 , //0 left, 1 center, 2 right
@@ -31,45 +33,45 @@ cc.Label = cc.Node.extend({
31
33
_fontSize : 20 ,
32
34
_overFlow : 0 , //0 clamp, 1 shrink 2, resize to content
33
35
_isWrapText : true ,
34
- _spacingX : 0 ,
35
- _spacingY : 0 ,
36
+ _spacingX : 0 ,
37
+ _spacingY : 0 ,
36
38
37
39
_labelSkinDirty : true ,
38
40
_labelIsTTF : true ,
39
41
_fontHandle : "" ,
40
42
41
43
//fontHandle it is a font name or bmfont file.
42
- ctor : function ( fontHandle , isTTF ) {
44
+ ctor : function ( fontHandle , isTTF ) {
43
45
fontHandle = fontHandle || "" ;
44
46
this . _fontHandle = fontHandle ;
45
47
isTTF = isTTF || true ;
46
48
this . _labelIsTTF = isTTF ;
47
49
cc . Node . prototype . ctor . call ( this ) ;
48
- this . setContentSize ( cc . size ( 128 , 128 ) ) ;
50
+ this . setContentSize ( cc . size ( 128 , 128 ) ) ;
49
51
} ,
50
52
51
- setHorizontalAlign : function ( align ) {
52
- if ( this . _hAlign === align ) return ;
53
+ setHorizontalAlign : function ( align ) {
54
+ if ( this . _hAlign === align ) return ;
53
55
this . _hAlign = align ;
54
56
this . _notifyLabelSkinDirty ( ) ;
55
57
} ,
56
58
57
- getHorizontalAlign : function ( ) {
59
+ getHorizontalAlign : function ( ) {
58
60
return this . _hAlign ;
59
61
} ,
60
62
61
- setVerticalAlign : function ( align ) {
62
- if ( this . _vAlign === align ) return ;
63
+ setVerticalAlign : function ( align ) {
64
+ if ( this . _vAlign === align ) return ;
63
65
this . _vAlign = align ;
64
66
this . _notifyLabelSkinDirty ( ) ;
65
67
} ,
66
68
67
- getVerticalAlign : function ( ) {
69
+ getVerticalAlign : function ( ) {
68
70
return this . _vAlign ;
69
71
} ,
70
72
71
73
setString : function ( string ) {
72
- if ( this . _string === string ) return ;
74
+ if ( this . _string === string ) return ;
73
75
this . _string = string ;
74
76
this . _notifyLabelSkinDirty ( ) ;
75
77
} ,
@@ -79,7 +81,7 @@ cc.Label = cc.Node.extend({
79
81
} ,
80
82
81
83
enableWrapText : function ( enabled ) {
82
- if ( this . _isWrapText === enabled ) return ;
84
+ if ( this . _isWrapText === enabled ) return ;
83
85
this . _isWrapText = enabled ;
84
86
this . _notifyLabelSkinDirty ( ) ;
85
87
} ,
@@ -89,7 +91,7 @@ cc.Label = cc.Node.extend({
89
91
} ,
90
92
91
93
setFontSize : function ( fntSize ) {
92
- if ( this . _fontSize === fntSize ) return ;
94
+ if ( this . _fontSize === fntSize ) return ;
93
95
this . _fontSize = fntSize ;
94
96
this . _notifyLabelSkinDirty ( ) ;
95
97
} ,
@@ -99,7 +101,7 @@ cc.Label = cc.Node.extend({
99
101
} ,
100
102
101
103
setOverflow : function ( overflow ) {
102
- if ( this . _overFlow === overflow ) return ;
104
+ if ( this . _overFlow === overflow ) return ;
103
105
this . _overFlow = overflow ;
104
106
this . _notifyLabelSkinDirty ( ) ;
105
107
} ,
@@ -109,14 +111,14 @@ cc.Label = cc.Node.extend({
109
111
} ,
110
112
111
113
setSpacingX : function ( spacing ) {
112
- if ( this . _spacingX === spacing ) return ;
113
- this . _spacingX == spacing ;
114
+ if ( this . _spacingX === spacing ) return ;
115
+ this . _spacingX = spacing ;
114
116
this . _notifyLabelSkinDirty ( ) ;
115
117
} ,
116
118
117
119
setSpacingY : function ( spacing ) {
118
- if ( this . _spacingY === spacing ) return ;
119
- this . _spacingY == spacing ;
120
+ if ( this . _spacingY === spacing ) return ;
121
+ this . _spacingY = spacing ;
120
122
this . _notifyLabelSkinDirty ( ) ;
121
123
} ,
122
124
@@ -128,33 +130,43 @@ cc.Label = cc.Node.extend({
128
130
return this . _spacingY ;
129
131
} ,
130
132
131
- setContentSize : function ( size ) {
132
- if ( cc . sizeEqualToSize ( this . _contentSize , size ) )
133
- {
133
+ setContentSize : function ( size ) {
134
+ if ( cc . sizeEqualToSize ( this . _contentSize , size ) ) {
134
135
return ;
135
136
}
136
137
cc . Node . prototype . setContentSize . call ( this , size ) ;
137
138
this . _notifyLabelSkinDirty ( ) ;
138
139
} ,
139
140
140
- _notifyLabelSkinDirty : function ( ) {
141
+ _notifyLabelSkinDirty : function ( ) {
141
142
this . _labelSkinDirty = true ;
142
143
this . _renderCmd . setDirtyFlag ( cc . Node . _dirtyFlags . textDirty ) ;
143
144
} ,
144
- _createRenderCmd : function ( ) {
145
+ _createRenderCmd : function ( ) {
145
146
146
- if ( this . _labelIsTTF ) {
147
+ if ( this . _labelIsTTF ) {
147
148
if ( cc . _renderType === cc . game . RENDER_TYPE_WEBGL )
148
149
return new cc . Label . TTFWebGLRenderCmd ( this ) ;
149
150
else
150
151
return new cc . Label . TTFCanvasRenderCmd ( this ) ;
151
- }
152
- else {
152
+ } else {
153
153
//todo:add label bmfont here
154
154
}
155
155
}
156
156
} ) ;
157
157
158
- cc . Label . HorizontalAlign = { LEFT : 0 , CENTER : 1 , RIGHT : 2 } ;
159
- cc . Label . VerticalAlign = { BOTTOM : 0 , CENTER : 1 , TOP : 2 } ;
160
- cc . Label . Overflow = { CLAMP : 0 , SHRINK : 1 , RESIZE : 2 } ;
158
+ cc . Label . HorizontalAlign = {
159
+ LEFT : 0 ,
160
+ CENTER : 1 ,
161
+ RIGHT : 2
162
+ } ;
163
+ cc . Label . VerticalAlign = {
164
+ BOTTOM : 0 ,
165
+ CENTER : 1 ,
166
+ TOP : 2
167
+ } ;
168
+ cc . Label . Overflow = {
169
+ CLAMP : 0 ,
170
+ SHRINK : 1 ,
171
+ RESIZE : 2
172
+ } ;
0 commit comments