diff Platforms/WebAssembly/wasm-viewport.ts @ 229:b0ba3b38a23c am

ScheduleRedraw can handle multiple viewports
author am@osimis.io
date Thu, 14 Jun 2018 16:51:43 +0200
parents 210c1ce8e1a6
children 7d2631320615
line wrap: on
line diff
--- a/Platforms/WebAssembly/wasm-viewport.ts	Thu Jun 14 15:06:29 2018 +0200
+++ b/Platforms/WebAssembly/wasm-viewport.ts	Thu Jun 14 16:51:43 2018 +0200
@@ -1,3 +1,17 @@
+
+  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();
+      });
+    }
+  }
 
 module Stone {
   
@@ -7,9 +21,11 @@
   
   //const ASSETS_FOLDER : string = "assets/lib";
   //const WASM_FILENAME : string = "orthanc-framework";
-  
+
   export class WasmViewport {
 
+    private static cppWebViewportsMaps_ : Map<any, WasmViewport> = new Map<any, WasmViewport>();
+
     private module_ : any;
     private canvasId_ : string;
     private htmlCanvas_ : HTMLCanvasElement;
@@ -52,6 +68,14 @@
       return this.pimpl_;
     }
 
+    public static GetFromCppViewport(cppViewportHandle: any) : WasmViewport {
+      if (WasmViewport.cppWebViewportsMaps_[cppViewportHandle] !== undefined) {
+        return WasmViewport.cppWebViewportsMaps_[cppViewportHandle];
+      }
+      console.log("WasmViewport not found !");
+      return undefined;
+    }
+
     public Redraw() {
       if (this.imageData_ === null ||
           this.renderingBuffer_ === null ||
@@ -99,6 +123,7 @@
 
     public Initialize(cppViewport: any) {
       this.pimpl_ = cppViewport;
+      WasmViewport.cppWebViewportsMaps_[this.pimpl_] = this;
       
       console.log(this.pimpl_);
       // Force the rendering of the viewport for the first time