# HG changeset patch # User Sebastien Jodogne # Date 1601485743 -7200 # Node ID c476b0d5e59cd9a13b48617bbc58335e1fdca056 # Parent 1f812f4c95beebc80ede16a0b4a9b4a6786791e5 skeleton for cross-hair tool diff -r 1f812f4c95be -r c476b0d5e59c Applications/StoneWebViewer/WebApplication/index.html --- a/Applications/StoneWebViewer/WebApplication/index.html Thu Sep 24 17:20:36 2020 +0200 +++ b/Applications/StoneWebViewer/WebApplication/index.html Wed Sep 30 19:09:03 2020 +0200 @@ -302,24 +302,31 @@
+
+ +
diff -r 1f812f4c95be -r c476b0d5e59c Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp --- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp Thu Sep 24 17:20:36 2020 +0200 +++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp Wed Sep 30 19:09:03 2020 +0200 @@ -105,16 +105,43 @@ }; -enum EMSCRIPTEN_KEEPALIVE MouseAction +enum EMSCRIPTEN_KEEPALIVE WebViewerAction { - MouseAction_GrayscaleWindowing, - MouseAction_Zoom, - MouseAction_Pan, - MouseAction_Rotate + WebViewerAction_GrayscaleWindowing, + WebViewerAction_Zoom, + WebViewerAction_Pan, + WebViewerAction_Rotate, + WebViewerAction_Crosshair }; +static OrthancStone::MouseAction ConvertWebViewerAction(int action) +{ + switch (action) + { + case WebViewerAction_GrayscaleWindowing: + return OrthancStone::MouseAction_GrayscaleWindowing; + + case WebViewerAction_Zoom: + return OrthancStone::MouseAction_Zoom; + + case WebViewerAction_Pan: + return OrthancStone::MouseAction_Pan; + + case WebViewerAction_Rotate: + return OrthancStone::MouseAction_Rotate; + + case WebViewerAction_Crosshair: + return OrthancStone::MouseAction_None; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } +} + + + static const int PRIORITY_HIGH = -100; static const int PRIORITY_LOW = 100; static const int PRIORITY_NORMAL = 0; @@ -1892,19 +1919,73 @@ } } - void SetMouseButtonActions(OrthancStone::MouseAction leftAction, - OrthancStone::MouseAction middleAction, - OrthancStone::MouseAction rightAction) + + + class Interactor : public OrthancStone::DefaultViewportInteractor { - std::unique_ptr interactor( - new OrthancStone::DefaultViewportInteractor); + private: + WebViewerAction leftAction_; + WebViewerAction middleAction_; + WebViewerAction rightAction_; + + bool IsAction(const OrthancStone::PointerEvent& event, + WebViewerAction action) + { + switch (event.GetMouseButton()) + { + case OrthancStone::MouseButton_Left: + return (leftAction_ == action); + + case OrthancStone::MouseButton_Middle: + return (middleAction_ == action); + + case OrthancStone::MouseButton_Right: + return (rightAction_ == action); + + default: + return false; + } + } - interactor->SetLeftButtonAction(leftAction); - interactor->SetMiddleButtonAction(middleAction); - interactor->SetRightButtonAction(rightAction); + public: + Interactor(WebViewerAction leftAction, + WebViewerAction middleAction, + WebViewerAction rightAction) : + leftAction_(leftAction), + middleAction_(middleAction), + rightAction_(rightAction) + { + SetLeftButtonAction(ConvertWebViewerAction(leftAction)); + SetMiddleButtonAction(ConvertWebViewerAction(middleAction)); + SetRightButtonAction(ConvertWebViewerAction(rightAction)); + } + virtual OrthancStone::IFlexiblePointerTracker* CreateTracker( + boost::shared_ptr viewport, + const OrthancStone::PointerEvent& event, + unsigned int viewportWidth, + unsigned int viewportHeight) ORTHANC_OVERRIDE + { + if (IsAction(event, WebViewerAction_Crosshair)) + { + printf("CROSS-HAIR!\n"); + return NULL; + } + else + { + return DefaultViewportInteractor::CreateTracker( + viewport, event, viewportWidth, viewportHeight); + } + } + }; + + + void SetMouseButtonActions(WebViewerAction leftAction, + WebViewerAction middleAction, + WebViewerAction rightAction) + { assert(viewport_ != NULL); - viewport_->AcquireInteractor(interactor.release()); + viewport_->AcquireInteractor(new Interactor(leftAction, middleAction, rightAction)); } void FitForPrint() @@ -2019,9 +2100,9 @@ static boost::shared_ptr context_; static std::string stringBuffer_; static bool softwareRendering_ = false; -static OrthancStone::MouseAction leftButtonAction_ = OrthancStone::MouseAction_GrayscaleWindowing; -static OrthancStone::MouseAction middleButtonAction_ = OrthancStone::MouseAction_Pan; -static OrthancStone::MouseAction rightButtonAction_ = OrthancStone::MouseAction_Zoom; +static WebViewerAction leftButtonAction_ = WebViewerAction_GrayscaleWindowing; +static WebViewerAction middleButtonAction_ = WebViewerAction_Pan; +static WebViewerAction rightButtonAction_ = WebViewerAction_Zoom; static void FormatTags(std::string& target, @@ -2079,30 +2160,6 @@ } - -static OrthancStone::MouseAction ConvertMouseAction(int action) -{ - switch (action) - { - case MouseAction_GrayscaleWindowing: - return OrthancStone::MouseAction_GrayscaleWindowing; - - case MouseAction_Zoom: - return OrthancStone::MouseAction_Zoom; - - case MouseAction_Pan: - return OrthancStone::MouseAction_Pan; - - case MouseAction_Rotate: - return OrthancStone::MouseAction_Rotate; - - default: - throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); - } -} - - - extern "C" { int main(int argc, char const *argv[]) @@ -2451,9 +2508,9 @@ { try { - leftButtonAction_ = ConvertMouseAction(leftAction); - middleButtonAction_ = ConvertMouseAction(middleAction); - rightButtonAction_ = ConvertMouseAction(rightAction); + leftButtonAction_ = static_cast(leftAction); + middleButtonAction_ = static_cast(middleAction); + rightButtonAction_ = static_cast(rightAction); for (Viewports::iterator it = allViewports_.begin(); it != allViewports_.end(); ++it) { diff -r 1f812f4c95be -r c476b0d5e59c OrthancStone/Sources/StoneEnumerations.h --- a/OrthancStone/Sources/StoneEnumerations.h Thu Sep 24 17:20:36 2020 +0200 +++ b/OrthancStone/Sources/StoneEnumerations.h Wed Sep 30 19:09:03 2020 +0200 @@ -137,7 +137,8 @@ MouseAction_Pan, MouseAction_Zoom, MouseAction_Rotate, - MouseAction_GrayscaleWindowing + MouseAction_GrayscaleWindowing, + MouseAction_None }; SopClassUid StringToSopClassUid(const std::string& source); diff -r 1f812f4c95be -r c476b0d5e59c OrthancStone/Sources/Viewport/DefaultViewportInteractor.cpp --- a/OrthancStone/Sources/Viewport/DefaultViewportInteractor.cpp Thu Sep 24 17:20:36 2020 +0200 +++ b/OrthancStone/Sources/Viewport/DefaultViewportInteractor.cpp Wed Sep 30 19:09:03 2020 +0200 @@ -38,6 +38,9 @@ { switch (action) { + case MouseAction_None: + return NULL; + case MouseAction_Rotate: return new RotateSceneTracker(viewport, event); @@ -50,7 +53,7 @@ case MouseAction_Zoom: return new ZoomSceneTracker(viewport, event, viewportHeight); - + default: throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); }