comparison Framework/Scene2DViewport/ViewportController.cpp @ 891:0aff28f15ea2

new abstraction: IViewport
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jul 2019 18:18:42 +0200
parents a29c13497557
children 0c5201499af8
comparison
equal deleted inserted replaced
890:77c96ba899f9 891:0aff28f15ea2
27 27
28 #include <boost/make_shared.hpp> 28 #include <boost/make_shared.hpp>
29 29
30 namespace OrthancStone 30 namespace OrthancStone
31 { 31 {
32 ViewportController::ViewportController(boost::weak_ptr<UndoStack> undoStackW, MessageBroker& broker) 32 ViewportController::ViewportController(boost::weak_ptr<UndoStack> undoStackW,
33 MessageBroker& broker,
34 IViewport& viewport)
33 : IObservable(broker) 35 : IObservable(broker)
34 , undoStackW_(undoStackW) 36 , undoStackW_(undoStackW)
35 , canvasToSceneFactor_(0.0) 37 , canvasToSceneFactor_(0.0)
38 , viewport_(viewport)
39 , scene_(viewport.GetScene())
36 { 40 {
37 scene_ = boost::make_shared<Scene2D>();
38 } 41 }
39 42
40 boost::shared_ptr<UndoStack> ViewportController::GetUndoStack() 43 boost::shared_ptr<UndoStack> ViewportController::GetUndoStack()
41 { 44 {
42 return undoStackW_.lock(); 45 return undoStackW_.lock();
70 bool ViewportController::CanRedo() const 73 bool ViewportController::CanRedo() const
71 { 74 {
72 return GetUndoStack()->CanRedo(); 75 return GetUndoStack()->CanRedo();
73 } 76 }
74 77
75 boost::shared_ptr<const Scene2D> ViewportController::GetScene() const
76 {
77 return scene_;
78 }
79
80 boost::shared_ptr<Scene2D> ViewportController::GetScene()
81 {
82 return scene_;
83 }
84
85 bool ViewportController::HandlePointerEvent(PointerEvent e) 78 bool ViewportController::HandlePointerEvent(PointerEvent e)
86 { 79 {
87 throw StoneException(ErrorCode_NotImplemented); 80 throw StoneException(ErrorCode_NotImplemented);
88 } 81 }
89 82
109 } 102 }
110 } 103 }
111 104
112 const OrthancStone::AffineTransform2D& ViewportController::GetCanvasToSceneTransform() const 105 const OrthancStone::AffineTransform2D& ViewportController::GetCanvasToSceneTransform() const
113 { 106 {
114 return scene_->GetCanvasToSceneTransform(); 107 return GetScene().GetCanvasToSceneTransform();
115 } 108 }
116 109
117 const OrthancStone::AffineTransform2D& ViewportController::GetSceneToCanvasTransform() const 110 const OrthancStone::AffineTransform2D& ViewportController::GetSceneToCanvasTransform() const
118 { 111 {
119 return scene_->GetSceneToCanvasTransform(); 112 return GetScene().GetSceneToCanvasTransform();
120 } 113 }
121 114
122 void ViewportController::SetSceneToCanvasTransform( 115 void ViewportController::SetSceneToCanvasTransform(
123 const AffineTransform2D& transform) 116 const AffineTransform2D& transform)
124 { 117 {
125 scene_->SetSceneToCanvasTransform(transform); 118 viewport_.GetScene().SetSceneToCanvasTransform(transform);
126 BroadcastMessage(SceneTransformChanged(*this)); 119 BroadcastMessage(SceneTransformChanged(*this));
127 120
128 // update the canvas to scene factor 121 // update the canvas to scene factor
129 canvasToSceneFactor_ = 0.0; 122 canvasToSceneFactor_ = 0.0;
130 canvasToSceneFactor_ = GetCanvasToSceneFactor(); 123 canvasToSceneFactor_ = GetCanvasToSceneFactor();
131 } 124 }
132 125
133 void ViewportController::FitContent( 126 void ViewportController::FitContent(
134 unsigned int canvasWidth, unsigned int canvasHeight) 127 unsigned int canvasWidth, unsigned int canvasHeight)
135 { 128 {
136 scene_->FitContent(canvasWidth, canvasHeight); 129 viewport_.GetScene().FitContent(canvasWidth, canvasHeight);
137 BroadcastMessage(SceneTransformChanged(*this)); 130 BroadcastMessage(SceneTransformChanged(*this));
138 } 131 }
139 132
140 void ViewportController::AddMeasureTool(boost::shared_ptr<MeasureTool> measureTool) 133 void ViewportController::AddMeasureTool(boost::shared_ptr<MeasureTool> measureTool)
141 { 134 {
157 double ViewportController::GetCanvasToSceneFactor() const 150 double ViewportController::GetCanvasToSceneFactor() const
158 { 151 {
159 if (canvasToSceneFactor_ == 0) 152 if (canvasToSceneFactor_ == 0)
160 { 153 {
161 canvasToSceneFactor_ = 154 canvasToSceneFactor_ =
162 GetScene()->GetCanvasToSceneTransform().ComputeZoom(); 155 GetScene().GetCanvasToSceneTransform().ComputeZoom();
163 } 156 }
164 return canvasToSceneFactor_; 157 return canvasToSceneFactor_;
165 } 158 }
166 159
167 double ViewportController::GetHandleSideLengthS() const 160 double ViewportController::GetHandleSideLengthS() const