comparison Framework/Scene2D/RotateSceneTracker.cpp @ 1305:a5326ce4f24b broker

Trackers and measuring tools now use the viewport instead of ViewportController, so that proper locks can be used
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 04 Mar 2020 09:45:38 +0100
parents 2d8ab34c8c91
children ab81ee8fce1f
comparison
equal deleted inserted replaced
1304:b7fa67bf87fa 1305:a5326ce4f24b
11 * 11 *
12 * This program is distributed in the hope that it will be useful, but 12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details. 15 * Affero General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU Affero General Public License 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/>. 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/ 19 **/
20 20
21 #include "RotateSceneTracker.h" 21 #include "RotateSceneTracker.h"
22 #include "../Scene2DViewport/ViewportController.h" 22 #include "../Scene2DViewport/ViewportController.h"
23 23
24 namespace OrthancStone 24 namespace OrthancStone
25 { 25 {
26 RotateSceneTracker::RotateSceneTracker(boost::weak_ptr<ViewportController> controllerW, 26 RotateSceneTracker::RotateSceneTracker(IViewport& viewport,
27 const PointerEvent& event) 27 const PointerEvent& event)
28 : OneGesturePointerTracker(controllerW) 28 : OneGesturePointerTracker(viewport)
29 , click_(event.GetMainPosition()) 29 , click_(event.GetMainPosition())
30 , aligner_(controllerW, click_) 30 , aligner_(viewport, click_)
31 , isFirst_(true) 31 , isFirst_(true)
32 , originalSceneToCanvas_(GetController()->GetSceneToCanvasTransform())
33 { 32 {
33 std::unique_ptr<IViewport::ILock> lock(viewport_.Lock());
34 originalSceneToCanvas_ = lock->GetController().GetSceneToCanvasTransform();
35
34 } 36 }
35 37
36 void RotateSceneTracker::PointerMove(const PointerEvent& event) 38 void RotateSceneTracker::PointerMove(const PointerEvent& event)
37 { 39 {
38 ScenePoint2D p = event.GetMainPosition(); 40 ScenePoint2D p = event.GetMainPosition();
39 double dx = p.GetX() - click_.GetX(); 41 double dx = p.GetX() - click_.GetX();
40 double dy = p.GetY() - click_.GetY(); 42 double dy = p.GetY() - click_.GetY();
41 43
42 if (std::abs(dx) > 5.0 || 44 if (std::abs(dx) > 5.0 ||
43 std::abs(dy) > 5.0) 45 std::abs(dy) > 5.0)
44 { 46 {
45 double a = atan2(dy, dx); 47 double a = atan2(dy, dx);
46 48
47 if (isFirst_) 49 if (isFirst_)
48 { 50 {
49 referenceAngle_ = a; 51 referenceAngle_ = a;
50 isFirst_ = false; 52 isFirst_ = false;
51 } 53 }
52 54
53 // The controller is a weak pointer. It could be deleted when the 55 std::unique_ptr<IViewport::ILock> lock(viewport_.Lock());
54 // tracker is still alive (for instance, because of a lost WebGL 56
55 // context that triggers a recreation of the viewport) 57 lock->GetController().SetSceneToCanvasTransform(
56 if(GetController().get() != NULL) 58 AffineTransform2D::Combine(
57 { 59 AffineTransform2D::CreateRotation(a - referenceAngle_),
58 GetController()->SetSceneToCanvasTransform( 60 originalSceneToCanvas_));
59 AffineTransform2D::Combine( 61 aligner_.Apply();
60 AffineTransform2D::CreateRotation(a - referenceAngle_), 62 lock->Invalidate();
61 originalSceneToCanvas_));
62
63 aligner_.Apply();
64 }
65 } 63 }
66 } 64 }
67 65
68 void RotateSceneTracker::Cancel() 66 void RotateSceneTracker::Cancel()
69 { 67 {
70 // See remark above 68 // See remark above
71 if(GetController().get() != NULL) 69 std::unique_ptr<IViewport::ILock> lock(viewport_.Lock());
72 { 70 lock->GetController().SetSceneToCanvasTransform(originalSceneToCanvas_);
73 GetController()->SetSceneToCanvasTransform(originalSceneToCanvas_); 71 lock->Invalidate();
74 }
75 } 72 }
76
77 } 73 }