diff options
Diffstat (limited to 'js/tools/modifier-tool-base.js')
-rwxr-xr-x | js/tools/modifier-tool-base.js | 819 |
1 files changed, 410 insertions, 409 deletions
diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index 55baecc8..9b855e66 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js | |||
@@ -1,24 +1,25 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | ||
5 | 4 | ||
6 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
8 | 7 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 8 | * Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 9 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 10 | |
12 | notice, this list of conditions and the following disclaimer in the | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | documentation and/or other materials provided with the distribution. | 12 | this list of conditions and the following disclaimer in the documentation |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 13 | and/or other materials provided with the distribution. |
15 | may be used to endorse or promote products derived from this software | 14 | |
16 | without specific prior written permission. | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
17 | 18 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
@@ -45,43 +46,43 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
45 | //------------------------------------------------------------------------- | 46 | //------------------------------------------------------------------------- |
46 | // Snapping-specific properties | 47 | // Snapping-specific properties |
47 | _canSnap: { value: true }, | 48 | _canSnap: { value: true }, |
48 | _snapParam: { value: null }, | 49 | _snapParam: { value: null }, |
49 | _snapIndex: { value: -1 }, | 50 | _snapIndex: { value: -1 }, |
50 | _useQuadPt: { value: false }, | 51 | _useQuadPt: { value: false }, |
51 | _shouldUseQuadPt: { value: false }, | 52 | _shouldUseQuadPt: { value: false }, |
52 | 53 | ||
53 | // we set snapping capabilities depending on the tool. | 54 | // we set snapping capabilities depending on the tool. |
54 | // The following variables are set in a tool's initializeSnapping method called on mouse down. | 55 | // The following variables are set in a tool's initializeSnapping method called on mouse down. |
55 | _snapToElements: { value: true }, | 56 | _snapToElements: { value: true }, |
56 | _snapToGrid: { value: true }, | 57 | _snapToGrid: { value: true }, |
57 | 58 | ||
58 | _clickedObject : {value : null }, | 59 | _clickedObject : {value : null }, |
59 | clickedObject: | 60 | clickedObject: |
60 | { | 61 | { |
61 | get: function () { | 62 | get: function () { |
62 | return this._clickedObject; | 63 | return this._clickedObject; |
63 | }, | 64 | }, |
64 | set: function (value) { | 65 | set: function (value) { |
65 | if(value === this.application.ninja.currentDocument.model.documentRoot) | 66 | if(value === this.application.ninja.currentDocument.model.documentRoot) |
66 | { | 67 | { |
67 | this._clickedObject = this._target; | 68 | this._clickedObject = this._target; |
68 | } | 69 | } |
69 | else | 70 | else |
70 | { | 71 | { |
71 | this._clickedObject = value; | 72 | this._clickedObject = value; |
72 | } | 73 | } |
73 | 74 | ||
74 | if(value) | 75 | if(value) |
75 | { | 76 | { |
76 | this._startMat = viewUtils.getMatrixFromElement(this._clickedObject); | 77 | this._startMat = viewUtils.getMatrixFromElement(this._clickedObject); |
77 | } | 78 | } |
78 | else | 79 | else |
79 | { | 80 | { |
80 | this._startMat = null; | 81 | this._startMat = null; |
81 | } | 82 | } |
82 | } | 83 | } |
83 | }, | 84 | }, |
84 | 85 | ||
85 | _getObjectBeingTracked : | 86 | _getObjectBeingTracked : |
86 | { | 87 | { |
87 | value: function(hitRec) | 88 | value: function(hitRec) |
@@ -103,25 +104,25 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
103 | // override in subclasses | 104 | // override in subclasses |
104 | } | 105 | } |
105 | }, | 106 | }, |
106 | 107 | ||
107 | initializeSnapping: | 108 | initializeSnapping: |
108 | { | 109 | { |
109 | value: function(event) | 110 | value: function(event) |
110 | { | 111 | { |
111 | this._mouseDownHitRec = null; | 112 | this._mouseDownHitRec = null; |
112 | this._mouseUpHitRec = null; | 113 | this._mouseUpHitRec = null; |
113 | 114 | ||
114 | snapManager.clearAvoidList(); | 115 | snapManager.clearAvoidList(); |
115 | snapManager.clearDragPlane(); | 116 | snapManager.clearDragPlane(); |
116 | 117 | ||
117 | // the translate tool does snap align to the bounds of the object only. | 118 | // the translate tool does snap align to the bounds of the object only. |
118 | // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method | 119 | // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method |
119 | snapManager.enableSnapAlign( false ); | 120 | snapManager.enableSnapAlign( false ); |
120 | 121 | ||
121 | // snap to element and snap to grid are conditionally enabled based | 122 | // snap to element and snap to grid are conditionally enabled based |
122 | // on the snap results of the mouse down. enable everything for the first snap | 123 | // on the snap results of the mouse down. enable everything for the first snap |
123 | this._snapToElements = snapManager.elementSnapEnabledAppLevel(); | 124 | this._snapToElements = snapManager.elementSnapEnabledAppLevel(); |
124 | this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); | 125 | this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); |
125 | 126 | ||
126 | this._dragPlane = null; | 127 | this._dragPlane = null; |
127 | var do3DSnap = true; | 128 | var do3DSnap = true; |
@@ -132,8 +133,8 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
132 | // { | 133 | // { |
133 | // this.doSelection(event); | 134 | // this.doSelection(event); |
134 | 135 | ||
135 | snapManager.enableElementSnap ( true ); | 136 | snapManager.enableElementSnap ( true ); |
136 | // snapManager.enableGridSnap ( true ); | 137 | // snapManager.enableGridSnap ( true ); |
137 | // } | 138 | // } |
138 | // } | 139 | // } |
139 | // else | 140 | // else |
@@ -152,9 +153,9 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
152 | { | 153 | { |
153 | var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, | 154 | var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, |
154 | new WebKitPoint(event.pageX, event.pageY)); | 155 | new WebKitPoint(event.pageX, event.pageY)); |
155 | // do the snap before setting up the avoid list to allow | 156 | // do the snap before setting up the avoid list to allow |
156 | // a snap on the mouse down | 157 | // a snap on the mouse down |
157 | var hitRec = snapManager.snap(point.x, point.y, do3DSnap); | 158 | var hitRec = snapManager.snap(point.x, point.y, do3DSnap); |
158 | 159 | ||
159 | // TODO - Check that hitRec's element matches element that browser says we clicked on | 160 | // TODO - Check that hitRec's element matches element that browser says we clicked on |
160 | var elt = this.application.ninja.stage.getElement(event, true); | 161 | var elt = this.application.ninja.stage.getElement(event, true); |
@@ -168,21 +169,21 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
168 | snapManager.addToAvoidList(element); | 169 | snapManager.addToAvoidList(element); |
169 | }); | 170 | }); |
170 | 171 | ||
171 | if (hitRec) | 172 | if (hitRec) |
172 | { | 173 | { |
173 | // disable snap attributes | 174 | // disable snap attributes |
174 | if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT) | 175 | if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT) |
175 | { | 176 | { |
176 | this._snapToElements = false; | 177 | this._snapToElements = false; |
177 | this._snapToGrid = false; | 178 | this._snapToGrid = false; |
178 | } | 179 | } |
179 | else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER) | 180 | else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER) |
180 | { | 181 | { |
181 | snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); | 182 | snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); |
182 | } | 183 | } |
183 | 184 | ||
184 | // parameterize the snap point on the target | 185 | // parameterize the snap point on the target |
185 | this._snapParam = this.parameterizeSnap( hitRec ); | 186 | this._snapParam = this.parameterizeSnap( hitRec ); |
186 | 187 | ||
187 | if(!this._dragPlane) | 188 | if(!this._dragPlane) |
188 | { | 189 | { |
@@ -201,20 +202,20 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
201 | var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); | 202 | var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); |
202 | this._shouldUseQuadPt = (sign == 0) | 203 | this._shouldUseQuadPt = (sign == 0) |
203 | 204 | ||
204 | var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); | 205 | var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); |
205 | this._mouseDownHitRec = wpHitRec; | 206 | this._mouseDownHitRec = wpHitRec; |
206 | this._mouseUpHitRec = null; | 207 | this._mouseUpHitRec = null; |
207 | 208 | ||
208 | var pt = hitRec.getScreenPoint(); | 209 | var pt = hitRec.getScreenPoint(); |
209 | this.downPoint.x = pt[0]; |