comparison Framework/Scene2DViewport/ViewportController.cpp @ 774:66ac7a2d1e3a

A few renames and cleanups + moved GUI constants to controller + start work on hit tests for measure tools and mouse hover.
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 24 May 2019 15:59:51 +0200
parents 07adcffba38c
children e42b491f1fb2
comparison
equal deleted inserted replaced
761:07adcffba38c 774:66ac7a2d1e3a
28 namespace OrthancStone 28 namespace OrthancStone
29 { 29 {
30 ViewportController::ViewportController(MessageBroker& broker) 30 ViewportController::ViewportController(MessageBroker& broker)
31 : IObservable(broker) 31 : IObservable(broker)
32 , numAppliedCommands_(0) 32 , numAppliedCommands_(0)
33 , canvasToSceneFactor_(0.0)
33 { 34 {
34 scene_ = boost::make_shared<Scene2D>(); 35 scene_ = boost::make_shared<Scene2D>();
36 }
37
38 Scene2DConstPtr ViewportController::GetScene() const
39 {
40 return scene_;
35 } 41 }
36 42
37 Scene2DPtr ViewportController::GetScene() 43 Scene2DPtr ViewportController::GetScene()
38 { 44 {
39 return scene_; 45 return scene_;
47 std::vector<MeasureToolPtr> ViewportController::HitTestMeasureTools( 53 std::vector<MeasureToolPtr> ViewportController::HitTestMeasureTools(
48 ScenePoint2D p) 54 ScenePoint2D p)
49 { 55 {
50 std::vector<MeasureToolPtr> ret; 56 std::vector<MeasureToolPtr> ret;
51 57
52 58 for (size_t i = 0; i < measureTools_.size(); ++i)
53 //for (size_t i = 0; i < measureTools_.size(); ++i) 59 {
54 //{ 60 if (measureTools_[i]->HitTest(p))
55 61 ret.push_back(measureTools_[i]);
56 //} 62 }
57 return ret; 63 return ret;
58 } 64 }
59 65
60 const OrthancStone::AffineTransform2D& ViewportController::GetCanvasToSceneTransform() const 66 const OrthancStone::AffineTransform2D& ViewportController::GetCanvasToSceneTransform() const
61 { 67 {
70 void ViewportController::SetSceneToCanvasTransform( 76 void ViewportController::SetSceneToCanvasTransform(
71 const AffineTransform2D& transform) 77 const AffineTransform2D& transform)
72 { 78 {
73 scene_->SetSceneToCanvasTransform(transform); 79 scene_->SetSceneToCanvasTransform(transform);
74 BroadcastMessage(SceneTransformChanged(*this)); 80 BroadcastMessage(SceneTransformChanged(*this));
81
82 // update the canvas to scene factor
83 canvasToSceneFactor_ = 0.0;
84 canvasToSceneFactor_ = GetCanvasToSceneFactor();
75 } 85 }
76 86
77 void ViewportController::FitContent( 87 void ViewportController::FitContent(
78 unsigned int canvasWidth, unsigned int canvasHeight) 88 unsigned int canvasWidth, unsigned int canvasHeight)
79 { 89 {
130 != measureTools_.end(), "Measure tool not found"); 140 != measureTools_.end(), "Measure tool not found");
131 measureTools_.erase( 141 measureTools_.erase(
132 std::remove(measureTools_.begin(), measureTools_.end(), measureTool), 142 std::remove(measureTools_.begin(), measureTools_.end(), measureTool),
133 measureTools_.end()); 143 measureTools_.end());
134 } 144 }
145
146
147 double ViewportController::GetCanvasToSceneFactor() const
148 {
149 if (canvasToSceneFactor_ == 0)
150 {
151 canvasToSceneFactor_ =
152 GetScene()->GetCanvasToSceneTransform().ComputeZoom();
153 }
154 return canvasToSceneFactor_;
155 }
156
157 double ViewportController::GetHandleSideLengthS() const
158 {
159 return HANDLE_SIDE_LENGTH_CANVAS_COORD * GetCanvasToSceneFactor();
160 }
161
162 double ViewportController::GetAngleToolArcRadiusS() const
163 {
164 return ARC_RADIUS_CANVAS_COORD * GetCanvasToSceneFactor();
165 }
166
167 double ViewportController::GetHitTestMaximumDistanceS() const
168 {
169 return HIT_TEST_MAX_DISTANCE_CANVAS_COORD * GetCanvasToSceneFactor();
170 }
171
172 double ViewportController::GetAngleTopTextLabelDistanceS() const
173 {
174 return TEXT_CENTER_DISTANCE_CANVAS_COORD * GetCanvasToSceneFactor();
175 }
135 } 176 }
136 177