Documentation Fix
This commit is contained in:
parent
8093792ed5
commit
4dab30ee17
85 changed files with 16528 additions and 1633 deletions
|
@ -63,14 +63,20 @@
|
|||
|
||||
<li><a href="../classes/InteractionManager.html">InteractionManager</a></li>
|
||||
|
||||
<li><a href="../classes/JsonLoader.html">JsonLoader</a></li>
|
||||
|
||||
<li><a href="../classes/MovieClip.html">MovieClip</a></li>
|
||||
|
||||
<li><a href="../classes/Point.html">Point</a></li>
|
||||
|
||||
<li><a href="../classes/Polygon.html">Polygon</a></li>
|
||||
|
||||
<li><a href="../classes/Rectangle.html">Rectangle</a></li>
|
||||
|
||||
<li><a href="../classes/RenderTexture.html">RenderTexture</a></li>
|
||||
|
||||
<li><a href="../classes/Spine.html">Spine</a></li>
|
||||
|
||||
<li><a href="../classes/Sprite.html">Sprite</a></li>
|
||||
|
||||
<li><a href="../classes/SpriteSheetLoader.html">SpriteSheetLoader</a></li>
|
||||
|
@ -148,6 +154,8 @@
|
|||
* @param {String} [style.align="left"] An alignment of the multiline text ("left", "center" or "right")
|
||||
* @param {String} [style.stroke] A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00"
|
||||
* @param {Number} [style.strokeThickness=0] A number that represents the thickness of the stroke. Default is 0 (no stroke)
|
||||
* @param {Boolean} [style.wordWrap=false] Indicates if word wrap should be used
|
||||
* @param {Number} [style.wordWrapWidth=100] The width at which text will wrap
|
||||
*/
|
||||
PIXI.Text = function(text, style)
|
||||
{
|
||||
|
@ -173,8 +181,10 @@ PIXI.Text.prototype = Object.create(PIXI.Sprite.prototype);
|
|||
* @param {String} [style.font="bold 20pt Arial"] The style and size of the font
|
||||
* @param {Object} [style.fill="black"] A canvas fillstyle that will be used on the text eg "red", "#00FF00"
|
||||
* @param {String} [style.align="left"] An alignment of the multiline text ("left", "center" or "right")
|
||||
* @param {String} [style.stroke] A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00"
|
||||
* @param {String} [style.stroke="black"] A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00"
|
||||
* @param {Number} [style.strokeThickness=0] A number that represents the thickness of the stroke. Default is 0 (no stroke)
|
||||
* @param {Boolean} [style.wordWrap=false] Indicates if word wrap should be used
|
||||
* @param {Number} [style.wordWrapWidth=100] The width at which text will wrap
|
||||
*/
|
||||
PIXI.Text.prototype.setStyle = function(style)
|
||||
{
|
||||
|
@ -182,7 +192,10 @@ PIXI.Text.prototype.setStyle = function(style)
|
|||
style.font = style.font || "bold 20pt Arial";
|
||||
style.fill = style.fill || "black";
|
||||
style.align = style.align || "left";
|
||||
style.stroke = style.stroke || "black"; //provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136
|
||||
style.strokeThickness = style.strokeThickness || 0;
|
||||
style.wordWrap = style.wordWrap || false;
|
||||
style.wordWrapWidth = style.wordWrapWidth || 100;
|
||||
this.style = style;
|
||||
this.dirty = true;
|
||||
};
|
||||
|
@ -194,7 +207,7 @@ PIXI.Text.prototype.setStyle = function(style)
|
|||
*/
|
||||
PIXI.Sprite.prototype.setText = function(text)
|
||||
{
|
||||
this.text = text || " ";
|
||||
this.text = text.toString() || " ";
|
||||
this.dirty = true;
|
||||
};
|
||||
|
||||
|
@ -205,9 +218,15 @@ PIXI.Sprite.prototype.setText = function(text)
|
|||
PIXI.Text.prototype.updateText = function()
|
||||
{
|
||||
this.context.font = this.style.font;
|
||||
|
||||
var outputText = this.text;
|
||||
|
||||
// word wrap
|
||||
// preserve original text
|
||||
if(this.style.wordWrap)outputText = this.wordWrap(this.text);
|
||||
|
||||
//split text into lines
|
||||
var lines = this.text.split(/(?:\r\n|\r|\n)/);
|
||||
var lines = outputText.split(/(?:\r\n|\r|\n)/);
|
||||
|
||||
//calculate text width
|
||||
var lineWidths = [];
|
||||
|
@ -309,7 +328,7 @@ PIXI.Text.prototype.determineFontHeight = function(fontStyle)
|
|||
var dummy = document.createElement("div");
|
||||
var dummyText = document.createTextNode("M");
|
||||
dummy.appendChild(dummyText);
|
||||
dummy.setAttribute("style", fontStyle);
|
||||
dummy.setAttribute("style", fontStyle + ';position:absolute;top:0;left:0');
|
||||
body.appendChild(dummy);
|
||||
|
||||
result = dummy.offsetHeight;
|
||||
|
@ -321,6 +340,57 @@ PIXI.Text.prototype.determineFontHeight = function(fontStyle)
|
|||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* A Text Object will apply wordwrap
|
||||
* @private
|
||||
*/
|
||||
PIXI.Text.prototype.wordWrap = function(text)
|
||||
{
|
||||
// search good wrap position
|
||||
var searchWrapPos = function(ctx, text, start, end, wrapWidth)
|
||||
{
|
||||
var p = Math.floor((end-start) / 2) + start;
|
||||
if(p == start) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(ctx.measureText(text.substring(0,p)).width <= wrapWidth)
|
||||
{
|
||||
if(ctx.measureText(text.substring(0,p+1)).width > wrapWidth)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
else
|
||||
{
|
||||
return arguments.callee(ctx, text, p, end, wrapWidth);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return arguments.callee(ctx, text, start, p, wrapWidth);
|
||||
}
|
||||
};
|
||||
|
||||
var lineWrap = function(ctx, text, wrapWidth)
|
||||
{
|
||||
if(ctx.measureText(text).width <= wrapWidth || text.length < 1)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
var pos = searchWrapPos(ctx, text, 0, text.length, wrapWidth);
|
||||
return text.substring(0, pos) + "\n" + arguments.callee(ctx, text.substring(pos), wrapWidth);
|
||||
};
|
||||
|
||||
var result = "";
|
||||
var lines = text.split("\n");
|
||||
for (var i = 0; i < lines.length; i++)
|
||||
{
|
||||
result += lineWrap(this.context, lines[i], this.style.wordWrapWidth) + "\n";
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
PIXI.Text.prototype.destroy = function(destroyTexture)
|
||||
{
|
||||
if(destroyTexture)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue