# HG changeset patch # User Sebastien Jodogne # Date 1559133877 -7200 # Node ID 467d58a59718485836757aeb19cdd371c24503da # Parent 76e8224bc300f77b75dc9f73c0cb6a8ee62f6627 wheel diff -r 76e8224bc300 -r 467d58a59718 Samples/WebAssembly/BasicMPR.cpp --- a/Samples/WebAssembly/BasicMPR.cpp Wed May 29 14:19:06 2019 +0200 +++ b/Samples/WebAssembly/BasicMPR.cpp Wed May 29 14:44:37 2019 +0200 @@ -362,6 +362,34 @@ viewport_.Refresh(); } } + + void Scroll(int delta) + { + if (!planes_.empty()) + { + int tmp = static_cast(currentPlane_) + delta; + unsigned int next; + + if (tmp < 0) + { + next = 0; + } + else if (tmp >= static_cast(planes_.size())) + { + next = planes_.size() - 1; + } + else + { + next = static_cast(tmp); + } + + if (next != currentPlane_) + { + currentPlane_ = next; + Refresh(); + } + } + } }; @@ -846,6 +874,57 @@ } +static bool ctrlDown_ = false; + + +EM_BOOL OnMouseWheel(int eventType, + const EmscriptenWheelEvent *wheelEvent, + void *userData) +{ + try + { + if (userData != NULL) + { + int delta = 0; + + if (wheelEvent->deltaY < 0) + { + delta = -1; + } + + if (wheelEvent->deltaY > 0) + { + delta = 1; + } + + if (ctrlDown_) + { + delta *= 10; + } + + reinterpret_cast(userData)->Scroll(delta); + } + } + catch (Orthanc::OrthancException& e) + { + LOG(ERROR) << "Exception in the wheel event: " << e.What(); + } + + return true; +} + + +EM_BOOL OnKey(int eventType, + const EmscriptenKeyboardEvent *keyEvent, + void *userData) +{ + ctrlDown_ = keyEvent->ctrlKey; + return false; +} + + + + extern "C" { int main(int argc, char const *argv[]) @@ -876,6 +955,13 @@ viewport3_->UpdateSize(); emscripten_set_resize_callback("#window", NULL, false, OnWindowResize); + + emscripten_set_wheel_callback("mycanvas1", viewport1_.get(), false, OnMouseWheel); + emscripten_set_wheel_callback("mycanvas2", viewport2_.get(), false, OnMouseWheel); + emscripten_set_wheel_callback("mycanvas3", viewport3_.get(), false, OnMouseWheel); + + emscripten_set_keydown_callback("#window", NULL, false, OnKey); + emscripten_set_keyup_callback("#window", NULL, false, OnKey); emscripten_request_animation_frame_loop(OnAnimationFrame, NULL);