Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/wasm-application-runner.ts @ 476:a95090305dd4 am-touch-events
Introduced ControlPoint instead of Corner in the trackers and layers + drawing mask from the ControlPoints
author | am@osimis.io |
---|---|
date | Wed, 13 Feb 2019 12:04:02 +0100 |
parents | e641d3978856 |
children | 5055031f4a06 |
rev | line source |
---|---|
287 | 1 ///<reference path='stone-framework-loader.ts'/> |
2 ///<reference path='wasm-viewport.ts'/> | |
3 | |
4 if (!('WebAssembly' in window)) { | |
5 alert('Sorry, your browser does not support WebAssembly :('); | |
6 } | |
7 | |
8 declare var StoneFrameworkModule : Stone.Framework; | |
9 | |
10 // global functions | |
11 var WasmWebService_NotifyError: Function = null; | |
12 var WasmWebService_NotifySuccess: Function = null; | |
435
e641d3978856
WasmWebService now using BaseWebService and supporting cache
am@osimis.io
parents:
431
diff
changeset
|
13 var WasmWebService_NotifyCachedSuccess: Function = null; |
431
26b90b110719
added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
418
diff
changeset
|
14 var WasmDelayedCallExecutor_ExecuteCallback: Function = null; |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
15 var WasmDoAnimation: Function = null; |
287 | 16 var SetStartupParameter: Function = null; |
17 var CreateWasmApplication: Function = null; | |
18 var CreateCppViewport: Function = null; | |
19 var ReleaseCppViewport: Function = null; | |
20 var StartWasmApplication: Function = null; | |
21 var SendMessageToStoneApplication: Function = null; | |
22 | |
23 | |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
24 function DoAnimationThread() { |
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
25 if (WasmDoAnimation != null) { |
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
26 WasmDoAnimation(); |
287 | 27 } |
28 | |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
29 setTimeout(DoAnimationThread, 100); // Update the viewport content every 100ms if need be |
287 | 30 } |
31 | |
32 | |
313 | 33 function GetUriParameters(): Map<string, string> { |
287 | 34 var parameters = window.location.search.substr(1); |
35 | |
36 if (parameters != null && | |
37 parameters != '') { | |
313 | 38 var result = new Map<string, string>(); |
287 | 39 var tokens = parameters.split('&'); |
40 | |
41 for (var i = 0; i < tokens.length; i++) { | |
42 var tmp = tokens[i].split('='); | |
43 if (tmp.length == 2) { | |
44 result[tmp[0]] = decodeURIComponent(tmp[1]); | |
45 } | |
46 } | |
47 | |
48 return result; | |
49 } | |
50 else { | |
313 | 51 return new Map<string, string>(); |
287 | 52 } |
53 } | |
54 | |
55 // function UpdateWebApplication(statusUpdateMessage: string) { | |
56 // console.log(statusUpdateMessage); | |
57 // } | |
58 | |
314 | 59 function _InitializeWasmApplication(orthancBaseUrl: string): void { |
287 | 60 |
61 CreateWasmApplication(); | |
62 | |
63 // parse uri and transmit the parameters to the app before initializing it | |
313 | 64 let parameters = GetUriParameters(); |
287 | 65 |
313 | 66 for (let key in parameters) { |
287 | 67 if (parameters.hasOwnProperty(key)) { |
68 SetStartupParameter(key, parameters[key]); | |
69 } | |
70 } | |
71 | |
418 | 72 StartWasmApplication(orthancBaseUrl); |
313 | 73 |
418 | 74 // trigger a first resize of the canvas that has just been initialized |
314 | 75 Stone.WasmViewport.ResizeAll(); |
287 | 76 |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
77 DoAnimationThread(); |
287 | 78 } |
79 | |
314 | 80 function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) { |
287 | 81 |
82 Stone.Framework.Configure(wasmModuleName); | |
83 | |
84 // Wait for the Orthanc Framework to be initialized (this initializes | |
85 // the WebAssembly environment) and then, create and initialize the Wasm application | |
86 Stone.Framework.Initialize(true, function () { | |
87 | |
88 console.log("Connecting C++ methods to JS methods"); | |
89 | |
90 SetStartupParameter = StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']); | |
91 CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']); | |
92 CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []); | |
93 ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']); | |
418 | 94 StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']); |
287 | 95 |
435
e641d3978856
WasmWebService now using BaseWebService and supporting cache
am@osimis.io
parents:
431
diff
changeset
|
96 WasmWebService_NotifyCachedSuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifyCachedSuccess', null, ['number']); |
287 | 97 WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']); |
98 WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']); | |
431
26b90b110719
added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
418
diff
changeset
|
99 WasmDelayedCallExecutor_ExecuteCallback = StoneFrameworkModule.cwrap('WasmDelayedCallExecutor_ExecuteCallback', null, ['number']); |
386
e33659decec5
renamed UpdateContent() as DoAnimation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
100 WasmDoAnimation = StoneFrameworkModule.cwrap('WasmDoAnimation', null, []); |
287 | 101 |
102 SendMessageToStoneApplication = StoneFrameworkModule.cwrap('SendMessageToStoneApplication', 'string', ['string']); | |
103 | |
104 console.log("Connecting C++ methods to JS methods - done"); | |
105 | |
106 // Prevent scrolling | |
107 document.body.addEventListener('touchmove', function (event) { | |
108 event.preventDefault(); | |
109 }, false); | |
110 | |
314 | 111 _InitializeWasmApplication(orthancBaseUrl); |
287 | 112 }); |
113 } |