Mercurial > hg > orthanc-stone
changeset 1312:4f8c9065ee52 broker
coping with both viewport and loader changes
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 09 Mar 2020 14:56:04 +0100 |
parents | 3d26447ddd28 |
children | f30905f5d246 |
files | Applications/Generic/GuiAdapter.cpp Applications/Generic/GuiAdapter.h |
diffstat | 2 files changed, 45 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- 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<EM_BOOL>(capture), func); } - void GuiAdapter::SetResizeCallback(std::string canvasId, void* userData, bool capture, OnWindowResizeFunc func) - { - emscripten_set_resize_callback(canvasId.c_str(), userData, static_cast<EM_BOOL>(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<EM_BOOL>(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<OnWindowResizeFunc>(canvasId, func, userData)); + resizeHandlers_.push_back(EventHandlerData<OnSdlWindowResizeFunc>(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 */) {
--- 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<std::pair<OnAnimationFrameFunc, void*> > animationFrameHandlers_; - void OnResize(); + void OnResize(unsigned int width, unsigned int height); #if ORTHANC_ENABLE_SDL == 1 template<typename Func> @@ -326,14 +310,14 @@ Func func; void* userData; }; - std::vector<EventHandlerData<OnWindowResizeFunc> > resizeHandlers_; - std::vector<EventHandlerData<OnMouseEventFunc > > mouseDownHandlers_; - std::vector<EventHandlerData<OnMouseEventFunc > > mouseDblCickHandlers_; - std::vector<EventHandlerData<OnMouseEventFunc > > mouseMoveHandlers_; - std::vector<EventHandlerData<OnMouseEventFunc > > mouseUpHandlers_; - std::vector<EventHandlerData<OnMouseWheelFunc > > mouseWheelHandlers_; - std::vector<EventHandlerData<OnKeyDownFunc > > keyDownHandlers_; - std::vector<EventHandlerData<OnKeyUpFunc > > keyUpHandlers_; + std::vector<EventHandlerData<OnSdlWindowResizeFunc> > resizeHandlers_; + std::vector<EventHandlerData<OnMouseEventFunc > > mouseDownHandlers_; + std::vector<EventHandlerData<OnMouseEventFunc > > mouseDblCickHandlers_; + std::vector<EventHandlerData<OnMouseEventFunc > > mouseMoveHandlers_; + std::vector<EventHandlerData<OnMouseEventFunc > > mouseUpHandlers_; + std::vector<EventHandlerData<OnMouseWheelFunc > > mouseWheelHandlers_; + std::vector<EventHandlerData<OnKeyDownFunc > > keyDownHandlers_; + std::vector<EventHandlerData<OnKeyUpFunc > > keyUpHandlers_; /** This executes all the registered headers if needed (in wasm, the browser