# HG changeset patch # User am@osimis.io # Date 1538578865 -7200 # Node ID 8bdc6112bc2e8b87744c2361f5e123332f04a11a # Parent a91ad36b684c09aad796d301fd4c0d5a68e12a3b initial resize of canvas diff -r a91ad36b684c -r 8bdc6112bc2e Framework/Widgets/WorldSceneWidget.cpp --- 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 #include #include +#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(y - downY_) / diff -r a91ad36b684c -r 8bdc6112bc2e Platforms/Wasm/wasm-application-runner.ts --- 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 { var parameters = window.location.search.substr(1); if (parameters != null && parameters != '') { - var result = {}; + var result = new Map(); var tokens = parameters.split('&'); for (var i = 0; i < tokens.length; i++) { @@ -47,7 +47,7 @@ return result; } else { - return {}; + return new Map(); } } @@ -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 diff -r a91ad36b684c -r 8bdc6112bc2e Platforms/Wasm/wasm-viewport.ts --- 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 = new Map(); + private static viewportsMapByCppHandle_ : Map = new Map(); // key = the C++ handle + private static viewportsMapByCanvasId_ : Map = new Map(); // 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();