Fix canvas size when grid display is active

- Dynamic resizing of canvas when display_grid is activated/deactivated
 - Adding a main-wrapper to get a perfect alignement at the top and
bottom the application screen
 - fix DPI update on page load (independent of grid option).
 - fix available width for DPI calculation (using margin-box, was using
only content before)
This commit is contained in:
Vince 2013-06-19 19:01:12 +02:00
parent 6cb145ae34
commit 4618cb643a
3 changed files with 126 additions and 93 deletions

View File

@ -12,39 +12,48 @@ body {
* Application layout * Application layout
*/ */
.main-wrapper {
position: absolute;
top: 5px;
right: 0;
bottom: 5px;
left: 0;
}
.column-wrapper { .column-wrapper {
text-align: center; text-align: center;
font-size: 0; font-size: 0;
position: absolute; position: absolute;
left: 100px; /* Reserve room for tools on the left edge of the screen. */ left: 100px; /* Reserve room for tools on the left edge of the screen. */
top: 10px; top: 0;
right: 50px; /* Reserve room for actions on the right edge of the screen. */ right: 50px; /* Reserve room for actions on the right edge of the screen. */
bottom: 10px; bottom: 0;
}
.column {
display: inline-block;
} }
.left-column { .left-column {
display: inline-block;
vertical-align: top; vertical-align: top;
height: 100%; height: 100%;
margin-right: 7px; margin-right: 7px;
} }
.main-column { .main-column {
display: inline-block;
height: 100%; height: 100%;
position: relative; position: relative;
} }
.drawing-canvas-container {
font-size: 0;
}
.right-column { .right-column {
display: inline-block;
vertical-align: top; vertical-align: top;
margin-left: 10px; margin-left: 10px;
} }
.drawing-canvas-container {
font-size: 0;
}
.sticky-section { .sticky-section {
display: table; display: table;
height: 100%; height: 100%;

View File

@ -16,6 +16,7 @@
<link rel="stylesheet" type="text/css" href="css/preview-film-section.css"> <link rel="stylesheet" type="text/css" href="css/preview-film-section.css">
</head> </head>
<body> <body>
<div id="main-wrapper" class="main-wrapper">
<div class="sticky-section left-sticky-section" id="tool-section"> <div class="sticky-section left-sticky-section" id="tool-section">
<div class="wrap"> <div class="wrap">
<ul id="tools-container" class="tools-wrapper"></ul> <ul id="tools-container" class="tools-wrapper"></ul>
@ -76,8 +77,8 @@
</div> </div>
</div> </div>
<div class="column-wrapper"> <div id="column-wrapper" class="column-wrapper">
<div class='left-column'> <div class='column left-column'>
<!-- List of frames: --> <!-- List of frames: -->
<div id="preview-list-wrapper" class="preview-list-wrapper"> <div id="preview-list-wrapper" class="preview-list-wrapper">
@ -89,14 +90,14 @@
</div> </div>
</div> </div>
<div class='main-column'> <div class='column main-column'>
<!-- Drawing area: --> <!-- Drawing area: -->
<div id="drawing-canvas-container" class="drawing-canvas-container canvas-container"> <div id="drawing-canvas-container" class="drawing-canvas-container canvas-container">
<div class="canvas-background"></div> <div class="canvas-background"></div>
</div> </div>
</div> </div>
<div class="right-column"> <div class="column right-column">
<!-- Animation preview: --> <!-- Animation preview: -->
<div class='preview-container'> <div class='preview-container'>
<div id='preview-canvas-container' class="canvas-container"> <div id='preview-canvas-container' class="canvas-container">
@ -109,6 +110,7 @@
</div> </div>
</div> </div>
</div> </div>
</div>
<!-- Core libraries: --> <!-- Core libraries: -->
<script src="js/lib/jquery-1.8.0.js"></script> <script src="js/lib/jquery-1.8.0.js"></script>

View File

@ -60,8 +60,10 @@
$(window).resize($.proxy(this.startDPIUpdateTimer_, this)); $(window).resize($.proxy(this.startDPIUpdateTimer_, this));
$.subscribe(Events.FRAME_SIZE_CHANGED, $.proxy(this.updateDPI_, this));
$.subscribe(Events.USER_SETTINGS_CHANGED, $.proxy(this.onUserSettingsChange_, this)); $.subscribe(Events.USER_SETTINGS_CHANGED, $.proxy(this.onUserSettingsChange_, this));
$.subscribe(Events.FRAME_SIZE_CHANGED, $.proxy(this.updateDPI_, this));
this.updateDPI_();
}; };
ns.DrawingController.prototype.initMouseBehavior = function() { ns.DrawingController.prototype.initMouseBehavior = function() {
@ -88,7 +90,7 @@
*/ */
ns.DrawingController.prototype.onUserSettingsChange_ = function (evt, settingsName, settingsValue) { ns.DrawingController.prototype.onUserSettingsChange_ = function (evt, settingsName, settingsValue) {
if(settingsName == pskl.UserSettings.SHOW_GRID) { if(settingsName == pskl.UserSettings.SHOW_GRID) {
this.forceRendering_(); this.updateDPI_();
} }
}, },
@ -268,13 +270,20 @@
* @private * @private
*/ */
ns.DrawingController.prototype.calculateDPI_ = function() { ns.DrawingController.prototype.calculateDPI_ = function() {
var availableViewportHeight = $('.main-column').height(), var availableViewportHeight = $('#main-wrapper').height(),
leftSectionWidth = $('.left-column').width(), leftSectionWidth = $('.left-column').outerWidth(true),
rightSectionWidth = $('.right-column').width(), rightSectionWidth = $('.right-column').outerWidth(true),
availableViewportWidth = $('body').width() - leftSectionWidth - rightSectionWidth, availableViewportWidth = $('#main-wrapper').width() - leftSectionWidth - rightSectionWidth,
framePixelHeight = this.framesheet.getCurrentFrame().getHeight(), framePixelHeight = this.framesheet.getCurrentFrame().getHeight(),
framePixelWidth = this.framesheet.getCurrentFrame().getWidth(); framePixelWidth = this.framesheet.getCurrentFrame().getWidth();
var dpi = pskl.PixelUtils.calculateDPI(availableViewportHeight, availableViewportWidth, framePixelHeight, framePixelWidth);
if (pskl.UserSettings.get(pskl.UserSettings.SHOW_GRID)) {
availableViewportWidth = availableViewportWidth - (framePixelWidth * Constants.GRID_STROKE_WIDTH);
availableViewportHeight = availableViewportHeight - (framePixelHeight * Constants.GRID_STROKE_WIDTH);
}
var dpi = pskl.PixelUtils.calculateDPI(
availableViewportHeight, availableViewportWidth, framePixelHeight, framePixelWidth);
return dpi; return dpi;
}; };
@ -286,6 +295,19 @@
var dpi = this.calculateDPI_(); var dpi = this.calculateDPI_();
this.renderer.updateDPI(dpi); this.renderer.updateDPI(dpi);
this.overlayRenderer.updateDPI(dpi); this.overlayRenderer.updateDPI(dpi);
var currentFrameHeight = this.framesheet.getCurrentFrame().getHeight();
var canvasHeight = currentFrameHeight * dpi;
if (pskl.UserSettings.get(pskl.UserSettings.SHOW_GRID)) {
canvasHeight += Constants.GRID_STROKE_WIDTH * currentFrameHeight;
}
var verticalGapInPixel = Math.floor(($('#main-wrapper').height() - canvasHeight) / 2);
$('#column-wrapper').css({
'top': verticalGapInPixel + 'px',
'height': canvasHeight + 'px'
});
this.forceRendering_(); this.forceRendering_();
}; };
})(); })();