Skip to content

Commit 956b26e

Browse files
author
pandamicro
committed
Fix issues in cocos2d#3407
1 parent 735ec99 commit 956b26e

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

Diff for: cocos2d/core/labelttf/CCLabelTTF.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,9 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
610610
* @param {Number} [scaleY=]
611611
*/
612612
setScale: function (scale, scaleY) {
613-
this._scaleX = scale / cc.view.getDevicePixelRatio();
614-
this._scaleY = ((scaleY || scaleY === 0) ? scaleY : scale) /
615-
cc.view.getDevicePixelRatio();
613+
var ratio = cc.view.getDevicePixelRatio();
614+
this._scaleX = scale / ratio;
615+
this._scaleY = ((scaleY || scaleY === 0) ? scaleY : scale) / ratio;
616616
this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
617617
},
618618

@@ -806,25 +806,37 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
806806
getContentSize: function () {
807807
if (this._needUpdateTexture)
808808
this._renderCmd._updateTTF();
809-
return cc.size(
810-
this._contentSize.width / cc.view.getDevicePixelRatio(),
811-
this._contentSize.height / cc.view.getDevicePixelRatio());
809+
var ratio = cc.view.getDevicePixelRatio();
810+
return cc.size( this._contentSize.width / ratio, this._contentSize.height / ratio );
812811
},
813812

814813
_getWidth: function () {
815814
if (this._needUpdateTexture)
816815
this._renderCmd._updateTTF();
817-
return cc.Sprite.prototype._getWidth.call(this);
816+
return this._contentSize.width / cc.view.getDevicePixelRatio();
818817
},
819818
_getHeight: function () {
820819
if (this._needUpdateTexture)
821820
this._renderCmd._updateTTF();
822-
return cc.Sprite.prototype._getHeight.call(this);
821+
return this._contentSize.height / cc.view.getDevicePixelRatio();
823822
},
824823

825824
setTextureRect: function (rect, rotated, untrimmedSize) {
826-
//set needConvert to false
827-
cc.Sprite.prototype.setTextureRect.call(this, rect, rotated, untrimmedSize, false);
825+
var _t = this;
826+
_t._rectRotated = rotated || false;
827+
_t.setContentSize(untrimmedSize || rect);
828+
829+
_t.setVertexRect(rect);
830+
_t._renderCmd._setTextureCoords(rect, false);
831+
832+
var relativeOffsetX = _t._unflippedOffsetPositionFromCenter.x, relativeOffsetY = _t._unflippedOffsetPositionFromCenter.y;
833+
if (_t._flippedX)
834+
relativeOffsetX = -relativeOffsetX;
835+
if (_t._flippedY)
836+
relativeOffsetY = -relativeOffsetY;
837+
var locRect = _t._rect;
838+
_t._offsetPosition.x = relativeOffsetX + (rect.width - locRect.width) / 2;
839+
_t._offsetPosition.y = relativeOffsetY + (rect.height - locRect.height) / 2;
828840
},
829841

830842
/**

Diff for: cocos2d/core/labelttf/CCLabelTTFCanvasRenderCmd.js

+3-18
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
103103

104104
proto._updateTTF = function () {
105105
var node = this._node;
106-
var locDimensionsWidth = node._dimensions.width, i, strLength;
106+
var pixelRatio = cc.view.getDevicePixelRatio();
107+
var locDimensionsWidth = node._dimensions.width * pixelRatio, i, strLength;
107108
var locLineWidth = this._lineWidths;
108109
locLineWidth.length = 0;
109110

@@ -135,7 +136,6 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
135136
locStrokeShadowOffsetY += Math.abs(locOffsetSize.y) * 2;
136137
}
137138

138-
var pixelRatio = cc.view.getDevicePixelRatio();
139139
//get offset for stroke and shadow
140140
if (locDimensionsWidth === 0) {
141141
if (this._isMultiLine)
@@ -178,6 +178,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
178178

179179
proto._saveStatus = function () {
180180
var node = this._node;
181+
var scale = cc.view.getDevicePixelRatio();
181182
var locStrokeShadowOffsetX = node._strokeShadowOffsetX, locStrokeShadowOffsetY = node._strokeShadowOffsetY;
182183
var locContentSizeHeight = node._contentSize.height - locStrokeShadowOffsetY, locVAlignment = node._vAlignment,
183184
locHAlignment = node._hAlignment;
@@ -310,32 +311,16 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
310311

311312
proto.updateStatus = function () {
312313
var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
313-
314-
<<<<<<< HEAD
315-
=======
316-
cc.Node.RenderCmd.prototype.updateStatus.call(this);
317314

318-
>>>>>>> 45cdfaa... Revert "Fix UIText issue and Label getContentSize value wrong in retina mode"
319315
if (locFlag & flags.textDirty)
320316
this._updateTexture();
321317

322318
cc.Node.RenderCmd.prototype.updateStatus.call(this);
323-
324-
if (this._dirtyFlag & flags.transformDirty){
325-
this.transform(this.getParentRenderCmd(), true);
326-
this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.transformDirty ^ this._dirtyFlag;
327-
}
328319
};
329320

330321
proto._syncStatus = function (parentCmd) {
331322
var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
332-
<<<<<<< HEAD
333323

334-
=======
335-
336-
cc.Node.RenderCmd.prototype._syncStatus.call(this, parentCmd);
337-
338-
>>>>>>> 45cdfaa... Revert "Fix UIText issue and Label getContentSize value wrong in retina mode"
339324
if (locFlag & flags.textDirty)
340325
this._updateTexture();
341326

Diff for: extensions/ccui/uiwidgets/UIText.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ccui.Text = ccui.Widget.extend(/** @lends ccui.Text# */{
4646
_fontName: "Arial",
4747
_fontSize: 16,
4848
_onSelectedScaleOffset:0.5,
49-
_labelRenderer: "",
49+
_labelRenderer: null,
5050
_textAreaSize: null,
5151
_textVerticalAlignment: 0,
5252
_textHorizontalAlignment: 0,

0 commit comments

Comments
 (0)