Mercurial > hg > orthanc-stone
comparison Framework/Deprecated/Widgets/ZoomMouseTracker.cpp @ 732:c35e98d22764
move Deprecated classes to a separate folder
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 21 May 2019 14:27:35 +0200 |
parents | Framework/Widgets/ZoomMouseTracker.cpp@4f2416d519b4 |
children | 2d8ab34c8c91 |
comparison
equal
deleted
inserted
replaced
729:529189f399ec | 732:c35e98d22764 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "ZoomMouseTracker.h" | |
23 | |
24 #include <Core/Logging.h> | |
25 #include <Core/OrthancException.h> | |
26 | |
27 namespace Deprecated | |
28 { | |
29 ZoomMouseTracker::ZoomMouseTracker(WorldSceneWidget& that, | |
30 int x, | |
31 int y) : | |
32 that_(that), | |
33 originalZoom_(that.GetView().GetZoom()), | |
34 downX_(x), | |
35 downY_(y) | |
36 { | |
37 that.GetView().MapPixelCenterToScene(centerX_, centerY_, x, y); | |
38 | |
39 unsigned int height = that.GetView().GetDisplayHeight(); | |
40 | |
41 if (height <= 3) | |
42 { | |
43 idle_ = true; | |
44 LOG(WARNING) << "image is too small to zoom (current height = " << height << ")"; | |
45 } | |
46 else | |
47 { | |
48 idle_ = false; | |
49 normalization_ = 1.0 / static_cast<double>(height - 1); | |
50 } | |
51 } | |
52 | |
53 | |
54 void ZoomMouseTracker::Render(OrthancStone::CairoContext& context, | |
55 double zoom) | |
56 { | |
57 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
58 } | |
59 | |
60 | |
61 void ZoomMouseTracker::MouseMove(int displayX, | |
62 int displayY, | |
63 double x, | |
64 double y, | |
65 const std::vector<Touch>& displayTouches, | |
66 const std::vector<Touch>& sceneTouches) | |
67 { | |
68 static const double MIN_ZOOM = -4; | |
69 static const double MAX_ZOOM = 4; | |
70 | |
71 | |
72 if (!idle_) | |
73 { | |
74 double dy = static_cast<double>(displayY - downY_) * normalization_; // In the range [-1,1] | |
75 double z; | |
76 | |
77 // Linear interpolation from [-1, 1] to [MIN_ZOOM, MAX_ZOOM] | |
78 if (dy < -1.0) | |
79 { | |
80 z = MIN_ZOOM; | |
81 } | |
82 else if (dy > 1.0) | |
83 { | |
84 z = MAX_ZOOM; | |
85 } | |
86 else | |
87 { | |
88 z = MIN_ZOOM + (MAX_ZOOM - MIN_ZOOM) * (dy + 1.0) / 2.0; | |
89 } | |
90 | |
91 z = pow(2.0, z); | |
92 | |
93 ViewportGeometry view = that_.GetView(); | |
94 | |
95 view.SetZoom(z * originalZoom_); | |
96 | |
97 // Correct the pan so that the original click point is kept at | |
98 // the same location on the display | |
99 double panX, panY; | |
100 view.GetPan(panX, panY); | |
101 | |
102 int tx, ty; | |
103 view.MapSceneToDisplay(tx, ty, centerX_, centerY_); | |
104 view.SetPan(panX + static_cast<double>(downX_ - tx), | |
105 panY + static_cast<double>(downY_ - ty)); | |
106 | |
107 that_.SetView(view); | |
108 } | |
109 } | |
110 } |