mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Resize is now bound to height and width, and also avoids overlap with preview
This commit is contained in:
parent
6a822f1299
commit
a9b01cd7c2
33
js/piskel.js
33
js/piskel.js
@ -112,8 +112,37 @@ $.namespace("pskl");
|
||||
* @private
|
||||
*/
|
||||
calculateDPIsForDrawingCanvas_ : function() {
|
||||
var availableViewportHeight = $('.main-panel').height();
|
||||
return Math.floor(availableViewportHeight / framePixelHeight);
|
||||
var availableViewportHeight = $('.main-panel').height(),
|
||||
availableViewportWidth = $('.main-panel').width(),
|
||||
previewHeight = $(".preview-container").height(),
|
||||
previewWidth = $(".preview-container").width();
|
||||
|
||||
var heightBoundDpi = Math.floor(availableViewportHeight / framePixelHeight),
|
||||
widthBoundDpi = Math.floor(availableViewportWidth / framePixelWidth);
|
||||
|
||||
var dpi = Math.min(heightBoundDpi, widthBoundDpi);
|
||||
|
||||
var drawingCanvasHeight = dpi * framePixelHeight;
|
||||
var drawingCanvasWidth = dpi * framePixelWidth;
|
||||
|
||||
// Check if preview and drawing canvas overlap
|
||||
var heightGap = drawingCanvasHeight + previewHeight - availableViewportHeight,
|
||||
widthGap = drawingCanvasWidth + previewWidth - availableViewportWidth;
|
||||
if (heightGap > 0 && widthGap > 0) {
|
||||
// Calculate the DPI change needed to bridge height and width gap
|
||||
var heightGapDpi = Math.ceil(heightGap / framePixelHeight),
|
||||
widthGapDpi = Math.ceil(widthGap / framePixelWidth);
|
||||
|
||||
// substract smallest dpi change to initial dpi
|
||||
dpi -= Math.min(heightGapDpi, widthGapDpi);
|
||||
}
|
||||
|
||||
// var drawingCanvasWidth = dpi * framePixelWidth;
|
||||
// if (availableViewportWidth - drawingCanvasWidth < previewWidth) {
|
||||
// dpi -= Math.floor(previewWidth / framePixelWidth);
|
||||
// }
|
||||
|
||||
return dpi;
|
||||
},
|
||||
|
||||
finishInit : function () {
|
||||
|
Loading…
Reference in New Issue
Block a user