changeset 230:7d2631320615 am

wasm-application.js is now in ts
author am@osimis.io
date Thu, 14 Jun 2018 17:14:10 +0200
parents b0ba3b38a23c
children 5027cb2feb51
files Platforms/WebAssembly/wasm-application.js Platforms/WebAssembly/wasm-application.ts Platforms/WebAssembly/wasm-viewport.ts
diffstat 3 files changed, 121 insertions(+), 127 deletions(-) [+]
line wrap: on
line diff
--- a/Platforms/WebAssembly/wasm-application.js	Thu Jun 14 16:51:43 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +0,0 @@
-
-
-// Global context used by "library.js"
-var viewport = null;
-var WasmWebService_NotifyError = null;
-var WasmWebService_NotifySuccess = null;
-var NotifyUpdateContent = null;
-
-function UpdateContentThread()
-{
-  if (NotifyUpdateContent != null) {
-    NotifyUpdateContent();
-  }
-  
-  setTimeout(UpdateContentThread, 100);  // Update the viewport content every 100ms if need be
-}
-
-
-function GetUriParameters()
-{
-  var parameters = window.location.search.substr(1);
-
-  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]);
-      }
-    }
-    
-    return result;
-  }
-  else
-  {
-    return {};
-  }
-}
-
-
-
-function InitializeWasmApplication(canvasId)
-{
-  console.log("Initializing wasm-app");
-
-  console.log("Connecting C++ methods to JS methods");
-  SetStartupParameter = StoneFrameworkModule.cwrap('SetStartupParameter', null, [ 'string', 'string' ]);
-  CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, [ 'any' ], [ ]);
-  CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'any', [ ], [ ]);
-  ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, [ 'any' ], [ ]);
-  StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, [ ], [ ]);
-  WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null,
-                                              [ 'number', 'string', 'array', 'number', 'number' ]);
-  WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null,
-                                            [ 'number', 'string', 'number' ]);
-  NotifyUpdateContent = StoneFrameworkModule.cwrap('NotifyUpdateContent', null, [  ]);
-                                 
-  console.log("Creating main viewport");
-
-  viewport = new Stone.WasmViewport(StoneFrameworkModule, canvasId);
-  viewport.Initialize(CreateCppViewport());
-
-  // Prevent scrolling
-  document.body.addEventListener('touchmove', function(event) {
-    event.preventDefault();
-  }, false);
-  
-  document.getElementById(canvasId).onclick = function() {
-    viewport.Redraw();
-  };
-
-
-  /************************************** */
-  CreateWasmApplication();
-
-  // 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]);
-    }
-  }
-
-  StartWasmApplication(viewport.GetCppViewport());
-  /************************************** */
-
-  UpdateContentThread();
-}
-
-if (!('WebAssembly' in window)) {
-  alert('Sorry, your browser does not support WebAssembly :(');
-} else {
-  
-}
--- a/Platforms/WebAssembly/wasm-application.ts	Thu Jun 14 16:51:43 2018 +0200
+++ b/Platforms/WebAssembly/wasm-application.ts	Thu Jun 14 17:14:10 2018 +0200
@@ -1,37 +1,131 @@
 ///<reference path='stone-framework-loader.ts'/>
 ///<reference path='wasm-viewport.ts'/>
 
+if (!('WebAssembly' in window)) {
+    alert('Sorry, your browser does not support WebAssembly :(');
+}
+
+declare var StoneFrameworkModule : Stone.Framework;
+
+var viewport = null;
+
+// global functions
+var WasmWebService_NotifyError: Function = null;
+var WasmWebService_NotifySuccess: Function = null;
+var NotifyUpdateContent: Function = null;
+var SetStartupParameter: Function = null;
+var CreateWasmApplication: Function = null;
+var CreateCppViewport: Function = null;
+var ReleaseCppViewport: Function = null;
+var StartWasmApplication: Function = null;
+
+
+function UpdateContentThread() {
+    if (NotifyUpdateContent != null) {
+        NotifyUpdateContent();
+    }
+
+    setTimeout(UpdateContentThread, 100);  // Update the viewport content every 100ms if need be
+}
+
+
+function GetUriParameters() {
+    var parameters = window.location.search.substr(1);
+
+    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]);
+            }
+        }
+
+        return result;
+    }
+    else {
+        return {};
+    }
+}
+
 module Stone {
-  
+
     //  export declare type InitializationCallback = () => void;
-      
+
     //  export declare var StoneFrameworkModule : any;
-      
-      //const ASSETS_FOLDER : string = "assets/lib";
-      //const WASM_FILENAME : string = "orthanc-framework";
-      
-      export class WasmApplication {
-    
-        private viewport_ : WasmViewport;
+
+    //const ASSETS_FOLDER : string = "assets/lib";
+    //const WASM_FILENAME : string = "orthanc-framework";
+
+    export class WasmApplication {
+
+        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.canvasId_ = canvasId;
             //this.module_ = module;
         }
     }
 }
-    
+
+
+function InitializeWasmApplication(canvasId: string): void {
+
+    console.log("Creating main viewport");
 
-declare function InitializeWasmApplication(canvasId: string) :void; // still in a js file
+    viewport = new Stone.WasmViewport(StoneFrameworkModule, canvasId);
+    viewport.Initialize(CreateCppViewport());
+
+    document.getElementById(canvasId).onclick = function () {
+        viewport.Redraw();
+    };
 
 
+    /************************************** */
+    CreateWasmApplication();
 
+    // 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]);
+        }
+    }
+
+    StartWasmApplication(viewport.GetCppViewport());
+    /************************************** */
+
+    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() {
+Stone.Framework.Initialize(true, function () {
+
+    console.log("Connecting C++ methods to JS methods");
+    
+    SetStartupParameter = StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']);
+    CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['any']);
+    CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'any', []);
+    ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['any']);
+    StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, []);
+
+    WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']);
+    WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']);
+    NotifyUpdateContent = StoneFrameworkModule.cwrap('NotifyUpdateContent', null, []);
+
+    // Prevent scrolling
+    document.body.addEventListener('touchmove', function (event) {
+        event.preventDefault();
+    }, false);
+
+
     InitializeWasmApplication("canvas");
 });
\ No newline at end of file
--- a/Platforms/WebAssembly/wasm-viewport.ts	Thu Jun 14 16:51:43 2018 +0200
+++ b/Platforms/WebAssembly/wasm-viewport.ts	Thu Jun 14 17:14:10 2018 +0200
@@ -1,17 +1,16 @@
-
-  var isPendingRedraw = false;
+var isPendingRedraw = false;
 
-  function ScheduleWebViewportRedraw(cppViewportHandle: any) : void
-  {
-    if (!isPendingRedraw) {
-      isPendingRedraw = true;
-      console.log('Scheduling a refresh of the viewport, as its content changed');
-      window.requestAnimationFrame(function() {
-        isPendingRedraw = false;
-        Stone.WasmViewport.GetFromCppViewport(cppViewportHandle).Redraw();
-      });
-    }
+function ScheduleWebViewportRedraw(cppViewportHandle: any) : void
+{
+  if (!isPendingRedraw) {
+    isPendingRedraw = true;
+    console.log('Scheduling a refresh of the viewport, as its content changed');
+    window.requestAnimationFrame(function() {
+      isPendingRedraw = false;
+      Stone.WasmViewport.GetFromCppViewport(cppViewportHandle).Redraw();
+    });
   }
+}
 
 module Stone {