Mercurial > hg > orthanc-stone
comparison Applications/Generic/GuiAdapter.cpp @ 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 | 257f2c9a02ac |
children | f30905f5d246 |
comparison
equal
deleted
inserted
replaced
1311:3d26447ddd28 | 1312:4f8c9065ee52 |
---|---|
356 userData, | 356 userData, |
357 capture, | 357 capture, |
358 func); | 358 func); |
359 } | 359 } |
360 | 360 |
361 #if 0 | |
362 // useless under Wasm where canvas resize is handled automatically | |
361 void GuiAdapter::SetResizeCallback( | 363 void GuiAdapter::SetResizeCallback( |
362 std::string canvasId, void* userData, bool capture, OnWindowResizeFunc func) | 364 std::string canvasId, void* userData, bool capture, OnWindowResizeFunc func) |
363 { | 365 { |
364 SetCallback<OnWindowResizeFunc, GuiAdapterUiEvent, EmscriptenUiEvent>( | 366 SetCallback<OnWindowResizeFunc, GuiAdapterUiEvent, EmscriptenUiEvent>( |
365 &emscripten_set_resize_callback_on_thread, | 367 &emscripten_set_resize_callback_on_thread, |
366 canvasId, | 368 canvasId, |
367 userData, | 369 userData, |
368 capture, | 370 capture, |
369 func); | 371 func); |
370 } | 372 } |
373 #endif | |
371 | 374 |
372 void GuiAdapter::RequestAnimationFrame( | 375 void GuiAdapter::RequestAnimationFrame( |
373 OnAnimationFrameFunc func, void* userData) | 376 OnAnimationFrameFunc func, void* userData) |
374 { | 377 { |
375 // LOG(ERROR) << "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"; | 378 // LOG(ERROR) << "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"; |
391 std::string canvasId, void* userData, bool capture, OnKeyUpFunc func) | 394 std::string canvasId, void* userData, bool capture, OnKeyUpFunc func) |
392 { | 395 { |
393 emscripten_set_keyup_callback(canvasId.c_str(), userData, static_cast<EM_BOOL>(capture), func); | 396 emscripten_set_keyup_callback(canvasId.c_str(), userData, static_cast<EM_BOOL>(capture), func); |
394 } | 397 } |
395 | 398 |
396 void GuiAdapter::SetResizeCallback(std::string canvasId, void* userData, bool capture, OnWindowResizeFunc func) | 399 // handled from within WebAssemblyViewport |
397 { | 400 //void GuiAdapter::SetResizeCallback(std::string canvasId, void* userData, bool capture, OnWindowResizeFunc func) |
398 emscripten_set_resize_callback(canvasId.c_str(), userData, static_cast<EM_BOOL>(capture), func); | 401 //{ |
399 } | 402 // emscripten_set_resize_callback(canvasId.c_str(), userData, static_cast<EM_BOOL>(capture), func); |
403 //} | |
400 | 404 |
401 void GuiAdapter::RequestAnimationFrame(OnAnimationFrameFunc func, void* userData) | 405 void GuiAdapter::RequestAnimationFrame(OnAnimationFrameFunc func, void* userData) |
402 { | 406 { |
403 emscripten_request_animation_frame_loop(func, userData); | 407 emscripten_request_animation_frame_loop(func, userData); |
404 } | 408 } |
515 else | 519 else |
516 dest.altKey = false; | 520 dest.altKey = false; |
517 } | 521 } |
518 | 522 |
519 | 523 |
520 | 524 #if ORTHANC_ENABLE_WASM != 1 |
521 // SDL ONLY | 525 // SDL ONLY |
522 void GuiAdapter::SetResizeCallback( | 526 void GuiAdapter::SetSdlResizeCallback( |
523 std::string canvasId, void* userData, bool capture, OnWindowResizeFunc func) | 527 std::string canvasId, void* userData, bool capture, OnSdlWindowResizeFunc func) |
524 { | 528 { |
525 resizeHandlers_.push_back(EventHandlerData<OnWindowResizeFunc>(canvasId, func, userData)); | 529 resizeHandlers_.push_back(EventHandlerData<OnSdlWindowResizeFunc>(canvasId, func, userData)); |
526 } | 530 } |
531 #endif | |
527 | 532 |
528 // SDL ONLY | 533 // SDL ONLY |
529 void GuiAdapter::SetMouseDownCallback( | 534 void GuiAdapter::SetMouseDownCallback( |
530 std::string canvasId, void* userData, bool capture, OnMouseEventFunc func) | 535 std::string canvasId, void* userData, bool capture, OnMouseEventFunc func) |
531 { | 536 { |
594 animationFrameHandlers_.erase(animationFrameHandlers_.begin() + disabledAnimationHandlers[i]); | 599 animationFrameHandlers_.erase(animationFrameHandlers_.begin() + disabledAnimationHandlers[i]); |
595 } | 600 } |
596 } | 601 } |
597 | 602 |
598 // SDL ONLY | 603 // SDL ONLY |
599 void GuiAdapter::OnResize() | 604 void GuiAdapter::OnResize(unsigned int width, unsigned int height) |
600 { | 605 { |
601 for (size_t i = 0; i < resizeHandlers_.size(); i++) | 606 for (size_t i = 0; i < resizeHandlers_.size(); i++) |
602 { | 607 { |
603 (*(resizeHandlers_[i].func))( | 608 (*(resizeHandlers_[i].func))( |
604 resizeHandlers_[i].canvasName, 0, resizeHandlers_[i].userData); | 609 resizeHandlers_[i].canvasName, nullptr, width, height, resizeHandlers_[i].userData); |
605 } | 610 } |
606 } | 611 } |
607 | 612 |
608 // SDL ONLY | 613 // SDL ONLY |
609 void GuiAdapter::OnMouseWheelEvent(uint32_t windowID, const GuiAdapterWheelEvent& event) | 614 void GuiAdapter::OnMouseWheelEvent(uint32_t windowID, const GuiAdapterWheelEvent& event) |
787 | 792 |
788 bool stop = false; | 793 bool stop = false; |
789 while (!stop) | 794 while (!stop) |
790 { | 795 { |
791 { | 796 { |
792 Deprecated::LockingEmitter::WriterLock lock(lockingEmitter_); | 797 // TODO: lock all viewports here! (use a scoped object) |
793 if(func != NULL) | 798 if(func != NULL) |
794 (*func)(cookie); | 799 (*func)(cookie); |
795 OnAnimationFrame(); // in SDL we must call it | 800 OnAnimationFrame(); // in SDL we must call it |
796 } | 801 } |
797 | 802 |
798 SDL_Event event; | 803 SDL_Event event; |
799 | 804 |
800 while (!stop && SDL_PollEvent(&event)) | 805 while (!stop && SDL_PollEvent(&event)) |
801 { | 806 { |
802 Deprecated::LockingEmitter::WriterLock lock(lockingEmitter_); | 807 // TODO: lock all viewports here! (use a scoped object) |
803 | 808 |
804 if (event.type == SDL_QUIT) | 809 if (event.type == SDL_QUIT) |
805 { | 810 { |
806 // TODO: call exit callbacks here | 811 // TODO: call exit callbacks here |
807 stop = true; | 812 stop = true; |
878 //else if (event.wheel.y < 0) | 883 //else if (event.wheel.y < 0) |
879 //{ | 884 //{ |
880 // locker.GetCentralViewport().MouseWheel(MouseWheelDirection_Down, x, y, modifiers); | 885 // locker.GetCentralViewport().MouseWheel(MouseWheelDirection_Down, x, y, modifiers); |
881 //} | 886 //} |
882 } | 887 } |
883 else if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) | 888 else if (event.type == SDL_WINDOWEVENT && |
889 (event.window.event == SDL_WINDOWEVENT_RESIZED || | |
890 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) | |
884 { | 891 { |
885 #if 0 | 892 #if 0 |
886 tracker.reset(); | 893 tracker.reset(); |
887 #endif | 894 #endif |
888 OnResize(); | 895 OnResize(event.window.data1, event.window.data2); |
889 } | 896 } |
890 else if (event.type == SDL_KEYDOWN && event.key.repeat == 0 /* Ignore key bounce */) | 897 else if (event.type == SDL_KEYDOWN && event.key.repeat == 0 /* Ignore key bounce */) |
891 { | 898 { |
892 switch (event.key.keysym.sym) | 899 switch (event.key.keysym.sym) |
893 { | 900 { |