annotate Platforms/Wasm/wasm-viewport.ts @ 504:7cdb4634846c

Merge
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 26 Feb 2019 21:15:20 +0100
parents 50229f6eb4cd 5055031f4a06
children 801d2697a1b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
4 var isPendingRedraw = false;
229
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
5
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
6 function ScheduleWebViewportRedraw(cppViewportHandle: any) : void
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
7 {
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
8 if (!isPendingRedraw) {
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
9 isPendingRedraw = true;
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
10 console.log('Scheduling a refresh of the viewport, as its content changed');
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
11 window.requestAnimationFrame(function() {
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
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
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
14 });
229
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
15 }
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
16 }
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
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
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
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
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
33 // export declare type InitializationCallback = () => void;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
34
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
35 // export declare var StoneFrameworkModule : any;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
36
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
37 //const ASSETS_FOLDER : string = "assets/lib";
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
38 //const WASM_FILENAME : string = "orthanc-framework";
229
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
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
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
41
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
42 private static viewportsMapByCppHandle_ : Map<number, WasmViewport> = new Map<number, WasmViewport>(); // key = the C++ handle
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
43 private static viewportsMapByCanvasId_ : Map<string, WasmViewport> = new Map<string, WasmViewport>(); // key = the canvasId
229
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
44
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
45 private module_ : any;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
46 private canvasId_ : string;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
47 private htmlCanvas_ : HTMLCanvasElement;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
48 private context_ : CanvasRenderingContext2D;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
49 private imageData_ : any = null;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
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
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
56 private touchZoom_ : any = false;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
57 private touchTranslation_ : any = false;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
58
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
59 private ViewportSetSize : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
60 private ViewportRender : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
61 private ViewportMouseDown : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
62 private ViewportMouseMove : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
63 private ViewportMouseUp : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
64 private ViewportMouseEnter : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
65 private ViewportMouseLeave : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
66 private ViewportMouseWheel : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
67 private ViewportKeyPressed : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
68
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
69 private pimpl_ : any; // Private pointer to the underlying WebAssembly C++ object
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
70
231
5027cb2feb51 viewport is now part of the Application itself and not global anymore
am@osimis.io
parents: 230
diff changeset
71 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
72
5027cb2feb51 viewport is now part of the Application itself and not global anymore
am@osimis.io
parents: 230
diff changeset
73 this.pimpl_ = cppViewport;
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
74 WasmViewport.viewportsMapByCppHandle_[this.pimpl_] = this;
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
75 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
76
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
77 this.module_ = module;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
78 this.canvasId_ = canvasId;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
79 this.htmlCanvas_ = document.getElementById(this.canvasId_) as HTMLCanvasElement;
244
313903066093 cleanup
am@osimis.io
parents: 236
diff changeset
80 if (this.htmlCanvas_ == null) {
313903066093 cleanup
am@osimis.io
parents: 236
diff changeset
81 console.log("Can not create WasmViewport, did not find the canvas whose id is '", this.canvasId_, "'");
313903066093 cleanup
am@osimis.io
parents: 236
diff changeset
82 }
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
83 this.context_ = this.htmlCanvas_.getContext('2d');
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
84
234
9afb50d1ac14 configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents: 231
diff changeset
85 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
86 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
87 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
88 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
89 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
90 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
91 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
92 this.ViewportMouseWheel = this.module_.cwrap('ViewportMouseWheel', null, [ 'number', 'number', 'number', 'number', 'number' ]);
327
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 314
diff changeset
93 this.ViewportKeyPressed = this.module_.cwrap('ViewportKeyPressed', null, [ 'number', 'number', 'string', 'number', 'number' ]);
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
94 }
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
95
234
9afb50d1ac14 configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents: 231
diff changeset
96 public GetCppViewport() : number {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
97 return this.pimpl_;
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
98 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
99
234
9afb50d1ac14 configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents: 231
diff changeset
100 public static GetFromCppViewport(cppViewportHandle: number) : WasmViewport {
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
101 if (WasmViewport.viewportsMapByCppHandle_[cppViewportHandle] !== undefined) {
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
102 return WasmViewport.viewportsMapByCppHandle_[cppViewportHandle];
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
103 }
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
104 console.log("WasmViewport not found !");
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
105 return undefined;
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
106 }
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
107
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
108 public static GetFromCanvasId(canvasId: string) : WasmViewport {
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
109 if (WasmViewport.viewportsMapByCanvasId_[canvasId] !== undefined) {
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
110 return WasmViewport.viewportsMapByCanvasId_[canvasId];
229
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
111 }
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
112 console.log("WasmViewport not found !");
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
113 return undefined;
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
114 }
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 228
diff changeset
115
314
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
116 public static ResizeAll() {
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
117 for (let canvasId in WasmViewport.viewportsMapByCanvasId_) {
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
118 WasmViewport.viewportsMapByCanvasId_[canvasId].Resize();
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
119 }
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
120 }
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
121
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
122 public Redraw() {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
123 if (this.imageData_ === null ||
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
124 this.renderingBuffer_ === null ||
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
125 this.ViewportRender(this.pimpl_,
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
126 this.imageData_.width,
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
127 this.imageData_.height,
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
128 this.renderingBuffer_) == 0) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
129 console.log('The rendering has failed');
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
130 } else {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
131 // Create an accessor to the rendering buffer (i.e. create a
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
132 // "window" above the heap of the WASM module), then copy it to
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
133 // the ImageData object
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
134 this.imageData_.data.set(new Uint8ClampedArray(
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
135 this.module_.buffer,
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
136 this.renderingBuffer_,
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
137 this.imageData_.width * this.imageData_.height * 4));
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
138
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
139 this.context_.putImageData(this.imageData_, 0, 0);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
140 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
141 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
142
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
143 public Resize() {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
144 if (this.imageData_ != null &&
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
145 (this.imageData_.width != window.innerWidth ||
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
146 this.imageData_.height != window.innerHeight)) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
147 this.imageData_ = null;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
148 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
149
420
8bf717c4e497 canvas size is now defined by the parent div size
am@osimis.io
parents: 327
diff changeset
150 // 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
151 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
152 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
153
9afb50d1ac14 configure WasmViewport size relative to window size through html attributes
am@osimis.io
parents: 231
diff changeset
154 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
155
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
156 if (this.imageData_ === null) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
157 this.imageData_ = this.context_.getImageData(0, 0, this.htmlCanvas_.width, this.htmlCanvas_.height);
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
158 this.ViewportSetSize(this.pimpl_, this.htmlCanvas_.width, this.htmlCanvas_.height);
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
159
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
160 if (this.renderingBuffer_ != null) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
161 this.module_._free(this.renderingBuffer_);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
162 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
163
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
164 this.renderingBuffer_ = this.module_._malloc(this.imageData_.width * this.imageData_.height * 4);
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
165 } else {
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 244
diff changeset
166 this.ViewportSetSize(this.pimpl_, this.htmlCanvas_.width, this.htmlCanvas_.height);
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
167 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
168
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
169 this.Redraw();
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
170 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
171
231
5027cb2feb51 viewport is now part of the Application itself and not global anymore
am@osimis.io
parents: 230
diff changeset
172 public Initialize() {
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
173
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
174 // Force the rendering of the viewport for the first time
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
175 this.Resize();
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
176
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
177 var that : WasmViewport = this;
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
178 // Register an event listener to call the Resize() function
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
179 // each time the window is resized.
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
180 window.addEventListener('resize', function(event) {
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
181 that.Resize();
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
182 }, false);
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
183
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
184 this.htmlCanvas_.addEventListener('contextmenu', function(event) {
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
185 // Prevent right click on the canvas
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
186 event.preventDefault();
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
187 }, false);
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
188
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
189 this.htmlCanvas_.addEventListener('mouseleave', function(event) {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
190 that.ViewportMouseLeave(that.pimpl_);
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
191 });
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
192
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
193 this.htmlCanvas_.addEventListener('mouseenter', function(event) {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
194 that.ViewportMouseEnter(that.pimpl_);
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
195 });
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
196
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
197 this.htmlCanvas_.addEventListener('mousedown', function(event) {
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
198 var x = event.pageX - this.offsetLeft;
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
199 var y = event.pageY - this.offsetTop;
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
200 that.ViewportMouseDown(that.pimpl_, event.button, x, y, 0 /* TODO detect modifier keys*/);
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
201 });
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
202
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
203 this.htmlCanvas_.addEventListener('mousemove', function(event) {
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
204 var x = event.pageX - this.offsetLeft;
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
205 var y = event.pageY - this.offsetTop;
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
206 that.ViewportMouseMove(that.pimpl_, x, y);
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
207 });
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
208
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
209 this.htmlCanvas_.addEventListener('mouseup', function(event) {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
210 that.ViewportMouseUp(that.pimpl_);
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
211 });
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
212
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
213 window.addEventListener('keydown', function(event) {
327
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 314
diff changeset
214 var keyChar = event.key;
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 314
diff changeset
215 var keyCode = event.keyCode
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 314
diff changeset
216 if (keyChar.length == 1) {
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 314
diff changeset
217 keyCode = 0; // maps to OrthancStone::KeyboardKeys_Generic
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 314
diff changeset
218 } else {
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 314
diff changeset
219 keyChar = null;
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 314
diff changeset
220 }
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 314
diff changeset
221 // console.log("key: ", keyCode, keyChar);
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 314
diff changeset
222 that.ViewportKeyPressed(that.pimpl_, keyCode, keyChar, event.shiftKey, event.ctrlKey, event.altKey);
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
223 });
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
224
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
225 this.htmlCanvas_.addEventListener('wheel', function(event) {
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
226 var x = event.pageX - this.offsetLeft;
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
227 var y = event.pageY - this.offsetTop;
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
228 that.ViewportMouseWheel(that.pimpl_, event.deltaY, x, y, event.ctrlKey);
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
229 event.preventDefault();
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
230 });
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
231
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
232 this.htmlCanvas_.addEventListener('touchstart', function(event) {
453
59b4afa92dee TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents: 420
diff changeset
233 // 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
234 event.preventDefault();
59b4afa92dee TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents: 420
diff changeset
235 event.stopPropagation();
59b4afa92dee TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents: 420
diff changeset
236
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
237 that.ResetTouch();
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
238 });
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
239
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
240 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
241 // 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
242 event.preventDefault();
59b4afa92dee TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents: 420
diff changeset
243 event.stopPropagation();
59b4afa92dee TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents: 420
diff changeset
244
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
245 that.ResetTouch();
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
246 });
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
247
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
248 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
249
59b4afa92dee TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents: 420
diff changeset
250 // 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
251 event.preventDefault();
59b4afa92dee TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents: 420
diff changeset
252 event.stopPropagation();
59b4afa92dee TS: stop propagating touch events to the whole html doc
Alain Mazy <alain@mazy.be>
parents: 420
diff changeset
253
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
254 // 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
255 // // 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
256 // 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
257 // 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
258 // 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
259 // }
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
260 // 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
261 // } 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
262 // // 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
263 // // 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
264
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
265 // 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
266
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
267 // }
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
268 // }
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
269
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
270 // 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
271
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
272 if (that.touchTranslation_.length == 2) { //
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
273 var t = that.GetTouchTranslation(event);
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
274 that.ViewportMouseMove(that.pimpl_, t[0], t[1]);
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
275 }
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
276 else if (that.touchZoom_.length == 3) {
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
277 var z0 = that.touchZoom_;
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
278 var z1 = that.GetTouchZoom(event);
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
279 that.ViewportMouseMove(that.pimpl_, z0[0], z0[1] - z0[2] + z1[2]);
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
280 }
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
281 else {
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
282 // Realize the gesture event
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
283 if (event.targetTouches.length == 1) {
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
284 // Exactly one finger inside the canvas => Setup a translation
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
285 that.touchTranslation_ = that.GetTouchTranslation(event);
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
286 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
287 0 /* left button */,
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
288 that.touchTranslation_[0],
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
289 that.touchTranslation_[1], 0);
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
290 } else if (event.targetTouches.length == 2) {
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
291 // Exactly 2 fingers inside the canvas => Setup a pinch/zoom
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
292 that.touchZoom_ = that.GetTouchZoom(event);
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
293 var z0 = that.touchZoom_;
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
294 that.ViewportMouseDown(that.pimpl_,
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
295 2 /* right button */,
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
296 z0[0],
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
297 z0[1], 0);
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
298 }
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
299 }
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
300 });
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
301 }
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
302
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
303 public ResetTouch() {
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
304 if (this.touchTranslation_ ||
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
305 this.touchZoom_) {
228
210c1ce8e1a6 WasmViewport is no more a singleton
am@osimis.io
parents: 227
diff changeset
306 this.ViewportMouseUp(this.pimpl_);
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
307 }
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
308
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
309 this.touchTranslation_ = false;
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
310 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
311
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
312 // 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
313 // 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
314 // this.touchGestureLastCoordinates_ = [];
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
315 }
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
316
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
317 public GetTouchTranslation(event) {
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
318 var touch = event.targetTouches[0];
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
319 return [
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
320 touch.pageX,
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
321 touch.pageY
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
322 ];
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
323 }
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
324
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
325 public GetTouchZoom(event) {
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
326 var touch1 = event.targetTouches[0];
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
327 var touch2 = event.targetTouches[1];
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
328 var dx = (touch1.pageX - touch2.pageX);
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
329 var dy = (touch1.pageY - touch2.pageY);
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
330 var d = Math.sqrt(dx * dx + dy * dy);
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
331 return [
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
332 (touch1.pageX + touch2.pageX) / 2.0,
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
333 (touch1.pageY + touch2.pageY) / 2.0,
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
334 d
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
335 ];
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
336 }
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
337
227
c8f11437a6fd getting ready for multiple viewports
am@osimis.io
parents: 226
diff changeset
338 }
466
5055031f4a06 - Added browserify to build. This allows using require calls for modules that
bgo-osimis
parents: 420
diff changeset
339
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
340