changeset 1346:df8bf351c23f broker

The flag that allows the WebAssemblyViewport to **not** register the mouse events in the canvas (in case they are handled by other means) is now correctly passed down from the factory method.
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 06 Apr 2020 16:57:56 +0200
parents 0d6a01ffa1dd
children bfd77672d825
files Framework/Viewport/WebAssemblyViewport.cpp Framework/Viewport/WebAssemblyViewport.h Framework/Viewport/WebGLViewport.cpp Framework/Viewport/WebGLViewport.h
diffstat 4 files changed, 27 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Viewport/WebAssemblyViewport.cpp	Mon Apr 06 09:17:40 2020 +0200
+++ b/Framework/Viewport/WebAssemblyViewport.cpp	Mon Apr 06 16:57:56 2020 +0200
@@ -160,23 +160,16 @@
     
   EM_BOOL WebAssemblyViewport::OnMouseMove(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
   {
-    LOG(TRACE) << "WebAssemblyViewport::OnMouseMove CP1. userData = " << userData;
-    
     WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData);
-    LOG(TRACE) << "WebAssemblyViewport::OnMouseMove CP2";
 
     if (that->compositor_.get() != NULL &&
         that->controller_->HasActiveTracker())
     {
-      LOG(TRACE) << "WebAssemblyViewport::OnMouseMove CP3";
       PointerEvent pointer;
       ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_);
-      LOG(TRACE) << "WebAssemblyViewport::OnMouseMove CP4";
       if (that->controller_->HandleMouseMove(pointer))
       {
-        LOG(TRACE) << "WebAssemblyViewport::OnMouseMove CP5";
         that->Invalidate();
-        LOG(TRACE) << "WebAssemblyViewport::OnMouseMove CP6";
       }
     }
 
@@ -219,11 +212,11 @@
   }
 
   WebAssemblyViewport::WebAssemblyViewport(
-    const std::string& canvasId, bool enableEmscriptenEvents) :
+    const std::string& canvasId, bool enableEmscriptenMouseEvents) :
     shortCanvasId_(canvasId),
     fullCanvasId_(canvasId),
     interactor_(new DefaultViewportInteractor),
-    enableEmscriptenEvents_(enableEmscriptenEvents)
+    enableEmscriptenMouseEvents_(enableEmscriptenMouseEvents)
   {
   }
 
@@ -253,14 +246,15 @@
       shortCanvasId_.c_str()   // $0
       );
 
-    if (enableEmscriptenEvents_)
+    // It is not possible to monitor the resizing of individual
+    // canvas, so we track the full window of the browser
+    emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW,
+                                   reinterpret_cast<void*>(this),
+                                   false,
+                                   OnResize);
+
+    if (enableEmscriptenMouseEvents_)
     {
-      // It is not possible to monitor the resizing of individual
-      // canvas, so we track the full window of the browser
-      emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW,
-                                     reinterpret_cast<void*>(this),
-                                     false,
-                                     OnResize);
 
       emscripten_set_mousedown_callback(fullCanvasId_.c_str(),
                                         reinterpret_cast<void*>(this),
@@ -281,12 +275,13 @@
 
   WebAssemblyViewport::~WebAssemblyViewport()
   {
-    if (enableEmscriptenEvents_)
+    emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW,
+                                   reinterpret_cast<void*>(this),
+                                   false,
+                                   NULL);
+
+    if (enableEmscriptenMouseEvents_)
     {
-      emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW,
-                                     reinterpret_cast<void*>(this),
-                                     false,
-                                     NULL);
 
       emscripten_set_mousedown_callback(fullCanvasId_.c_str(),
                                         reinterpret_cast<void*>(this),
--- a/Framework/Viewport/WebAssemblyViewport.h	Mon Apr 06 09:17:40 2020 +0200
+++ b/Framework/Viewport/WebAssemblyViewport.h	Mon Apr 06 16:57:56 2020 +0200
@@ -53,7 +53,7 @@
     std::unique_ptr<ICompositor>          compositor_;
     std::unique_ptr<ViewportController>   controller_;
     std::unique_ptr<IViewportInteractor>  interactor_;
-    bool                                  enableEmscriptenEvents_;
+    bool                                  enableEmscriptenMouseEvents_;
 
     static EM_BOOL OnRequestAnimationFrame(double time, void *userData);
     
@@ -90,7 +90,7 @@
     to interactors is finished.
     */
     WebAssemblyViewport(const std::string& canvasId, 
-                        bool enableEmscriptenEvents = true);
+                        bool enableEmscriptenMouseEvents = true);
 
     void PostConstructor();
 
--- a/Framework/Viewport/WebGLViewport.cpp	Mon Apr 06 09:17:40 2020 +0200
+++ b/Framework/Viewport/WebGLViewport.cpp	Mon Apr 06 16:57:56 2020 +0200
@@ -79,18 +79,19 @@
     }
   }
 
-  WebGLViewport::WebGLViewport(const std::string& canvasId) :
-    WebAssemblyViewport(canvasId),
+  WebGLViewport::WebGLViewport(const std::string& canvasId, bool enableEmscriptenMouseEvents) :
+    WebAssemblyViewport(canvasId,enableEmscriptenMouseEvents),
     context_(GetFullCanvasId())
   {
     AcquireCompositor(new OpenGLCompositor(context_));
   }
 
   boost::shared_ptr<WebGLViewport> WebGLViewport::Create(
-    const std::string& canvasId)
+    const std::string& canvasId, bool enableEmscriptenMouseEvents)
   {
-    boost::shared_ptr<WebGLViewport> that = 
-      boost::shared_ptr<WebGLViewport>(new WebGLViewport(canvasId));
+    boost::shared_ptr<WebGLViewport> that = boost::shared_ptr<WebGLViewport>(
+        new WebGLViewport(canvasId, enableEmscriptenMouseEvents));
+    
     that->WebAssemblyViewport::PostConstructor();
     return that;
   }
--- a/Framework/Viewport/WebGLViewport.h	Mon Apr 06 09:17:40 2020 +0200
+++ b/Framework/Viewport/WebGLViewport.h	Mon Apr 06 16:57:56 2020 +0200
@@ -30,8 +30,8 @@
   {
   private:
     OpenGL::WebAssemblyOpenGLContext  context_;
-
-    WebGLViewport(const std::string& canvasId);
+    
+    WebGLViewport(const std::string& canvasId, bool enableEmscriptenMouseEvents);
 
   protected:
     virtual void Paint(ICompositor& compositor,
@@ -40,7 +40,7 @@
     virtual void UpdateSize(ICompositor& compositor) ORTHANC_OVERRIDE;
 
   public:
-    static boost::shared_ptr<WebGLViewport> Create(const std::string& canvasId);
+    static boost::shared_ptr<WebGLViewport> Create(const std::string& canvasId, bool enableEmscriptenMouseEvents = true);
 
     virtual ~WebGLViewport();