annotate Framework/Widgets/ZoomMouseTracker.cpp @ 560:aaeec7be8fb7

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