2013-11-01 20:17:41 +04:00
|
|
|
(function () {
|
|
|
|
var ns = $.namespace('pskl.rendering.layer');
|
|
|
|
|
|
|
|
ns.LayersRenderer = function (container, renderingOptions, piskelController) {
|
|
|
|
pskl.rendering.CompositeRenderer.call(this);
|
|
|
|
|
|
|
|
this.piskelController = piskelController;
|
|
|
|
|
2013-11-02 14:39:35 +04:00
|
|
|
// 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"]);
|
2013-11-01 20:17:41 +04:00
|
|
|
|
|
|
|
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 () {
|
2013-11-02 14:39:35 +04:00
|
|
|
var offset = this.getOffset();
|
|
|
|
var size = this.getDisplaySize();
|
2013-11-01 20:17:41 +04:00
|
|
|
var layers = this.piskelController.getLayers();
|
|
|
|
var currentFrameIndex = this.piskelController.currentFrameIndex;
|
|
|
|
var currentLayerIndex = this.piskelController.currentLayerIndex;
|
|
|
|
|
|
|
|
var serializedRendering = [
|
|
|
|
this.getZoom(),
|
2013-11-05 03:05:49 +04:00
|
|
|
this.isGridEnabled(),
|
2013-11-02 14:39:35 +04:00
|
|
|
offset.x,
|
|
|
|
offset.y,
|
|
|
|
size.width,
|
|
|
|
size.height,
|
2013-11-01 20:17:41 +04:00
|
|
|
currentFrameIndex,
|
|
|
|
currentLayerIndex,
|
|
|
|
layers.length
|
|
|
|
].join("-");
|
|
|
|
|
2013-11-02 14:39:35 +04:00
|
|
|
|
2013-11-01 20:17:41 +04:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
})();
|