mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	started working on changing image block proportions when zooming...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									b32dc97c6a
								
							
						
					
					
						commit
						47ed9e35d1
					
				| @ -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:
 |  | ||||||
| 	// 			r tends to R relative to ???
 |  | ||||||
| 	// 		- when W == w && H == h
 |  | ||||||
| 	// 			r == R
 |  | ||||||
| 	// 		- beyond 
 |  | ||||||
| 	// 			r tends to actual image proportions
 |  | ||||||
| 	// 		- when (W == w || H == h) && r == actual image proportions
 |  | ||||||
| 	// 			we change nothing...
 |  | ||||||
| 
 | 
 | ||||||
| 	// reset image proportions to square...
 | 		// get dimensional scale....
 | ||||||
| 	if(scale > threshold){ | 		var s = Math.min(W, H) / Math.min(w, h) | ||||||
| 		image.css({ | 
 | ||||||
| 			width: '', | 		// XXX proportion s between s and 1 depending on c position 
 | ||||||
| 			height: '', | 		// 		between threshold and 1
 | ||||||
|  | 		// 			s: const 				- changes with viewer size
 | ||||||
|  | 		// 			c: threshold -> 1
 | ||||||
|  | 		//
 | ||||||
|  | 		//		factor:
 | ||||||
|  | 		// 			f: 1/s -> 1
 | ||||||
|  | 		//
 | ||||||
|  | 		//var f = 
 | ||||||
|  | 		//s *= f
 | ||||||
|  | 
 | ||||||
|  | 		// 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 
 | 			viewer.find('.ribbon .image') | ||||||
| 	// proportions...
 | 				.css({ | ||||||
| 	} else if(W != w || H != h){ | 					width: '', | ||||||
| 		// XXX
 | 					height: '', | ||||||
|  | 				}) | ||||||
| 
 | 
 | ||||||
| 	// image container proportions are the same as image proportions...
 | 			that.centerImage() | ||||||
| 	} else { | 
 | ||||||
| 		// XXX
 | 			that.ribbons.restoreTransitions(true) | ||||||
|  | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -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) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user