comparison Applications/Generic/GuiAdapter.h @ 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 6ab03e429f06
children f30905f5d246
comparison
equal deleted inserted replaced
1311:3d26447ddd28 1312:4f8c9065ee52
100 typedef bool (*OnMouseWheelFunc)(std::string canvasId, const GuiAdapterWheelEvent* wheelEvent, void* userData); 100 typedef bool (*OnMouseWheelFunc)(std::string canvasId, const GuiAdapterWheelEvent* wheelEvent, void* userData);
101 typedef bool (*OnKeyDownFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData); 101 typedef bool (*OnKeyDownFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData);
102 typedef bool (*OnKeyUpFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData); 102 typedef bool (*OnKeyUpFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData);
103 103
104 typedef bool (*OnAnimationFrameFunc)(double time, void* userData); 104 typedef bool (*OnAnimationFrameFunc)(double time, void* userData);
105 typedef bool (*OnWindowResizeFunc)(std::string canvasId, const GuiAdapterUiEvent* uiEvent, void* userData); 105
106 #if ORTHANC_ENABLE_WASM != 1
107 typedef bool (*OnSdlWindowResizeFunc)(std::string canvasId,
108 const GuiAdapterUiEvent* uiEvent,
109 unsigned int width,
110 unsigned int height,
111 void* userData);
112 #endif
106 113
107 #else 114 #else
108 115
109 #if ORTHANC_ENABLE_WASM == 1 116 #if ORTHANC_ENABLE_WASM == 1
110 typedef EM_BOOL (*OnMouseEventFunc)(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData); 117 typedef EM_BOOL (*OnMouseEventFunc)(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData);
220 typedef void (*GuiAdapterRunFunc)(void*); 227 typedef void (*GuiAdapterRunFunc)(void*);
221 228
222 class GuiAdapter 229 class GuiAdapter
223 { 230 {
224 public: 231 public:
225 #if ORTHANC_ENABLE_THREADS == 1
226 GuiAdapter(Deprecated::LockingEmitter& lockingEmitter) : lockingEmitter_(lockingEmitter)
227 #else
228 GuiAdapter() 232 GuiAdapter()
229 #endif
230 { 233 {
231 static int instanceCount = 0; 234 static int instanceCount = 0;
232 ORTHANC_ASSERT(instanceCount == 0); 235 ORTHANC_ASSERT(instanceCount == 0);
233 instanceCount = 1; 236 instanceCount = 1;
234 } 237 }
256 void SetMouseUpCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func); 259 void SetMouseUpCallback (std::string canvasId, void* userData, bool capture, OnMouseEventFunc func);
257 void SetWheelCallback (std::string canvasId, void* userData, bool capture, OnMouseWheelFunc func); 260 void SetWheelCallback (std::string canvasId, void* userData, bool capture, OnMouseWheelFunc func);
258 void SetKeyDownCallback (std::string canvasId, void* userData, bool capture, OnKeyDownFunc func); 261 void SetKeyDownCallback (std::string canvasId, void* userData, bool capture, OnKeyDownFunc func);
259 void SetKeyUpCallback (std::string canvasId, void* userData, bool capture, OnKeyUpFunc func); 262 void SetKeyUpCallback (std::string canvasId, void* userData, bool capture, OnKeyUpFunc func);
260 263
261 // if you pass "#window", under SDL, then any Window resize will trigger the callback 264 #if ORTHANC_ENABLE_WASM != 1
262 void SetResizeCallback (std::string canvasId, void* userData, bool capture, OnWindowResizeFunc func); 265 // if you pass "#window", then any Window resize will trigger the callback
266 void SetSdlResizeCallback(std::string canvasId,
267 void* userData,
268 bool capture,
269 OnSdlWindowResizeFunc func);
270 #endif
263 271
264 void RequestAnimationFrame(OnAnimationFrameFunc func, void* userData); 272 void RequestAnimationFrame(OnAnimationFrameFunc func, void* userData);
265 273
266 // TODO: implement and call to remove canvases [in SDL, although code should be generic] 274 // TODO: implement and call to remove canvases [in SDL, although code should be generic]
267 void SetOnExitCallback(); 275 void SetOnExitCallback();
268
269 // void
270 // OnWindowResize
271 // oracle
272 // broker
273 276
274 /** 277 /**
275 Under SDL, this function does NOT return until all windows have been closed. 278 Under SDL, this function does NOT return until all windows have been closed.
276 Under wasm, it returns without doing anything, since the event loop is managed 279 Under wasm, it returns without doing anything, since the event loop is managed
277 by the browser. 280 by the browser.
278 */ 281 */
279 void Run(GuiAdapterRunFunc func = NULL, void* cookie = NULL); 282 void Run(GuiAdapterRunFunc func = NULL, void* cookie = NULL);
280 283
281 #if ORTHANC_ENABLE_WASM != 1
282 /**
283 This method must be called in order for callback handler to be allowed to
284 be registered.
285
286 We'll retrieve its name and use it as the canvas name in all subsequent
287 calls
288 */
289 //void RegisterSdlWindow(SDL_Window* window);
290 //void UnregisterSdlWindow(SDL_Window* window);
291 #endif
292
293 private: 284 private:
294 285
295 #if ORTHANC_ENABLE_THREADS == 1
296 /**
297 This object is used by the multithreaded Oracle to serialize access to
298 shared data. We need to use it as soon as we access the state.
299 */
300 Deprecated::LockingEmitter& lockingEmitter_;
301 #endif
302 286
303 /** 287 /**
304 In SDL, this executes all the registered headers 288 In SDL, this executes all the registered headers
305 */ 289 */
306 void OnAnimationFrame(); 290 void OnAnimationFrame();
307 291
308 //void RequestAnimationFrame(OnAnimationFrameFunc func, void* userData); 292 //void RequestAnimationFrame(OnAnimationFrameFunc func, void* userData);
309 std::vector<std::pair<OnAnimationFrameFunc, void*> > 293 std::vector<std::pair<OnAnimationFrameFunc, void*> >
310 animationFrameHandlers_; 294 animationFrameHandlers_;
311 295
312 void OnResize(); 296 void OnResize(unsigned int width, unsigned int height);
313 297
314 #if ORTHANC_ENABLE_SDL == 1 298 #if ORTHANC_ENABLE_SDL == 1
315 template<typename Func> 299 template<typename Func>
316 struct EventHandlerData 300 struct EventHandlerData
317 { 301 {
324 308
325 std::string canvasName; 309 std::string canvasName;
326 Func func; 310 Func func;
327 void* userData; 311 void* userData;
328 }; 312 };
329 std::vector<EventHandlerData<OnWindowResizeFunc> > resizeHandlers_; 313 std::vector<EventHandlerData<OnSdlWindowResizeFunc> > resizeHandlers_;
330 std::vector<EventHandlerData<OnMouseEventFunc > > mouseDownHandlers_; 314 std::vector<EventHandlerData<OnMouseEventFunc > > mouseDownHandlers_;
331 std::vector<EventHandlerData<OnMouseEventFunc > > mouseDblCickHandlers_; 315 std::vector<EventHandlerData<OnMouseEventFunc > > mouseDblCickHandlers_;
332 std::vector<EventHandlerData<OnMouseEventFunc > > mouseMoveHandlers_; 316 std::vector<EventHandlerData<OnMouseEventFunc > > mouseMoveHandlers_;
333 std::vector<EventHandlerData<OnMouseEventFunc > > mouseUpHandlers_; 317 std::vector<EventHandlerData<OnMouseEventFunc > > mouseUpHandlers_;
334 std::vector<EventHandlerData<OnMouseWheelFunc > > mouseWheelHandlers_; 318 std::vector<EventHandlerData<OnMouseWheelFunc > > mouseWheelHandlers_;
335 std::vector<EventHandlerData<OnKeyDownFunc > > keyDownHandlers_; 319 std::vector<EventHandlerData<OnKeyDownFunc > > keyDownHandlers_;
336 std::vector<EventHandlerData<OnKeyUpFunc > > keyUpHandlers_; 320 std::vector<EventHandlerData<OnKeyUpFunc > > keyUpHandlers_;
337 321
338 /** 322 /**
339 This executes all the registered headers if needed (in wasm, the browser 323 This executes all the registered headers if needed (in wasm, the browser
340 deals with this) 324 deals with this)
341 */ 325 */