mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
6e1ce724cb
- fix : removed duplicated code between ImageResizer and CanvasUtils (disabledImageSmoothing utility method) - added pskl.utils.UserAgent, basic user agent sniffer. I need it to sniff out IE10 for frame rendering (and it's not possible to feature detect here). Can check isChrome, isFirefox, isIE and get the version for each of them - added resizeNearestNeighbour in ImageResizer. Readapted from piskel website, this allows us to 1 - resize without AA on IE10, and 2 - add a pixel gap to reenable the GRID - finally : added back support for GRID ! - also extracted the 'zoomed out background color' as a constant in Constant.js
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
(function () {
|
|
var ns = $.namespace("pskl");
|
|
|
|
ns.CanvasUtils = {
|
|
createCanvas : function (width, height, classList) {
|
|
var canvas = document.createElement("canvas");
|
|
canvas.setAttribute("width", width);
|
|
canvas.setAttribute("height", height);
|
|
|
|
if (typeof classList == "string") {
|
|
classList = [classList];
|
|
}
|
|
if (Array.isArray(classList)) {
|
|
for (var i = 0 ; i < classList.length ; i++) {
|
|
canvas.classList.add(classList[i]);
|
|
}
|
|
}
|
|
|
|
return canvas;
|
|
},
|
|
|
|
disableImageSmoothing : function (canvas) {
|
|
var context = canvas.getContext('2d');
|
|
context.imageSmoothingEnabled = false;
|
|
context.mozImageSmoothingEnabled = false;
|
|
context.oImageSmoothingEnabled = false;
|
|
context.webkitImageSmoothingEnabled = false;
|
|
context.msImageSmoothingEnabled = false;
|
|
},
|
|
|
|
clear : function (canvas) {
|
|
if (canvas) {
|
|
canvas.getContext("2d").clearRect(0, 0, canvas.width, canvas.height);
|
|
}
|
|
},
|
|
|
|
getImageDataFromCanvas : function (canvas) {
|
|
var sourceContext = canvas.getContext('2d');
|
|
return sourceContext.getImageData(0, 0, canvas.width, canvas.height).data;
|
|
}
|
|
};
|
|
})(); |