# HG changeset patch # User am@osimis.io # Date 1528994959 -7200 # Node ID 5027cb2feb51cd6b06d42f551bc11cb1eb6c3f02 # Parent 7d2631320615e23aa811cbc807c327ce7630ebd2 viewport is now part of the Application itself and not global anymore diff -r 7d2631320615 -r 5027cb2feb51 Applications/BasicApplicationContext.h --- a/Applications/BasicApplicationContext.h Thu Jun 14 17:14:10 2018 +0200 +++ b/Applications/BasicApplicationContext.h Thu Jun 14 18:49:19 2018 +0200 @@ -35,7 +35,7 @@ BasicApplicationContext() {} virtual IWebService& GetWebService() = 0; - virtual IWidget& SetCentralWidget(IWidget* widget) = 0; // Takes ownership +// virtual IWidget& SetCentralWidget(IWidget* widget) = 0; // Takes ownership virtual ~BasicApplicationContext() {} }; diff -r 7d2631320615 -r 5027cb2feb51 Applications/IBasicApplication.h --- a/Applications/IBasicApplication.h Thu Jun 14 17:14:10 2018 +0200 +++ b/Applications/IBasicApplication.h Thu Jun 14 18:49:19 2018 +0200 @@ -67,7 +67,7 @@ #if ORTHANC_ENABLE_SDL == 1 virtual BasicApplicationContext& CreateApplicationContext(Orthanc::WebServiceParameters& orthancWebService) = 0; #else - virtual BasicApplicationContext& CreateApplicationContext(IWebService& orthancWebService, std::shared_ptr centralViewport) = 0; + virtual BasicApplicationContext& CreateApplicationContext(IWebService& orthancWebService) = 0; #endif virtual std::string GetTitle() const = 0; diff -r 7d2631320615 -r 5027cb2feb51 Applications/Wasm/BasicWasmApplicationContext.cpp --- a/Applications/Wasm/BasicWasmApplicationContext.cpp Thu Jun 14 17:14:10 2018 +0200 +++ b/Applications/Wasm/BasicWasmApplicationContext.cpp Thu Jun 14 18:49:19 2018 +0200 @@ -2,13 +2,5 @@ namespace OrthancStone { - IWidget& BasicWasmApplicationContext::SetCentralWidget(IWidget* widget) // Takes ownership - { - printf("BasicWasmApplicationContext::SetCentralWidget %x %x\n", centralViewport_.get(), widget); - assert(centralViewport_.get() != NULL); - centralViewport_->SetCentralWidget(widget); - printf("BasicWasmApplicationContext::SetCentralWidget done\n"); - return *widget; - } } \ No newline at end of file diff -r 7d2631320615 -r 5027cb2feb51 Applications/Wasm/BasicWasmApplicationContext.h --- a/Applications/Wasm/BasicWasmApplicationContext.h Thu Jun 14 17:14:10 2018 +0200 +++ b/Applications/Wasm/BasicWasmApplicationContext.h Thu Jun 14 18:49:19 2018 +0200 @@ -30,18 +30,14 @@ class BasicWasmApplicationContext : public BasicApplicationContext { private: - std::shared_ptr centralViewport_; IWebService& webService_; public: - BasicWasmApplicationContext(IWebService& webService, std::shared_ptr centralViewport) //shared ownership of centralViewport - : webService_(webService), - centralViewport_(centralViewport) + BasicWasmApplicationContext(IWebService& webService) + : webService_(webService) { } - virtual IWidget& SetCentralWidget(IWidget* widget); // Takes ownership of central widget - IWebService& GetWebService() { return webService_; diff -r 7d2631320615 -r 5027cb2feb51 Platforms/WebAssembly/Defaults.cpp --- a/Platforms/WebAssembly/Defaults.cpp Thu Jun 14 17:14:10 2018 +0200 +++ b/Platforms/WebAssembly/Defaults.cpp Thu Jun 14 18:49:19 2018 +0200 @@ -73,7 +73,7 @@ application->SetStartupParameter(keyc, value); } - void EMSCRIPTEN_KEEPALIVE StartWasmApplication(ViewportHandle viewport) { + void EMSCRIPTEN_KEEPALIVE StartWasmApplication() { printf("StartWasmApplication\n"); @@ -81,10 +81,10 @@ boost::program_options::variables_map parameters; application->GetStartupParameters(parameters); - BasicWasmApplicationContext& context = dynamic_cast(application->CreateApplicationContext(OrthancStone::WasmWebService::GetInstance(), FindViewportSharedPtr(viewport))); + BasicWasmApplicationContext& context = dynamic_cast(application->CreateApplicationContext(OrthancStone::WasmWebService::GetInstance())); application->Initialize(statusBar_, parameters); - viewport->SetSize(width_, height_); +// viewport->SetSize(width_, height_); printf("StartWasmApplication - completed\n"); } diff -r 7d2631320615 -r 5027cb2feb51 Platforms/WebAssembly/WasmViewport.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Platforms/WebAssembly/WasmViewport.h Thu Jun 14 18:49:19 2018 +0200 @@ -0,0 +1,16 @@ +#pragma once + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + // JS methods accessible from C++ + extern OrthancStone::WidgetViewport* CreateWasmViewportFromCpp(const char* htmlCanvasId); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff -r 7d2631320615 -r 5027cb2feb51 Platforms/WebAssembly/default-library.js --- a/Platforms/WebAssembly/default-library.js Thu Jun 14 17:14:10 2018 +0200 +++ b/Platforms/WebAssembly/default-library.js Thu Jun 14 18:49:19 2018 +0200 @@ -3,6 +3,9 @@ mergeInto(LibraryManager.library, { ScheduleWebViewportRedrawFromCpp: function(cppViewportHandle) { ScheduleWebViewportRedraw(cppViewportHandle); - } - }); + }, + CreateWasmViewportFromCpp: function(htmlCanvasId) { + return CreateWasmViewport(htmlCanvasId); + } +}); \ No newline at end of file diff -r 7d2631320615 -r 5027cb2feb51 Platforms/WebAssembly/wasm-application.ts --- a/Platforms/WebAssembly/wasm-application.ts Thu Jun 14 17:14:10 2018 +0200 +++ b/Platforms/WebAssembly/wasm-application.ts Thu Jun 14 18:49:19 2018 +0200 @@ -7,8 +7,6 @@ declare var StoneFrameworkModule : Stone.Framework; -var viewport = null; - // global functions var WasmWebService_NotifyError: Function = null; var WasmWebService_NotifySuccess: Function = null; @@ -77,16 +75,6 @@ function InitializeWasmApplication(canvasId: string): void { - console.log("Creating main viewport"); - - viewport = new Stone.WasmViewport(StoneFrameworkModule, canvasId); - viewport.Initialize(CreateCppViewport()); - - document.getElementById(canvasId).onclick = function () { - viewport.Redraw(); - }; - - /************************************** */ CreateWasmApplication(); @@ -99,7 +87,7 @@ } } - StartWasmApplication(viewport.GetCppViewport()); + StartWasmApplication(); /************************************** */ UpdateContentThread(); @@ -112,9 +100,9 @@ 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']); + CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']); + CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []); + ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']); StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, []); WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']); diff -r 7d2631320615 -r 5027cb2feb51 Platforms/WebAssembly/wasm-viewport.ts --- a/Platforms/WebAssembly/wasm-viewport.ts Thu Jun 14 17:14:10 2018 +0200 +++ b/Platforms/WebAssembly/wasm-viewport.ts Thu Jun 14 18:49:19 2018 +0200 @@ -12,6 +12,17 @@ } } +declare function UTF8ToString(any): string; + +function CreateWasmViewport(htmlCanvasId: string) : any { + var cppViewportHandle = CreateCppViewport(); + 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; +} + module Stone { // export declare type InitializationCallback = () => void; @@ -46,7 +57,11 @@ private pimpl_ : any; // Private pointer to the underlying WebAssembly C++ object - public constructor(module: any, canvasId: string) { + public constructor(module: any, canvasId: string, cppViewport: any) { + + this.pimpl_ = cppViewport; + WasmViewport.cppWebViewportsMaps_[this.pimpl_] = this; + this.module_ = module; this.canvasId_ = canvasId; this.htmlCanvas_ = document.getElementById(this.canvasId_) as HTMLCanvasElement; @@ -120,11 +135,8 @@ this.Redraw(); } - public Initialize(cppViewport: any) { - this.pimpl_ = cppViewport; - WasmViewport.cppWebViewportsMaps_[this.pimpl_] = this; + public Initialize() { - console.log(this.pimpl_); // Force the rendering of the viewport for the first time this.Resize();