changeset 2383:a77e2bb865c1 refactoring

fix WebAssemblyViewport
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 11 Oct 2026 09:56:48 +0200
parents d27f022ac3ec
children 83ea57ed2863
files OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyViewport.h OrthancStone/Sources/Scene2DViewport/ViewportController.cpp OrthancStone/Sources/Scene2DViewport/ViewportController.h
diffstat 3 files changed, 60 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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<ICompositor>          compositor_;
-    std::unique_ptr<ViewportController>   controller_;
+    boost::shared_ptr<ViewportController> controller_;
     std::unique_ptr<IViewportInteractor>  interactor_;
     bool                                  enableEmscriptenMouseEvents_;
     unsigned int                          canvasWidth_;
--- 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<boost::shared_ptr<MeasureTool> > 
-    ViewportController::HitTestMeasureTools(ScenePoint2D p)
+  ViewportController::HitTestMeasureTools(ScenePoint2D p)
   {
     std::vector<boost::shared_ptr<MeasureTool> > 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<IViewport> sharedViewport(viewport_.lock());
-
-    if (sharedViewport)
-    {
-      std::unique_ptr<IViewport::ILock> 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<IViewport> sharedViewport(viewport_.lock());
+
+    if (sharedViewport)
+    {
+      std::unique_ptr<IViewport::ILock> lock(sharedViewport->Lock());
+      lock->Invalidate();
+    }
+  }
+
+
+  void ViewportController::FitContent()
+  {
+    boost::shared_ptr<IViewport> sharedViewport(viewport_.lock());
+
+    if (sharedViewport)
+    {
+      std::unique_ptr<IViewport::ILock> 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<IViewport> sharedViewport(viewport_.lock());
+
+    if (sharedViewport)
+    {
+      std::unique_ptr<IViewport::ILock> lock(sharedViewport->Lock());
+      if (lock->HasCompositor())
+      {
+        width = lock->GetCompositor().GetCanvasWidth();
+        height = lock->GetCompositor().GetCanvasHeight();
+        return;
+      }
+    }
+
+    width = 0;
+    height = 0;
+  }
 }
--- 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