Mercurial > hg > orthanc-stone
diff Framework/Scene2DViewport/ViewportController.cpp @ 1203:f3bb9a6dd949 broker
locking abstraction in IViewport
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 29 Nov 2019 21:22:21 +0100 |
parents | e713f1a99861 |
children | 00e6bff9ea39 |
line wrap: on
line diff
--- a/Framework/Scene2DViewport/ViewportController.cpp Fri Nov 29 11:03:41 2019 +0100 +++ b/Framework/Scene2DViewport/ViewportController.cpp Fri Nov 29 21:22:21 2019 +0100 @@ -136,20 +136,26 @@ } } - const OrthancStone::AffineTransform2D& ViewportController::GetCanvasToSceneTransform() const + OrthancStone::AffineTransform2D ViewportController::GetCanvasToSceneTransform() const { - return GetScene().GetCanvasToSceneTransform(); + std::auto_ptr<IViewport::ILock> lock(viewport_.Lock()); + return lock->GetScene().GetCanvasToSceneTransform(); } - const OrthancStone::AffineTransform2D& ViewportController::GetSceneToCanvasTransform() const + OrthancStone::AffineTransform2D ViewportController::GetSceneToCanvasTransform() const { - return GetScene().GetSceneToCanvasTransform(); + std::auto_ptr<IViewport::ILock> lock(viewport_.Lock()); + return lock->GetScene().GetSceneToCanvasTransform(); } void ViewportController::SetSceneToCanvasTransform( const AffineTransform2D& transform) { - viewport_.GetScene().SetSceneToCanvasTransform(transform); + { + std::auto_ptr<IViewport::ILock> lock(viewport_.Lock()); + lock->GetScene().SetSceneToCanvasTransform(transform); + } + BroadcastMessage(SceneTransformChanged(*this)); // update the canvas to scene factor @@ -160,16 +166,22 @@ void ViewportController::FitContent( unsigned int canvasWidth, unsigned int canvasHeight) { - viewport_.GetScene().FitContent(canvasWidth, canvasHeight); + { + std::auto_ptr<IViewport::ILock> lock(viewport_.Lock()); + lock->GetScene().FitContent(canvasWidth, canvasHeight); + } + BroadcastMessage(SceneTransformChanged(*this)); } void ViewportController::FitContent() { - if (viewport_.HasCompositor()) + std::auto_ptr<IViewport::ILock> lock(viewport_.Lock()); + + if (lock->HasCompositor()) { - const ICompositor& compositor = viewport_.GetCompositor(); - viewport_.GetScene().FitContent(compositor.GetCanvasWidth(), compositor.GetCanvasHeight()); + const ICompositor& compositor = lock->GetCompositor(); + lock->GetScene().FitContent(compositor.GetCanvasWidth(), compositor.GetCanvasHeight()); BroadcastMessage(SceneTransformChanged(*this)); } } @@ -195,8 +207,8 @@ { if (canvasToSceneFactor_ == 0) { - canvasToSceneFactor_ = - GetScene().GetCanvasToSceneTransform().ComputeZoom(); + std::auto_ptr<IViewport::ILock> lock(viewport_.Lock()); + canvasToSceneFactor_ = lock->GetScene().GetCanvasToSceneTransform().ComputeZoom(); } return canvasToSceneFactor_; }