client/js/renderer/scene.js
changeset 377 1d87c4342e5d
parent 373 e21c96e251ee
child 379 81573f4331b5
--- a/client/js/renderer/scene.js	Sun Jan 11 20:43:48 2015 +0100
+++ b/client/js/renderer/scene.js	Tue Jan 13 10:14:53 2015 +0100
@@ -29,6 +29,9 @@
         this.buttons_layer = new paper.Layer();
         this.delete_list = [];
         this.redrawActive = true;
+        
+        var currentWidth = this.canvas_$.width();
+        var currentHeight = this.canvas_$.height();
 
         if (_renkan.options.show_minimap) {
             this.minimap = {
@@ -276,8 +279,10 @@
         bindClick(".Rk-Fold-Bins", "foldBins");
 
         paper.view.onResize = function(_event) {
-            // Because of paper bug which does not calculate the good height (and width a fortiori)
-            // We have to update manually the canvas's height
+        	var _ratio,
+        		newWidth= _this.canvas_$.parent().width(),
+				newHeight = _this.canvas_$.parent().height();
+        	
             paper.view._viewSize.height =  _event.size.height = _this.canvas_$.parent().height();
 
             if (_this.minimap) {
@@ -285,7 +290,20 @@
                 _this.minimap.rectangle.fitBounds(_this.minimap.topleft.subtract([2,2]), _this.minimap.size.add([4,4]));
                 _this.minimap.cliprectangle.fitBounds(_this.minimap.topleft, _this.minimap.size);
             }
-            _this.redraw();
+            
+            if (newHeight < newWidth) {
+            		_ratio = (newHeight/currentHeight);
+            } else {
+            	_ratio = (newWidth/currentWidth);
+            }
+            
+        	_this.resizeZoom((newWidth/currentWidth), (newHeight/currentHeight), _ratio);
+        	
+        	currentWidth = newWidth;
+        	currentHeight = newHeight;
+        	
+        	_this.redraw();
+            
         };
 
         var _thRedraw = _.throttle(function() {
@@ -1173,6 +1191,23 @@
                         break;
                     }
                 }
+                var widthAft = this.$.width();
+                var heightAft = this.$.height();
+                
+                if (this.renkan.options.show_top_bar) {
+                	heightAft -= this.$.find(".Rk-TopBar").height();
+                }
+                if (this.renkan.options.show_bins && (this.renkan.$.find(".Rk-Bins").position().left > 0)) {
+                	widthAft -= this.renkan.$.find(".Rk-Bins").width();
+                }
+                
+                this.canvas_$.attr({
+                	width: widthAft,
+                	height: heightAft
+                });
+                
+                paper.view.viewSize = new paper.Size([this.canvas_$.width(), this.canvas_$.height()]);
+                
             } else {
                 for (i = 0; i < _requestMethods.length; i++) {
                     if (typeof _el[_requestMethods[i]] === "function") {
@@ -1198,6 +1233,14 @@
                                        ]).multiply( 0.5 * ( 1 - Math.SQRT2 ) ).add(this.offset.multiply( Math.SQRT2 ));
             this.setScale( _newScale, _offset );
         },
+        resizeZoom: function(_scaleWidth, _scaleHeight, _ratio) {
+        	var _newScale = this.scale * _ratio,
+            	_offset = new paper.Point([
+                                       (this.offset.x * _scaleWidth),
+                                       (this.offset.y * _scaleHeight)
+                                       ]);
+            this.setScale( _newScale, _offset );
+        },
         addNodeBtn: function() {
             if (this.click_mode === Utils._CLICKMODE_ADDNODE) {
                 this.click_mode = false;
@@ -1259,13 +1302,20 @@
         foldBins: function() {
             var foldBinsButton = this.$.find(".Rk-Fold-Bins"),
                 bins = this.renkan.$.find(".Rk-Bins");
-            var _this = this;
+            var _this = this,
+            	sizeBef = _this.$.width(),
+            	sizeAft;
             if (bins.position().left < 0) {
                 bins.animate({left: 0},250);
                 this.$.animate({left: 300},250,function() {
                     var w = _this.$.width();
                     paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
                 });
+                if ((sizeBef -  bins.width()) < bins.width()){
+                	sizeAft = sizeBef;
+                } else {
+                	sizeAft = sizeBef - bins.width();
+                }
                 foldBinsButton.html("&laquo;");
             } else {
                 bins.animate({left: -300},250);
@@ -1273,8 +1323,10 @@
                     var w = _this.$.width();
                     paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
                 });
+                sizeAft = sizeBef+300;
                 foldBinsButton.html("&raquo;");
             }
+            _this.resizeZoom(1, 1, (sizeAft/sizeBef));
         },
         save: function() { },
         open: function() { }