2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2016-11-26 00:35:49 +00:00
|
|
|
|
2017-06-08 14:03:55 +00:00
|
|
|
// Browser specific prefix, so not going to change between contexts, only between browsers
|
|
|
|
var prefix = '';
|
2016-11-26 00:35:49 +00:00
|
|
|
|
2017-06-08 14:03:55 +00:00
|
|
|
var Smoothing = function ()
|
|
|
|
{
|
2017-08-01 12:10:08 +00:00
|
|
|
// Gets the Smoothing Enabled vendor prefix being used on the given context, or null if not set.
|
2017-06-08 14:03:55 +00:00
|
|
|
var getPrefix = function (context)
|
2016-11-26 00:35:49 +00:00
|
|
|
{
|
|
|
|
var vendors = [ 'i', 'webkitI', 'msI', 'mozI', 'oI' ];
|
|
|
|
|
2017-06-08 14:03:55 +00:00
|
|
|
for (var i = 0; i < vendors.length; i++)
|
2016-11-26 00:35:49 +00:00
|
|
|
{
|
2017-06-08 14:03:55 +00:00
|
|
|
var s = vendors[i] + 'mageSmoothingEnabled';
|
2016-11-26 00:35:49 +00:00
|
|
|
|
2017-06-08 14:03:55 +00:00
|
|
|
if (s in context)
|
2016-11-26 00:35:49 +00:00
|
|
|
{
|
|
|
|
return s;
|
|
|
|
}
|
2017-06-08 14:03:55 +00:00
|
|
|
}
|
2016-11-26 02:32:59 +00:00
|
|
|
|
2016-11-26 00:35:49 +00:00
|
|
|
return null;
|
2017-06-08 14:03:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the Image Smoothing property on the given context. Set to false to disable image smoothing.
|
|
|
|
* By default browsers have image smoothing enabled, which isn't always what you visually want, especially
|
|
|
|
* when using pixel art in a game. Note that this sets the property on the context itself, so that any image
|
|
|
|
* drawn to the context will be affected. This sets the property across all current browsers but support is
|
|
|
|
* patchy on earlier browsers, especially on mobile.
|
|
|
|
*/
|
|
|
|
var enable = function (context)
|
|
|
|
{
|
|
|
|
if (prefix === '')
|
|
|
|
{
|
|
|
|
prefix = getPrefix(context);
|
|
|
|
}
|
2016-11-26 02:32:59 +00:00
|
|
|
|
2017-06-08 14:03:55 +00:00
|
|
|
if (prefix)
|
|
|
|
{
|
|
|
|
context[prefix] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return context;
|
|
|
|
};
|
2016-11-26 00:35:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the Image Smoothing property on the given context. Set to false to disable image smoothing.
|
|
|
|
* By default browsers have image smoothing enabled, which isn't always what you visually want, especially
|
|
|
|
* when using pixel art in a game. Note that this sets the property on the context itself, so that any image
|
|
|
|
* drawn to the context will be affected. This sets the property across all current browsers but support is
|
|
|
|
* patchy on earlier browsers, especially on mobile.
|
|
|
|
*/
|
2017-06-08 14:03:55 +00:00
|
|
|
var disable = function (context)
|
2016-11-26 00:35:49 +00:00
|
|
|
{
|
2017-06-08 14:03:55 +00:00
|
|
|
if (prefix === '')
|
|
|
|
{
|
|
|
|
prefix = getPrefix(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prefix)
|
2016-11-26 00:35:49 +00:00
|
|
|
{
|
2017-06-08 14:03:55 +00:00
|
|
|
context[prefix] = false;
|
2016-11-26 00:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return context;
|
2017-06-08 14:03:55 +00:00
|
|
|
};
|
2016-11-26 00:35:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns `true` if the given context has image smoothing enabled, otherwise returns `false`.
|
2016-11-26 02:32:59 +00:00
|
|
|
* Returns null if no smoothing prefix is available.
|
2016-11-26 00:35:49 +00:00
|
|
|
*/
|
2017-06-08 14:03:55 +00:00
|
|
|
var isEnabled = function (context)
|
2016-11-26 00:35:49 +00:00
|
|
|
{
|
2017-06-08 14:03:55 +00:00
|
|
|
return (prefix !== null) ? context[prefix] : null;
|
|
|
|
};
|
2016-11-26 00:35:49 +00:00
|
|
|
|
2017-06-08 14:03:55 +00:00
|
|
|
return {
|
|
|
|
disable: disable,
|
|
|
|
enable: enable,
|
|
|
|
getPrefix: getPrefix,
|
|
|
|
isEnabled: isEnabled
|
|
|
|
};
|
2016-11-26 00:35:49 +00:00
|
|
|
};
|
|
|
|
|
2016-11-26 02:32:59 +00:00
|
|
|
module.exports = Smoothing();
|