aboutsummaryrefslogtreecommitdiff
path: root/js/tools/PanTool.js
diff options
context:
space:
mode:
authorAnanya Sen2012-07-09 16:52:49 -0700
committerAnanya Sen2012-07-09 16:52:49 -0700
commit2eb84584f44b8c774479d1af2ee1d810597474cf (patch)
tree64cb3e09a8daeb340261dd7f3869c73f7b90b643 /js/tools/PanTool.js
parentbf9dba001ec84243e2f12cd13b0c0ae020fba4a2 (diff)
parentcee0deca695359ab468bd06d0e05ed3b2010b338 (diff)
downloadninja-2eb84584f44b8c774479d1af2ee1d810597474cf.tar.gz
Merge branch 'refs/heads/ninja-internal-master' into codemirror-custom-theme-removal
Conflicts: js/code-editor/codemirror-ninja/theme/lesser-dark-ninja.css js/code-editor/codemirror-ninja/theme/xq-dark-ninja.css Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/tools/PanTool.js')
-rwxr-xr-xjs/tools/PanTool.js655
1 files changed, 328 insertions, 327 deletions
diff --git a/js/tools/PanTool.js b/js/tools/PanTool.js
index 6b3dbdbb..374886e8 100755
--- a/js/tools/PanTool.js
+++ b/js/tools/PanTool.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, 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
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -38,33 +39,33 @@ var Montage = require("montage/core/core").Montage,
38 39
39exports.PanTool = Montage.create(toolBase, 40exports.PanTool = Montage.create(toolBase,
40{ 41{
41 _localPt :{value: [0,0] , writable:true}, 42 _localPt :{value: [0,0] , writable:true},
42 _worldPt :{value: [0,0] , writable:true}, 43 _worldPt :{value: [0,0] , writable:true},
43 _globalPt :{value: [0,0] , writable:true}, 44 _globalPt :{value: [0,0] , writable:true},
44 _globalToUCWorld :{value: [] , writable:true}, 45 _globalToUCWorld :{value: [] , writable:true},
45 _lastGPt :{value: [0,0], writable:true}, 46 _lastGPt :{value: [0,0], writable:true},
46 _lastY :{value: 0, writable:true}, 47 _lastY :{value: 0, writable:true},
47 48
48 _maxHorizontalScroll: {value: 0, writable:true}, 49 _maxHorizontalScroll: {value: 0, writable:true},
49 _maxVerticalScroll: {value: 0, writable:true}, 50 _maxVerticalScroll: {value: 0, writable:true},
50 51
51 Configure: { 52 Configure: {
52 value: function ( doActivate ) 53 value: function ( doActivate )
53 { 54 {
54 if (doActivate) 55 if (doActivate)
55 { 56 {
56 NJevent("enableStageMove"); 57 NJevent("enableStageMove");
57 this.eventManager.addEventListener( "toolDoubleClick", this, false); 58 this.eventManager.addEventListener( "toolDoubleClick", this, false);
58 this.application.ninja.stage.canvas.addEventListener("mousewheel", this, false); 59 this.application.ninja.stage.canvas.addEventListener("mousewheel", this, false);
59 this.activate(); 60 this.activate();
60 } 61 }
61 else 62 else
62 { 63 {
63 NJevent("disableStageMove"); 64 NJevent("disableStageMove");
64 this.eventManager.removeEventListener( "toolDoubleClick", this, false); 65 this.eventManager.removeEventListener( "toolDoubleClick", this, false);
65 this.application.ninja.stage.canvas.removeEventListener("mousewheel", this, false); 66 this.application.ninja.stage.canvas.removeEventListener("mousewheel", this, false);
66 this.deactivate(); 67 this.deactivate();
67 } 68 }
68 } 69 }
69 }, 70 },
70 71
@@ -87,23 +88,23 @@ exports.PanTool = Montage.create(toolBase,
87 }, 88 },
88 89
89 HandleMouseMove: 90 HandleMouseMove:
90 { 91 {
91 value : function (event) 92 value : function (event)
92 { 93 {
93 this.mouseMove( event ); 94 this.mouseMove( event );
94 } 95 }
95 }, 96 },
96 97
97 HandleLeftButtonUp: 98 HandleLeftButtonUp:
98 { 99 {
99 value : function ( event ) 100 value : function ( event )
100 { 101 {
101 //if(this._isDrawing) 102 //if(this._isDrawing)
102 { 103 {
103 // do one final mouse move to update the scrollbars 104 // do one final mouse move to update the scrollbars
104 this.mouseUp( event ); 105 this.mouseUp( event );
105 106
106 this.application.ninja.stage.clearDrawingCanvas(); 107 this.application.ninja.stage.clearDrawingCanvas();
107 this._hasDraw = false; 108 this._hasDraw = false;
108 this._isDrawing = false; 109 this._isDrawing = false;
109 this.isDrawing = false; 110 this.isDrawing = false;
@@ -114,248 +115,248 @@ exports.PanTool = Montage.create(toolBase,
114 HandleKeyPress: { 115 HandleKeyPress: {
115 value: function(event) { 116 value: function(event) {
116 if(event.altKey) 117 if(event.altKey)
117 { 118 {
118 this._altKeyDown = true; 119 this._altKeyDown = true;
119 } 120 }
120 else if (event.shiftKey) 121 else if (event.shiftKey)
121 { 122 {
122 if (!this._shiftKeyDown) 123 if (!this._shiftKeyDown)
123 { 124 {
124 this._shiftKeyDown = true; 125 this._shiftKeyDown = true;
125 this._shiftPt = this._lastGPt.slice(); 126 this._shiftPt = this._lastGPt.slice();
126 } 127 }
127 } 128 }
128 } 129 }
129 }, 130 },
130 131
131 HandleKeyUp: { 132 HandleKeyUp: {
132 value: function(event) { 133 value: function(event) {
133 if(event.keyCode === Keyboard.ALT) 134 if(event.keyCode === Keyboard.ALT)
134 { 135 {
135 this._altKeyDown = false; 136 this._altKeyDown = false;
136 } 137 }
137 else if (event.keyCode === Keyboard.SHIFT) 138 else if (event.keyCode === Keyboard.SHIFT)
138 { 139 {
139 this._shiftKeyDown = false; 140 this._shiftKeyDown = false;
140 } 141 }
141 } 142 }
142 }, 143 },
143 144
144 handleToolDoubleClick: 145 handleToolDoubleClick:
145 { 146 {
146 value: function () 147 value: function ()
147 { 148 {
148 var uc = this.application.ninja.currentDocument.model.documentRoot; 149 var uc = this.application.ninja.currentDocument.model.documentRoot;
149 var ucMat = viewUtils.getMatrixFromElement(uc); 150 var ucMat = viewUtils.getMatrixFromElement(uc);
150 151
151 var noTrans = ucMat.slice(); 152 var noTrans = ucMat.slice();
152 noTrans[12] = 0; noTrans[13] = 0; noTrans[14] = 0; 153 noTrans[12] = 0; noTrans[13] = 0; noTrans[14] = 0;
153 var ucMatInv = glmat4.inverse( ucMat, [] ); 154 var ucMatInv = glmat4.inverse( ucMat, [] );
154 var deltaMat = glmat4.multiply( noTrans, ucMatInv, [] ); 155 var deltaMat = glmat4.multiply( noTrans, ucMatInv, [] );
155 156
156 this.application.ninja.stage.centerStage(); 157 this.application.ninja.stage.centerStage();
157 158
158 this.applyDeltaMat( deltaMat ); 159 this.applyDeltaMat( deltaMat );
159 } 160 }
160 }, 161 },
161 162
162 handleMousewheel : 163 handleMousewheel :
163 { 164 {
164 value:function(event) 165 value:function(event)
165 { 166 {
166 var zoom = this.application.ninja.documentBar.zoomFactor/100.0; 167 var zoom = this.application.ninja.documentBar.zoomFactor/100.0;
167 if (!zoom) zoom = 1.0; 168 if (!zoom) zoom = 1.0;
168 169
169 var delta = 0; 170 var delta = 0;
170 if (event.wheelDelta) 171 if (event.wheelDelta)
171 delta = 10*event.wheelDelta/120; 172 delta = 10*event.wheelDelta/120;
172 //console.log( "delta: " + delta ); 173 //console.log( "delta: " + delta );
173 174
174 this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft += delta; 175 this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft += delta;
175 176
176 delta *= zoom; 177 delta *= zoom;
177 178
178 var uc = this.application.ninja.currentDocument.model.documentRoot; 179 var uc = this.application.ninja.currentDocument.model.documentRoot;
179 var ucMat = viewUtils.getMatrixFromElement(uc); 180 var ucMat = viewUtils.getMatrixFromElement(uc);
180 var offset = viewUtils.getElementOffset( uc ); 181 var offset = viewUtils.getElementOffset( uc );
181 //console.log( "uc offset: " + offset[0] ); 182 //console.log( "uc offset: " + offset[0] );
182 183