Skip to content

Commit 735ec99

Browse files
author
pandamicro
committed
Merge branch 'simpler-getContentSize' of github.com:ntrrgc/cocos2d-html5 into legend
2 parents d79cf76 + 946367a commit 735ec99

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ cc.LabelTTF = cc.Sprite.extend(/** @lends cc.LabelTTF# */{
612612
setScale: function (scale, scaleY) {
613613
this._scaleX = scale / cc.view.getDevicePixelRatio();
614614
this._scaleY = ((scaleY || scaleY === 0) ? scaleY : scale) /
615-
cc.view.getDevicePixelRatio();
615+
cc.view.getDevicePixelRatio();
616616
this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
617617
},
618618

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

812814
_getWidth: function () {
813815
if (this._needUpdateTexture)
814816
this._renderCmd._updateTTF();
815-
return this._contentSize.width;
817+
return cc.Sprite.prototype._getWidth.call(this);
816818
},
817819
_getHeight: function () {
818820
if (this._needUpdateTexture)
819821
this._renderCmd._updateTTF();
820-
return this._contentSize.height;
822+
return cc.Sprite.prototype._getHeight.call(this);
821823
},
822824

823825
setTextureRect: function (rect, rotated, untrimmedSize) {

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

+28-27
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
4848
this._status = [];
4949
this._renderingIndex = 0;
5050

51-
this._texRect = cc.rect();
5251
this._canUseDirtyRegion = true;
5352
};
5453
var proto = cc.LabelTTF.RenderCmd.prototype;
@@ -104,8 +103,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
104103

105104
proto._updateTTF = function () {
106105
var node = this._node;
107-
var pixelRatio = cc.view.getDevicePixelRatio();
108-
var locDimensionsWidth = node._dimensions.width * pixelRatio, i, strLength;
106+
var locDimensionsWidth = node._dimensions.width, i, strLength;
109107
var locLineWidth = this._lineWidths;
110108
locLineWidth.length = 0;
111109

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

138+
var pixelRatio = cc.view.getDevicePixelRatio();
140139
//get offset for stroke and shadow
141140
if (locDimensionsWidth === 0) {
142141
if (this._isMultiLine)
@@ -167,16 +166,7 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
167166
if (node._getFontStyle() !== "normal") { //add width for 'italic' and 'oblique'
168167
locSize.width = Math.ceil(locSize.width + node._fontSize * 0.3);
169168
}
170-
if (this._strings.length === 0) {
171-
this._texRect.width = 1;
172-
this._texRect.height = locSize.height || 1;
173-
}
174-
else {
175-
this._texRect.width = locSize.width;
176-
this._texRect.height = locSize.height;
177-
}
178-
var nodeW = locSize.width / pixelRatio, nodeH = locSize.height / pixelRatio;
179-
node.setContentSize(nodeW, nodeH);
169+
node.setContentSize(locSize);
180170
node._strokeShadowOffsetX = locStrokeShadowOffsetX;
181171
node._strokeShadowOffsetY = locStrokeShadowOffsetY;
182172

@@ -188,14 +178,13 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
188178

189179
proto._saveStatus = function () {
190180
var node = this._node;
191-
var scale = cc.view.getDevicePixelRatio();
192181
var locStrokeShadowOffsetX = node._strokeShadowOffsetX, locStrokeShadowOffsetY = node._strokeShadowOffsetY;
193-
var locContentSizeHeight = node._contentSize.height * scale - locStrokeShadowOffsetY, locVAlignment = node._vAlignment,
182+
var locContentSizeHeight = node._contentSize.height - locStrokeShadowOffsetY, locVAlignment = node._vAlignment,
194183
locHAlignment = node._hAlignment;
195184
var dx = locStrokeShadowOffsetX * 0.5,
196185
dy = locContentSizeHeight + locStrokeShadowOffsetY * 0.5;
197186
var xOffset = 0, yOffset = 0, OffsetYArray = [];
198-
var locContentWidth = node._contentSize.width * scale - locStrokeShadowOffsetX;
187+
var locContentWidth = node._contentSize.width - locStrokeShadowOffsetX;
199188

200189
//lineHeight
201190
var lineHeight = node.getLineHeight() * scale;
@@ -322,6 +311,11 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
322311
proto.updateStatus = function () {
323312
var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
324313

314+
<<<<<<< HEAD
315+
=======
316+
cc.Node.RenderCmd.prototype.updateStatus.call(this);
317+
318+
>>>>>>> 45cdfaa... Revert "Fix UIText issue and Label getContentSize value wrong in retina mode"
325319
if (locFlag & flags.textDirty)
326320
this._updateTexture();
327321

@@ -335,7 +329,13 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
335329

336330
proto._syncStatus = function (parentCmd) {
337331
var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
332+
<<<<<<< HEAD
338333

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"
339339
if (locFlag & flags.textDirty)
340340
this._updateTexture();
341341

@@ -393,7 +393,6 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
393393
locCanvas.width = 1;
394394
locCanvas.height = 1;
395395
this._labelContext = locCanvas.getContext("2d");
396-
this._texRect = cc.rect();
397396
};
398397

399398
cc.LabelTTF.CacheRenderCmd.prototype = Object.create( cc.LabelTTF.RenderCmd.prototype);
@@ -405,8 +404,9 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
405404
proto._updateTexture = function () {
406405
this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.textDirty ^ this._dirtyFlag;
407406
var node = this._node;
407+
var locContentSize = node._contentSize;
408408
this._updateTTF();
409-
var width = this._texRect.width, height = this._texRect.height;
409+
var width = locContentSize.width, height = locContentSize.height;
410410

411411
var locContext = this._labelContext, locLabelCanvas = this._labelCanvas;
412412

@@ -417,24 +417,24 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
417417
}
418418

419419
if (node._string.length === 0) {
420-
locLabelCanvas.width = width;
421-
locLabelCanvas.height = height;
420+
locLabelCanvas.width = 1;
421+
locLabelCanvas.height = locContentSize.height || 1;
422422
node._texture && node._texture.handleLoadedTexture();
423-
node.setTextureRect(this._texRect);
423+
node.setTextureRect(cc.rect(0, 0, 1, locContentSize.height));
424424
return true;
425425
}
426426

427427
//set size for labelCanvas
428428
locContext.font = this._fontStyleStr;
429429

430430
var flag = locLabelCanvas.width === width && locLabelCanvas.height === height;
431-
locLabelCanvas.width = this._texRect.width;
432-
locLabelCanvas.height = this._texRect.height;
431+
locLabelCanvas.width = width;
432+
locLabelCanvas.height = height;
433433
if (flag) locContext.clearRect(0, 0, width, height);
434434
this._saveStatus();
435435
this._drawTTFInCanvas(locContext);
436436
node._texture && node._texture.handleLoadedTexture();
437-
node.setTextureRect(this._texRect);
437+
node.setTextureRect(cc.rect(0, 0, width, height));
438438
return true;
439439
};
440440

@@ -482,14 +482,15 @@ cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
482482
proto._updateTexture = function () {
483483
this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.textDirty ^ this._dirtyFlag;
484484
var node = this._node;
485-
var scale = cc.view.getDevicePixelRatio();
485+
var locContentSize = node._contentSize;
486486
this._updateTTF();
487+
var width = locContentSize.width, height = locContentSize.height;
487488
if (node._string.length === 0) {
488-
node.setTextureRect(this._texRect);
489+
node.setTextureRect(cc.rect(0, 0, 1, locContentSize.height));
489490
return true;
490491
}
491492
this._saveStatus();
492-
node.setTextureRect(this._texRect);
493+
node.setTextureRect(cc.rect(0, 0, width, height));
493494
return true;
494495
};
495496

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: null,
49+
_labelRenderer: "",
5050
_textAreaSize: null,
5151
_textVerticalAlignment: 0,
5252
_textHorizontalAlignment: 0,

0 commit comments

Comments
 (0)