Forked from ElliotChong/KineticJS-PixelRatio_Override.coffee
Created
August 21, 2013 15:25
-
-
Save alexlouden/6295913 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adjust device pixel ratio | |
setMaximumPixelRatio = (p_maximumRatio=1) -> | |
canvas = document.createElement('canvas') | |
context = canvas.getContext('2d') | |
devicePixelRatio = window.devicePixelRatio || 1 | |
backingStoreRatio = context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || context.backingStorePixelRatio || 1 | |
pixelRatio = devicePixelRatio / backingStoreRatio | |
for className in ["HitCanvas", "SceneCanvas", "Canvas"] | |
Kinetic[className].prototype.init = ((p_method) -> (p_config={}) -> | |
if p_config.pixelRatio? then pixelRatio = p_config.pixelRatio | |
p_config.pixelRatio = if pixelRatio > p_maximumRatio then p_maximumRatio else pixelRatio | |
p_method.call @, p_config | |
) Kinetic[className].prototype.init | |
setMaximumPixelRatio 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setMaximumPixelRatio = function(p_maximumRatio) { | |
var backingStoreRatio, canvas, className, context, devicePixelRatio, pixelRatio, _i, _len, _ref, _results; | |
if (p_maximumRatio == null) { | |
p_maximumRatio = 1; | |
} | |
canvas = document.createElement('canvas'); | |
context = canvas.getContext('2d'); | |
devicePixelRatio = window.devicePixelRatio || 1; | |
backingStoreRatio = context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || context.backingStorePixelRatio || 1; | |
pixelRatio = devicePixelRatio / backingStoreRatio; | |
_ref = ["HitCanvas", "SceneCanvas", "Canvas"]; | |
_results = []; | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
className = _ref[_i]; | |
_results.push(Kinetic[className].prototype.init = (function(p_method) { | |
return function(p_config) { | |
if (p_config == null) { | |
p_config = {}; | |
} | |
if (p_config.pixelRatio != null) { | |
pixelRatio = p_config.pixelRatio; | |
} | |
p_config.pixelRatio = pixelRatio > p_maximumRatio ? p_maximumRatio : pixelRatio; | |
return p_method.call(this, p_config); | |
}; | |
})(Kinetic[className].prototype.init)); | |
} | |
return _results; | |
}; | |
setMaximumPixelRatio(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment