Mercurial > hg > orthanc-stone
diff Platforms/Wasm/wasm-application.ts @ 238:126c9c0c9333 am
SimpleViewer demo running both with SDL and Wasm
author | am@osimis.io |
---|---|
date | Wed, 20 Jun 2018 09:25:39 +0200 |
parents | f73d722d98c8 |
children | ddbb339ed4cf |
line wrap: on
line diff
--- a/Platforms/Wasm/wasm-application.ts Wed Jun 20 09:03:48 2018 +0200 +++ b/Platforms/Wasm/wasm-application.ts Wed Jun 20 09:25:39 2018 +0200 @@ -2,7 +2,7 @@ ///<reference path='wasm-viewport.ts'/> if (!('WebAssembly' in window)) { - alert('Sorry, your browser does not support WebAssembly :('); + alert('Sorry, your browser does not support WebAssembly :('); } declare var StoneFrameworkModule : Stone.Framework; @@ -19,83 +19,80 @@ function UpdateContentThread() { - if (NotifyUpdateContent != null) { - NotifyUpdateContent(); - } + if (NotifyUpdateContent != null) { + NotifyUpdateContent(); + } - setTimeout(UpdateContentThread, 100); // Update the viewport content every 100ms if need be + setTimeout(UpdateContentThread, 100); // Update the viewport content every 100ms if need be } function GetUriParameters() { - var parameters = window.location.search.substr(1); + var parameters = window.location.search.substr(1); - if (parameters != null && - parameters != '') { - var result = {}; - var tokens = parameters.split('&'); + if (parameters != null && + parameters != '') { + var result = {}; + var tokens = parameters.split('&'); - for (var i = 0; i < tokens.length; i++) { - var tmp = tokens[i].split('='); - if (tmp.length == 2) { - result[tmp[0]] = decodeURIComponent(tmp[1]); - } - } + for (var i = 0; i < tokens.length; i++) { + var tmp = tokens[i].split('='); + if (tmp.length == 2) { + result[tmp[0]] = decodeURIComponent(tmp[1]); + } + } - return result; - } - else { - return {}; - } + return result; + } + else { + return {}; + } } module Stone { - // export declare type InitializationCallback = () => void; - - // export declare var StoneFrameworkModule : any; + export class WasmApplication { - //const ASSETS_FOLDER : string = "assets/lib"; - //const WASM_FILENAME : string = "orthanc-framework"; - - export class WasmApplication { + private viewport_: WasmViewport; + private canvasId_: string; - private viewport_: WasmViewport; - private canvasId_: string; - - private pimpl_: any; // Private pointer to the underlying WebAssembly C++ object + private pimpl_: any; // Private pointer to the underlying WebAssembly C++ object - public constructor(canvasId: string) { - this.canvasId_ = canvasId; - //this.module_ = module; - } + public constructor(canvasId: string) { + this.canvasId_ = canvasId; + //this.module_ = module; } + } } -function InitializeWasmApplication(canvasId: string): void { +function _InitializeWasmApplication(canvasId: string): void { - /************************************** */ - CreateWasmApplication(); + /************************************** */ + CreateWasmApplication(); - // parse uri and transmit the parameters to the app before initializing it - var parameters = GetUriParameters(); + // parse uri and transmit the parameters to the app before initializing it + var parameters = GetUriParameters(); - for (var key in parameters) { - if (parameters.hasOwnProperty(key)) { - SetStartupParameter(key, parameters[key]); - } + for (var key in parameters) { + if (parameters.hasOwnProperty(key)) { + SetStartupParameter(key, parameters[key]); } + } - StartWasmApplication(); - /************************************** */ + StartWasmApplication(); + /************************************** */ - UpdateContentThread(); + UpdateContentThread(); } -// Wait for the Orthanc Framework to be initialized (this initializes -// the WebAssembly environment) and then, create and initialize the Wasm application -Stone.Framework.Initialize(true, function () { +function InitializeWasmApplication(wasmModuleName: string) { + + Stone.Framework.Configure(wasmModuleName); + + // Wait for the Orthanc Framework to be initialized (this initializes + // the WebAssembly environment) and then, create and initialize the Wasm application + Stone.Framework.Initialize(true, function () { console.log("Connecting C++ methods to JS methods"); @@ -111,9 +108,9 @@ // Prevent scrolling document.body.addEventListener('touchmove', function (event) { - event.preventDefault(); + event.preventDefault(); }, false); - - InitializeWasmApplication("canvas"); -}); \ No newline at end of file + _InitializeWasmApplication("canvas"); + }); +} \ No newline at end of file