# HG changeset patch # User Sebastien Jodogne # Date 1556291114 -7200 # Node ID b716763571ad009944fc2fd01d0bfe537bf2945e # Parent 6e471e6cf09bca15e67a1cc0785204d7289ab644 IPointerTracker diff -r 6e471e6cf09b -r b716763571ad Framework/Scene2D/IPointerTracker.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/IPointerTracker.h Fri Apr 26 17:05:14 2019 +0200 @@ -0,0 +1,39 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#pragma once + +#include "PointerEvent.h" + +namespace OrthancStone +{ + class IPointerTracker : public boost::noncopyable + { + public: + virtual ~IPointerTracker() + { + } + + virtual void Update(const PointerEvent& event) = 0; + + virtual void Release() = 0; + }; +} diff -r 6e471e6cf09b -r b716763571ad Framework/Scene2D/Internals/FixedPointAligner.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/FixedPointAligner.cpp Fri Apr 26 17:05:14 2019 +0200 @@ -0,0 +1,51 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#include "FixedPointAligner.h" + +namespace OrthancStone +{ + namespace Internals + { + FixedPointAligner::FixedPointAligner(Scene2D& scene, + const ScenePoint2D& p, + unsigned int canvasWidth, + unsigned int canvasHeight) : + scene_(scene) + { + canvas_ = ScenePoint2D(p.GetX() - static_cast(canvasWidth) / 2.0, + p.GetY() - static_cast(canvasHeight) / 2.0); + pivot_ = canvas_.Apply(scene_.GetCanvasToSceneTransform()); + } + + + void FixedPointAligner::Apply() + { + ScenePoint2D p = canvas_.Apply(scene_.GetCanvasToSceneTransform()); + + scene_.SetSceneToCanvasTransform( + AffineTransform2D::Combine( + scene_.GetSceneToCanvasTransform(), + AffineTransform2D::CreateOffset(p.GetX() - pivot_.GetX(), + p.GetY() - pivot_.GetY()))); + } + } +} diff -r 6e471e6cf09b -r b716763571ad Framework/Scene2D/Internals/FixedPointAligner.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/Internals/FixedPointAligner.h Fri Apr 26 17:05:14 2019 +0200 @@ -0,0 +1,49 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#pragma once + +#include "../Scene2D.h" +#include "../ScenePoint2D.h" + +namespace OrthancStone +{ + namespace Internals + { + // During a mouse event that modifies the view of a scene, keeps + // one point (the pivot) at the same position on the canvas + class FixedPointAligner : public boost::noncopyable + { + private: + Scene2D& scene_; + ScenePoint2D pivot_; + ScenePoint2D canvas_; + + public: + FixedPointAligner(Scene2D& scene, + const ScenePoint2D& p, + unsigned int canvasWidth, + unsigned int canvasHeight); + + void Apply(); + }; + } +} diff -r 6e471e6cf09b -r b716763571ad Framework/Scene2D/PanSceneTracker.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/PanSceneTracker.cpp Fri Apr 26 17:05:14 2019 +0200 @@ -0,0 +1,46 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#include "PanSceneTracker.h" + +namespace OrthancStone +{ + PanSceneTracker::PanSceneTracker(Scene2D& scene, + const PointerEvent& event) : + scene_(scene), + originalSceneToCanvas_(scene_.GetSceneToCanvasTransform()), + originalCanvasToScene_(scene_.GetCanvasToSceneTransform()) + { + pivot_ = event.GetMainPosition().Apply(originalCanvasToScene_); + } + + + void PanSceneTracker::Update(const PointerEvent& event) + { + ScenePoint2D p = event.GetMainPosition().Apply(originalCanvasToScene_); + + scene_.SetSceneToCanvasTransform( + AffineTransform2D::Combine( + originalSceneToCanvas_, + AffineTransform2D::CreateOffset(p.GetX() - pivot_.GetX(), + p.GetY() - pivot_.GetY()))); + } +} diff -r 6e471e6cf09b -r b716763571ad Framework/Scene2D/PanSceneTracker.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/PanSceneTracker.h Fri Apr 26 17:05:14 2019 +0200 @@ -0,0 +1,47 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#pragma once + +#include "IPointerTracker.h" +#include "Scene2D.h" + +namespace OrthancStone +{ + class PanSceneTracker : public IPointerTracker + { + private: + Scene2D& scene_; + ScenePoint2D pivot_; + AffineTransform2D originalSceneToCanvas_; + AffineTransform2D originalCanvasToScene_; + + public: + PanSceneTracker(Scene2D& scene, + const PointerEvent& event); + + virtual void Update(const PointerEvent& event); + + virtual void Release() + { + } + }; +} diff -r 6e471e6cf09b -r b716763571ad Framework/Scene2D/PointerEvent.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/PointerEvent.cpp Fri Apr 26 17:05:14 2019 +0200 @@ -0,0 +1,69 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#include "PointerEvent.h" + +#include + +namespace OrthancStone +{ + PointerEvent::PointerEvent() : + hasAltModifier_(false), + hasControlModifier_(false), + hasShiftModifier_(false) + { + } + + + ScenePoint2D PointerEvent::GetMainPosition() const + { + if (positions_.empty()) + { + return ScenePoint2D(0, 0); + } + else + { + return positions_[0]; + } + } + + + // Add the center of the pixel + void PointerEvent::AddIntegerPosition(int x, + int y) + { + AddPosition(static_cast(x) + 0.5, + static_cast(y) + 0.5); + } + + + ScenePoint2D PointerEvent::GetPosition(size_t index) const + { + if (index < positions_.size()) + { + return positions_[index]; + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + } +} diff -r 6e471e6cf09b -r b716763571ad Framework/Scene2D/PointerEvent.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/PointerEvent.h Fri Apr 26 17:05:14 2019 +0200 @@ -0,0 +1,91 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#pragma once + +#include "ScenePoint2D.h" + +#include +#include + +namespace OrthancStone +{ + class PointerEvent : public boost::noncopyable + { + private: + std::vector positions_; + bool hasAltModifier_; + bool hasControlModifier_; + bool hasShiftModifier_; + + public: + PointerEvent(); + + ScenePoint2D GetMainPosition() const; + + void AddPosition(double x, + double y) + { + positions_.push_back(ScenePoint2D(x, y)); + } + + // Add the center of the pixel + void AddIntegerPosition(int x, + int y); + + size_t GetPositionsCount() const + { + return positions_.size(); + } + + ScenePoint2D GetPosition(size_t index) const; + + void SetAltModifier(bool value) + { + hasAltModifier_ = value; + } + + bool HasAltModifier() const + { + return hasAltModifier_; + } + + void SetControlModifier(bool value) + { + hasControlModifier_ = value; + } + + bool HasControlModifier() const + { + return hasControlModifier_; + } + + void SetShiftModifier(bool value) + { + hasShiftModifier_ = value; + } + + bool HasShiftModifier() const + { + return hasShiftModifier_; + } + }; +} diff -r 6e471e6cf09b -r b716763571ad Framework/Scene2D/RotateSceneTracker.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/RotateSceneTracker.cpp Fri Apr 26 17:05:14 2019 +0200 @@ -0,0 +1,64 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#include "RotateSceneTracker.h" + +namespace OrthancStone +{ + RotateSceneTracker::RotateSceneTracker(Scene2D& scene, + const PointerEvent& event, + unsigned int canvasWidth, + unsigned int canvasHeight) : + scene_(scene), + click_(event.GetMainPosition()), + aligner_(scene, click_, canvasWidth, canvasHeight), + isFirst_(true), + originalSceneToCanvas_(scene.GetSceneToCanvasTransform()) + { + } + + + void RotateSceneTracker::Update(const PointerEvent& event) + { + ScenePoint2D p = event.GetMainPosition(); + double dx = p.GetX() - click_.GetX(); + double dy = p.GetY() - click_.GetY(); + + if (std::abs(dx) > 5.0 || + std::abs(dy) > 5.0) + { + double a = atan2(dy, dx); + + if (isFirst_) + { + referenceAngle_ = a; + isFirst_ = false; + } + + scene_.SetSceneToCanvasTransform( + AffineTransform2D::Combine( + AffineTransform2D::CreateRotation(a - referenceAngle_), + originalSceneToCanvas_)); + + aligner_.Apply(); + } + } +} diff -r 6e471e6cf09b -r b716763571ad Framework/Scene2D/RotateSceneTracker.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/RotateSceneTracker.h Fri Apr 26 17:05:14 2019 +0200 @@ -0,0 +1,51 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#pragma once + +#include "IPointerTracker.h" +#include "Internals/FixedPointAligner.h" + +namespace OrthancStone +{ + class RotateSceneTracker : public IPointerTracker + { + private: + Scene2D& scene_; + ScenePoint2D click_; + Internals::FixedPointAligner aligner_; + double referenceAngle_; + bool isFirst_; + AffineTransform2D originalSceneToCanvas_; + + public: + RotateSceneTracker(Scene2D& scene, + const PointerEvent& event, + unsigned int canvasWidth, + unsigned int canvasHeight); + + virtual void Update(const PointerEvent& event); + + virtual void Release() + { + } + }; +} diff -r 6e471e6cf09b -r b716763571ad Framework/Scene2D/ScenePoint2D.h --- a/Framework/Scene2D/ScenePoint2D.h Fri Apr 26 15:11:11 2019 +0200 +++ b/Framework/Scene2D/ScenePoint2D.h Fri Apr 26 17:05:14 2019 +0200 @@ -33,6 +33,12 @@ double y_; public: + ScenePoint2D() : + x_(0), + y_(0) + { + } + ScenePoint2D(double x, double y) : x_(x), diff -r 6e471e6cf09b -r b716763571ad Framework/Scene2D/ZoomSceneTracker.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/ZoomSceneTracker.cpp Fri Apr 26 17:05:14 2019 +0200 @@ -0,0 +1,82 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#include "ZoomSceneTracker.h" + +namespace OrthancStone +{ + ZoomSceneTracker::ZoomSceneTracker(Scene2D& scene, + const PointerEvent& event, + unsigned int canvasWidth, + unsigned int canvasHeight) : + scene_(scene), + clickY_(event.GetMainPosition().GetY()), + aligner_(scene, event.GetMainPosition(), canvasWidth, canvasHeight), + originalSceneToCanvas_(scene.GetSceneToCanvasTransform()) + { + if (canvasHeight <= 3) + { + active_ = false; + } + else + { + normalization_ = 1.0 / static_cast(canvasHeight - 1); + active_ = true; + } + } + + + void ZoomSceneTracker::Update(const PointerEvent& event) + { + static const double MIN_ZOOM = -4; + static const double MAX_ZOOM = 4; + + if (active_) + { + double y = event.GetMainPosition().GetY(); + double dy = static_cast(y - clickY_) * normalization_; // In the range [-1,1] + double z; + + // Linear interpolation from [-1, 1] to [MIN_ZOOM, MAX_ZOOM] + if (dy < -1.0) + { + z = MIN_ZOOM; + } + else if (dy > 1.0) + { + z = MAX_ZOOM; + } + else + { + z = MIN_ZOOM + (MAX_ZOOM - MIN_ZOOM) * (dy + 1.0) / 2.0; + } + + double zoom = pow(2.0, z); + + scene_.SetSceneToCanvasTransform( + AffineTransform2D::Combine( + AffineTransform2D::CreateScaling(zoom, zoom), + originalSceneToCanvas_)); + + aligner_.Apply(); + } + } +} diff -r 6e471e6cf09b -r b716763571ad Framework/Scene2D/ZoomSceneTracker.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Scene2D/ZoomSceneTracker.h Fri Apr 26 17:05:14 2019 +0200 @@ -0,0 +1,51 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#pragma once + +#include "IPointerTracker.h" +#include "Internals/FixedPointAligner.h" + +namespace OrthancStone +{ + class ZoomSceneTracker : public IPointerTracker + { + private: + Scene2D& scene_; + double clickY_; + bool active_; + double normalization_; + Internals::FixedPointAligner aligner_; + AffineTransform2D originalSceneToCanvas_; + + public: + ZoomSceneTracker(Scene2D& scene, + const PointerEvent& event, + unsigned int canvasWidth, + unsigned int canvasHeight); + + virtual void Update(const PointerEvent& event); + + virtual void Release() + { + } + }; +} diff -r 6e471e6cf09b -r b716763571ad Framework/Viewport/IMouseTracker.h --- a/Framework/Viewport/IMouseTracker.h Fri Apr 26 15:11:11 2019 +0200 +++ b/Framework/Viewport/IMouseTracker.h Fri Apr 26 17:05:14 2019 +0200 @@ -62,7 +62,5 @@ virtual void MouseMove(int x, int y, const std::vector& displayTouches) = 0; - - virtual bool IsTouchTracker() const {return false;} }; } diff -r 6e471e6cf09b -r b716763571ad Resources/CMake/OrthancStoneConfiguration.cmake --- a/Resources/CMake/OrthancStoneConfiguration.cmake Fri Apr 26 15:11:11 2019 +0200 +++ b/Resources/CMake/OrthancStoneConfiguration.cmake Fri Apr 26 17:05:14 2019 +0200 @@ -262,10 +262,15 @@ ${ORTHANC_STONE_ROOT}/Framework/Scene2D/InfoPanelSceneLayer.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/CairoPolylineRenderer.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/CompositorHelper.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Internals/FixedPointAligner.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/PanSceneTracker.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/PointerEvent.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/PolylineSceneLayer.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/RotateSceneTracker.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/Scene2D.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/TextSceneLayer.cpp ${ORTHANC_STONE_ROOT}/Framework/Scene2D/TextureBaseSceneLayer.cpp + ${ORTHANC_STONE_ROOT}/Framework/Scene2D/ZoomSceneTracker.cpp ${ORTHANC_STONE_ROOT}/Framework/Fonts/FontRenderer.cpp ${ORTHANC_STONE_ROOT}/Framework/Fonts/Glyph.cpp