diff options
Diffstat (limited to 'js/helper-classes/3D')
-rwxr-xr-x | js/helper-classes/3D/draw-utils.js | 94 | ||||
-rwxr-xr-x | js/helper-classes/3D/snap-manager.js | 40 | ||||
-rwxr-xr-x | js/helper-classes/3D/view-utils.js | 69 |
3 files changed, 111 insertions, 92 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 88830964..bf48a723 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js | |||
@@ -119,19 +119,43 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
119 | 119 | ||
120 | initializeFromDocument:{ | 120 | initializeFromDocument:{ |
121 | value:function(){ | 121 | value:function(){ |
122 | var documentRootChildren = null, i; | 122 | var documentRootChildren = null, i, stage = this.application.ninja.stage; |
123 | //initialize with current document | 123 | //initialize with current document |
124 | this._eltArray = []; | 124 | this._eltArray = []; |
125 | this._planesArray = []; | 125 | this._planesArray = []; |
126 | this.setDrawingSurfaceElement(this.application.ninja.stage.canvas); | 126 | this.setDrawingSurfaceElement(stage.canvas); |
127 | this.setSourceSpaceElement( this.application.ninja.stage.stageDeps.currentStage ); | 127 | this.setSourceSpaceElement( this.application.ninja.currentDocument.documentRoot); |
128 | this.setWorkingPlane( [0,0,1,0] ); | 128 | this.setWorkingPlane( [0,0,1,0] ); |
129 | 129 | ||
130 | //Loop through all the top-level children of the current document and call drawUtils.addElement on them | 130 | //Loop through all the top-level children of the current document and call drawUtils.addElement on them |
131 | if(this.application.ninja.currentDocument._liveNodeList.length > 0){ | 131 | if(this.application.ninja.currentDocument._liveNodeList.length > 0){ |
132 | documentRootChildren = this.application.ninja.currentDocument._liveNodeList; | 132 | documentRootChildren = this.application.ninja.currentDocument._liveNodeList; |
133 | for(i=0;i<documentRootChildren.length;i++){ | 133 | var len = documentRootChildren.length, |
134 | this.addElement(documentRootChildren[i]); | 134 | minLeft = stage.userPaddingLeft, |
135 | minTop = stage.userPaddingTop, | ||
136 | docLeft = stage.documentOffsetLeft, | ||
137 | docTop = stage.documentOffsetTop, | ||
138 | l, | ||
139 | t, | ||
140 | plane, | ||
141 | elt; | ||
142 | for(i=0; i<len; i++) { | ||
143 | elt = documentRootChildren[i]; | ||
144 | plane = this.addElement(elt); | ||
145 | l = plane._rect.m_left - docLeft; | ||
146 | t = plane._rect.m_top - docTop; | ||
147 | if(l < minLeft) { | ||
148 | minLeft = l; | ||
149 | } | ||
150 | if(t < minTop) { | ||
151 | minTop = t; | ||
152 | } | ||
153 | } | ||
154 | if(minLeft !== stage.userPaddingLeft) { | ||
155 | stage.userPaddingLeft = minLeft; | ||
156 | } | ||
157 | if(minTop !== stage.userPaddingTop) { | ||
158 | stage.userPaddingTop = minTop; | ||
135 | } | 159 | } |
136 | } | 160 | } |
137 | } | 161 | } |
@@ -245,16 +269,45 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
245 | } | 269 | } |
246 | var els = event.detail.data.els; | 270 | var els = event.detail.data.els; |
247 | if(els && this._shouldUpdatePlanes(event.detail.data.prop)) { | 271 | if(els && this._shouldUpdatePlanes(event.detail.data.prop)) { |
248 | var len = els.length; | 272 | var len = els.length, |
273 | stage = this.application.ninja.stage, | ||
274 | minLeft = stage.userPaddingLeft, | ||
275 | minTop = stage.userPaddingTop, | ||
276 | docLeft = stage.documentOffsetLeft, | ||
277 | docTop = stage.documentOffsetTop, | ||
278 | l, | ||
279 | t, | ||
280 | plane, | ||
281 | changed = false; | ||
249 | for(var i=0; i < len; i++) { | 282 | for(var i=0; i < len; i++) { |
250 | if(els[i].elementModel.props3D.elementPlane) { | 283 | plane = els[i].elementModel.props3D.elementPlane; |
251 | els[i].elementModel.props3D.elementPlane.init(); | 284 | if(plane) { |
285 | plane.init(); | ||
286 | l = plane._rect.m_left - docLeft; | ||
287 | t = plane._rect.m_top - docTop; | ||
288 | if(l < minLeft) { | ||
289 | minLeft = l; | ||
290 | } | ||
291 | if(t < minTop) { | ||
292 | minTop = t; | ||
293 | } | ||
252 | } | 294 | } |
253 | } | 295 | } |
254 | 296 | ||
255 | this.application.ninja.stage.layout.draw(); | 297 | if(minLeft !== stage.userPaddingLeft) { |
256 | this.drawWorkingPlane(); | 298 | stage.userPaddingLeft = minLeft; |
257 | this.draw3DCompass(); | 299 | changed = true; |
300 | } | ||
301 | if(minTop !== stage.userPaddingTop) { | ||
302 | stage.userPaddingTop = minTop; | ||
303 | changed = true; | ||
304 | } | ||
305 | |||
306 | if(!changed) { | ||
307 | stage.layout.draw(); | ||
308 | this.drawWorkingPlane(); | ||
309 | this.draw3DCompass(); | ||
310 | } | ||
258 | } | 311 | } |
259 | } | 312 | } |
260 | }, | 313 | }, |
@@ -281,6 +334,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
281 | plane.init(); | 334 | plane.init(); |
282 | this._planesArray.push( plane ); | 335 | this._planesArray.push( plane ); |
283 | elt.elementModel.props3D.elementPlane = plane; | 336 | elt.elementModel.props3D.elementPlane = plane; |
337 | return plane; | ||
284 | } | 338 | } |
285 | }, | 339 | }, |
286 | 340 | ||
@@ -584,18 +638,10 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
584 | var ptOnPlane = MathUtils.getPointOnPlane(this._workingPlane); | 638 | var ptOnPlane = MathUtils.getPointOnPlane(this._workingPlane); |
585 | 639 | ||
586 | // define the grid parameters | 640 | // define the grid parameters |
587 | var width, | 641 | var width = this.snapManager.getStageWidth(), |
588 | height, | 642 | height = this.snapManager.getStageHeight(), |
589 | nLines = 10; | 643 | nLines = 10; |
590 | 644 | ||
591 | // if(this.application.ninja.documentController.webTemplate) { | ||
592 | if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") { | ||
593 | width = this.application.ninja.currentDocument.documentRoot.scrollWidth; | ||
594 | height = this.application.ninja.currentDocument.documentRoot.scrollHeight; | ||
595 | } else { | ||
596 | width = this.snapManager.getStageWidth(); | ||
597 | height = this.snapManager.getStageHeight(); | ||
598 | } | ||
599 | // get a matrix from working plane space to the world | 645 | // get a matrix from working plane space to the world |
600 | var mat = this.getPlaneToWorldMatrix(zAxis, ptOnPlane); | 646 | var mat = this.getPlaneToWorldMatrix(zAxis, ptOnPlane); |
601 | var tMat = Matrix.Translation( [0.5*width, 0.5*height, 0] ); | 647 | var tMat = Matrix.Translation( [0.5*width, 0.5*height, 0] ); |
@@ -1178,8 +1224,8 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
1178 | var saveColor = this._lineColor; | 1224 | var saveColor = this._lineColor; |
1179 | var saveLineWidth = this._lineWidth; | 1225 | var saveLineWidth = this._lineWidth; |
1180 | 1226 | ||
1181 | var origLeft = 50; | 1227 | var origLeft = 60; |
1182 | var origTop = 50; | 1228 | var origTop = this.snapManager.getStageHeight() - 60; |
1183 | 1229 | ||
1184 | var mat = this.viewUtils.getMatrixFromElement( this._sourceSpaceElt ); | 1230 | var mat = this.viewUtils.getMatrixFromElement( this._sourceSpaceElt ); |
1185 | var tMat = Matrix.Translation([origLeft,origTop,0]); | 1231 | var tMat = Matrix.Translation([origLeft,origTop,0]); |
@@ -1211,7 +1257,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
1211 | this.setDrawingSurfaceElement(this.application.ninja.stage.layoutCanvas); | 1257 | this.setDrawingSurfaceElement(this.application.ninja.stage.layoutCanvas); |
1212 | // clear just the 3d compass area | 1258 | // clear just the 3d compass area |
1213 | this._drawingContext.save(); | 1259 | this._drawingContext.save(); |
1214 | this._drawingContext.rect(0, 0, 100, 100); | 1260 | this._drawingContext.rect(10, origTop-60, 100, 110); |
1215 | this._drawingContext.clip(); | 1261 | this._drawingContext.clip(); |
1216 | 1262 | ||
1217 | this._drawingContext.lineWidth = 2.0; | 1263 | this._drawingContext.lineWidth = 2.0; |
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 97901d50..0f456e1e 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js | |||
@@ -21,7 +21,6 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
21 | /////////////////////////////////////////////////////////////////////// | 21 | /////////////////////////////////////////////////////////////////////// |
22 | // Instance variables | 22 | // Instance variables |
23 | /////////////////////////////////////////////////////////////////////// | 23 | /////////////////////////////////////////////////////////////////////// |
24 | currentStage: { value: null, writable: true }, | ||
25 | drawingCanvas: { value: null, writable: true}, | 24 | drawingCanvas: { value: null, writable: true}, |
26 | 25 | ||
27 | // we keep a stack of working planes to facilitate working on other planes temporarily | 26 | // we keep a stack of working planes to facilitate working on other planes temporarily |
@@ -84,14 +83,14 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
84 | popWorkingPlane : { value: function () { workingPlane = this._workingPlaneStack.pop(); return workingPlane; }}, | 83 | popWorkingPlane : { value: function () { workingPlane = this._workingPlaneStack.pop(); return workingPlane; }}, |
85 | 84 | ||
86 | getStageWidth : { value: function () { | 85 | getStageWidth : { value: function () { |
87 | return parseInt(this.currentStage.offsetWidth); | 86 | return parseInt(this.application.ninja.currentDocument.documentRoot.offsetWidth); |
88 | }}, | 87 | }}, |
89 | 88 | ||
90 | getStageHeight : { value: function () { | 89 | getStageHeight : { value: function () { |
91 | return parseInt(this.currentStage.offsetHeight); | 90 | return parseInt(this.application.ninja.currentDocument.documentRoot.offsetHeight); |
92 | }}, | 91 | }}, |
93 | 92 | ||
94 | getStage : { value: function() { return this.currentStage; }}, | 93 | getStage : { value: function() { return this.application.ninja.currentDocument.documentRoot; }}, |
95 | 94 | ||
96 | getGridVertexHitRad : { value: function() { return this._gridVertexHitRad; }}, | 95 | getGridVertexHitRad : { value: function() { return this._gridVertexHitRad; }}, |
97 | getGridEdgeHitRad : { value: function() { return this._gridEdgeHitRad; }}, | 96 | getGridEdgeHitRad : { value: function() { return this._gridEdgeHitRad; }}, |
@@ -130,10 +129,10 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
130 | 129 | ||
131 | bindSnap: { | 130 | bindSnap: { |
132 | value: function() { | 131 | value: function() { |
133 | this.addEventListener("change@appModel.snap", this.toggleSnap, false); | 132 | this.addPropertyChangeListener("appModel.snap", this.toggleSnap, false); |
134 | this.addEventListener("change@appModel |