aboutsummaryrefslogtreecommitdiff
path: root/js/tools/ZoomTool.js
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/tools/ZoomTool.js
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/tools/ZoomTool.js')
-rw-r--r--js/tools/ZoomTool.js442
1 files changed, 442 insertions, 0 deletions
diff --git a/js/tools/ZoomTool.js b/js/tools/ZoomTool.js
new file mode 100644
index 00000000..cabf3a3d
--- /dev/null
+++ b/js/tools/ZoomTool.js
@@ -0,0 +1,442 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7
8var Montage = require("montage/core/core").Montage,
9 snapManager = require("js/helper-classes/3D/snap-manager").SnapManager,
10 viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils,
11 vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils,
12 drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils,
13 DrawingTool = require("js/tools/drawing-tool").DrawingTool;
14
15exports.ZoomTool = Montage.create(DrawingTool, {
16 drawingFeedback: { value: { mode: "Draw2D", type: "" } },
17 _mode :{ value: null},
18 _isDrawing: {value: false},
19 _zoomFactor :{value: 1.0},
20 _hasDraw :{value:false},
21 _escPressed:{value:true},
22 _layerX:{value:0},
23 _layerY:{value:0},
24 _delta:{value:0},
25 _x:{value:0},
26 _y:{value:0},
27 _factor:{value:1},
28
29
30 HandleLeftButtonDown: {
31 value : function (event) {
32
33 NJevent("enableStageMove");
34 this._isDrawing=true;
35
36 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas,
37 new WebKitPoint(event.pageX, event.pageY));
38 this.downPoint.x = point.x;
39 this.downPoint.y = point.y;
40 }
41 },
42
43 HandleAltKeyDown: {
44 value: function(event) {
45
46 this.setCursor();
47 this._altKeyDown=true;
48
49 }
50 },
51
52 HandleAltKeyUp: {
53 value: function(event) {
54
55 this.setCursor();
56 this._altKeyDown=false;
57 }
58 },
59
60 HandleEscape: {
61 value: function(event) {
62 this.application.ninja.stage.clearDrawingCanvas();
63 this._escPressed=false;
64 }
65 },
66
67 Configure: {
68 value: function(wasSelected) {
69
70 if(this.options.selectedElement==="zoomOutTool"){
71 var cursor = "url('images/cursors/zoom_minus.png'), default";
72 this.application.ninja.stage.drawingCanvas.style.cursor = cursor;
73 }
74 if(wasSelected) {
75 this.AddCustomFeedback();
76 this.eventManager.addEventListener( "toolDoubleClick", this, false);
77
78 } else {
79 this.RemoveCustomFeedback();
80 this.eventManager.removeEventListener( "toolDoubleClick", this, false);
81 }
82 }
83 },
84
85 AddCustomFeedback: {
86 value: function (event) {
87
88 this.application.ninja.stage.canvas.addEventListener("mousewheel", this, false);
89
90 }
91 },
92
93 handleScrollValue:{
94 value:function(){
95
96 this._mode = "mouseWheelZoom";
97 this._zoomFactor= this.application.ninja.documentBar.zoomFactor/100;
98
99 if(this._delta > 0){
100 this._zoomFactor *= 1.2;
101 }
102 else{
103 this._zoomFactor /= 1.2;
104 }
105 this._zoomFactor = this.checkZoomLimit(this._zoomFactor);
106 this._setZoom(this._mode,this._zoomFactor);
107 this._mode="modeReset";
108
109 }
110 },
111
112 handleMousewheel :{
113 value:function(event){
114
115 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas,
116 new WebKitPoint(event.pageX, event.pageY));
117 this._layerX = point.x;
118 this._layerY = point.y;
119
120 this._delta = 0;
121
122 if (event.wheelDelta) {
123 this._delta = event.wheelDelta/120;
124 }
125
126 if (this._delta){
127 this.handleScrollValue(this._delta);
128 }
129
130 if (event.preventDefault)
131 event.preventDefault();
132 event.returnValue = false;
133
134 }
135 },
136
137 HandleMouseMove:
138 {
139 value : function (event)
140 {
141 // check for some reasonable amount of mouse movement
142 var dx = Math.abs(event.layerX - this.downPoint.x),
143 dy = Math.abs(event.layerY - this.downPoint.y);
144
145 if ((dx >= 4) || (dy >= 4))
146 {
147 // Drawing the Marquee
148 if(this.options.selectedElement==="zoomInTool")
149 {
150 if(this._altKeyDown)
151 this._hasDraw=false;
152 else
153 this._hasDraw = true;
154 }
155 else
156 {
157 if(this._altKeyDown)
158 this._hasDraw=true;
159 else
160 this._hasDraw=false;
161 }
162
163 if(this._hasDraw)
164 {
165 this.doDraw(event);
166 this._x = this.downPoint.x;
167 this._y = this.downPoint.y;
168 }
169 }
170 }
171 },
172
173 handleZoomChange:
174 {
175 value: function(event)
176 {
177 }
178 },
179
180 _setZoom:{
181 value:function(mode,zoomFactor)
182 {
183 var userContent = this.application.ninja.currentDocument.documentRoot;
184 this._oldValue = this.application.ninja.documentBar.zoomFactor;
185
186 var globalPt;
187 if(this._mode==="mouseClickZoom")
188 {
189 if(this.options.selectedElement==="zoomInTool")
190 {
191 if(this._altKeyDown)
192 this._factor = this._oldValue/(zoomFactor*100);
193 else
194 this._factor = (zoomFactor*100)/this._oldValue;
195 }
196 else
197 {
198 if(this._altKeyDown)
199 this._factor = (zoomFactor*100)/this._oldValue;
200 else
201 this._factor = this._oldValue/(zoomFactor*100);
202 }
203
204 var hitRec = snapManager.snap( this._layerX, this._layerY, true );
205 if (hitRec)
206 {
207 var elt = hitRec.getElement();
208 if (elt)
209 {
210// console.log( "hit: " + hitRec.getElement().id );
211 var localToGlobalMat = viewUtils.getLocalToGlobalMatrix( elt );
212 var localPt;
213 if (elt != userContent)
214 localPt = hitRec.calculateElementPreTransformScreenPoint();
215 else
216 {
217 localPt = hitRec.calculateElementWorldPoint();
218 viewUtils.pushViewportObj( userContent );
219 var cop = viewUtils.getCenterOfProjection();
220 this._localPt = [cop[0] + localPt[0], cop[1] + localPt[1], localPt[2]];
221 localPt = this._localPt.slice();
222 viewUtils.popViewportObj();
223 }
224
225 globalPt = MathUtils.transformAndDivideHomogeneousPoint( localPt, localToGlobalMat );
226 }
227 else
228 globalPt = [this._layerX, this._layerY, 0];
229 }
230 else
231 globalPt = [this._layerX, this._layerY, 0];
232 }
233 else if (this._mode==="marqueeZoom")
234 {
235 this._factor = (zoomFactor*100)/this._oldValue;
236
237 var p0 = [this._x, this._y, 0];
238 var p1 = [this._layerX, this._layerY, 0];
239 globalPt = vecUtils.vecAdd(3, p0, p1);
240 vecUtils.vecScale(3, globalPt, 0.5);
241
242 var hitRec = snapMan