From 4f46850b376b2d428a3d9415b1dc69b36b875a2c Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 16 May 2012 13:06:34 -0700 Subject: Automatically add scrollbars when moving content to negative space. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/draw-utils.js | 41 ++++++++++++++++++++++++++++++++------ js/stage/stage.reel/stage.js | 31 ++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 8 deletions(-) (limited to 'js') diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index b53ac4ad..b268b8f0 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -245,16 +245,45 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { } var els = event.detail.data.els; if(els && this._shouldUpdatePlanes(event.detail.data.prop)) { - var len = els.length; + var len = els.length, + stage = this.application.ninja.stage, + minLeft = stage.userPaddingLeft, + minTop = stage.userPaddingTop, + docLeft = stage.documentOffsetLeft, + docTop = stage.documentOffsetTop, + l, + t, + plane, + changed = false; for(var i=0; i < len; i++) { - if(els[i].elementModel.props3D.elementPlane) { - els[i].elementModel.props3D.elementPlane.init(); + plane = els[i].elementModel.props3D.elementPlane; + if(plane) { + plane.init(); + l = plane._rect.m_left - docLeft; + t = plane._rect.m_top - docTop; + if(l < minLeft) { + minLeft = l; + } + if(t < minTop) { + minTop = t; + } } } - this.application.ninja.stage.layout.draw(); - this.drawWorkingPlane(); - this.draw3DCompass(); + if(minLeft !== stage.userPaddingLeft) { + stage.userPaddingLeft = minLeft; + changed = true; + } + if(minTop !== stage.userPaddingTop) { + stage.userPaddingTop = minTop; + changed = true; + } + + if(!changed) { + stage.layout.draw(); + this.drawWorkingPlane(); + this.draw3DCompass(); + } } } }, diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js index 125155d8..05376527 100755 --- a/js/stage/stage.reel/stage.js +++ b/js/stage/stage.reel/stage.js @@ -187,6 +187,33 @@ exports.Stage = Montage.create(Component, { enumerable : false }, + _userPaddingLeft: { value: 0 }, + _userPaddingTop: { value: 0 }, + + userPaddingLeft: { + get: function() { return this._userPaddingLeft; }, + set: function(value) { + this._userPaddingLeft = value; + this._documentOffsetLeft = -value; + this.application.ninja.stylesController.setElementStyle(this._documentRoot.ownerDocument.getElementsByTagName("HTML")[0], + "padding-left", -value + "px", true); + this.userContentLeft = this._documentOffsetLeft; + this.updatedStage = true; + } + }, + + userPaddingTop: { + get: function() { return this._userPaddingTop; }, + set: function(value) { + this._userPaddingTop = value; + this._documentOffsetTop = -value; + this.application.ninja.stylesController.setElementStyle(this._documentRoot.ownerDocument.getElementsByTagName("HTML")[0], + "padding-top", -value + "px", true); + this.userContentTop = this._documentOffsetTop; + this.updatedStage = true; + } + }, + willDraw: { value: function() { if(this.resizeCanvases) { @@ -490,8 +517,8 @@ exports.Stage = Montage.create(Component, { this._scrollLeft = this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft; this._scrollTop = this.application.ninja.currentDocument.model.views.design.document.body.scrollTop; - this.userContentLeft = -this._scrollLeft; - this.userContentTop = -this._scrollTop; + this.userContentLeft = this._documentOffsetLeft - this._scrollLeft; + this.userContentTop = this._documentOffsetTop - this._scrollTop; // TODO - scroll events are not dependable. We may need to use a timer to simulate // scrollBegin and scrollEnd. For now, the Pan Tool will keep track of the stage's scroll values -- cgit v1.2.3