2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2017-03-15 01:07:58 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-04-25 17:07:15 +00:00
|
|
|
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
|
2018-02-07 00:18:22 +00:00
|
|
|
var GetValue = require('../../utils/object/GetValue');
|
2017-03-20 16:09:01 +00:00
|
|
|
var MeasureText = require('./MeasureText');
|
2017-03-15 01:07:58 +00:00
|
|
|
|
2017-03-16 17:15:58 +00:00
|
|
|
// Key: [ Object Key, Default Value ]
|
|
|
|
|
|
|
|
var propertyMap = {
|
2017-11-30 17:17:06 +00:00
|
|
|
fontFamily: [ 'fontFamily', 'Courier' ],
|
|
|
|
fontSize: [ 'fontSize', '16px' ],
|
|
|
|
fontStyle: [ 'fontStyle', '' ],
|
2017-03-16 17:15:58 +00:00
|
|
|
backgroundColor: [ 'backgroundColor', null ],
|
2017-11-30 17:17:06 +00:00
|
|
|
color: [ 'color', '#fff' ],
|
2017-03-16 17:15:58 +00:00
|
|
|
stroke: [ 'stroke', '#fff' ],
|
|
|
|
strokeThickness: [ 'strokeThickness', 0 ],
|
|
|
|
shadowOffsetX: [ 'shadow.offsetX', 0 ],
|
|
|
|
shadowOffsetY: [ 'shadow.offsetY', 0 ],
|
|
|
|
shadowColor: [ 'shadow.color', '#000' ],
|
|
|
|
shadowBlur: [ 'shadow.blur', 0 ],
|
|
|
|
shadowStroke: [ 'shadow.stroke', false ],
|
|
|
|
shadowFill: [ 'shadow.fill', false ],
|
|
|
|
align: [ 'align', 'left' ],
|
2017-03-20 16:09:01 +00:00
|
|
|
maxLines: [ 'maxLines', 0 ],
|
2018-02-07 02:46:11 +00:00
|
|
|
fixedWidth: [ 'fixedWidth', 0 ],
|
|
|
|
fixedHeight: [ 'fixedHeight', 0 ],
|
2018-07-17 21:44:12 +00:00
|
|
|
resolution: [ 'resolution', 0 ],
|
2017-11-30 17:17:06 +00:00
|
|
|
rtl: [ 'rtl', false ],
|
2018-03-13 13:21:51 +00:00
|
|
|
testString: [ 'testString', '|MÉqgy' ],
|
|
|
|
baselineX: [ 'baselineX', 1.2 ],
|
|
|
|
baselineY: [ 'baselineY', 1.4 ],
|
2017-12-13 21:07:37 +00:00
|
|
|
wordWrapWidth: [ 'wordWrap.width', null ],
|
|
|
|
wordWrapCallback: [ 'wordWrap.callback', null ],
|
|
|
|
wordWrapCallbackScope: [ 'wordWrap.callbackScope', null ],
|
|
|
|
wordWrapUseAdvanced: [ 'wordWrap.useAdvancedWrap', false ]
|
2017-03-16 17:15:58 +00:00
|
|
|
};
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-02-07 15:27:21 +00:00
|
|
|
* @classdesc
|
2019-02-01 18:02:58 +00:00
|
|
|
* A TextStyle class manages all of the style settings for a Text object.
|
|
|
|
*
|
|
|
|
* Text Game Objects create a TextStyle instance automatically, which is
|
|
|
|
* accessed via the `Text.style` property. You do not normally need to
|
|
|
|
* instantiate one yourself.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @class TextStyle
|
2019-02-01 18:02:58 +00:00
|
|
|
* @memberof Phaser.GameObjects
|
2018-02-07 02:46:11 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.Text} text - The Text object that this TextStyle is styling.
|
2019-07-02 11:32:18 +00:00
|
|
|
* @param {Phaser.Types.GameObjects.Text.TextStyle} style - The style settings to set.
|
2018-02-07 02:46:11 +00:00
|
|
|
*/
|
2017-03-15 01:07:58 +00:00
|
|
|
var TextStyle = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function TextStyle (text, style)
|
|
|
|
{
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
|
|
|
* The Text object that this TextStyle is styling.
|
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#parent
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {Phaser.GameObjects.Text}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-16 21:59:50 +00:00
|
|
|
this.parent = text;
|
2017-03-15 01:07:58 +00:00
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The font family.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#fontFamily
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {string}
|
|
|
|
* @default 'Courier'
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-30 17:17:06 +00:00
|
|
|
this.fontFamily;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The font size.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#fontSize
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {string}
|
|
|
|
* @default '16px'
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-30 17:17:06 +00:00
|
|
|
this.fontSize;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The font style.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#fontStyle
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {string}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-30 17:17:06 +00:00
|
|
|
this.fontStyle;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The background color.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#backgroundColor
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {string}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.backgroundColor;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The text fill color.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#color
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {string}
|
|
|
|
* @default '#fff'
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-30 17:17:06 +00:00
|
|
|
this.color;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The text stroke color.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#stroke
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {string}
|
|
|
|
* @default '#fff'
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.stroke;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The text stroke thickness.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#strokeThickness
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.strokeThickness;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The horizontal shadow offset.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#shadowOffsetX
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.shadowOffsetX;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The vertical shadow offset.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#shadowOffsetY
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.shadowOffsetY;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The shadow color.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#shadowColor
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {string}
|
|
|
|
* @default '#000'
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.shadowColor;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The shadow blur radius.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#shadowBlur
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.shadowBlur;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Whether shadow stroke is enabled or not.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#shadowStroke
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.shadowStroke;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Whether shadow fill is enabled or not.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#shadowFill
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.shadowFill;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The text alignment.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#align
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {string}
|
|
|
|
* @default 'left'
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.align;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The maximum number of lines to draw.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#maxLines
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {integer}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.maxLines;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The fixed width of the text.
|
|
|
|
*
|
|
|
|
* `0` means no fixed with.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#fixedWidth
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.fixedWidth;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The fixed height of the text.
|
|
|
|
*
|
|
|
|
* `0` means no fixed height.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#fixedHeight
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.fixedHeight;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
2018-07-17 21:44:12 +00:00
|
|
|
/**
|
|
|
|
* The resolution the text is rendered to its internal canvas at.
|
|
|
|
* The default is 0, which means it will use the resolution set in the Game Config.
|
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#resolution
|
2018-07-17 21:44:12 +00:00
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.12.0
|
|
|
|
*/
|
|
|
|
this.resolution;
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Whether the text should render right to left.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#rtl
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-21 20:25:15 +00:00
|
|
|
this.rtl;
|
2018-02-07 02:46:11 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The test string to use when measuring the font.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#testString
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {string}
|
|
|
|
* @default '|MÉqgy'
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-30 17:17:06 +00:00
|
|
|
this.testString;
|
2017-03-21 20:25:15 +00:00
|
|
|
|
2018-03-13 13:21:51 +00:00
|
|
|
/**
|
2019-05-30 22:01:53 +00:00
|
|
|
* The amount of horizontal padding added to the width of the text when calculating the font metrics.
|
2018-03-13 13:21:51 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#baselineX
|
2018-03-13 13:21:51 +00:00
|
|
|
* @type {number}
|
|
|
|
* @default 1.2
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
|
|
|
this.baselineX;
|
|
|
|
|
|
|
|
/**
|
2019-05-30 22:01:53 +00:00
|
|
|
* The amount of vertical padding added to the height of the text when calculating the font metrics.
|
2018-03-13 13:21:51 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#baselineY
|
2018-03-13 13:21:51 +00:00
|
|
|
* @type {number}
|
|
|
|
* @default 1.4
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
|
|
|
this.baselineY;
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* The font style, size and family.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @name Phaser.GameObjects.TextStyle#_font
|
2018-02-07 02:46:11 +00:00
|
|
|
* @type {string}
|
|
|
|
* @private
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-30 17:17:06 +00:00
|
|
|
this._font;
|
2017-03-16 17:15:58 +00:00
|
|
|
|
2017-11-30 17:17:06 +00:00
|
|
|
// Set to defaults + user style
|
2018-09-04 21:43:25 +00:00
|
|
|
this.setStyle(style, false, true);
|
2017-03-20 16:09:01 +00:00
|
|
|
|
2017-04-26 15:03:14 +00:00
|
|
|
var metrics = GetValue(style, 'metrics', false);
|
2017-04-26 14:54:23 +00:00
|
|
|
|
|
|
|
// Provide optional TextMetrics in the style object to avoid the canvas look-up / scanning
|
2017-11-30 17:17:06 +00:00
|
|
|
// Doing this is reset if you then change the font of this TextStyle after creation
|
2017-04-26 14:54:23 +00:00
|
|
|
if (metrics)
|
|
|
|
{
|
|
|
|
this.metrics = {
|
2017-04-26 15:03:14 +00:00
|
|
|
ascent: GetValue(metrics, 'ascent', 0),
|
|
|
|
descent: GetValue(metrics, 'descent', 0),
|
|
|
|
fontSize: GetValue(metrics, 'fontSize', 0)
|
2017-04-26 14:54:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.metrics = MeasureText(this);
|
|
|
|
}
|
2017-03-16 17:15:58 +00:00
|
|
|
},
|
2017-03-15 01:07:58 +00:00
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the text style.
|
|
|
|
*
|
2018-06-14 13:49:29 +00:00
|
|
|
* @example
|
2018-06-14 13:41:17 +00:00
|
|
|
* text.setStyle({
|
|
|
|
* fontSize: '64px',
|
|
|
|
* fontFamily: 'Arial',
|
|
|
|
* color: '#ffffff',
|
|
|
|
* align: 'center',
|
|
|
|
* backgroundColor: '#ff00ff'
|
|
|
|
* });
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setStyle
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-07-02 11:32:18 +00:00
|
|
|
* @param {Phaser.Types.GameObjects.Text.TextStyle} style - The style settings to set.
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {boolean} [updateText=true] - Whether to update the text immediately.
|
2018-09-04 21:43:25 +00:00
|
|
|
* @param {boolean} [setDefaults=false] - Use the default values is not set, or the local values.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2018-03-12 16:13:42 +00:00
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
2018-02-07 02:46:11 +00:00
|
|
|
*/
|
2018-09-04 21:43:25 +00:00
|
|
|
setStyle: function (style, updateText, setDefaults)
|
2017-03-21 20:25:15 +00:00
|
|
|
{
|
2017-11-30 17:17:06 +00:00
|
|
|
if (updateText === undefined) { updateText = true; }
|
2018-09-04 21:43:25 +00:00
|
|
|
if (setDefaults === undefined) { setDefaults = false; }
|
2017-11-30 17:17:06 +00:00
|
|
|
|
|
|
|
// Avoid type mutation
|
|
|
|
if (style && style.hasOwnProperty('fontSize') && typeof style.fontSize === 'number')
|
|
|
|
{
|
|
|
|
style.fontSize = style.fontSize.toString() + 'px';
|
|
|
|
}
|
|
|
|
|
2017-03-21 20:25:15 +00:00
|
|
|
for (var key in propertyMap)
|
|
|
|
{
|
2018-09-04 21:43:25 +00:00
|
|
|
var value = (setDefaults) ? propertyMap[key][1] : this[key];
|
|
|
|
|
2017-12-13 21:07:37 +00:00
|
|
|
if (key === 'wordWrapCallback' || key === 'wordWrapCallbackScope')
|
|
|
|
{
|
|
|
|
// Callback & scope should be set without processing the values
|
2018-09-04 21:43:25 +00:00
|
|
|
this[key] = GetValue(style, propertyMap[key][0], value);
|
2017-12-13 21:07:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-04 21:43:25 +00:00
|
|
|
this[key] = GetAdvancedValue(style, propertyMap[key][0], value);
|
2017-12-13 21:07:37 +00:00
|
|
|
}
|
2017-11-30 17:17:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 03:11:57 +00:00
|
|
|
// Allow for 'font' override
|
|
|
|
var font = GetValue(style, 'font', null);
|
|
|
|
|
2018-10-09 09:28:02 +00:00
|
|
|
if (font !== null)
|
2017-12-01 03:11:57 +00:00
|
|
|
{
|
2018-10-09 09:13:23 +00:00
|
|
|
this.setFont(font, false);
|
2017-12-01 03:11:57 +00:00
|
|
|
}
|
2018-10-19 12:35:30 +00:00
|
|
|
|
2019-01-22 14:02:25 +00:00
|
|
|
this._font = [ this.fontStyle, this.fontSize, this.fontFamily ].join(' ').trim();
|
2017-12-01 03:11:57 +00:00
|
|
|
|
|
|
|
// Allow for 'fill' to be used in place of 'color'
|
|
|
|
var fill = GetValue(style, 'fill', null);
|
|
|
|
|
|
|
|
if (fill !== null)
|
|
|
|
{
|
|
|
|
this.color = fill;
|
|
|
|
}
|
2017-11-30 17:17:06 +00:00
|
|
|
|
|
|
|
if (updateText)
|
|
|
|
{
|
2018-03-12 16:13:42 +00:00
|
|
|
return this.update(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this.parent;
|
2017-03-21 20:25:15 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Synchronize the font settings to the given Canvas Rendering Context.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#syncFont
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {HTMLCanvasElement} canvas - The Canvas Element.
|
|
|
|
* @param {CanvasRenderingContext2D} context - The Canvas Rendering Context.
|
2018-02-07 02:46:11 +00:00
|
|
|
*/
|
2017-03-16 21:59:50 +00:00
|
|
|
syncFont: function (canvas, context)
|
|
|
|
{
|
2017-11-30 17:17:06 +00:00
|
|
|
context.font = this._font;
|
2017-12-13 21:08:43 +00:00
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Synchronize the text style settings to the given Canvas Rendering Context.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#syncStyle
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {HTMLCanvasElement} canvas - The Canvas Element.
|
|
|
|
* @param {CanvasRenderingContext2D} context - The Canvas Rendering Context.
|
2018-02-07 02:46:11 +00:00
|
|
|
*/
|
2017-12-13 21:08:43 +00:00
|
|
|
syncStyle: function (canvas, context)
|
|
|
|
{
|
2017-03-16 21:59:50 +00:00
|
|
|
context.textBaseline = 'alphabetic';
|
|
|
|
|
2017-11-30 17:17:06 +00:00
|
|
|
context.fillStyle = this.color;
|
2017-03-16 21:59:50 +00:00
|
|
|
context.strokeStyle = this.stroke;
|
|
|
|
|
|
|
|
context.lineWidth = this.strokeThickness;
|
|
|
|
context.lineCap = 'round';
|
|
|
|
context.lineJoin = 'round';
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Synchronize the shadow settings to the given Canvas Rendering Context.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#syncShadow
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {CanvasRenderingContext2D} context - The Canvas Rendering Context.
|
|
|
|
* @param {boolean} enabled - Whether shadows are enabled or not.
|
2018-02-07 02:46:11 +00:00
|
|
|
*/
|
2017-03-20 16:48:04 +00:00
|
|
|
syncShadow: function (context, enabled)
|
2017-03-16 21:59:50 +00:00
|
|
|
{
|
2017-03-20 16:48:04 +00:00
|
|
|
if (enabled)
|
2017-03-16 21:59:50 +00:00
|
|
|
{
|
2017-03-21 20:25:15 +00:00
|
|
|
context.shadowOffsetX = this.shadowOffsetX;
|
|
|
|
context.shadowOffsetY = this.shadowOffsetY;
|
|
|
|
context.shadowColor = this.shadowColor;
|
|
|
|
context.shadowBlur = this.shadowBlur;
|
2017-03-16 21:59:50 +00:00
|
|
|
}
|
2017-03-20 16:48:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
context.shadowOffsetX = 0;
|
|
|
|
context.shadowOffsetY = 0;
|
|
|
|
context.shadowColor = 0;
|
|
|
|
context.shadowBlur = 0;
|
|
|
|
}
|
2017-03-20 16:09:01 +00:00
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Update the style settings for the parent Text object.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#update
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {boolean} recalculateMetrics - Whether to recalculate font and text metrics.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-03-20 16:09:01 +00:00
|
|
|
update: function (recalculateMetrics)
|
|
|
|
{
|
|
|
|
if (recalculateMetrics)
|
2017-03-16 21:59:50 +00:00
|
|
|
{
|
2019-01-22 14:02:25 +00:00
|
|
|
this._font = [ this.fontStyle, this.fontSize, this.fontFamily ].join(' ').trim();
|
2017-11-30 17:17:06 +00:00
|
|
|
|
2017-03-20 16:09:01 +00:00
|
|
|
this.metrics = MeasureText(this);
|
2017-03-16 21:59:50 +00:00
|
|
|
}
|
2017-03-20 16:09:01 +00:00
|
|
|
|
2017-03-20 16:28:09 +00:00
|
|
|
return this.parent.updateText();
|
2017-03-16 21:59:50 +00:00
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the font.
|
|
|
|
*
|
|
|
|
* If a string is given, the font family is set.
|
|
|
|
*
|
|
|
|
* If an object is given, the `fontFamily`, `fontSize` and `fontStyle`
|
|
|
|
* properties of that object are set.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setFont
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {(string|object)} font - The font family or font settings to set.
|
2018-10-09 09:13:23 +00:00
|
|
|
* @param {boolean} [updateText=true] - Whether to update the text immediately.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2018-10-09 09:13:23 +00:00
|
|
|
setFont: function (font, updateText)
|
2017-03-16 17:15:58 +00:00
|
|
|
{
|
2018-10-09 09:13:23 +00:00
|
|
|
if (updateText === undefined) { updateText = true; }
|
2018-10-09 09:50:21 +00:00
|
|
|
|
2018-09-29 10:21:31 +00:00
|
|
|
var fontFamily = font;
|
|
|
|
var fontSize = '';
|
|
|
|
var fontStyle = '';
|
|
|
|
|
|
|
|
if (typeof font !== 'string')
|
2017-12-01 03:11:57 +00:00
|
|
|
{
|
2018-09-29 10:21:31 +00:00
|
|
|
fontFamily = GetValue(font, 'fontFamily', 'Courier');
|
|
|
|
fontSize = GetValue(font, 'fontSize', '16px');
|
|
|
|
fontStyle = GetValue(font, 'fontStyle', '');
|
2017-12-01 03:11:57 +00:00
|
|
|
}
|
2018-10-09 09:13:23 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
var fontSplit = font.split(' ');
|
2018-10-19 12:35:30 +00:00
|
|
|
|
2018-10-09 09:13:23 +00:00
|
|
|
var i = 0;
|
2018-10-19 12:35:30 +00:00
|
|
|
|
2018-11-22 08:40:10 +00:00
|
|
|
fontStyle = (fontSplit.length > 2) ? fontSplit[i++] : '';
|
|
|
|
fontSize = fontSplit[i++] || '16px';
|
|
|
|
fontFamily = fontSplit[i++] || 'Courier';
|
2018-10-09 09:13:23 +00:00
|
|
|
}
|
2018-09-29 10:21:31 +00:00
|
|
|
|
|
|
|
if (fontFamily !== this.fontFamily || fontSize !== this.fontSize || fontStyle !== this.fontStyle)
|
2017-12-01 03:11:57 +00:00
|
|
|
{
|
2018-09-29 10:21:31 +00:00
|
|
|
this.fontFamily = fontFamily;
|
|
|
|
this.fontSize = fontSize;
|
|
|
|
this.fontStyle = fontStyle;
|
2018-10-09 09:50:21 +00:00
|
|
|
|
2018-10-09 09:13:23 +00:00
|
|
|
if (updateText)
|
|
|
|
{
|
|
|
|
this.update(true);
|
|
|
|
}
|
2017-12-01 03:11:57 +00:00
|
|
|
}
|
2017-11-30 17:17:06 +00:00
|
|
|
|
2018-09-29 10:21:31 +00:00
|
|
|
return this.parent;
|
2017-11-30 17:17:06 +00:00
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the font family.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setFontFamily
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {string} family - The font family.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-11-30 17:17:06 +00:00
|
|
|
setFontFamily: function (family)
|
|
|
|
{
|
2018-09-29 10:21:31 +00:00
|
|
|
if (this.fontFamily !== family)
|
|
|
|
{
|
|
|
|
this.fontFamily = family;
|
2017-11-30 17:17:06 +00:00
|
|
|
|
2018-09-29 10:21:31 +00:00
|
|
|
this.update(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.parent;
|
2017-11-30 17:17:06 +00:00
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the font style.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setFontStyle
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {string} style - The font style.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-11-30 17:17:06 +00:00
|
|
|
setFontStyle: function (style)
|
|
|
|
{
|
2018-09-29 10:21:31 +00:00
|
|
|
if (this.fontStyle !== style)
|
|
|
|
{
|
|
|
|
this.fontStyle = style;
|
2017-11-30 17:17:06 +00:00
|
|
|
|
2018-09-29 10:21:31 +00:00
|
|
|
this.update(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.parent;
|
2017-11-30 17:17:06 +00:00
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the font size.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setFontSize
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {(number|string)} size - The font size.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-11-30 17:17:06 +00:00
|
|
|
setFontSize: function (size)
|
|
|
|
{
|
|
|
|
if (typeof size === 'number')
|
2017-03-16 17:15:58 +00:00
|
|
|
{
|
2017-11-30 17:17:06 +00:00
|
|
|
size = size.toString() + 'px';
|
2017-03-16 17:15:58 +00:00
|
|
|
}
|
2017-03-15 01:07:58 +00:00
|
|
|
|
2018-09-29 10:21:31 +00:00
|
|
|
if (this.fontSize !== size)
|
|
|
|
{
|
|
|
|
this.fontSize = size;
|
2017-11-30 17:17:06 +00:00
|
|
|
|
2018-09-29 10:21:31 +00:00
|
|
|
this.update(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.parent;
|
2017-03-14 16:37:32 +00:00
|
|
|
},
|
2017-03-15 01:07:58 +00:00
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the test string to use when measuring the font.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setTestString
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {string} string - The test string to use when measuring the font.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-11-30 17:17:06 +00:00
|
|
|
setTestString: function (string)
|
2017-03-15 01:07:58 +00:00
|
|
|
{
|
2017-11-30 17:17:06 +00:00
|
|
|
this.testString = string;
|
2017-03-15 01:07:58 +00:00
|
|
|
|
2017-03-20 16:09:01 +00:00
|
|
|
return this.update(true);
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set a fixed width and height for the text.
|
|
|
|
*
|
|
|
|
* Pass in `0` for either of these parameters to disable fixed width or height respectively.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setFixedSize
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {number} width - The fixed width to set.
|
|
|
|
* @param {number} height - The fixed height to set.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-03-20 16:09:01 +00:00
|
|
|
setFixedSize: function (width, height)
|
|
|
|
{
|
|
|
|
this.fixedWidth = width;
|
|
|
|
this.fixedHeight = height;
|
|
|
|
|
|
|
|
if (width)
|
|
|
|
{
|
2018-03-12 16:34:21 +00:00
|
|
|
this.parent.width = width;
|
2017-03-20 16:09:01 +00:00
|
|
|
}
|
2017-03-16 21:59:50 +00:00
|
|
|
|
2017-03-20 16:09:01 +00:00
|
|
|
if (height)
|
|
|
|
{
|
2018-03-12 16:34:21 +00:00
|
|
|
this.parent.height = height;
|
2017-03-20 16:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.update(false);
|
2017-03-16 17:15:58 +00:00
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the background color.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setBackgroundColor
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {string} color - The background color.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-03-16 21:59:50 +00:00
|
|
|
setBackgroundColor: function (color)
|
2017-03-16 17:15:58 +00:00
|
|
|
{
|
2017-03-16 21:59:50 +00:00
|
|
|
this.backgroundColor = color;
|
2017-03-16 17:15:58 +00:00
|
|
|
|
2017-03-20 16:09:01 +00:00
|
|
|
return this.update(false);
|
2017-03-16 17:15:58 +00:00
|
|
|
},
|
2017-03-15 01:07:58 +00:00
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the text fill color.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setFill
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {string} color - The text fill color.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-12-01 03:11:57 +00:00
|
|
|
setFill: function (color)
|
|
|
|
{
|
|
|
|
this.color = color;
|
|
|
|
|
|
|
|
return this.update(false);
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the text fill color.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setColor
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {string} color - The text fill color.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-11-30 17:17:06 +00:00
|
|
|
setColor: function (color)
|
2017-03-16 21:59:50 +00:00
|
|
|
{
|
2017-11-30 17:17:06 +00:00
|
|
|
this.color = color;
|
2017-03-16 21:59:50 +00:00
|
|
|
|
2017-03-20 16:09:01 +00:00
|
|
|
return this.update(false);
|
2017-03-16 21:59:50 +00:00
|
|
|
},
|
|
|
|
|
2018-07-18 13:45:10 +00:00
|
|
|
/**
|
|
|
|
* Set the resolution used by the Text object.
|
|
|
|
*
|
|
|
|
* By default it will be set to match the resolution set in the Game Config,
|
|
|
|
* but you can override it via this method. It allows for much clearer text on High DPI devices,
|
|
|
|
* at the cost of memory because it uses larger internal Canvas textures for the Text.
|
|
|
|
*
|
|
|
|
* Please use with caution, as the more high res Text you have, the more memory it uses up.
|
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setResolution
|
2018-07-18 13:45:10 +00:00
|
|
|
* @since 3.12.0
|
|
|
|
*
|
|
|
|
* @param {number} value - The resolution for this Text object to use.
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
|
|
|
setResolution: function (value)
|
|
|
|
{
|
|
|
|
this.resolution = value;
|
|
|
|
|
|
|
|
return this.update(false);
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the stroke settings.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setStroke
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {string} color - The stroke color.
|
|
|
|
* @param {number} thickness - The stroke thickness.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-03-16 21:59:50 +00:00
|
|
|
setStroke: function (color, thickness)
|
|
|
|
{
|
2018-09-29 10:21:31 +00:00
|
|
|
if (thickness === undefined) { thickness = this.strokeThickness; }
|
|
|
|
|
|
|
|
if (color === undefined && this.strokeThickness !== 0)
|
2017-03-16 21:59:50 +00:00
|
|
|
{
|
|
|
|
// Reset the stroke to zero (disabling it)
|
|
|
|
this.strokeThickness = 0;
|
2018-09-29 10:21:31 +00:00
|
|
|
|
|
|
|
this.update(true);
|
2017-03-16 21:59:50 +00:00
|
|
|
}
|
2018-09-29 10:21:31 +00:00
|
|
|
else if (this.stroke !== color || this.strokeThickness !== thickness)
|
2017-03-16 21:59:50 +00:00
|
|
|
{
|
|
|
|
this.stroke = color;
|
|
|
|
this.strokeThickness = thickness;
|
2018-09-29 10:21:31 +00:00
|
|
|
|
|
|
|
this.update(true);
|
2017-03-16 21:59:50 +00:00
|
|
|
}
|
|
|
|
|
2018-09-29 10:21:31 +00:00
|
|
|
return this.parent;
|
2017-03-16 21:59:50 +00:00
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the shadow settings.
|
2018-09-29 10:21:31 +00:00
|
|
|
*
|
|
|
|
* Calling this method always re-measures the parent Text object,
|
|
|
|
* so only call it when you actually change the shadow settings.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setShadow
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {number} [x=0] - The horizontal shadow offset.
|
|
|
|
* @param {number} [y=0] - The vertical shadow offset.
|
|
|
|
* @param {string} [color='#000'] - The shadow color.
|
|
|
|
* @param {number} [blur=0] - The shadow blur radius.
|
|
|
|
* @param {boolean} [shadowStroke=false] - Whether to stroke the shadow.
|
|
|
|
* @param {boolean} [shadowFill=true] - Whether to fill the shadow.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-03-16 21:59:50 +00:00
|
|
|
setShadow: function (x, y, color, blur, shadowStroke, shadowFill)
|
|
|
|
{
|
2017-03-20 16:48:04 +00:00
|
|
|
if (x === undefined) { x = 0; }
|
2017-03-16 21:59:50 +00:00
|
|
|
if (y === undefined) { y = 0; }
|
|
|
|
if (color === undefined) { color = '#000'; }
|
|
|
|
if (blur === undefined) { blur = 0; }
|
|
|
|
if (shadowStroke === undefined) { shadowStroke = false; }
|
2017-08-11 15:59:29 +00:00
|
|
|
if (shadowFill === undefined) { shadowFill = true; }
|
2017-03-16 21:59:50 +00:00
|
|
|
|
|
|
|
this.shadowOffsetX = x;
|
|
|
|
this.shadowOffsetY = y;
|
|
|
|
this.shadowColor = color;
|
|
|
|
this.shadowBlur = blur;
|
|
|
|
this.shadowStroke = shadowStroke;
|
|
|
|
this.shadowFill = shadowFill;
|
|
|
|
|
2017-03-20 16:09:01 +00:00
|
|
|
return this.update(false);
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the shadow offset.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setShadowOffset
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {number} [x=0] - The horizontal shadow offset.
|
|
|
|
* @param {number} [y=0] - The vertical shadow offset.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-03-20 16:09:01 +00:00
|
|
|
setShadowOffset: function (x, y)
|
|
|
|
{
|
|
|
|
if (x === undefined) { x = 0; }
|
|
|
|
if (y === undefined) { y = x; }
|
|
|
|
|
|
|
|
this.shadowOffsetX = x;
|
|
|
|
this.shadowOffsetY = y;
|
2017-03-16 21:59:50 +00:00
|
|
|
|
2017-03-20 16:09:01 +00:00
|
|
|
return this.update(false);
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the shadow color.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setShadowColor
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {string} [color='#000'] - The shadow color.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-03-20 16:09:01 +00:00
|
|
|
setShadowColor: function (color)
|
|
|
|
{
|
|
|
|
if (color === undefined) { color = '#000'; }
|
|
|
|
|
|
|
|
this.shadowColor = color;
|
|
|
|
|
|
|
|
return this.update(false);
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the shadow blur radius.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setShadowBlur
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {number} [blur=0] - The shadow blur radius.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-03-20 16:09:01 +00:00
|
|
|
setShadowBlur: function (blur)
|
|
|
|
{
|
|
|
|
if (blur === undefined) { blur = 0; }
|
|
|
|
|
|
|
|
this.shadowBlur = blur;
|
|
|
|
|
|
|
|
return this.update(false);
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Enable or disable shadow stroke.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setShadowStroke
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {boolean} enabled - Whether shadow stroke is enabled or not.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-03-20 16:09:01 +00:00
|
|
|
setShadowStroke: function (enabled)
|
|
|
|
{
|
|
|
|
this.shadowStroke = enabled;
|
|
|
|
|
|
|
|
return this.update(false);
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Enable or disable shadow fill.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setShadowFill
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {boolean} enabled - Whether shadow fill is enabled or not.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-03-20 16:09:01 +00:00
|
|
|
setShadowFill: function (enabled)
|
|
|
|
{
|
|
|
|
this.shadowFill = enabled;
|
|
|
|
|
|
|
|
return this.update(false);
|
2017-03-16 21:59:50 +00:00
|
|
|
},
|
|
|
|
|
2017-12-13 21:28:52 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the width (in pixels) to use for wrapping lines.
|
|
|
|
*
|
|
|
|
* Pass in null to remove wrapping by width.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setWordWrapWidth
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
2017-12-13 21:28:52 +00:00
|
|
|
*
|
2018-02-07 02:46:11 +00:00
|
|
|
* @param {number} width - The maximum width of a line in pixels. Set to null to remove wrapping.
|
2017-12-13 21:28:52 +00:00
|
|
|
* @param {boolean} [useAdvancedWrap=false] - Whether or not to use the advanced wrapping
|
|
|
|
* algorithm. If true, spaces are collapsed and whitespace is trimmed from lines. If false,
|
|
|
|
* spaces and whitespace are left as is.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
2017-12-13 21:28:52 +00:00
|
|
|
*/
|
2017-12-13 21:07:37 +00:00
|
|
|
setWordWrapWidth: function (width, useAdvancedWrap)
|
|
|
|
{
|
|
|
|
if (useAdvancedWrap === undefined) { useAdvancedWrap = false; }
|
|
|
|
|
|
|
|
this.wordWrapWidth = width;
|
|
|
|
this.wordWrapUseAdvanced = useAdvancedWrap;
|
|
|
|
|
|
|
|
return this.update(false);
|
|
|
|
},
|
|
|
|
|
2017-12-13 21:28:52 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set a custom callback for wrapping lines.
|
|
|
|
*
|
|
|
|
* Pass in null to remove wrapping by callback.
|
2017-12-13 21:28:52 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setWordWrapCallback
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-03-19 21:27:16 +00:00
|
|
|
* @param {TextStyleWordWrapCallback} callback - A custom function that will be responsible for wrapping the
|
2017-12-13 21:28:52 +00:00
|
|
|
* text. It will receive two arguments: text (the string to wrap), textObject (this Text
|
|
|
|
* instance). It should return the wrapped lines either as an array of lines or as a string with
|
|
|
|
* newline characters in place to indicate where breaks should happen.
|
|
|
|
* @param {object} [scope=null] - The scope that will be applied when the callback is invoked.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
2017-12-13 21:28:52 +00:00
|
|
|
*/
|
2017-12-13 21:07:37 +00:00
|
|
|
setWordWrapCallback: function (callback, scope)
|
|
|
|
{
|
|
|
|
if (scope === undefined) { scope = null; }
|
|
|
|
|
|
|
|
this.wordWrapCallback = callback;
|
|
|
|
this.wordWrapCallbackScope = scope;
|
|
|
|
|
|
|
|
return this.update(false);
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2019-06-19 08:46:32 +00:00
|
|
|
* Set the alignment of the text in this Text object.
|
|
|
|
*
|
|
|
|
* The argument can be one of: `left`, `right`, `center` or `justify`.
|
|
|
|
*
|
|
|
|
* Alignment only works if the Text object has more than one line of text.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setAlign
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-06-19 08:46:32 +00:00
|
|
|
* @param {string} [align='left'] - The text alignment for multi-line text.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-03-16 21:59:50 +00:00
|
|
|
setAlign: function (align)
|
|
|
|
{
|
|
|
|
if (align === undefined) { align = 'left'; }
|
|
|
|
|
|
|
|
this.align = align;
|
|
|
|
|
2017-03-20 16:09:01 +00:00
|
|
|
return this.update(false);
|
2017-03-16 21:59:50 +00:00
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Set the maximum number of lines to draw.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#setMaxLines
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @param {integer} [max=0] - The maximum number of lines to draw.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The parent Text object.
|
|
|
|
*/
|
2017-03-16 21:59:50 +00:00
|
|
|
setMaxLines: function (max)
|
|
|
|
{
|
|
|
|
if (max === undefined) { max = 0; }
|
|
|
|
|
|
|
|
this.maxLines = max;
|
|
|
|
|
2017-03-20 16:09:01 +00:00
|
|
|
return this.update(false);
|
2017-03-16 21:59:50 +00:00
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Get the current text metrics.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#getTextMetrics
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-05-09 14:32:53 +00:00
|
|
|
* @return {Phaser.Types.GameObjects.Text.TextMetrics} The text metrics.
|
2018-02-07 02:46:11 +00:00
|
|
|
*/
|
2017-04-26 14:54:23 +00:00
|
|
|
getTextMetrics: function ()
|
|
|
|
{
|
|
|
|
var metrics = this.metrics;
|
|
|
|
|
|
|
|
return {
|
|
|
|
ascent: metrics.ascent,
|
|
|
|
descent: metrics.descent,
|
|
|
|
fontSize: metrics.fontSize
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Build a JSON representation of this Text Style.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#toJSON
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-14 13:27:31 +00:00
|
|
|
* @return {object} A JSON representation of this Text Style.
|
2018-02-07 02:46:11 +00:00
|
|
|
*/
|
2017-04-25 17:24:37 +00:00
|
|
|
toJSON: function ()
|
|
|
|
{
|
|
|
|
var output = {};
|
|
|
|
|
|
|
|
for (var key in propertyMap)
|
|
|
|
{
|
|
|
|
output[key] = this[key];
|
|
|
|
}
|
|
|
|
|
2017-04-26 14:54:23 +00:00
|
|
|
output.metrics = this.getTextMetrics();
|
|
|
|
|
2017-04-25 17:24:37 +00:00
|
|
|
return output;
|
|
|
|
},
|
|
|
|
|
2018-02-07 02:46:11 +00:00
|
|
|
/**
|
2018-06-14 13:27:31 +00:00
|
|
|
* Destroy this Text Style.
|
2018-02-07 02:46:11 +00:00
|
|
|
*
|
2019-02-01 18:02:58 +00:00
|
|
|
* @method Phaser.GameObjects.TextStyle#destroy
|
2018-02-07 02:46:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-03-16 21:59:50 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
this.parent = undefined;
|
|
|
|
}
|
|
|
|
|
2017-03-15 01:07:58 +00:00
|
|
|
});
|
2017-03-13 23:38:48 +00:00
|
|
|
|
|
|
|
module.exports = TextStyle;
|