Mercurial > hg > orthanc-stone
diff Applications/Generic/GuiAdapter.h @ 1313:f30905f5d246 broker
Added support for OnGenericSdlEvent to GuiAdapter.
This makes it possible to piggyback app-specific logic
to special events (here, to support the Viewport refresh
events)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 16 Mar 2020 11:12:39 +0100 |
parents | 4f8c9065ee52 |
children | cbfdba08e039 |
line wrap: on
line diff
--- a/Applications/Generic/GuiAdapter.h Mon Mar 09 14:56:04 2020 +0100 +++ b/Applications/Generic/GuiAdapter.h Mon Mar 16 11:12:39 2020 +0100 @@ -53,6 +53,14 @@ namespace OrthancStone { +#if ORTHANC_ENABLE_WASM != 1 + class SdlViewport; +#endif + +#if 0 + + // events are now handled directly by the VolumeSlicerWidget... The + // GuiAdapter doesn't know about widgets anymore /** This interface is used to store the widgets that are controlled by the @@ -64,8 +72,17 @@ { public: virtual ~IGuiAdapterWidget() {} + +#if ORTHANC_ENABLE_WASM != 1 + /** + Returns the SdlViewport that this widget contains. If the underlying + viewport type is *not* SDL, then an error is returned. + */ + virtual SdlViewport& GetSdlViewport() = 0; +#endif + }; - }; +#endif enum GuiAdapterMouseButtonType { @@ -96,12 +113,12 @@ struct GuiAdapterKeyboardEvent; #if 1 - typedef bool (*OnMouseEventFunc)(std::string canvasId, const GuiAdapterMouseEvent* mouseEvent, void* userData); - typedef bool (*OnMouseWheelFunc)(std::string canvasId, const GuiAdapterWheelEvent* wheelEvent, void* userData); - typedef bool (*OnKeyDownFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData); - typedef bool (*OnKeyUpFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData); - + typedef bool (*OnMouseEventFunc) (std::string canvasId, const GuiAdapterMouseEvent* mouseEvent, void* userData); + typedef bool (*OnMouseWheelFunc) (std::string canvasId, const GuiAdapterWheelEvent* wheelEvent, void* userData); + typedef bool (*OnKeyDownFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData); + typedef bool (*OnKeyUpFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData); typedef bool (*OnAnimationFrameFunc)(double time, void* userData); + typedef bool (*OnSdlEventCallback) (std::string canvasId, const SDL_Event& sdlEvent, void* userData); #if ORTHANC_ENABLE_WASM != 1 typedef bool (*OnSdlWindowResizeFunc)(std::string canvasId, @@ -109,6 +126,8 @@ unsigned int width, unsigned int height, void* userData); + + #endif #else @@ -253,14 +272,18 @@ */ - void SetMouseDownCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); - void SetMouseDblClickCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); - void SetMouseMoveCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); - void SetMouseUpCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); - void SetWheelCallback (std::string canvasId, void* userData, bool capture, OnMouseWheelFunc func); - void SetKeyDownCallback (std::string canvasId, void* userData, bool capture, OnKeyDownFunc func); - void SetKeyUpCallback (std::string canvasId, void* userData, bool capture, OnKeyUpFunc func); - + void SetMouseDownCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); + void SetMouseDblClickCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); + void SetMouseMoveCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); + void SetMouseUpCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); + void SetWheelCallback (std::string canvasId, void* userData, bool capture, OnMouseWheelFunc func); + void SetKeyDownCallback (std::string canvasId, void* userData, bool capture, OnKeyDownFunc func); + void SetKeyUpCallback (std::string canvasId, void* userData, bool capture, OnKeyUpFunc func); + void SetGenericSdlEventCallback (std::string canvasId, void* userData, bool capture, OnSdlEventCallback func); + + typedef bool (*OnSdlEventCallback) (std::string canvasId, const SDL_Event& sdlEvent, void* userData); + + #if ORTHANC_ENABLE_WASM != 1 // if you pass "#window", then any Window resize will trigger the callback void SetSdlResizeCallback(std::string canvasId, @@ -283,6 +306,13 @@ private: +#if ORTHANC_ENABLE_WASM != 1 + /** + Gives observers a chance to react based on generic event handlers. This + is used, for instance, when the viewport lock interface is invalidated. + */ + void OnSdlGenericEvent(const SDL_Event& sdlEvent); +#endif /** In SDL, this executes all the registered headers @@ -318,6 +348,7 @@ std::vector<EventHandlerData<OnMouseWheelFunc > > mouseWheelHandlers_; std::vector<EventHandlerData<OnKeyDownFunc > > keyDownHandlers_; std::vector<EventHandlerData<OnKeyUpFunc > > keyUpHandlers_; + std::vector<EventHandlerData<OnSdlEventCallback > > sdlEventHandlers_; /** This executes all the registered headers if needed (in wasm, the browser @@ -332,8 +363,6 @@ */ void OnMouseWheelEvent(uint32_t windowID, const GuiAdapterWheelEvent& event); - boost::shared_ptr<IGuiAdapterWidget> GetWidgetFromWindowId(); - #endif /**