changeset 895:6073c980323a am-dev

wip: adapting basic scene webassembly sample
author Alain Mazy <alain@mazy.be>
date Fri, 12 Jul 2019 14:57:06 +0200
parents 5cfb479fdbde
children 875bd6aca5e6
files Samples/Qt/BasicScene.cpp Samples/Shared/SharedBasicScene.cpp Samples/Shared/SharedBasicScene.h Samples/WebAssembly/BasicScene.cpp Samples/WebAssembly/CMakeLists.txt Samples/WebAssembly/dev.h
diffstat 6 files changed, 19 insertions(+), 101 deletions(-) [+]
line wrap: on
line diff
--- a/Samples/Qt/BasicScene.cpp	Tue Jul 09 17:36:47 2019 +0200
+++ b/Samples/Qt/BasicScene.cpp	Fri Jul 12 14:57:06 2019 +0200
@@ -94,7 +94,7 @@
     boost::shared_ptr<UndoStack> undoStack(new UndoStack);
     boost::shared_ptr<ViewportController> controller = boost::make_shared<ViewportController>(
       undoStack, boost::ref(broker));
-    PrepareScene(controller);
+    PrepareScene(*(controller->GetScene()));
 
     boost::shared_ptr<OrthancStone::Scene2DInteractor> interactor(new BasicScene2DInteractor(controller));
     window.GetOpenGlWidget().SetInteractor(interactor);
--- a/Samples/Shared/SharedBasicScene.cpp	Tue Jul 09 17:36:47 2019 +0200
+++ b/Samples/Shared/SharedBasicScene.cpp	Fri Jul 12 14:57:06 2019 +0200
@@ -42,9 +42,9 @@
 const unsigned int BASIC_SCENE_FONT_SIZE = 32;
 const int BASIC_SCENE_LAYER_POSITION = 150;
 
-void PrepareScene(boost::shared_ptr<OrthancStone::ViewportController> controller)
+void PrepareScene(Scene2D& scene)
 {
-  Scene2D& scene(*controller->GetScene());
+  //Scene2D& scene(*controller->GetScene());
   // Texture of 2x2 size
   {
     Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false);
@@ -131,6 +131,7 @@
   }
 }
 
+#if ORTHANC_SANDBOXED == 0
 void TakeScreenshot(const std::string& target,
                     const OrthancStone::Scene2D& scene,
                     unsigned int canvasWidth,
@@ -151,6 +152,7 @@
   Orthanc::PngWriter writer;
   writer.WriteToFile(target, png);
 }
+#endif
 
 void ShowCursorInfo(Scene2D& scene, const PointerEvent& pointerEvent)
 {
@@ -199,6 +201,8 @@
     {
       currentTracker_->PointerMove(pointerEvent);
     };break;
+    default:
+      return false;
     }
     return true;
   }
@@ -240,12 +244,14 @@
       viewportController_->FitContent(compositor_->GetWidth(), compositor_->GetHeight());
       return true;
     };
+#if ORTHANC_SANDBOXED == 0
     case 'c':
     {
       Scene2D& scene(*(viewportController_->GetScene()));
       TakeScreenshot("screenshot.png", scene, compositor_->GetWidth(), compositor_->GetHeight());
       return true;
     }
