# HG changeset patch # User Sebastien Jodogne # Date 1791705408 -7200 # Node ID a77e2bb865c149b10bdaff2b997e9361e7889dc8 # Parent d27f022ac3ec005b0017343b22be80a2d3ef24ea fix WebAssemblyViewport diff -r d27f022ac3ec -r a77e2bb865c1 OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyViewport.h --- a/OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyViewport.h Fri Oct 09 16:50:12 2026 +0200 +++ b/OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyViewport.h Sun Oct 11 09:56:48 2026 +0200 @@ -58,7 +58,7 @@ std::string canvasId_; std::string canvasCssSelector_; std::unique_ptr compositor_; - std::unique_ptr controller_; + boost::shared_ptr controller_; std::unique_ptr interactor_; bool enableEmscriptenMouseEvents_; unsigned int canvasWidth_; diff -r d27f022ac3ec -r a77e2bb865c1 OrthancStone/Sources/Scene2DViewport/ViewportController.cpp --- a/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp Fri Oct 09 16:50:12 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/ViewportController.cpp Sun Oct 11 09:56:48 2026 +0200 @@ -101,7 +101,7 @@ } std::vector > - ViewportController::HitTestMeasureTools(ScenePoint2D p) + ViewportController::HitTestMeasureTools(ScenePoint2D p) { std::vector > ret; @@ -143,7 +143,7 @@ ORTHANC_ASSERT(std::find(measureTools_.begin(), measureTools_.end(), measureTool) == measureTools_.end(), - "Duplicate measure tool"); + "Duplicate measure tool"); measureTools_.push_back(measureTool); } @@ -154,7 +154,7 @@ ORTHANC_ASSERT(std::find(measureTools_.begin(), measureTools_.end(), measureTool) != measureTools_.end(), - "Measure tool not found"); + "Measure tool not found"); measureTools_.erase( std::remove(measureTools_.begin(), measureTools_.end(), measureTool), measureTools_.end()); @@ -191,18 +191,6 @@ } - void ViewportController::InvalidateViewport() - { - boost::shared_ptr sharedViewport(viewport_.lock()); - - if (sharedViewport) - { - std::unique_ptr lock(sharedViewport->Lock()); - lock->Invalidate(); - } - } - - void ViewportController::HandleMousePress(IViewportInteractor& interactor, const PointerEvent& event, unsigned int viewportWidth, @@ -285,4 +273,55 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); } } + + + void ViewportController::InvalidateViewport() + { + boost::shared_ptr sharedViewport(viewport_.lock()); + + if (sharedViewport) + { + std::unique_ptr lock(sharedViewport->Lock()); + lock->Invalidate(); + } + } + + + void ViewportController::FitContent() + { + boost::shared_ptr sharedViewport(viewport_.lock()); + + if (sharedViewport) + { + std::unique_ptr lock(sharedViewport->Lock()); + if (lock->HasCompositor()) + { + lock->GetCompositor().FitContent(*scene_); + lock->Invalidate(); + + BroadcastMessage(SceneTransformChanged(*this)); + } + } + } + + + void ViewportController::GetCanvasSize(unsigned int& width, + unsigned int& height) + { + boost::shared_ptr sharedViewport(viewport_.lock()); + + if (sharedViewport) + { + std::unique_ptr lock(sharedViewport->Lock()); + if (lock->HasCompositor()) + { + width = lock->GetCompositor().GetCanvasWidth(); + height = lock->GetCompositor().GetCanvasHeight(); + return; + } + } + + width = 0; + height = 0; + } } diff -r d27f022ac3ec -r a77e2bb865c1 OrthancStone/Sources/Scene2DViewport/ViewportController.h --- a/OrthancStone/Sources/Scene2DViewport/ViewportController.h Fri Oct 09 16:50:12 2026 +0200 +++ b/OrthancStone/Sources/Scene2DViewport/ViewportController.h Sun Oct 11 09:56:48 2026 +0200 @@ -193,6 +193,11 @@ void InvalidateViewport(); + void FitContent(); + + void GetCanvasSize(unsigned int& width, + unsigned int& height); + private: // The scene can be used by the higher-level objects (including the // measuring tools), possibly in their destructor, and so it must be