2016-11-26 02:32:59 +00:00
|
|
|
var CanvasPool = require('./CanvasPool');
|
2016-11-26 00:35:49 +00:00
|
|
|
|
2016-11-26 02:32:59 +00:00
|
|
|
var Smoothing = {
|
2016-11-26 00:35:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Smoothing Enabled vendor prefix being used on the given context, or null if not set.
|
2016-11-26 02:32:59 +00:00
|
|
|
* iife
|
2016-11-26 00:35:49 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Canvas.getSmoothingPrefix
|
|
|
|
* @param {CanvasRenderingContext2D} context - The context to enable or disable the image smoothing on.
|
|
|
|
* @return {string|null} Returns the smoothingEnabled vendor prefix, or null if not set on the context.
|
|
|
|
*/
|
2016-11-26 02:32:59 +00:00
|
|
|
prefix: (function ()
|
2016-11-26 00:35:49 +00:00
|
|
|
{
|
2016-11-26 02:32:59 +00:00
|
|
|
var canvas = CanvasPool.create(this, 1, 1);
|
|
|
|
var ctx = canvas.getContext('2d');
|
|
|
|
|
2016-11-26 00:35:49 +00:00
|
|
|
var vendors = [ 'i', 'webkitI', 'msI', 'mozI', 'oI' ];
|
|
|
|
|
|
|
|
vendors.forEach(function (vendor)
|
|
|
|
{
|
|
|
|
var s = vendor + 'mageSmoothingEnabled';
|
|
|
|
|
2016-11-26 02:32:59 +00:00
|
|
|
if (s in ctx)
|
2016-11-26 00:35:49 +00:00
|
|
|
{
|
2016-11-26 02:32:59 +00:00
|
|
|
CanvasPool.remove(canvas);
|
2016-11-26 00:35:49 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-26 02:32:59 +00:00
|
|
|
CanvasPool.remove(canvas);
|
|
|
|
|
2016-11-26 00:35:49 +00:00
|
|
|
return null;
|
2016-11-26 02:32:59 +00:00
|
|
|
|
|
|
|
})(),
|
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.
|
|
|
|
*
|
|
|
|
* @method Phaser.Canvas.setSmoothingEnabled
|
|
|
|
* @param {CanvasRenderingContext2D} context - The context to enable or disable the image smoothing on.
|
|
|
|
* @param {boolean} value - If set to true it will enable image smoothing, false will disable it.
|
|
|
|
* @return {CanvasRenderingContext2D} Returns the source context.
|
|
|
|
*/
|
|
|
|
enable: function (context, value)
|
|
|
|
{
|
2016-11-26 02:32:59 +00:00
|
|
|
if (Smoothing.prefix)
|
2016-11-26 00:35:49 +00:00
|
|
|
{
|
2016-11-26 02:32:59 +00:00
|
|
|
context[Smoothing.prefix] = value;
|
2016-11-26 00:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return context;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*
|
|
|
|
* @method Phaser.Canvas.getSmoothingEnabled
|
|
|
|
* @param {CanvasRenderingContext2D} context - The context to check for smoothing on.
|
|
|
|
* @return {boolean} True if the given context has image smoothing enabled, otherwise false.
|
|
|
|
*/
|
|
|
|
isEnabled: function (context)
|
|
|
|
{
|
2016-11-26 02:32:59 +00:00
|
|
|
return (Smoothing.prefix !== null) ? context[Smoothing.prefix] : null;
|
2016-11-26 00:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-11-26 02:32:59 +00:00
|
|
|
module.exports = Smoothing();
|