Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/wasm-viewport.ts @ 457:3b4df9925db6 am-touch-events
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Thu, 24 Jan 2019 16:42:27 +0100 |
parents | 50229f6eb4cd |
children | 801d2697a1b1 |
rev | line source |
---|---|
230 | 1 var isPendingRedraw = false; |
229 | 2 |
230 | 3 function ScheduleWebViewportRedraw(cppViewportHandle: any) : void |
4 { | |
5 if (!isPendingRedraw) { | |
6 isPendingRedraw = true; | |
7 console.log('Scheduling a refresh of the viewport, as its content changed'); | |
8 window.requestAnimationFrame(function() { | |
9 isPendingRedraw = false; | |
10 Stone.WasmViewport.GetFromCppViewport(cppViewportHandle).Redraw(); | |
11 }); | |
229 | 12 } |
230 | 13 } |
226 | 14 |
231
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
15 declare function UTF8ToString(any): string; |
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
16 |
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
17 function CreateWasmViewport(htmlCanvasId: string) : any { |
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
18 var cppViewportHandle = CreateCppViewport(); |
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
19 var canvasId = UTF8ToString(htmlCanvasId); |
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
20 var webViewport = new Stone.WasmViewport(StoneFrameworkModule, canvasId, cppViewportHandle); // viewports are stored in a static map in WasmViewport -> won't be deleted |
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
21 webViewport.Initialize(); |
314 | 22 |
231
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
23 return cppViewportHandle; |
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
24 } |
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
25 |
226 | 26 module Stone { |
27 | |
28 // export declare type InitializationCallback = () => void; | |
29 | |
30 // export declare var StoneFrameworkModule : any; | |
31 | |
32 //const ASSETS_FOLDER : string = "assets/lib"; | |
33 //const WASM_FILENAME : string = "orthanc-framework"; | |
229 | 34 |
226 | 35 export class WasmViewport { |
36 | |
313 | 37 private static viewportsMapByCppHandle_ : Map<number, WasmViewport> = new Map<number, WasmViewport>(); // key = the C++ handle |
38 private static viewportsMapByCanvasId_ : Map<string, WasmViewport> = new Map<string, WasmViewport>(); // key = the canvasId | |
229 | 39 |
226 | 40 private module_ : any; |
41 private canvasId_ : string; | |
42 private htmlCanvas_ : HTMLCanvasElement; | |
43 private context_ : CanvasRenderingContext2D; | |
44 private imageData_ : any = null; | |
45 private renderingBuffer_ : any = null; | |
454
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
46 |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
47 private touchGestureInProgress_: boolean = false; |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
48 private touchCount_: number = 0; |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
49 private touchGestureLastCoordinates_: [number, number][] = []; // last x,y coordinates of each touch |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
50 |
226 | 51 private touchZoom_ : any = false; |
52 private touchTranslation_ : any = false; | |
53 | |
54 private ViewportSetSize : Function; | |
55 private ViewportRender : Function; | |
56 private ViewportMouseDown : Function; | |
57 private ViewportMouseMove : Function; | |
58 private ViewportMouseUp : Function; | |
59 private ViewportMouseEnter : Function; | |
60 private ViewportMouseLeave : Function; | |
61 private ViewportMouseWheel : Function; | |
62 private ViewportKeyPressed : Function; | |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
63 private ViewportTouchStart : Function; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
64 private ViewportTouchMove : Function; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
65 private ViewportTouchEnd : Function; |
226 | 66 |
227 | 67 private pimpl_ : any; // Private pointer to the underlying WebAssembly C++ object |
68 | |
231
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
69 public constructor(module: any, canvasId: string, cppViewport: any) { |
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
70 |
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
71 this.pimpl_ = cppViewport; |
313 | 72 WasmViewport.viewportsMapByCppHandle_[this.pimpl_] = this; |
73 WasmViewport.viewportsMapByCanvasId_[canvasId] = this; | |
231
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
74 |
226 | 75 this.module_ = module; |
76 this.canvasId_ = canvasId; | |
77 this.htmlCanvas_ = document.getElementById(this.canvasId_) as HTMLCanvasElement; | |
244 | 78 if (this.htmlCanvas_ == null) { |
79 console.log("Can not create WasmViewport, did not find the canvas whose id is '", this.canvasId_, "'"); | |
80 } | |
226 | 81 this.context_ = this.htmlCanvas_.getContext('2d'); |
82 | |
234
9afb50d1ac14
configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents:
231
diff
changeset
|
83 this.ViewportSetSize = this.module_.cwrap('ViewportSetSize', null, [ 'number', 'number', 'number' ]); |
9afb50d1ac14
configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents:
231
diff
changeset
|
84 this.ViewportRender = this.module_.cwrap('ViewportRender', null, [ 'number', 'number', 'number', 'number' ]); |
9afb50d1ac14
configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents:
231
diff
changeset
|
85 this.ViewportMouseDown = this.module_.cwrap('ViewportMouseDown', null, [ 'number', 'number', 'number', 'number', 'number' ]); |
9afb50d1ac14
configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents:
231
diff
changeset
|
86 this.ViewportMouseMove = this.module_.cwrap('ViewportMouseMove', null, [ 'number', 'number', 'number' ]); |
9afb50d1ac14
configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents:
231
diff
changeset
|
87 this.ViewportMouseUp = this.module_.cwrap('ViewportMouseUp', null, [ 'number' ]); |
9afb50d1ac14
configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents:
231
diff
changeset
|
88 this.ViewportMouseEnter = this.module_.cwrap('ViewportMouseEnter', null, [ 'number' ]); |
9afb50d1ac14
configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents:
231
diff
changeset
|
89 this.ViewportMouseLeave = this.module_.cwrap('ViewportMouseLeave', null, [ 'number' ]); |
9afb50d1ac14
configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents:
231
diff
changeset
|
90 this.ViewportMouseWheel = this.module_.cwrap('ViewportMouseWheel', null, [ 'number', 'number', 'number', 'number', 'number' ]); |
327 | 91 this.ViewportKeyPressed = this.module_.cwrap('ViewportKeyPressed', null, [ 'number', 'number', 'string', 'number', 'number' ]); |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
92 this.ViewportTouchStart = this.module_.cwrap('ViewportTouchStart', null, [ 'number', 'number', 'number', 'number', 'number', 'number', 'number' ]); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
93 this.ViewportTouchMove = this.module_.cwrap('ViewportTouchMove', null, [ 'number', 'number', 'number', 'number', 'number', 'number', 'number' ]); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
94 this.ViewportTouchEnd = this.module_.cwrap('ViewportTouchEnd', null, [ 'number', 'number', 'number', 'number', 'number', 'number', 'number' ]); |
228 | 95 } |
96 | |
234
9afb50d1ac14
configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents:
231
diff
changeset
|
97 public GetCppViewport() : number { |
228 | 98 return this.pimpl_; |
226 | 99 } |
100 | |
234
9afb50d1ac14
configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents:
231
diff
changeset
|
101 public static GetFromCppViewport(cppViewportHandle: number) : WasmViewport { |
313 | 102 if (WasmViewport.viewportsMapByCppHandle_[cppViewportHandle] !== undefined) { |
103 return WasmViewport.viewportsMapByCppHandle_[cppViewportHandle]; | |
104 } | |
105 console.log("WasmViewport not found !"); | |
106 return undefined; | |
107 } | |
108 | |
109 public static GetFromCanvasId(canvasId: string) : WasmViewport { | |
110 if (WasmViewport.viewportsMapByCanvasId_[canvasId] !== undefined) { | |
111 return WasmViewport.viewportsMapByCanvasId_[canvasId]; | |
229 | 112 } |
113 console.log("WasmViewport not found !"); | |
114 return undefined; | |
115 } | |
116 | |
314 | 117 public static ResizeAll() { |
118 for (let canvasId in WasmViewport.viewportsMapByCanvasId_) { | |
119 WasmViewport.viewportsMapByCanvasId_[canvasId].Resize(); | |
120 } | |
121 } | |
122 | |
226 | 123 public Redraw() { |
124 if (this.imageData_ === null || | |
125 this.renderingBuffer_ === null || | |
227 | 126 this.ViewportRender(this.pimpl_, |
127 this.imageData_.width, | |
226 | 128 this.imageData_.height, |
129 this.renderingBuffer_) == 0) { | |
130 console.log('The rendering has failed'); | |
131 } else { | |
132 // Create an accessor to the rendering buffer (i.e. create a | |
133 // "window" above the heap of the WASM module), then copy it to | |
134 // the ImageData object | |
135 this.imageData_.data.set(new Uint8ClampedArray( | |
136 this.module_.buffer, | |
137 this.renderingBuffer_, | |
138 this.imageData_.width * this.imageData_.height * 4)); | |
139 | |
140 this.context_.putImageData(this.imageData_, 0, 0); | |
141 } | |
142 } | |
143 | |
144 public Resize() { | |
145 if (this.imageData_ != null && | |
146 (this.imageData_.width != window.innerWidth || | |
147 this.imageData_.height != window.innerHeight)) { | |
148 this.imageData_ = null; | |
149 } | |
150 | |
420
8bf717c4e497
canvas size is now defined by the parent div size
am@osimis.io
parents:
327
diff
changeset
|
151 // width/height is defined by the parent width/height |
8bf717c4e497
canvas size is now defined by the parent div size
am@osimis.io
parents:
327
diff
changeset
|
152 this.htmlCanvas_.width = this.htmlCanvas_.parentElement.offsetWidth; |
8bf717c4e497
canvas size is now defined by the parent div size
am@osimis.io
parents:
327
diff
changeset
|
153 this.htmlCanvas_.height = this.htmlCanvas_.parentElement.offsetHeight; |
234
9afb50d1ac14
configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents:
231
diff
changeset
|
154 |
9afb50d1ac14
configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents:
231
diff
changeset
|
155 console.log("resizing WasmViewport: ", this.htmlCanvas_.width, "x", this.htmlCanvas_.height); |
9afb50d1ac14
configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents:
231
diff
changeset
|
156 |
226 | 157 if (this.imageData_ === null) { |
158 this.imageData_ = this.context_.getImageData(0, 0, this.htmlCanvas_.width, this.htmlCanvas_.height); | |
228 | 159 this.ViewportSetSize(this.pimpl_, this.htmlCanvas_.width, this.htmlCanvas_.height); |
226 | 160 |
161 if (this.renderingBuffer_ != null) { | |
162 this.module_._free(this.renderingBuffer_); | |
163 } | |
164 | |
165 this.renderingBuffer_ = this.module_._malloc(this.imageData_.width * this.imageData_.height * 4); | |
313 | 166 } else { |
167 this.ViewportSetSize(this.pimpl_, this.htmlCanvas_.width, this.htmlCanvas_.height); | |
226 | 168 } |
169 | |
170 this.Redraw(); | |
171 } | |
172 | |
231
5027cb2feb51
viewport is now part of the Application itself and not global anymore
am@osimis.io
parents:
230
diff
changeset
|
173 public Initialize() { |
227 | 174 |
175 // Force the rendering of the viewport for the first time | |
176 this.Resize(); | |
226 | 177 |
228 | 178 var that : WasmViewport = this; |
227 | 179 // Register an event listener to call the Resize() function |
180 // each time the window is resized. | |
228 | 181 window.addEventListener('resize', function(event) { |
182 that.Resize(); | |
183 }, false); | |
226 | 184 |
227 | 185 this.htmlCanvas_.addEventListener('contextmenu', function(event) { |
186 // Prevent right click on the canvas | |
187 event.preventDefault(); | |
188 }, false); | |
189 | |
190 this.htmlCanvas_.addEventListener('mouseleave', function(event) { | |
228 | 191 that.ViewportMouseLeave(that.pimpl_); |
227 | 192 }); |
193 | |
194 this.htmlCanvas_.addEventListener('mouseenter', function(event) { | |
228 | 195 that.ViewportMouseEnter(that.pimpl_); |
227 | 196 }); |
197 | |
198 this.htmlCanvas_.addEventListener('mousedown', function(event) { | |
199 var x = event.pageX - this.offsetLeft; | |
200 var y = event.pageY - this.offsetTop; | |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
201 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
202 that.ViewportMouseDown(that.pimpl_, event.button, x, y, 0 /* TODO detect modifier keys*/); |
227 | 203 }); |
204 | |
205 this.htmlCanvas_.addEventListener('mousemove', function(event) { | |
206 var x = event.pageX - this.offsetLeft; | |
207 var y = event.pageY - this.offsetTop; | |
228 | 208 that.ViewportMouseMove(that.pimpl_, x, y); |
227 | 209 }); |
210 | |
211 this.htmlCanvas_.addEventListener('mouseup', function(event) { | |
228 | 212 that.ViewportMouseUp(that.pimpl_); |
227 | 213 }); |
214 | |
215 window.addEventListener('keydown', function(event) { | |
327 | 216 var keyChar = event.key; |
217 var keyCode = event.keyCode | |
218 if (keyChar.length == 1) { | |
219 keyCode = 0; // maps to OrthancStone::KeyboardKeys_Generic | |
220 } else { | |
221 keyChar = null; | |
222 } | |
223 // console.log("key: ", keyCode, keyChar); | |
224 that.ViewportKeyPressed(that.pimpl_, keyCode, keyChar, event.shiftKey, event.ctrlKey, event.altKey); | |
227 | 225 }); |
226 | 226 |
227 | 227 this.htmlCanvas_.addEventListener('wheel', function(event) { |
228 var x = event.pageX - this.offsetLeft; | |
229 var y = event.pageY - this.offsetTop; | |
228 | 230 that.ViewportMouseWheel(that.pimpl_, event.deltaY, x, y, event.ctrlKey); |
227 | 231 event.preventDefault(); |
232 }); | |
233 | |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
234 this.htmlCanvas_.addEventListener('touchstart', function(event: TouchEvent) { |
453
59b4afa92dee
TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents:
420
diff
changeset
|
235 // don't propagate events to the whole body (this could zoom the entire page instead of zooming the viewport) |
59b4afa92dee
TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents:
420
diff
changeset
|
236 event.preventDefault(); |
59b4afa92dee
TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents:
420
diff
changeset
|
237 event.stopPropagation(); |
59b4afa92dee
TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents:
420
diff
changeset
|
238 |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
239 // TODO: find a way to pass the coordinates as an array between JS and C++ |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
240 var x0 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
241 var y0 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
242 var x1 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
243 var y1 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
244 var x2 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
245 var y2 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
246 if (event.targetTouches.length > 0) { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
247 x0 = event.targetTouches[0].pageX; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
248 y0 = event.targetTouches[0].pageY; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
249 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
250 if (event.targetTouches.length > 1) { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
251 x1 = event.targetTouches[1].pageX; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
252 y1 = event.targetTouches[1].pageY; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
253 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
254 if (event.targetTouches.length > 2) { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
255 x2 = event.targetTouches[2].pageX; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
256 y2 = event.targetTouches[2].pageY; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
257 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
258 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
259 that.ViewportTouchStart(that.pimpl_, event.targetTouches.length, x0, y0, x1, y1, x2, y2); |
227 | 260 }); |
261 | |
262 this.htmlCanvas_.addEventListener('touchend', function(event) { | |
453
59b4afa92dee
TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents:
420
diff
changeset
|
263 // don't propagate events to the whole body (this could zoom the entire page instead of zooming the viewport) |
59b4afa92dee
TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents:
420
diff
changeset
|
264 event.preventDefault(); |
59b4afa92dee
TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents:
420
diff
changeset
|
265 event.stopPropagation(); |
59b4afa92dee
TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents:
420
diff
changeset
|
266 |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
267 // TODO: find a way to pass the coordinates as an array between JS and C++ |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
268 var x0 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
269 var y0 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
270 var x1 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
271 var y1 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
272 var x2 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
273 var y2 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
274 if (event.targetTouches.length > 0) { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
275 x0 = event.targetTouches[0].pageX; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
276 y0 = event.targetTouches[0].pageY; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
277 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
278 if (event.targetTouches.length > 1) { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
279 x1 = event.targetTouches[1].pageX; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
280 y1 = event.targetTouches[1].pageY; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
281 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
282 if (event.targetTouches.length > 2) { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
283 x2 = event.targetTouches[2].pageX; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
284 y2 = event.targetTouches[2].pageY; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
285 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
286 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
287 that.ViewportTouchEnd(that.pimpl_, event.targetTouches.length, x0, y0, x1, y1, x2, y2); |
227 | 288 }); |
289 | |
454
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
290 this.htmlCanvas_.addEventListener('touchmove', function(event: TouchEvent) { |
453
59b4afa92dee
TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents:
420
diff
changeset
|
291 |
59b4afa92dee
TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents:
420
diff
changeset
|
292 // don't propagate events to the whole body (this could zoom the entire page instead of zooming the viewport) |
59b4afa92dee
TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents:
420
diff
changeset
|
293 event.preventDefault(); |
59b4afa92dee
TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents:
420
diff
changeset
|
294 event.stopPropagation(); |
59b4afa92dee
TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents:
420
diff
changeset
|
295 |
457
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
296 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
297 // TODO: find a way to pass the coordinates as an array between JS and C++ |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
298 var x0 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
299 var y0 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
300 var x1 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
301 var y1 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
302 var x2 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
303 var y2 = 0; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
304 if (event.targetTouches.length > 0) { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
305 x0 = event.targetTouches[0].pageX; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
306 y0 = event.targetTouches[0].pageY; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
307 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
308 if (event.targetTouches.length > 1) { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
309 x1 = event.targetTouches[1].pageX; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
310 y1 = event.targetTouches[1].pageY; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
311 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
312 if (event.targetTouches.length > 2) { |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
313 x2 = event.targetTouches[2].pageX; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
314 y2 = event.targetTouches[2].pageY; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
315 } |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
316 |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
317 that.ViewportTouchMove(that.pimpl_, event.targetTouches.length, x0, y0, x1, y1, x2, y2); |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
318 return; |
3b4df9925db6
added support for 'touch' in mouse trackers. This is still a bit hacky and we need to refactor it to make it clean. Thanks to that, Pan and zoom are available together with 2 touches
Alain Mazy <alain@mazy.be>
parents:
454
diff
changeset
|
319 |
454
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
320 // if (!that.touchGestureInProgress_) { |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
321 // // starting a new gesture |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
322 // that.touchCount_ = event.targetTouches.length; |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
323 // for (var t = 0; t < event.targetTouches.length; t++) { |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
324 // that.touchGestureLastCoordinates_.push([event.targetTouches[t].pageX, event.targetTouches[t].pageY]); |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
325 // } |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
326 // that.touchGestureInProgress_ = true; |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
327 // } else { |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
328 // // continuing a gesture |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
329 // // TODO: we shall probably forward all touches to the C++ code and let the "interactors/trackers" handle them |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
330 |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
331 // if (that.touchCount_ == 1) { // consider it's a left mouse drag |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
332 |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
333 // } |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
334 // } |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
335 |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
336 // TODO: we shall probably forward all touches to the C++ code and let the "interactors/trackers" handle them |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
337 |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
338 if (that.touchTranslation_.length == 2) { // |
227 | 339 var t = that.GetTouchTranslation(event); |
228 | 340 that.ViewportMouseMove(that.pimpl_, t[0], t[1]); |
227 | 341 } |
342 else if (that.touchZoom_.length == 3) { | |
226 | 343 var z0 = that.touchZoom_; |
227 | 344 var z1 = that.GetTouchZoom(event); |
228 | 345 that.ViewportMouseMove(that.pimpl_, z0[0], z0[1] - z0[2] + z1[2]); |
227 | 346 } |
347 else { | |
348 // Realize the gesture event | |
349 if (event.targetTouches.length == 1) { | |
350 // Exactly one finger inside the canvas => Setup a translation | |
351 that.touchTranslation_ = that.GetTouchTranslation(event); | |
228 | 352 that.ViewportMouseDown(that.pimpl_, |
454
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
353 0 /* left button */, |
227 | 354 that.touchTranslation_[0], |
355 that.touchTranslation_[1], 0); | |
356 } else if (event.targetTouches.length == 2) { | |
357 // Exactly 2 fingers inside the canvas => Setup a pinch/zoom | |
358 that.touchZoom_ = that.GetTouchZoom(event); | |
359 var z0 = that.touchZoom_; | |
228 | 360 that.ViewportMouseDown(that.pimpl_, |
361 2 /* right button */, | |
227 | 362 z0[0], |
363 z0[1], 0); | |
364 } | |
365 } | |
366 }); | |
367 } | |
226 | 368 |
369 public ResetTouch() { | |
227 | 370 if (this.touchTranslation_ || |
371 this.touchZoom_) { | |
228 | 372 this.ViewportMouseUp(this.pimpl_); |
226 | 373 } |
227 | 374 |
375 this.touchTranslation_ = false; | |
376 this.touchZoom_ = false; | |
454
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
377 |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
378 // this.touchGestureInProgress_ = false; |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
379 // this.touchCount_ = 0; |
50229f6eb4cd
TS: one touch drag is not equivalent to left mouse drag instead of middle mouse drag
Alain Mazy <alain@mazy.be>
parents:
453
diff
changeset
|
380 // this.touchGestureLastCoordinates_ = []; |
227 | 381 } |
226 | 382 |
383 public GetTouchTranslation(event) { | |
227 | 384 var touch = event.targetTouches[0]; |
385 return [ | |
386 touch.pageX, | |
387 touch.pageY | |
388 ]; | |
389 } | |
226 | 390 |
391 public GetTouchZoom(event) { | |
227 | 392 var touch1 = event.targetTouches[0]; |
393 var touch2 = event.targetTouches[1]; | |
394 var dx = (touch1.pageX - touch2.pageX); | |
395 var dy = (touch1.pageY - touch2.pageY); | |
396 var d = Math.sqrt(dx * dx + dy * dy); | |
397 return [ | |
398 (touch1.pageX + touch2.pageX) / 2.0, | |
399 (touch1.pageY + touch2.pageY) / 2.0, | |
400 d | |
401 ]; | |
402 } | |
226 | 403 |
227 | 404 } |
226 | 405 } |
406 |