# HG changeset patch # User Benjamin Golinvaux # Date 1583762164 -3600 # Node ID 4f8c9065ee52eb2128d862896118988ede84eeb4 # Parent 3d26447ddd2885a775495895a77cace8044325e9 coping with both viewport and loader changes diff -r 3d26447ddd28 -r 4f8c9065ee52 Applications/Generic/GuiAdapter.cpp --- a/Applications/Generic/GuiAdapter.cpp Mon Mar 09 14:55:22 2020 +0100 +++ b/Applications/Generic/GuiAdapter.cpp Mon Mar 09 14:56:04 2020 +0100 @@ -358,6 +358,8 @@ func); } +#if 0 + // useless under Wasm where canvas resize is handled automatically void GuiAdapter::SetResizeCallback( std::string canvasId, void* userData, bool capture, OnWindowResizeFunc func) { @@ -368,6 +370,7 @@ capture, func); } +#endif void GuiAdapter::RequestAnimationFrame( OnAnimationFrameFunc func, void* userData) @@ -393,10 +396,11 @@ emscripten_set_keyup_callback(canvasId.c_str(), userData, static_cast(capture), func); } - void GuiAdapter::SetResizeCallback(std::string canvasId, void* userData, bool capture, OnWindowResizeFunc func) - { - emscripten_set_resize_callback(canvasId.c_str(), userData, static_cast(capture), func); - } + // handled from within WebAssemblyViewport + //void GuiAdapter::SetResizeCallback(std::string canvasId, void* userData, bool capture, OnWindowResizeFunc func) + //{ + // emscripten_set_resize_callback(canvasId.c_str(), userData, static_cast(capture), func); + //} void GuiAdapter::RequestAnimationFrame(OnAnimationFrameFunc func, void* userData) { @@ -517,13 +521,14 @@ } - +#if ORTHANC_ENABLE_WASM != 1 // SDL ONLY - void GuiAdapter::SetResizeCallback( - std::string canvasId, void* userData, bool capture, OnWindowResizeFunc func) + void GuiAdapter::SetSdlResizeCallback( + std::string canvasId, void* userData, bool capture, OnSdlWindowResizeFunc func) { - resizeHandlers_.push_back(EventHandlerData(canvasId, func, userData)); + resizeHandlers_.push_back(EventHandlerData(canvasId, func, userData)); } +#endif // SDL ONLY void GuiAdapter::SetMouseDownCallback( @@ -596,12 +601,12 @@ } // SDL ONLY - void GuiAdapter::OnResize() + void GuiAdapter::OnResize(unsigned int width, unsigned int height) { for (size_t i = 0; i < resizeHandlers_.size(); i++) { (*(resizeHandlers_[i].func))( - resizeHandlers_[i].canvasName, 0, resizeHandlers_[i].userData); + resizeHandlers_[i].canvasName, nullptr, width, height, resizeHandlers_[i].userData); } } @@ -789,7 +794,7 @@ while (!stop) { { - Deprecated::LockingEmitter::WriterLock lock(lockingEmitter_); + // TODO: lock all viewports here! (use a scoped object) if(func != NULL) (*func)(cookie); OnAnimationFrame(); // in SDL we must call it @@ -799,7 +804,7 @@ while (!stop && SDL_PollEvent(&event)) { - Deprecated::LockingEmitter::WriterLock lock(lockingEmitter_); + // TODO: lock all viewports here! (use a scoped object) if (event.type == SDL_QUIT) { @@ -880,12 +885,14 @@ // locker.GetCentralViewport().MouseWheel(MouseWheelDirection_Down, x, y, modifiers); //} } - else if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) + else if (event.type == SDL_WINDOWEVENT && + (event.window.event == SDL_WINDOWEVENT_RESIZED || + event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) { #if 0 tracker.reset(); #endif - OnResize(); + OnResize(event.window.data1, event.window.data2); } else if (event.type == SDL_KEYDOWN && event.key.repeat == 0 /* Ignore key bounce */) { diff -r 3d26447ddd28 -r 4f8c9065ee52 Applications/Generic/GuiAdapter.h --- a/Applications/Generic/GuiAdapter.h Mon Mar 09 14:55:22 2020 +0100 +++ b/Applications/Generic/GuiAdapter.h Mon Mar 09 14:56:04 2020 +0100 @@ -102,7 +102,14 @@ typedef bool (*OnKeyUpFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData); typedef bool (*OnAnimationFrameFunc)(double time, void* userData); - typedef bool (*OnWindowResizeFunc)(std::string canvasId, const GuiAdapterUiEvent* uiEvent, void* userData); + +#if ORTHANC_ENABLE_WASM != 1 + typedef bool (*OnSdlWindowResizeFunc)(std::string canvasId, + const GuiAdapterUiEvent* uiEvent, + unsigned int width, + unsigned int height, + void* userData); +#endif #else @@ -222,11 +229,7 @@ class GuiAdapter { public: -#if ORTHANC_ENABLE_THREADS == 1 - GuiAdapter(Deprecated::LockingEmitter& lockingEmitter) : lockingEmitter_(lockingEmitter) -#else GuiAdapter() -#endif { static int instanceCount = 0; ORTHANC_ASSERT(instanceCount == 0); @@ -258,19 +261,19 @@ void SetKeyDownCallback (std::string canvasId, void* userData, bool capture, OnKeyDownFunc func); void SetKeyUpCallback (std::string canvasId, void* userData, bool capture, OnKeyUpFunc func); - // if you pass "#window", under SDL, then any Window resize will trigger the callback - void SetResizeCallback (std::string canvasId, void* userData, bool capture, OnWindowResizeFunc func); +#if ORTHANC_ENABLE_WASM != 1 + // if you pass "#window", then any Window resize will trigger the callback + void SetSdlResizeCallback(std::string canvasId, + void* userData, + bool capture, + OnSdlWindowResizeFunc func); +#endif void RequestAnimationFrame(OnAnimationFrameFunc func, void* userData); // TODO: implement and call to remove canvases [in SDL, although code should be generic] void SetOnExitCallback(); - // void - // OnWindowResize - // oracle - // broker - /** Under SDL, this function does NOT return until all windows have been closed. Under wasm, it returns without doing anything, since the event loop is managed @@ -278,27 +281,8 @@ */ void Run(GuiAdapterRunFunc func = NULL, void* cookie = NULL); -#if ORTHANC_ENABLE_WASM != 1 - /** - This method must be called in order for callback handler to be allowed to - be registered. - - We'll retrieve its name and use it as the canvas name in all subsequent - calls - */ - //void RegisterSdlWindow(SDL_Window* window); - //void UnregisterSdlWindow(SDL_Window* window); -#endif - private: -#if ORTHANC_ENABLE_THREADS == 1 - /** - This object is used by the multithreaded Oracle to serialize access to - shared data. We need to use it as soon as we access the state. - */ - Deprecated::LockingEmitter& lockingEmitter_; -#endif /** In SDL, this executes all the registered headers @@ -309,7 +293,7 @@ std::vector > animationFrameHandlers_; - void OnResize(); + void OnResize(unsigned int width, unsigned int height); #if ORTHANC_ENABLE_SDL == 1 template @@ -326,14 +310,14 @@ Func func; void* userData; }; - std::vector > resizeHandlers_; - std::vector > mouseDownHandlers_; - std::vector > mouseDblCickHandlers_; - std::vector > mouseMoveHandlers_; - std::vector > mouseUpHandlers_; - std::vector > mouseWheelHandlers_; - std::vector > keyDownHandlers_; - std::vector > keyUpHandlers_; + std::vector > resizeHandlers_; + std::vector > mouseDownHandlers_; + std::vector > mouseDblCickHandlers_; + std::vector > mouseMoveHandlers_; + std::vector > mouseUpHandlers_; + std::vector > mouseWheelHandlers_; + std::vector > keyDownHandlers_; + std::vector > keyUpHandlers_; /** This executes all the registered headers if needed (in wasm, the browser