Mercurial > hg > orthanc-stone
comparison Framework/Scene2D/ZoomSceneTracker.cpp @ 700:059e1fd05fd6 refactor-viewport-controller
Introduced the ViewportController that sits between the application and the
Scene2D to handle the trackers and measuring tools. This is a work in progress.
The Scene2D is no longer an observable. Message sending is managed by the
ViewportController.
Move some refs to shared and weak to prevent lifetime issues.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Sun, 19 May 2019 16:26:17 +0200 |
parents | 7efa2543699d |
children | c0fcb2757b0a |
comparison
equal
deleted
inserted
replaced
699:5c551f078c18 | 700:059e1fd05fd6 |
---|---|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
22 #include "ZoomSceneTracker.h" | 22 #include "ZoomSceneTracker.h" |
23 #include <Framework/Scene2DViewport/ViewportController.h> | |
23 | 24 |
24 namespace OrthancStone | 25 namespace OrthancStone |
25 { | 26 { |
26 ZoomSceneTracker::ZoomSceneTracker(Scene2D& scene, | 27 ZoomSceneTracker::ZoomSceneTracker(ViewportControllerWPtr controllerW, |
27 const PointerEvent& event, | 28 const PointerEvent& event, |
28 unsigned int canvasHeight) : | 29 unsigned int canvasHeight) |
29 scene_(scene), | 30 : OneGesturePointerTracker(controllerW) |
30 clickY_(event.GetMainPosition().GetY()), | 31 , clickY_(event.GetMainPosition().GetY()) |
31 aligner_(scene, event.GetMainPosition()), | 32 , aligner_(controllerW, event.GetMainPosition()) |
32 originalSceneToCanvas_(scene.GetSceneToCanvasTransform()) | 33 , originalSceneToCanvas_(GetController()->GetSceneToCanvasTransform()) |
33 { | 34 { |
34 if (canvasHeight <= 3) | 35 if (canvasHeight <= 3) |
35 { | 36 { |
36 active_ = false; | 37 active_ = false; |
37 } | 38 } |
40 normalization_ = 1.0 / static_cast<double>(canvasHeight - 1); | 41 normalization_ = 1.0 / static_cast<double>(canvasHeight - 1); |
41 active_ = true; | 42 active_ = true; |
42 } | 43 } |
43 } | 44 } |
44 | 45 |
45 | 46 void ZoomSceneTracker::PointerMove(const PointerEvent& event) |
46 void ZoomSceneTracker::Update(const PointerEvent& event) | |
47 { | 47 { |
48 static const double MIN_ZOOM = -4; | 48 static const double MIN_ZOOM = -4; |
49 static const double MAX_ZOOM = 4; | 49 static const double MAX_ZOOM = 4; |
50 | 50 |
51 if (active_) | 51 if (active_) |
52 { | 52 { |
53 double y = event.GetMainPosition().GetY(); | 53 double y = event.GetMainPosition().GetY(); |
54 double dy = static_cast<double>(y - clickY_) * normalization_; // In the range [-1,1] | 54 |
55 // In the range [-1,1] | |
56 double dy = static_cast<double>(y - clickY_) * normalization_; | |
57 | |
55 double z; | 58 double z; |
56 | 59 |
57 // Linear interpolation from [-1, 1] to [MIN_ZOOM, MAX_ZOOM] | 60 // Linear interpolation from [-1, 1] to [MIN_ZOOM, MAX_ZOOM] |
58 if (dy < -1.0) | 61 if (dy < -1.0) |
59 { | 62 { |
68 z = MIN_ZOOM + (MAX_ZOOM - MIN_ZOOM) * (dy + 1.0) / 2.0; | 71 z = MIN_ZOOM + (MAX_ZOOM - MIN_ZOOM) * (dy + 1.0) / 2.0; |
69 } | 72 } |
70 | 73 |
71 double zoom = pow(2.0, z); | 74 double zoom = pow(2.0, z); |
72 | 75 |
73 scene_.SetSceneToCanvasTransform( | 76 GetController()->SetSceneToCanvasTransform( |
74 AffineTransform2D::Combine( | 77 AffineTransform2D::Combine( |
75 AffineTransform2D::CreateScaling(zoom, zoom), | 78 AffineTransform2D::CreateScaling(zoom, zoom), |
76 originalSceneToCanvas_)); | 79 originalSceneToCanvas_)); |
77 | 80 |
78 aligner_.Apply(); | 81 aligner_.Apply(); |
79 } | 82 } |
80 } | 83 } |
84 | |
85 void ZoomSceneTracker::Cancel() | |
86 { | |
87 GetController()->SetSceneToCanvasTransform(originalSceneToCanvas_); | |
88 } | |
81 } | 89 } |