started working on changing image block proportions when zooming...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-04-24 03:21:41 +03:00
parent b32dc97c6a
commit 47ed9e35d1
2 changed files with 83 additions and 52 deletions

View File

@ -85,57 +85,92 @@ var core = require('features/core')
// //
// //
// XXX should this be an action??? // XXX should this be an action???
// XXX problems: // XXX .ribbons.correctImageProportionsForRotation(..) might be working
// Q: what do we use for scale?? // incorrectly...
// ...when scaling a horizontal image, the thing starts jumping around....
function updateImageProportions(){ function updateImageProportions(){
var that = this
// XXX get this from config...
var threshold = this.config['single-image-proportions-threshold'] || 2
var viewer = this.ribbons.viewer var viewer = this.ribbons.viewer
var image = viewer.find('.image')
var W = viewer.width() // XXX
var H = viewer.height() return
var w = image.width()
var h = image.height()
var R = W/H var img = this.ribbons.getImage()
var r = w/h var w = img.outerWidth()
var h = img.outerHeight()
var threshold = 3 var c = Math.min(this.screenwidth, this.screenheight)
var scale = Math.min(this.screenwidth, this.screenheight)
// XXX the idea is that: // change proportions...
// - up until a specific threshold: if(c < threshold){
// r is 1 var W = viewer.width()
// we do not care about R var H = viewer.height()
// XXX how do we define the threshold???
// - above that threshold: // get dimensional scale....
// r tends to R relative to ??? var s = Math.min(W, H) / Math.min(w, h)
// - when W == w && H == h
// r == R // XXX proportion s between s and 1 depending on c position
// - beyond // between threshold and 1
// r tends to actual image proportions // s: const - changes with viewer size
// - when (W == w || H == h) && r == actual image proportions // c: threshold -> 1
// we change nothing... //
// factor:
// reset image proportions to square... // f: 1/s -> 1
if(scale > threshold){ //
image.css({ //var f =
width: '', //s *= f
height: '',
// get new dimension in image scale...
var n = Math.max(W, H) / s
if(n == Math.max(w, h)){
return
}
getAnimationFrame(function(){
that.ribbons.preventTransitions()
// horizontal viewer...
if(Math.min(W, H) == H){
// XXX
viewer.find('.ribbon .image')
.css({
width: n,
height: '',
})
// vertical viewer...
} else {
// XXX
viewer.find('.ribbon .image')
.css({
width: '',
height: n,
})
}
that.centerImage()
that.ribbons.restoreTransitions(true)
}) })
// shift image container proportions between 1 and R, from threshold // reset proportions to square...
// scale to 1... } else if(w != h) {
} else if(scale >= 1){ getAnimationFrame(function(){
// XXX that.ribbons.preventTransitions()
// shift image container proportions between R and actual image
// proportions...
} else if(W != w || H != h){
// XXX
// image container proportions are the same as image proportions... viewer.find('.ribbon .image')
} else { .css({
// XXX width: '',
height: '',
})
that.centerImage()
that.ribbons.restoreTransitions(true)
})
} }
} }

View File

@ -538,19 +538,15 @@ module.ViewerActions = actions.Actions({
function(){ function(){
this.ribbons.origin() this.ribbons.origin()
var s = this.scale * (this.config['zoom-step'] || 1.2) var d = (this.config['zoom-step'] || 1.2)
var W = this.ribbons.viewer.width()
var H = this.ribbons.viewer.height()
var w = this.ribbons.getVisibleImageSize('width', s)
var h = this.ribbons.getVisibleImageSize('height', s)
// limit scaling to screen dimensions... // limit scaling to screen dimensions...
if(this.config['max-zoom-to-screen'] && (W < w || H < h)){ if(this.config['max-zoom-to-screen']
this.fitImage(1) && (Math.min(this.screenwidth, this.screenheight) / d) < 1){
this.scale /= 1 / Math.min(this.screenwidth, this.screenheight)
} else { } else {
this.scale = s this.scale *= d
} }
}], }],
zoomOut: ['Zoom/Zoom out', zoomOut: ['Zoom/Zoom out',
@ -560,7 +556,7 @@ module.ViewerActions = actions.Actions({
var max = this.config['max-screen-images'] var max = this.config['max-screen-images']
if(max && max < (this.screenwidth * (this.config['zoom-step'] || 1.2))){ if(max && max < (this.screenwidth * (this.config['zoom-step'] || 1.2))){
this.fitImage(max) this.scale /= max / Math.min(this.screenwidth, this.screenheight)
} else { } else {
this.scale /= (this.config['zoom-step'] || 1.2) this.scale /= (this.config['zoom-step'] || 1.2)