Mercurial > hg > orthanc-stone
comparison Framework/Scene2DViewport/ViewportController.h @ 1208:00e6bff9ea39 broker
handling of mouse interactions in ViewportController
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 03 Dec 2019 18:51:03 +0100 |
parents | f3bb9a6dd949 |
children | 644baa70373d |
comparison
equal
deleted
inserted
replaced
1207:17a92c39c633 | 1208:00e6bff9ea39 |
---|---|
21 #pragma once | 21 #pragma once |
22 | 22 |
23 #include "PredeclaredTypes.h" | 23 #include "PredeclaredTypes.h" |
24 | 24 |
25 #include "../Viewport/IViewport.h" | 25 #include "../Viewport/IViewport.h" |
26 #include "../Scene2D/PointerEvent.h" | |
27 #include "../Scene2DViewport/IFlexiblePointerTracker.h" | 26 #include "../Scene2DViewport/IFlexiblePointerTracker.h" |
28 | 27 |
28 #include <boost/enable_shared_from_this.hpp> | |
29 #include <stack> | 29 #include <stack> |
30 | 30 |
31 namespace OrthancStone | 31 namespace OrthancStone |
32 { | 32 { |
33 // TODO - Move this to another file | |
34 class IViewportInteractor : public boost::noncopyable | |
35 { | |
36 public: | |
37 virtual ~IViewportInteractor() | |
38 { | |
39 } | |
40 | |
41 virtual IFlexiblePointerTracker* CreateTracker(boost::shared_ptr<ViewportController> controller, | |
42 const PointerEvent& event) = 0; | |
43 }; | |
44 | |
45 | |
46 // TODO - Move this to another file | |
47 class DefaultViewportInteractor : public IViewportInteractor | |
48 { | |
49 public: | |
50 virtual IFlexiblePointerTracker* CreateTracker(boost::shared_ptr<ViewportController> controller, | |
51 const PointerEvent& event) ORTHANC_OVERRIDE; | |
52 }; | |
53 | |
54 | |
33 class UndoStack; | 55 class UndoStack; |
34 | 56 |
35 const double ARC_RADIUS_CANVAS_COORD = 30.0; | 57 const double ARC_RADIUS_CANVAS_COORD = 30.0; |
36 const double TEXT_CENTER_DISTANCE_CANVAS_COORD = 90; | 58 const double TEXT_CENTER_DISTANCE_CANVAS_COORD = 90; |
37 | 59 |
72 The active tracker is also stored in the viewport controller. | 94 The active tracker is also stored in the viewport controller. |
73 | 95 |
74 Each canvas or other GUI area where we want to display a 2D image, either | 96 Each canvas or other GUI area where we want to display a 2D image, either |
75 directly or through slicing must be assigned a ViewportController. | 97 directly or through slicing must be assigned a ViewportController. |
76 */ | 98 */ |
77 class ViewportController : public IObservable | 99 class ViewportController : |
100 public IObservable, | |
101 public boost::enable_shared_from_this<ViewportController> | |
78 { | 102 { |
79 public: | 103 public: |
80 ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, \ | 104 ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, \ |
81 SceneTransformChanged, ViewportController); | 105 SceneTransformChanged, ViewportController); |
82 | 106 |
83 ViewportController(boost::weak_ptr<UndoStack> undoStackW, | 107 ViewportController(boost::weak_ptr<UndoStack> undoStackW, |
84 IViewport& viewport); | 108 boost::shared_ptr<IViewport> viewport); |
85 | |
86 | 109 |
87 ~ViewportController(); | 110 ~ViewportController(); |
88 | 111 |
89 /** | 112 void SetInteractor(boost::shared_ptr<IViewportInteractor> interactor); |
90 This method is called by the GUI system and should update/delete the | |
91 current tracker | |
92 */ | |
93 bool HandlePointerEvent(PointerEvent e); | |
94 | 113 |
95 /** | 114 /** |
96 This method returns the list of measure tools containing the supplied point | 115 This method returns the list of measure tools containing the supplied point |
97 (in scene coords). A tracker can then be requested from the chosen | 116 (in scene coords). A tracker can then be requested from the chosen |
98 measure tool, if needed | 117 measure tool, if needed |
107 | 126 |
108 /** | 127 /** |
109 With this method, the object takes ownership of the supplied tracker and | 128 With this method, the object takes ownership of the supplied tracker and |
110 updates it according to user interaction | 129 updates it according to user interaction |
111 */ | 130 */ |
112 void SetActiveTracker(boost::shared_ptr<IFlexiblePointerTracker> tracker); | 131 void AcquireActiveTracker(IFlexiblePointerTracker* tracker); |
113 | 132 |
114 /** Forwarded to the underlying scene */ | 133 /** Forwarded to the underlying scene */ |
115 AffineTransform2D GetCanvasToSceneTransform() const; | 134 AffineTransform2D GetCanvasToSceneTransform() const; |
116 | 135 |
117 /** Forwarded to the underlying scene */ | 136 /** Forwarded to the underlying scene */ |
119 | 138 |
120 /** Forwarded to the underlying scene, and broadcasted to the observers */ | 139 /** Forwarded to the underlying scene, and broadcasted to the observers */ |
121 void SetSceneToCanvasTransform(const AffineTransform2D& transform); | 140 void SetSceneToCanvasTransform(const AffineTransform2D& transform); |
122 | 141 |
123 /** Forwarded to the underlying scene, and broadcasted to the observers */ | 142 /** Forwarded to the underlying scene, and broadcasted to the observers */ |
124 void FitContent(unsigned int canvasWidth, unsigned int canvasHeight); | |
125 void FitContent(); | 143 void FitContent(); |
126 | 144 |
127 /** Adds a new measure tool */ | 145 /** Adds a new measure tool */ |
128 void AddMeasureTool(boost::shared_ptr<MeasureTool> measureTool); | 146 void AddMeasureTool(boost::shared_ptr<MeasureTool> measureTool); |
129 | 147 |
172 /** forwarded to the UndoStack */ | 190 /** forwarded to the UndoStack */ |
173 bool CanRedo() const; | 191 bool CanRedo() const; |
174 | 192 |
175 IViewport& GetViewport() const | 193 IViewport& GetViewport() const |
176 { | 194 { |
177 return viewport_; | 195 return *viewport_; |
178 } | 196 } |
197 | |
198 | |
199 // Must be expressed in canvas coordinates | |
200 void HandleMousePress(const PointerEvent& event); | |
201 | |
202 // Must be expressed in canvas coordinates | |
203 void HandleMouseMove(const PointerEvent& event); | |
204 | |
205 // Must be expressed in canvas coordinates | |
206 void HandleMouseRelease(const PointerEvent& event); | |
179 | 207 |
180 private: | 208 private: |
181 double GetCanvasToSceneFactor() const; | 209 double GetCanvasToSceneFactor() const; |
182 | 210 |
183 boost::weak_ptr<UndoStack> undoStackW_; | 211 boost::weak_ptr<UndoStack> undoStackW_; // Global stack, possibly shared by all viewports |
184 | 212 boost::shared_ptr<IViewport> viewport_; |
185 boost::shared_ptr<UndoStack> GetUndoStack(); | 213 boost::shared_ptr<IViewportInteractor> interactor_; // Application-specific factory of trackers |
186 boost::shared_ptr<const UndoStack> GetUndoStack() const; | 214 std::vector<boost::shared_ptr<MeasureTool> > measureTools_; |
187 | 215 boost::shared_ptr<IFlexiblePointerTracker> activeTracker_; // TODO - Can't this be a "std::auto_ptr"? |
188 std::vector<boost::shared_ptr<MeasureTool> > measureTools_; | |
189 boost::shared_ptr<IFlexiblePointerTracker> tracker_; | |
190 | 216 |
191 // this is cached | 217 // this is cached |
192 mutable double canvasToSceneFactor_; | 218 double canvasToSceneFactor_; |
193 | |
194 // Refactoring on 2019-07-10: Removing shared_ptr from scene | |
195 IViewport& viewport_; | |
196 }; | 219 }; |
197 } | 220 } |