mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Fixed dynamic dpi update for drawing canvas, added throttle on resize event.
This commit is contained in:
parent
2a4077eaad
commit
ba6879875c
@ -189,24 +189,19 @@
|
|||||||
ns.DrawingController.prototype.updateDPI = function (newDPI) {
|
ns.DrawingController.prototype.updateDPI = function (newDPI) {
|
||||||
this.renderer.updateDPI(newDPI);
|
this.renderer.updateDPI(newDPI);
|
||||||
this.overlayRenderer.updateDPI(newDPI);
|
this.overlayRenderer.updateDPI(newDPI);
|
||||||
|
this.forceRendering_();
|
||||||
this.render();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.DrawingController.prototype.render = function () {
|
ns.DrawingController.prototype.render = function () {
|
||||||
try {
|
|
||||||
this.renderFrame();
|
this.renderFrame();
|
||||||
this.renderOverlay();
|
this.renderOverlay();
|
||||||
} catch (e) {
|
|
||||||
// TODO : temporary t/c for integration
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.DrawingController.prototype.renderFrame = function () {
|
ns.DrawingController.prototype.renderFrame = function () {
|
||||||
var frame = this.framesheet.getCurrentFrame();
|
var frame = this.framesheet.getCurrentFrame();
|
||||||
var serializedFrame = frame.serialize();
|
var serializedFrame = frame.serialize();
|
||||||
if (this.serializedFrame != serializedFrame) {
|
if (this.serializedFrame != serializedFrame) {
|
||||||
this.serializedFrame = serializedFrame
|
this.serializedFrame = serializedFrame;
|
||||||
this.renderer.render(frame);
|
this.renderer.render(frame);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -214,8 +209,12 @@
|
|||||||
ns.DrawingController.prototype.renderOverlay = function () {
|
ns.DrawingController.prototype.renderOverlay = function () {
|
||||||
var serializedOverlay = this.overlayFrame.serialize();
|
var serializedOverlay = this.overlayFrame.serialize();
|
||||||
if (this.serializedOverlay != serializedOverlay) {
|
if (this.serializedOverlay != serializedOverlay) {
|
||||||
this.serializedOverlay = serializedOverlay
|
this.serializedOverlay = serializedOverlay;
|
||||||
this.overlayRenderer.render(this.overlayFrame);
|
this.overlayRenderer.render(this.overlayFrame);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ns.DrawingController.prototype.forceRendering_ = function () {
|
||||||
|
this.serializedFrame = this.serializedOverlay = null;
|
||||||
|
}
|
||||||
})();
|
})();
|
39
js/piskel.js
39
js/piskel.js
@ -17,8 +17,7 @@ $.namespace("pskl");
|
|||||||
framePixelHeight = 32,
|
framePixelHeight = 32,
|
||||||
|
|
||||||
// Scaling factors for a given frameSheet rendering:
|
// Scaling factors for a given frameSheet rendering:
|
||||||
// Main drawing area:
|
// Main drawing area dpi is calculated dynamically
|
||||||
drawingCanvasDpi = 20,
|
|
||||||
// Canvas preview film canvases:
|
// Canvas preview film canvases:
|
||||||
previewTileCanvasDpi = 4,
|
previewTileCanvasDpi = 4,
|
||||||
// Animated canvas preview:
|
// Animated canvas preview:
|
||||||
@ -30,15 +29,14 @@ $.namespace("pskl");
|
|||||||
var piskel = {
|
var piskel = {
|
||||||
|
|
||||||
init : function () {
|
init : function () {
|
||||||
piskel.initDPIs_();
|
|
||||||
|
|
||||||
frameSheet = new pskl.model.FrameSheet(framePixelWidth, framePixelHeight);
|
frameSheet = new pskl.model.FrameSheet(framePixelWidth, framePixelHeight);
|
||||||
frameSheet.addEmptyFrame();
|
frameSheet.addEmptyFrame();
|
||||||
|
frameSheet.setCurrentFrameIndex(0);
|
||||||
|
|
||||||
this.drawingController = new pskl.controller.DrawingController(
|
this.drawingController = new pskl.controller.DrawingController(
|
||||||
frameSheet,
|
frameSheet,
|
||||||
$('#drawing-canvas-container'),
|
$('#drawing-canvas-container'),
|
||||||
drawingCanvasDpi
|
this.calculateDPIsForDrawingCanvas_()
|
||||||
);
|
);
|
||||||
|
|
||||||
this.animationController = new pskl.controller.AnimatedPreviewController(
|
this.animationController = new pskl.controller.AnimatedPreviewController(
|
||||||
@ -47,7 +45,6 @@ $.namespace("pskl");
|
|||||||
previewAnimationCanvasDpi
|
previewAnimationCanvasDpi
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
this.previewsController = new pskl.controller.PreviewFilmController(
|
this.previewsController = new pskl.controller.PreviewFilmController(
|
||||||
frameSheet,
|
frameSheet,
|
||||||
$('#preview-list'),
|
$('#preview-list'),
|
||||||
@ -64,10 +61,6 @@ $.namespace("pskl");
|
|||||||
this.selectionManager =
|
this.selectionManager =
|
||||||
new pskl.selection.SelectionManager(this.drawingController.overlayFrame);
|
new pskl.selection.SelectionManager(this.drawingController.overlayFrame);
|
||||||
|
|
||||||
frameSheet.setCurrentFrameIndex(0);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.animationController.init();
|
this.animationController.init();
|
||||||
this.previewsController.init();
|
this.previewsController.init();
|
||||||
|
|
||||||
@ -92,6 +85,8 @@ $.namespace("pskl");
|
|||||||
var drawingLoop = new pskl.rendering.DrawingLoop();
|
var drawingLoop = new pskl.rendering.DrawingLoop();
|
||||||
drawingLoop.addCallback(this.render, this);
|
drawingLoop.addCallback(this.render, this);
|
||||||
drawingLoop.start();
|
drawingLoop.start();
|
||||||
|
|
||||||
|
this.connectResizeToDpiUpdate_();
|
||||||
},
|
},
|
||||||
|
|
||||||
render : function (delta) {
|
render : function (delta) {
|
||||||
@ -100,18 +95,18 @@ $.namespace("pskl");
|
|||||||
this.previewsController.render(delta);
|
this.previewsController.render(delta);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
connectResizeToDpiUpdate_ : function () {
|
||||||
* Override default DPIs.
|
$(window).resize($.proxy(this.startDPIUpdateTimer_, this));
|
||||||
* @private
|
},
|
||||||
*/
|
|
||||||
initDPIs_ : function() {
|
startDPIUpdateTimer_ : function () {
|
||||||
drawingCanvasDpi = piskel.calculateDPIsForDrawingCanvas_();
|
if (this.dpiUpdateTimer) window.clearInterval(this.dpiUpdateTimer);
|
||||||
// TODO(vincz): Add throttling on window.resize event.
|
this.dpiUpdateTimer = window.setTimeout($.proxy(this.updateDPIForViewport, this), 200);
|
||||||
$(window).resize($.proxy(function() {
|
},
|
||||||
drawingCanvasDpi = piskel.calculateDPIsForDrawingCanvas_();
|
|
||||||
this.drawingController.updateDPI(drawingCanvasDpi);
|
updateDPIForViewport : function () {
|
||||||
}, this));
|
var dpi = piskel.calculateDPIsForDrawingCanvas_();
|
||||||
// TODO(vincz): Check for user settings eventually from localstorage.
|
this.drawingController.updateDPI(dpi);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user