Skip to content

Commit

Permalink
Merge pull request cocos#679 from dabingnn/label_add_outline
Browse files Browse the repository at this point in the history
add width for stroke
  • Loading branch information
nantas committed May 17, 2016
2 parents 017f573 + a9d5ea5 commit edf92d2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
21 changes: 21 additions & 0 deletions cocos2d/core/components/CCLabelOutline.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var LabelOutline = cc.Class({
* outline.color = new cc.Color(0.5, 0.3, 0.7, 1.0);;
*/
_color: cc.color(255,255,255,255),
_width: 1,
color: {
get: function() {
return this._color;
Expand All @@ -69,6 +70,25 @@ var LabelOutline = cc.Class({
}
}
},
/**
* !#en Change the outline width
* !#zh 改变描边的宽度
* @property width
* @type {Number}
* @example
* outline.width = 3;
*/
width: {
get: function() {
return this._width;
},
set: function(value) {
this._width = value;
if(this._labelSGNode) {
this._labelSGNode.setOutlineWidth(value);
}
}
},
},

onEnable: function () {
Expand All @@ -77,6 +97,7 @@ var LabelOutline = cc.Class({
if(this._labelSGNode) {
sgNode.setOutlined(true);
sgNode.setOutlineColor(cc.color(this._color));
sgNode.setOutlineWidth(this._width);
}
},

Expand Down
10 changes: 10 additions & 0 deletions cocos2d/core/label/CCSGLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ _ccsg.Label = _ccsg.Node.extend({
_lineHeight: 40,
_outlined: false,
_outlineColor: null,
_outlineWidth: 1,
_className: "Label",

//fontHandle it is a system font name, ttf file path or bmfont file path.
Expand Down Expand Up @@ -273,6 +274,15 @@ _ccsg.Label = _ccsg.Node.extend({
this._notifyLabelSkinDirty();
},

setOutlineWidth: function(value) {
this._outlineWidth = value;
this._notifyLabelSkinDirty();
},

getOutlineWidth: function() {
return this._outlineWidth;
},

_updateWrapText: function(overflow){
if ( overflow === _ccsg.Label.Overflow.RESIZE_HEIGHT) {
this._isWrapText = true;
Expand Down
7 changes: 2 additions & 5 deletions cocos2d/core/label/CCSGLabelCanvasRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,8 @@
var strokeColor = this._node.getOutlineColor() || cc.color(255,255,255,255);
this._labelContext.globalCompositeOperation = 'source-over';
this._labelContext.strokeStyle = 'rgb(' + strokeColor.r + ',' + strokeColor.g + ',' + strokeColor.b + ')';
//draw it several times to make it clearer.
var strokRepeatTimes = 5;
for(var strokeRepeatIndex = 0; strokeRepeatIndex < strokRepeatTimes; ++strokeRepeatIndex) {
this._labelContext.strokeText(this._splitedStrings[i], startPosition.x, startPosition.y + i * lineHeight);
}
this._labelContext.lineWidth = this._node.getOutlineWidth();
this._labelContext.strokeText(this._splitedStrings[i], startPosition.x, startPosition.y + i * lineHeight);
}
}

Expand Down

0 comments on commit edf92d2

Please sign in to comment.