piskel/js/rendering/layer/LayersRenderer.js
jdescottes 6e1ce724cb feature : zoom level
- 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
2013-11-05 00:05:49 +01:00

68 lines
2.2 KiB
JavaScript

(function () {
var ns = $.namespace('pskl.rendering.layer');
ns.LayersRenderer = function (container, renderingOptions, piskelController) {
pskl.rendering.CompositeRenderer.call(this);
this.piskelController = piskelController;
// Do not use CachedFrameRenderers here, since the caching will be performed in the render method of LayersRenderer
this.belowRenderer = new pskl.rendering.frame.FrameRenderer(container, renderingOptions, ["layers-canvas", "layers-below-canvas"]);
this.aboveRenderer = new pskl.rendering.frame.FrameRenderer(container, renderingOptions, ["layers-canvas", "layers-above-canvas"]);
this.add(this.belowRenderer);
this.add(this.aboveRenderer);
this.serializedRendering = '';
};
pskl.utils.inherit(pskl.rendering.layer.LayersRenderer, pskl.rendering.CompositeRenderer);
ns.LayersRenderer.prototype.render = function () {
var offset = this.getOffset();
var size = this.getDisplaySize();
var layers = this.piskelController.getLayers();
var currentFrameIndex = this.piskelController.currentFrameIndex;
var currentLayerIndex = this.piskelController.currentLayerIndex;
var serializedRendering = [
this.getZoom(),
this.isGridEnabled(),
offset.x,
offset.y,
size.width,
size.height,
currentFrameIndex,
currentLayerIndex,
layers.length
].join("-");
if (this.serializedRendering != serializedRendering) {
this.serializedRendering = serializedRendering;
this.clear();
var downLayers = layers.slice(0, currentLayerIndex);
if (downLayers.length > 0) {
var downFrame = this.getFrameForLayersAt_(currentFrameIndex, downLayers);
this.belowRenderer.render(downFrame);
}
var upLayers = layers.slice(currentLayerIndex + 1, layers.length);
if (upLayers.length > 0) {
var upFrame = this.getFrameForLayersAt_(currentFrameIndex, upLayers);
this.aboveRenderer.render(upFrame);
}
}
};
ns.LayersRenderer.prototype.getFrameForLayersAt_ = function (frameIndex, layers) {
var frames = layers.map(function (l) {
return l.getFrameAt(frameIndex);
});
return pskl.utils.FrameUtils.merge(frames);
};
})();