changeset 313:8bdc6112bc2e am-2

initial resize of canvas
author am@osimis.io
date Wed, 03 Oct 2018 17:01:05 +0200
parents a91ad36b684c
children 97f16214dc5e
files Framework/Widgets/WorldSceneWidget.cpp Platforms/Wasm/wasm-application-runner.ts Platforms/Wasm/wasm-viewport.ts
diffstat 3 files changed, 33 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Widgets/WorldSceneWidget.cpp	Tue Oct 02 10:15:36 2018 +0200
+++ b/Framework/Widgets/WorldSceneWidget.cpp	Wed Oct 03 17:01:05 2018 +0200
@@ -24,6 +24,7 @@
 #include <math.h>
 #include <memory>
 #include <cassert>
+#include "Core/Logging.h"
 
 namespace OrthancStone
 {
@@ -138,7 +139,8 @@
 
     if (that_.view_.GetDisplayHeight() <= 3)
     {
-      return;   // Cannot zoom on such a small image
+      LOG(WARNING) << "image is too small to zoom (current height = " << that_.view_.GetDisplayHeight() << ")";
+      return;
     }
 
     double dy = (static_cast<double>(y - downY_) /
--- a/Platforms/Wasm/wasm-application-runner.ts	Tue Oct 02 10:15:36 2018 +0200
+++ b/Platforms/Wasm/wasm-application-runner.ts	Wed Oct 03 17:01:05 2018 +0200
@@ -29,12 +29,12 @@
 }
 
 
-function GetUriParameters() {
+function GetUriParameters(): Map<string, string> {
   var parameters = window.location.search.substr(1);
 
   if (parameters != null &&
     parameters != '') {
-    var result = {};
+    var result = new Map<string, string>();
     var tokens = parameters.split('&');
 
     for (var i = 0; i < tokens.length; i++) {
@@ -47,7 +47,7 @@
     return result;
   }
   else {
-    return {};
+    return new Map<string, string>();
   }
 }
 
@@ -55,29 +55,32 @@
 //   console.log(statusUpdateMessage);
 // }
 
-function _InitializeWasmApplication(canvasId: string, orthancBaseUrl: string): void {
+function _InitializeWasmApplication(canvasIds: string[], orthancBaseUrl: string): void {
 
-  /************************************** */
   CreateWasmApplication();
   WasmWebService_SetBaseUri(orthancBaseUrl);
 
 
   // parse uri and transmit the parameters to the app before initializing it
-  var parameters = GetUriParameters();
+  let parameters = GetUriParameters();
 
-  for (var key in parameters) {
+  for (let key in parameters) {
     if (parameters.hasOwnProperty(key)) {
       SetStartupParameter(key, parameters[key]);
     }
   }
 
   StartWasmApplication();
-  /************************************** */
+
+  // trigger a first resize of the canvas that have just been initialized
+  for (let canvasId of canvasIds) {
+    Stone.WasmViewport.GetFromCanvasId(canvasId).Resize();
+  }
 
   UpdateContentThread();
 }
 
-function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) {
+function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string, canvasIds: string[]) {
   
   Stone.Framework.Configure(wasmModuleName);
 
@@ -107,6 +110,6 @@
       event.preventDefault();
     }, false);
 
-    _InitializeWasmApplication("canvas", orthancBaseUrl);
+    _InitializeWasmApplication(canvasIds, orthancBaseUrl);
   });
 }
\ No newline at end of file
--- a/Platforms/Wasm/wasm-viewport.ts	Tue Oct 02 10:15:36 2018 +0200
+++ b/Platforms/Wasm/wasm-viewport.ts	Wed Oct 03 17:01:05 2018 +0200
@@ -19,7 +19,7 @@
   var canvasId = UTF8ToString(htmlCanvasId);
   var webViewport = new Stone.WasmViewport(StoneFrameworkModule, canvasId, cppViewportHandle);  // viewports are stored in a static map in WasmViewport -> won't be deleted
   webViewport.Initialize();
-
+  
   return cppViewportHandle;
 }
 
@@ -34,7 +34,8 @@
 
   export class WasmViewport {
 
-    private static cppWebViewportsMaps_ : Map<number, WasmViewport> = new Map<number, WasmViewport>();
+    private static viewportsMapByCppHandle_ : Map<number, WasmViewport> = new Map<number, WasmViewport>(); // key = the C++ handle
+    private static viewportsMapByCanvasId_ : Map<string, WasmViewport> = new Map<string, WasmViewport>(); // key = the canvasId
 
     private module_ : any;
     private canvasId_ : string;
@@ -60,7 +61,8 @@
     public constructor(module: any, canvasId: string, cppViewport: any) {
       
       this.pimpl_ = cppViewport;
-      WasmViewport.cppWebViewportsMaps_[this.pimpl_] = this;
+      WasmViewport.viewportsMapByCppHandle_[this.pimpl_] = this;
+      WasmViewport.viewportsMapByCanvasId_[canvasId] = this;
 
       this.module_ = module;
       this.canvasId_ = canvasId;
@@ -86,8 +88,16 @@
     }
 
     public static GetFromCppViewport(cppViewportHandle: number) : WasmViewport {
-      if (WasmViewport.cppWebViewportsMaps_[cppViewportHandle] !== undefined) {
-        return WasmViewport.cppWebViewportsMaps_[cppViewportHandle];
+      if (WasmViewport.viewportsMapByCppHandle_[cppViewportHandle] !== undefined) {
+        return WasmViewport.viewportsMapByCppHandle_[cppViewportHandle];
+      }
+      console.log("WasmViewport not found !");
+      return undefined;
+    }
+
+    public static GetFromCanvasId(canvasId: string) : WasmViewport {
+      if (WasmViewport.viewportsMapByCanvasId_[canvasId] !== undefined) {
+        return WasmViewport.viewportsMapByCanvasId_[canvasId];
       }
       console.log("WasmViewport not found !");
       return undefined;
@@ -139,6 +149,8 @@
         }
         
         this.renderingBuffer_ = this.module_._malloc(this.imageData_.width * this.imageData_.height * 4);
+      } else {
+        this.ViewportSetSize(this.pimpl_, this.htmlCanvas_.width, this.htmlCanvas_.height);
       }
       
       this.Redraw();