596
|
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 "ZoomSceneTracker.h"
|
|
23
|
|
24 namespace OrthancStone
|
|
25 {
|
|
26 ZoomSceneTracker::ZoomSceneTracker(Scene2D& scene,
|
|
27 const PointerEvent& event,
|
|
28 unsigned int canvasHeight) :
|
|
29 scene_(scene),
|
|
30 clickY_(event.GetMainPosition().GetY()),
|
617
|
31 aligner_(scene, event.GetMainPosition()),
|
596
|
32 originalSceneToCanvas_(scene.GetSceneToCanvasTransform())
|
|
33 {
|
|
34 if (canvasHeight <= 3)
|
|
35 {
|
|
36 active_ = false;
|
|
37 }
|
|
38 else
|
|
39 {
|
|
40 normalization_ = 1.0 / static_cast<double>(canvasHeight - 1);
|
|
41 active_ = true;
|
|
42 }
|
|
43 }
|
|
44
|
|
45
|
|
46 void ZoomSceneTracker::Update(const PointerEvent& event)
|
|
47 {
|
|
48 static const double MIN_ZOOM = -4;
|
|
49 static const double MAX_ZOOM = 4;
|
|
50
|
|
51 if (active_)
|
|
52 {
|
|
53 double y = event.GetMainPosition().GetY();
|
|
54 double dy = static_cast<double>(y - clickY_) * normalization_; // In the range [-1,1]
|
|
55 double z;
|
|
56
|
|
57 // Linear interpolation from [-1, 1] to [MIN_ZOOM, MAX_ZOOM]
|
|
58 if (dy < -1.0)
|
|
59 {
|
|
60 z = MIN_ZOOM;
|
|
61 }
|
|
62 else if (dy > 1.0)
|
|
63 {
|
|
64 z = MAX_ZOOM;
|
|
65 }
|
|
66 else
|
|
67 {
|
|
68 z = MIN_ZOOM + (MAX_ZOOM - MIN_ZOOM) * (dy + 1.0) / 2.0;
|
|
69 }
|
|
70
|
|
71 double zoom = pow(2.0, z);
|
|
72
|
|
73 scene_.SetSceneToCanvasTransform(
|
|
74 AffineTransform2D::Combine(
|
|
75 AffineTransform2D::CreateScaling(zoom, zoom),
|
|
76 originalSceneToCanvas_));
|
|
77
|
|
78 aligner_.Apply();
|
|
79 }
|
|
80 }
|
|
81 }
|