+#endif
     case 'd':
     {
       showCursorInfo_ = !showCursorInfo_;
--- a/Samples/Shared/SharedBasicScene.h	Tue Jul 09 17:36:47 2019 +0200
+++ b/Samples/Shared/SharedBasicScene.h	Fri Jul 12 14:57:06 2019 +0200
@@ -22,11 +22,12 @@
 
 #include <boost/shared_ptr.hpp>
 #include "../../Framework/Scene2DViewport/ViewportController.h"
+#include "../../Framework/Scene2D/Scene2D.h"
 
 extern const unsigned int BASIC_SCENE_FONT_SIZE;
 extern const int BASIC_SCENE_LAYER_POSITION;
 
-extern void PrepareScene(boost::shared_ptr<OrthancStone::ViewportController> controller);
+extern void PrepareScene(OrthancStone::Scene2D& scene);
 extern void TakeScreenshot(const std::string& target,
                            const OrthancStone::Scene2D& scene,
                            unsigned int canvasWidth,
@@ -48,7 +49,7 @@
   {}
 
   virtual bool OnMouseEvent(const OrthancStone::GuiAdapterMouseEvent& event, const OrthancStone::PointerEvent& pointerEvent) override;
-  virtual bool OnKeyboardEvent(const OrthancStone::GuiAdapterKeyboardEvent& guiEvent);
-  virtual bool OnWheelEvent(const OrthancStone::GuiAdapterWheelEvent& guiEvent);
+  virtual bool OnKeyboardEvent(const OrthancStone::GuiAdapterKeyboardEvent& guiEvent) override;
+  virtual bool OnWheelEvent(const OrthancStone::GuiAdapterWheelEvent& guiEvent) override;
 };
 
--- a/Samples/WebAssembly/BasicScene.cpp	Tue Jul 09 17:36:47 2019 +0200
+++ b/Samples/WebAssembly/BasicScene.cpp	Fri Jul 12 14:57:06 2019 +0200
@@ -33,98 +33,7 @@
 #include <Core/Logging.h>
 #include <Core/OrthancException.h>
 
-void PrepareScene(OrthancStone::Scene2D& scene)
-{
-  using namespace OrthancStone;
-
-  // Texture of 2x2 size
-  if (1)
-  {
-    Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false);
-    
-    uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0));
-    p[0] = 255;
-    p[1] = 0;
-    p[2] = 0;
-
-    p[3] = 0;
-    p[4] = 255;
-    p[5] = 0;
-
-    p = reinterpret_cast<uint8_t*>(i.GetRow(1));
-    p[0] = 0;
-    p[1] = 0;
-    p[2] = 255;
-
-    p[3] = 255;
-    p[4] = 0;
-    p[5] = 0;
-
-    scene.SetLayer(12, new ColorTextureSceneLayer(i));
-
-    std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i));
-    l->SetOrigin(-3, 2);
-    l->SetPixelSpacing(1.5, 1);
-    l->SetAngle(20.0 / 180.0 * M_PI);
-    scene.SetLayer(14, l.release());
-  }
-
-  // Texture of 1x1 size
-  if (1)
-  {
-    Orthanc::Image i(Orthanc::PixelFormat_RGB24, 1, 1, false);
-    
-    uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0));
-    p[0] = 255;
-    p[1] = 0;
-    p[2] = 0;
-
-    std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i));
-    l->SetOrigin(-2, 1);
-    l->SetAngle(20.0 / 180.0 * M_PI);
-    scene.SetLayer(13, l.release());
-  }
-
-  // Some lines
-  {
-    std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
-
-    layer->SetThickness(1);
-
-    PolylineSceneLayer::Chain chain;
-    chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5));
-    chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5));
-    chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5));
-    chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5));
-    layer->AddChain(chain, true, 255, 0, 0);
-
-    chain.clear();
-    chain.push_back(ScenePoint2D(-5, -5));
-    chain.push_back(ScenePoint2D(5, -5));
-    chain.push_back(ScenePoint2D(5, 5));
-    chain.push_back(ScenePoint2D(-5, 5));
-    layer->AddChain(chain, true, 0, 255, 0);
-
-    double dy = 1.01;
-    chain.clear();
-    chain.push_back(ScenePoint2D(-4, -4));
-    chain.push_back(ScenePoint2D(4, -4 + dy));
-    chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy));
-    chain.push_back(ScenePoint2D(4, 2));
-    layer->AddChain(chain, false, 0, 0, 255);
-
-    scene.SetLayer(50, layer.release());
-  }
-
-  // Some text
-  if (1)
-  {
-    std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer);
-    layer->SetText("Hello");
-    scene.SetLayer(100, layer.release());
-  }
-}
-
+#include "../Shared/SharedBasicScene.h"
 
 std::auto_ptr<OrthancStone::WebAssemblyViewport>  viewport1_;
 std::auto_ptr<OrthancStone::WebAssemblyViewport>  viewport2_;
--- a/Samples/WebAssembly/CMakeLists.txt	Tue Jul 09 17:36:47 2019 +0200
+++ b/Samples/WebAssembly/CMakeLists.txt	Fri Jul 12 14:57:06 2019 +0200
@@ -77,6 +77,8 @@
 if (ON)
   add_executable(BasicScene
     BasicScene.cpp
+    ${CMAKE_CURRENT_LIST_DIR}/../Shared/SharedBasicScene.h
+    ${CMAKE_CURRENT_LIST_DIR}/../Shared/SharedBasicScene.cpp
     )
 
   target_link_libraries(BasicScene OrthancStone)
--- a/Samples/WebAssembly/dev.h	Tue Jul 09 17:36:47 2019 +0200
+++ b/Samples/WebAssembly/dev.h	Fri Jul 12 14:57:06 2019 +0200
@@ -119,9 +119,9 @@
     
   public:
     ActiveTracker(const boost::shared_ptr<IFlexiblePointerTracker>& tracker,
-                  const WebAssemblyViewport& viewport) :
+                  const std::string& canvasIdentifier) :
       tracker_(tracker),
-      canvasIdentifier_(viewport.GetCanvasIdentifier()),
+      canvasIdentifier_(canvasIdentifier),
       insideCanvas_(true)
     {
       if (tracker_.get() == NULL)
@@ -227,7 +227,7 @@
         if (t.get() != NULL)
         {
           tracker_.reset(
-            new OrthancStone::ActiveTracker(t, viewport));
+            new OrthancStone::ActiveTracker(t, viewport.GetCanvasIdentifier()));
           viewport.Refresh();
         }