comparison Framework/Scene2D/RotateSceneTracker.cpp @ 596:b716763571ad

IPointerTracker
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Apr 2019 17:05:14 +0200
parents
children 7efa2543699d
comparison
equal deleted inserted replaced
595:6e471e6cf09b 596:b716763571ad
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 "RotateSceneTracker.h"
23
24 namespace OrthancStone
25 {
26 RotateSceneTracker::RotateSceneTracker(Scene2D& scene,
27 const PointerEvent& event,
28 unsigned int canvasWidth,
29 unsigned int canvasHeight) :
30 scene_(scene),
31 click_(event.GetMainPosition()),
32 aligner_(scene, click_, canvasWidth, canvasHeight),
33 isFirst_(true),
34 originalSceneToCanvas_(scene.GetSceneToCanvasTransform())
35 {
36 }
37
38
39 void RotateSceneTracker::Update(const PointerEvent& event)
40 {
41 ScenePoint2D p = event.GetMainPosition();
42 double dx = p.GetX() - click_.GetX();
43 double dy = p.GetY() - click_.GetY();
44
45 if (std::abs(dx) > 5.0 ||
46 std::abs(dy) > 5.0)
47 {
48 double a = atan2(dy, dx);
49
50 if (isFirst_)
51 {
52 referenceAngle_ = a;
53 isFirst_ = false;
54 }
55
56 scene_.SetSceneToCanvasTransform(
57 AffineTransform2D::Combine(
58 AffineTransform2D::CreateRotation(a - referenceAngle_),
59 originalSceneToCanvas_));
60
61 aligner_.Apply();
62 }
63 }
64 }