mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Fixed Smoothing so it doesn't use the CanvasPool.
This commit is contained in:
parent
74e4357bcd
commit
b17d3679fa
1 changed files with 55 additions and 22 deletions
|
@ -1,7 +1,9 @@
|
|||
var CanvasPool = require('./CanvasPool');
|
||||
|
||||
var Smoothing = {
|
||||
// Browser specific prefix, so not going to change between contexts, only between browsers
|
||||
var prefix = '';
|
||||
|
||||
var Smoothing = function ()
|
||||
{
|
||||
/**
|
||||
* Gets the Smoothing Enabled vendor prefix being used on the given context, or null if not set.
|
||||
* iife
|
||||
|
@ -10,29 +12,22 @@ var Smoothing = {
|
|||
* @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.
|
||||
*/
|
||||
prefix: (function ()
|
||||
var getPrefix = function (context)
|
||||
{
|
||||
var canvas = CanvasPool.create(this, 1, 1);
|
||||
var ctx = canvas.getContext('2d');
|
||||
|
||||
var vendors = [ 'i', 'webkitI', 'msI', 'mozI', 'oI' ];
|
||||
|
||||
vendors.forEach(function (vendor)
|
||||
for (var i = 0; i < vendors.length; i++)
|
||||
{
|
||||
var s = vendor + 'mageSmoothingEnabled';
|
||||
var s = vendors[i] + 'mageSmoothingEnabled';
|
||||
|
||||
if (s in ctx)
|
||||
if (s in context)
|
||||
{
|
||||
CanvasPool.remove(canvas);
|
||||
return s;
|
||||
}
|
||||
});
|
||||
|
||||
CanvasPool.remove(canvas);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
})(),
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the Image Smoothing property on the given context. Set to false to disable image smoothing.
|
||||
|
@ -46,15 +41,47 @@ var Smoothing = {
|
|||
* @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)
|
||||
var enable = function (context)
|
||||
{
|
||||
if (Smoothing.prefix)
|
||||
if (prefix === '')
|
||||
{
|
||||
context[Smoothing.prefix] = value;
|
||||
prefix = getPrefix(context);
|
||||
}
|
||||
|
||||
if (prefix)
|
||||
{
|
||||
context[prefix] = true;
|
||||
}
|
||||
|
||||
return context;
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
var disable = function (context)
|
||||
{
|
||||
if (prefix === '')
|
||||
{
|
||||
prefix = getPrefix(context);
|
||||
}
|
||||
|
||||
if (prefix)
|
||||
{
|
||||
context[prefix] = false;
|
||||
}
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns `true` if the given context has image smoothing enabled, otherwise returns `false`.
|
||||
|
@ -64,11 +91,17 @@ var Smoothing = {
|
|||
* @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)
|
||||
var isEnabled = function (context)
|
||||
{
|
||||
return (Smoothing.prefix !== null) ? context[Smoothing.prefix] : null;
|
||||
}
|
||||
return (prefix !== null) ? context[prefix] : null;
|
||||
};
|
||||
|
||||
return {
|
||||
disable: disable,
|
||||
enable: enable,
|
||||
getPrefix: getPrefix,
|
||||
isEnabled: isEnabled
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = Smoothing();
|
||||
|
|
Loading…
Add table
Reference in a new issue