Mercurial > hg > orthanc-stone
changeset 231:5027cb2feb51 am
viewport is now part of the Application itself and not global anymore
author | am@osimis.io |
---|---|
date | Thu, 14 Jun 2018 18:49:19 +0200 |
parents | 7d2631320615 |
children | 7d3b2c4f9ba1 |
files | Applications/BasicApplicationContext.h Applications/IBasicApplication.h Applications/Wasm/BasicWasmApplicationContext.cpp Applications/Wasm/BasicWasmApplicationContext.h Platforms/WebAssembly/Defaults.cpp Platforms/WebAssembly/WasmViewport.h Platforms/WebAssembly/default-library.js Platforms/WebAssembly/wasm-application.ts Platforms/WebAssembly/wasm-viewport.ts |
diffstat | 9 files changed, 49 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- 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() {} };
--- 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<WidgetViewport> centralViewport) = 0; + virtual BasicApplicationContext& CreateApplicationContext(IWebService& orthancWebService) = 0; #endif virtual std::string GetTitle() const = 0;
--- 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
--- 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<WidgetViewport> centralViewport_; IWebService& webService_; public: - BasicWasmApplicationContext(IWebService& webService, std::shared_ptr<WidgetViewport> 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_;
--- 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<BasicWasmApplicationContext&>(application->CreateApplicationContext(OrthancStone::WasmWebService::GetInstance(), FindViewportSharedPtr(viewport))); + BasicWasmApplicationContext& context = dynamic_cast<BasicWasmApplicationContext&>(application->CreateApplicationContext(OrthancStone::WasmWebService::GetInstance())); application->Initialize(statusBar_, parameters); - viewport->SetSize(width_, height_); +// viewport->SetSize(width_, height_); printf("StartWasmApplication - completed\n"); }
--- /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 <Framework/Viewport/WidgetViewport.h> + +#include <emscripten/emscripten.h> + +#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
--- 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
--- 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']);
--- 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();