annotate Platforms/WebAssembly/wasm-viewport.ts @ 226:1fa4c65c7e1b am

WasmViewport in ts
author am@osimis.io
date Thu, 14 Jun 2018 12:32:08 +0200
parents
children c8f11437a6fd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
1
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
2 module Stone {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
3
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
4 // export declare type InitializationCallback = () => void;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
5
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
6 // export declare var StoneFrameworkModule : any;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
7
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
8 //const ASSETS_FOLDER : string = "assets/lib";
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
9 //const WASM_FILENAME : string = "orthanc-framework";
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
10
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
11 export class WasmViewport {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
12
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
13 private module_ : any;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
14 private canvasId_ : string;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
15 private htmlCanvas_ : HTMLCanvasElement;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
16 private context_ : CanvasRenderingContext2D;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
17 private imageData_ : any = null;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
18 private renderingBuffer_ : any = null;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
19 private touchZoom_ : any = false;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
20 private touchTranslation_ : any = false;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
21
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
22 private ViewportSetSize : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
23 private ViewportRender : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
24 private ViewportMouseDown : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
25 private ViewportMouseMove : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
26 private ViewportMouseUp : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
27 private ViewportMouseEnter : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
28 private ViewportMouseLeave : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
29 private ViewportMouseWheel : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
30 private ViewportKeyPressed : Function;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
31
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
32 public constructor(module: any, canvasId: string) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
33 this.module_ = module;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
34 this.canvasId_ = canvasId;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
35 this.htmlCanvas_ = document.getElementById(this.canvasId_) as HTMLCanvasElement;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
36 this.context_ = this.htmlCanvas_.getContext('2d');
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
37
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
38 this.ViewportSetSize = this.module_.cwrap('ViewportSetSize', null, [ 'number', 'number' ]);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
39 this.ViewportRender = this.module_.cwrap('ViewportRender', null, [ 'number', 'number', 'number', 'number' ]);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
40 this.ViewportMouseDown = this.module_.cwrap('ViewportMouseDown', null, [ 'number', 'number', 'number', 'number' ]);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
41 this.ViewportMouseMove = this.module_.cwrap('ViewportMouseMove', null, [ 'number', 'number' ]);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
42 this.ViewportMouseUp = this.module_.cwrap('ViewportMouseUp', null, [ ]);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
43 this.ViewportMouseEnter = this.module_.cwrap('ViewportMouseEnter', null, []);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
44 this.ViewportMouseLeave = this.module_.cwrap('ViewportMouseLeave', null, []);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
45 this.ViewportMouseWheel = this.module_.cwrap('ViewportMouseWheel', null, [ 'number', 'number', 'number', 'number' ]);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
46 this.ViewportKeyPressed = this.module_.cwrap('ViewportKeyPressed', null, [ 'string', 'number', 'number' ]);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
47 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
48
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
49 public Redraw() {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
50 if (this.imageData_ === null ||
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
51 this.renderingBuffer_ === null ||
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
52 this.ViewportRender(this.imageData_.width,
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
53 this.imageData_.height,
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
54 this.renderingBuffer_) == 0) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
55 console.log('The rendering has failed');
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
56 } else {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
57 // Create an accessor to the rendering buffer (i.e. create a
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
58 // "window" above the heap of the WASM module), then copy it to
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
59 // the ImageData object
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
60 this.imageData_.data.set(new Uint8ClampedArray(
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
61 this.module_.buffer,
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
62 this.renderingBuffer_,
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
63 this.imageData_.width * this.imageData_.height * 4));
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
64
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
65 this.context_.putImageData(this.imageData_, 0, 0);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
66 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
67 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
68
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
69 public Resize() {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
70 if (this.imageData_ != null &&
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
71 (this.imageData_.width != window.innerWidth ||
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
72 this.imageData_.height != window.innerHeight)) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
73 this.imageData_ = null;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
74 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
75
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
76 this.htmlCanvas_.width = window.innerWidth;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
77 this.htmlCanvas_.height = window.innerHeight;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
78
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
79 if (this.imageData_ === null) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
80 this.imageData_ = this.context_.getImageData(0, 0, this.htmlCanvas_.width, this.htmlCanvas_.height);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
81 this.ViewportSetSize(this.htmlCanvas_.width, this.htmlCanvas_.height);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
82
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
83 if (this.renderingBuffer_ != null) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
84 this.module_._free(this.renderingBuffer_);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
85 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
86
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
87 this.renderingBuffer_ = this.module_._malloc(this.imageData_.width * this.imageData_.height * 4);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
88 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
89
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
90 this.Redraw();
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
91 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
92
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
93 public Initialize() {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
94
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
95 // Force the rendering of the viewport for the first time
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
96 this.Resize();
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
97
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
98 // Register an event listener to call the Resize() function
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
99 // each time the window is resized.
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
100 window.addEventListener('resize', this.Resize, false);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
101
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
102 var that = this;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
103
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
104 this.htmlCanvas_.addEventListener('contextmenu', function(event) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
105 // Prevent right click on the canvas
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
106 event.preventDefault();
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
107 }, false);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
108
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
109 this.htmlCanvas_.addEventListener('mouseleave', function(event) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
110 that.ViewportMouseLeave();
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
111 });
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
112
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
113 this.htmlCanvas_.addEventListener('mouseenter', function(event) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
114 that.ViewportMouseEnter();
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
115 });
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
116
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
117 this.htmlCanvas_.addEventListener('mousedown', function(event) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
118 var x = event.pageX - this.offsetLeft;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
119 var y = event.pageY - this.offsetTop;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
120 that.ViewportMouseDown(event.button, x, y, 0 /* TODO */);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
121 });
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
122
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
123 this.htmlCanvas_.addEventListener('mousemove', function(event) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
124 var x = event.pageX - this.offsetLeft;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
125 var y = event.pageY - this.offsetTop;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
126 that.ViewportMouseMove(x, y);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
127 });
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
128
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
129 this.htmlCanvas_.addEventListener('mouseup', function(event) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
130 that.ViewportMouseUp();
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
131 });
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
132
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
133 window.addEventListener('keydown', function(event) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
134 that.ViewportKeyPressed(event.key, event.shiftKey, event.ctrlKey, event.altKey);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
135 });
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
136
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
137 this.htmlCanvas_.addEventListener('wheel', function(event) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
138 var x = event.pageX - this.offsetLeft;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
139 var y = event.pageY - this.offsetTop;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
140 that.ViewportMouseWheel(event.deltaY, x, y, event.ctrlKey);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
141 event.preventDefault();
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
142 });
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
143
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
144 var that = this;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
145 this.htmlCanvas_.addEventListener('touchstart', function(event) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
146 that.ResetTouch();
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
147 });
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
148
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
149 this.htmlCanvas_.addEventListener('touchend', function(event) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
150 that.ResetTouch();
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
151 });
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
152
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
153 this.htmlCanvas_.addEventListener('touchmove', function(event) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
154 if (that.touchTranslation_.length == 2) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
155 var t = that.GetTouchTranslation(event);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
156 that.ViewportMouseMove(t[0], t[1]);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
157 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
158 else if (that.touchZoom_.length == 3) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
159 var z0 = that.touchZoom_;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
160 var z1 = that.GetTouchZoom(event);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
161 that.ViewportMouseMove(z0[0], z0[1] - z0[2] + z1[2]);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
162 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
163 else {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
164 // Realize the gesture event
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
165 if (event.targetTouches.length == 1) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
166 // Exactly one finger inside the canvas => Setup a translation
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
167 that.touchTranslation_ = that.GetTouchTranslation(event);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
168 that.ViewportMouseDown(1 /* middle button */,
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
169 that.touchTranslation_[0],
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
170 that.touchTranslation_[1], 0);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
171 } else if (event.targetTouches.length == 2) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
172 // Exactly 2 fingers inside the canvas => Setup a pinch/zoom
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
173 that.touchZoom_ = that.GetTouchZoom(event);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
174 var z0 = that.touchZoom_;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
175 that.ViewportMouseDown(2 /* right button */,
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
176 z0[0],
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
177 z0[1], 0);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
178 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
179 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
180 });
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
181 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
182
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
183 public ResetTouch() {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
184 if (this.touchTranslation_ ||
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
185 this.touchZoom_) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
186 this.ViewportMouseUp();
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
187 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
188
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
189 this.touchTranslation_ = false;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
190 this.touchZoom_ = false;
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
191 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
192
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
193 public GetTouchTranslation(event) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
194 var touch = event.targetTouches[0];
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
195 return [
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
196 touch.pageX,
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
197 touch.pageY
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
198 ];
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
199 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
200
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
201 public GetTouchZoom(event) {
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
202 var touch1 = event.targetTouches[0];
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
203 var touch2 = event.targetTouches[1];
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
204 var dx = (touch1.pageX - touch2.pageX);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
205 var dy = (touch1.pageY - touch2.pageY);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
206 var d = Math.sqrt(dx * dx + dy * dy);
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
207 return [
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
208 (touch1.pageX + touch2.pageX) / 2.0,
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
209 (touch1.pageY + touch2.pageY) / 2.0,
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
210 d
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
211 ];
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
212 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
213
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
214 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
215 }
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents:
diff changeset
216