annotate Platforms/Wasm/wasm-application-runner.ts @ 350:c57e049ed079 am-2

drawing corners for cropping
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Oct 2018 15:41:00 +0200
parents 97f16214dc5e
children e33659decec5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
1 ///<reference path='stone-framework-loader.ts'/>
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
2 ///<reference path='wasm-viewport.ts'/>
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
3
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
4 if (!('WebAssembly' in window)) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
5 alert('Sorry, your browser does not support WebAssembly :(');
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
6 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
7
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
8 declare var StoneFrameworkModule : Stone.Framework;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
9
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
10 // global functions
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
11 var WasmWebService_NotifyError: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
12 var WasmWebService_NotifySuccess: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
13 var WasmWebService_SetBaseUri: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
14 var NotifyUpdateContent: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
15 var SetStartupParameter: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
16 var CreateWasmApplication: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
17 var CreateCppViewport: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
18 var ReleaseCppViewport: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
19 var StartWasmApplication: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
20 var SendMessageToStoneApplication: Function = null;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
21
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
22
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
23 function UpdateContentThread() {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
24 if (NotifyUpdateContent != null) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
25 NotifyUpdateContent();
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
26 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
27
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
28 setTimeout(UpdateContentThread, 100); // Update the viewport content every 100ms if need be
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
29 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
30
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
31
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
32 function GetUriParameters(): Map<string, string> {
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
33 var parameters = window.location.search.substr(1);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
34
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
35 if (parameters != null &&
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
36 parameters != '') {
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
37 var result = new Map<string, string>();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
38 var tokens = parameters.split('&');
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
39
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
40 for (var i = 0; i < tokens.length; i++) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
41 var tmp = tokens[i].split('=');
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
42 if (tmp.length == 2) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
43 result[tmp[0]] = decodeURIComponent(tmp[1]);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
44 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
45 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
46
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
47 return result;
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
48 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
49 else {
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
50 return new Map<string, string>();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
51 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
52 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
53
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
54 // function UpdateWebApplication(statusUpdateMessage: string) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
55 // console.log(statusUpdateMessage);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
56 // }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
57
314
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
58 function _InitializeWasmApplication(orthancBaseUrl: string): void {
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
59
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
60 CreateWasmApplication();
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
61 WasmWebService_SetBaseUri(orthancBaseUrl);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
62
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
63
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
64 // parse uri and transmit the parameters to the app before initializing it
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
65 let parameters = GetUriParameters();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
66
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
67 for (let key in parameters) {
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
68 if (parameters.hasOwnProperty(key)) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
69 SetStartupParameter(key, parameters[key]);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
70 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
71 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
72
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
73 StartWasmApplication();
313
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
74
8bdc6112bc2e initial resize of canvas
am@osimis.io
parents: 303
diff changeset
75 // trigger a first resize of the canvas that have just been initialized
314
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
76 Stone.WasmViewport.ResizeAll();
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
77
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
78 UpdateContentThread();
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
79 }
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
80
314
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
81 function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) {
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
82
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
83 Stone.Framework.Configure(wasmModuleName);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
84
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
85 // Wait for the Orthanc Framework to be initialized (this initializes
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
86 // the WebAssembly environment) and then, create and initialize the Wasm application
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
87 Stone.Framework.Initialize(true, function () {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
88
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
89 console.log("Connecting C++ methods to JS methods");
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
90
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
91 SetStartupParameter = StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
92 CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
93 CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
94 ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
95 StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, ['number']);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
96
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
97 WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
98 WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
99 WasmWebService_SetBaseUri = StoneFrameworkModule.cwrap('WasmWebService_SetBaseUri', null, ['string']);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
100 NotifyUpdateContent = StoneFrameworkModule.cwrap('NotifyUpdateContent', null, []);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
101
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
102 SendMessageToStoneApplication = StoneFrameworkModule.cwrap('SendMessageToStoneApplication', 'string', ['string']);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
103
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
104 console.log("Connecting C++ methods to JS methods - done");
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
105
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
106 // Prevent scrolling
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
107 document.body.addEventListener('touchmove', function (event) {
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
108 event.preventDefault();
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
109 }, false);
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
110
314
97f16214dc5e cleanup
am@osimis.io
parents: 313
diff changeset
111 _InitializeWasmApplication(orthancBaseUrl);
287
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
112 });
2038d76bf13f interaction with HTML/JS
am@osimis.io
parents:
diff changeset
113 }