Mercurial > hg > orthanc-stone
comparison Samples/WebAssembly/BasicMPR.cpp @ 823:467d58a59718
wheel
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 29 May 2019 14:44:37 +0200 |
parents | 76e8224bc300 |
children | 15d493101c1e |
comparison
equal
deleted
inserted
replaced
822:76e8224bc300 | 823:467d58a59718 |
---|---|
358 if (source_.get() != NULL && | 358 if (source_.get() != NULL && |
359 currentPlane_ < planes_.size()) | 359 currentPlane_ < planes_.size()) |
360 { | 360 { |
361 source_->Update(planes_[currentPlane_]); | 361 source_->Update(planes_[currentPlane_]); |
362 viewport_.Refresh(); | 362 viewport_.Refresh(); |
363 } | |
364 } | |
365 | |
366 void Scroll(int delta) | |
367 { | |
368 if (!planes_.empty()) | |
369 { | |
370 int tmp = static_cast<int>(currentPlane_) + delta; | |
371 unsigned int next; | |
372 | |
373 if (tmp < 0) | |
374 { | |
375 next = 0; | |
376 } | |
377 else if (tmp >= static_cast<int>(planes_.size())) | |
378 { | |
379 next = planes_.size() - 1; | |
380 } | |
381 else | |
382 { | |
383 next = static_cast<size_t>(tmp); | |
384 } | |
385 | |
386 if (next != currentPlane_) | |
387 { | |
388 currentPlane_ = next; | |
389 Refresh(); | |
390 } | |
363 } | 391 } |
364 } | 392 } |
365 }; | 393 }; |
366 | 394 |
367 | 395 |
844 return false; | 872 return false; |
845 } | 873 } |
846 } | 874 } |
847 | 875 |
848 | 876 |
877 static bool ctrlDown_ = false; | |
878 | |
879 | |
880 EM_BOOL OnMouseWheel(int eventType, | |
881 const EmscriptenWheelEvent *wheelEvent, | |
882 void *userData) | |
883 { | |
884 try | |
885 { | |
886 if (userData != NULL) | |
887 { | |
888 int delta = 0; | |
889 | |
890 if (wheelEvent->deltaY < 0) | |
891 { | |
892 delta = -1; | |
893 } | |
894 | |
895 if (wheelEvent->deltaY > 0) | |
896 { | |
897 delta = 1; | |
898 } | |
899 | |
900 if (ctrlDown_) | |
901 { | |
902 delta *= 10; | |
903 } | |
904 | |
905 reinterpret_cast<OrthancStone::VolumeSlicerViewport*>(userData)->Scroll(delta); | |
906 } | |
907 } | |
908 catch (Orthanc::OrthancException& e) | |
909 { | |
910 LOG(ERROR) << "Exception in the wheel event: " << e.What(); | |
911 } | |
912 | |
913 return true; | |
914 } | |
915 | |
916 | |
917 EM_BOOL OnKey(int eventType, | |
918 const EmscriptenKeyboardEvent *keyEvent, | |
919 void *userData) | |
920 { | |
921 ctrlDown_ = keyEvent->ctrlKey; | |
922 return false; | |
923 } | |
924 | |
925 | |
926 | |
927 | |
849 extern "C" | 928 extern "C" |
850 { | 929 { |
851 int main(int argc, char const *argv[]) | 930 int main(int argc, char const *argv[]) |
852 { | 931 { |
853 OrthancStone::StoneInitialize(); | 932 OrthancStone::StoneInitialize(); |
874 viewport3_.reset(new OrthancStone::VolumeSlicerViewport(broker_, "mycanvas3", OrthancStone::VolumeProjection_Sagittal)); | 953 viewport3_.reset(new OrthancStone::VolumeSlicerViewport(broker_, "mycanvas3", OrthancStone::VolumeProjection_Sagittal)); |
875 viewport3_->SetSlicer(0, loader_, *loader_, new OrthancStone::GrayscaleStyleConfigurator); | 954 viewport3_->SetSlicer(0, loader_, *loader_, new OrthancStone::GrayscaleStyleConfigurator); |
876 viewport3_->UpdateSize(); | 955 viewport3_->UpdateSize(); |
877 | 956 |
878 emscripten_set_resize_callback("#window", NULL, false, OnWindowResize); | 957 emscripten_set_resize_callback("#window", NULL, false, OnWindowResize); |
958 | |
959 emscripten_set_wheel_callback("mycanvas1", viewport1_.get(), false, OnMouseWheel); | |
960 emscripten_set_wheel_callback("mycanvas2", viewport2_.get(), false, OnMouseWheel); | |
961 emscripten_set_wheel_callback("mycanvas3", viewport3_.get(), false, OnMouseWheel); | |
962 | |
963 emscripten_set_keydown_callback("#window", NULL, false, OnKey); | |
964 emscripten_set_keyup_callback("#window", NULL, false, OnKey); | |
879 | 965 |
880 emscripten_request_animation_frame_loop(OnAnimationFrame, NULL); | 966 emscripten_request_animation_frame_loop(OnAnimationFrame, NULL); |
881 | 967 |
882 oracle_.Start(); | 968 oracle_.Start(); |
883 loader_->LoadSeries("a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa"); | 969 loader_->LoadSeries("a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa"); |