Mercurial > hg > orthanc-stone
comparison 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 |
comparison
equal
deleted
inserted
replaced
1312:4f8c9065ee52 | 1313:f30905f5d246 |
---|---|
51 #include <boost/shared_ptr.hpp> | 51 #include <boost/shared_ptr.hpp> |
52 #include <boost/weak_ptr.hpp> | 52 #include <boost/weak_ptr.hpp> |
53 | 53 |
54 namespace OrthancStone | 54 namespace OrthancStone |
55 { | 55 { |
56 #if ORTHANC_ENABLE_WASM != 1 | |
57 class SdlViewport; | |
58 #endif | |
59 | |
60 #if 0 | |
61 | |
62 // events are now handled directly by the VolumeSlicerWidget... The | |
63 // GuiAdapter doesn't know about widgets anymore | |
56 | 64 |
57 /** | 65 /** |
58 This interface is used to store the widgets that are controlled by the | 66 This interface is used to store the widgets that are controlled by the |
59 GuiAdapter and receive event callbacks. | 67 GuiAdapter and receive event callbacks. |
60 The callbacks may possibly be downcast (using dynamic_cast, for safety) \ | 68 The callbacks may possibly be downcast (using dynamic_cast, for safety) \ |
62 */ | 70 */ |
63 class IGuiAdapterWidget | 71 class IGuiAdapterWidget |
64 { | 72 { |
65 public: | 73 public: |
66 virtual ~IGuiAdapterWidget() {} | 74 virtual ~IGuiAdapterWidget() {} |
67 | 75 |
68 }; | 76 #if ORTHANC_ENABLE_WASM != 1 |
77 /** | |
78 Returns the SdlViewport that this widget contains. If the underlying | |
79 viewport type is *not* SDL, then an error is returned. | |
80 */ | |
81 virtual SdlViewport& GetSdlViewport() = 0; | |
82 #endif | |
83 }; | |
84 | |
85 #endif | |
69 | 86 |
70 enum GuiAdapterMouseButtonType | 87 enum GuiAdapterMouseButtonType |
71 { | 88 { |
72 GUIADAPTER_MOUSEBUTTON_LEFT = 0, | 89 GUIADAPTER_MOUSEBUTTON_LEFT = 0, |
73 GUIADAPTER_MOUSEBUTTON_MIDDLE = 1, | 90 GUIADAPTER_MOUSEBUTTON_MIDDLE = 1, |
94 struct GuiAdapterMouseEvent; | 111 struct GuiAdapterMouseEvent; |
95 struct GuiAdapterWheelEvent; | 112 struct GuiAdapterWheelEvent; |
96 struct GuiAdapterKeyboardEvent; | 113 struct GuiAdapterKeyboardEvent; |
97 | 114 |
98 #if 1 | 115 #if 1 |
99 typedef bool (*OnMouseEventFunc)(std::string canvasId, const GuiAdapterMouseEvent* mouseEvent, void* userData); | 116 typedef bool (*OnMouseEventFunc) (std::string canvasId, const GuiAdapterMouseEvent* mouseEvent, void* userData); |
100 typedef bool (*OnMouseWheelFunc)(std::string canvasId, const GuiAdapterWheelEvent* wheelEvent, void* userData); | 117 typedef bool (*OnMouseWheelFunc) (std::string canvasId, const GuiAdapterWheelEvent* wheelEvent, void* userData); |
101 typedef bool (*OnKeyDownFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData); | 118 typedef bool (*OnKeyDownFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData); |
102 typedef bool (*OnKeyUpFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData); | 119 typedef bool (*OnKeyUpFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData); |
103 | |
104 typedef bool (*OnAnimationFrameFunc)(double time, void* userData); | 120 typedef bool (*OnAnimationFrameFunc)(double time, void* userData); |
121 typedef bool (*OnSdlEventCallback) (std::string canvasId, const SDL_Event& sdlEvent, void* userData); | |
105 | 122 |
106 #if ORTHANC_ENABLE_WASM != 1 | 123 #if ORTHANC_ENABLE_WASM != 1 |
107 typedef bool (*OnSdlWindowResizeFunc)(std::string canvasId, | 124 typedef bool (*OnSdlWindowResizeFunc)(std::string canvasId, |
108 const GuiAdapterUiEvent* uiEvent, | 125 const GuiAdapterUiEvent* uiEvent, |
109 unsigned int width, | 126 unsigned int width, |
110 unsigned int height, | 127 unsigned int height, |
111 void* userData); | 128 void* userData); |
129 | |
130 | |
112 #endif | 131 #endif |
113 | 132 |
114 #else | 133 #else |
115 | 134 |
116 #if ORTHANC_ENABLE_WASM == 1 | 135 #if ORTHANC_ENABLE_WASM == 1 |
251 SDL: | 270 SDL: |
252 see https://wiki.libsdl.org/SDL_CaptureMouse | 271 see https://wiki.libsdl.org/SDL_CaptureMouse |
253 | 272 |
254 */ | 273 */ |
255 | 274 |
256 void SetMouseDownCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); | 275 void SetMouseDownCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); |
257 void SetMouseDblClickCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); | 276 void SetMouseDblClickCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); |
258 void SetMouseMoveCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); | 277 void SetMouseMoveCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); |
259 void SetMouseUpCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); | 278 void SetMouseUpCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); |
260 void SetWheelCallback (std::string canvasId, void* userData, bool capture, OnMouseWheelFunc func); | 279 void SetWheelCallback (std::string canvasId, void* userData, bool capture, OnMouseWheelFunc func); |
261 void SetKeyDownCallback (std::string canvasId, void* userData, bool capture, OnKeyDownFunc func); | 280 void SetKeyDownCallback (std::string canvasId, void* userData, bool capture, OnKeyDownFunc func); |
262 void SetKeyUpCallback (std::string canvasId, void* userData, bool capture, OnKeyUpFunc func); | 281 void SetKeyUpCallback (std::string canvasId, void* userData, bool capture, OnKeyUpFunc func); |
263 | 282 void SetGenericSdlEventCallback (std::string canvasId, void* userData, bool capture, OnSdlEventCallback func); |
283 | |
284 typedef bool (*OnSdlEventCallback) (std::string canvasId, const SDL_Event& sdlEvent, void* userData); | |
285 | |
286 | |
264 #if ORTHANC_ENABLE_WASM != 1 | 287 #if ORTHANC_ENABLE_WASM != 1 |
265 // if you pass "#window", then any Window resize will trigger the callback | 288 // if you pass "#window", then any Window resize will trigger the callback |
266 void SetSdlResizeCallback(std::string canvasId, | 289 void SetSdlResizeCallback(std::string canvasId, |
267 void* userData, | 290 void* userData, |
268 bool capture, | 291 bool capture, |
281 */ | 304 */ |
282 void Run(GuiAdapterRunFunc func = NULL, void* cookie = NULL); | 305 void Run(GuiAdapterRunFunc func = NULL, void* cookie = NULL); |
283 | 306 |
284 private: | 307 private: |
285 | 308 |
309 #if ORTHANC_ENABLE_WASM != 1 | |
310 /** | |
311 Gives observers a chance to react based on generic event handlers. This | |
312 is used, for instance, when the viewport lock interface is invalidated. | |
313 */ | |
314 void OnSdlGenericEvent(const SDL_Event& sdlEvent); | |
315 #endif | |
286 | 316 |
287 /** | 317 /** |
288 In SDL, this executes all the registered headers | 318 In SDL, this executes all the registered headers |
289 */ | 319 */ |
290 void OnAnimationFrame(); | 320 void OnAnimationFrame(); |
316 std::vector<EventHandlerData<OnMouseEventFunc > > mouseMoveHandlers_; | 346 std::vector<EventHandlerData<OnMouseEventFunc > > mouseMoveHandlers_; |
317 std::vector<EventHandlerData<OnMouseEventFunc > > mouseUpHandlers_; | 347 std::vector<EventHandlerData<OnMouseEventFunc > > mouseUpHandlers_; |
318 std::vector<EventHandlerData<OnMouseWheelFunc > > mouseWheelHandlers_; | 348 std::vector<EventHandlerData<OnMouseWheelFunc > > mouseWheelHandlers_; |
319 std::vector<EventHandlerData<OnKeyDownFunc > > keyDownHandlers_; | 349 std::vector<EventHandlerData<OnKeyDownFunc > > keyDownHandlers_; |
320 std::vector<EventHandlerData<OnKeyUpFunc > > keyUpHandlers_; | 350 std::vector<EventHandlerData<OnKeyUpFunc > > keyUpHandlers_; |
351 std::vector<EventHandlerData<OnSdlEventCallback > > sdlEventHandlers_; | |
321 | 352 |
322 /** | 353 /** |
323 This executes all the registered headers if needed (in wasm, the browser | 354 This executes all the registered headers if needed (in wasm, the browser |
324 deals with this) | 355 deals with this) |
325 */ | 356 */ |
330 /** | 361 /** |
331 Same remark as OnMouseEvent | 362 Same remark as OnMouseEvent |
332 */ | 363 */ |
333 void OnMouseWheelEvent(uint32_t windowID, const GuiAdapterWheelEvent& event); | 364 void OnMouseWheelEvent(uint32_t windowID, const GuiAdapterWheelEvent& event); |
334 | 365 |
335 boost::shared_ptr<IGuiAdapterWidget> GetWidgetFromWindowId(); | |
336 | |
337 #endif | 366 #endif |
338 | 367 |
339 /** | 368 /** |
340 This executes all the registered headers if needed (in wasm, the browser | 369 This executes all the registered headers if needed (in wasm, the browser |
341 deals with this) | 370 deals with this) |