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