comparison Framework/Scene2DViewport/ViewportController.h @ 858:e3c56d4f863f

GuiAdapter : mouse event routing in SDL + split the undo stack from the ViewportController for multi-canvas apps + adapted the samples to this change
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 24 Jun 2019 10:31:04 +0200
parents 2b245953b44b
children a29c13497557
comparison
equal deleted inserted replaced
855:41d22389a7d2 858:e3c56d4f863f
28 28
29 #include <stack> 29 #include <stack>
30 30
31 namespace OrthancStone 31 namespace OrthancStone
32 { 32 {
33 /** 33 class UndoStack;
34 These constats are used 34
35
36 */
37 const double ARC_RADIUS_CANVAS_COORD = 30.0; 35 const double ARC_RADIUS_CANVAS_COORD = 30.0;
38 const double TEXT_CENTER_DISTANCE_CANVAS_COORD = 90; 36 const double TEXT_CENTER_DISTANCE_CANVAS_COORD = 90;
39 37
40 const double HANDLE_SIDE_LENGTH_CANVAS_COORD = 10.0; 38 const double HANDLE_SIDE_LENGTH_CANVAS_COORD = 10.0;
41 const double HIT_TEST_MAX_DISTANCE_CANVAS_COORD = 15.0; 39 const double HIT_TEST_MAX_DISTANCE_CANVAS_COORD = 15.0;
69 { 67 {
70 public: 68 public:
71 ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, \ 69 ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, \
72 SceneTransformChanged, ViewportController); 70 SceneTransformChanged, ViewportController);
73 71
74 ViewportController(MessageBroker& broker); 72 ViewportController(boost::weak_ptr<UndoStack> undoStackW, MessageBroker& broker);
75 73
76 boost::shared_ptr<const Scene2D> GetScene() const; 74 boost::shared_ptr<const Scene2D> GetScene() const;
77 boost::shared_ptr<Scene2D> GetScene(); 75 boost::shared_ptr<Scene2D> GetScene();
78 76
79 /** 77 /**
105 void SetSceneToCanvasTransform(const AffineTransform2D& transform); 103 void SetSceneToCanvasTransform(const AffineTransform2D& transform);
106 104
107 /** Forwarded to the underlying scene, and broadcasted to the observers */ 105 /** Forwarded to the underlying scene, and broadcasted to the observers */
108 void FitContent(unsigned int canvasWidth, unsigned int canvasHeight); 106 void FitContent(unsigned int canvasWidth, unsigned int canvasHeight);
109 107
110 /**
111 Stores a command :
112 - this first trims the undo stack to keep the first numAppliedCommands_
113 - then it adds the supplied command at the top of the undo stack
114
115 In other words, when a new command is pushed, all the undone (and not
116 redone) commands are removed.
117 */
118 void PushCommand(boost::shared_ptr<TrackerCommand> command);
119
120 /**
121 Undoes the command at the top of the undo stack, or throws if there is no
122 command to undo.
123 You can check "CanUndo" first to protect against extraneous redo.
124 */
125 void Undo();
126
127 /**
128 Redoes the command that is just above the last applied command in the undo
129 stack or throws if there is no command to redo.
130 You can check "CanRedo" first to protect against extraneous redo.
131 */
132 void Redo();
133
134 /** selfexpl */
135 bool CanUndo() const;
136
137 /** selfexpl */
138 bool CanRedo() const;
139
140 /** Adds a new measure tool */ 108 /** Adds a new measure tool */
141 void AddMeasureTool(boost::shared_ptr<MeasureTool> measureTool); 109 void AddMeasureTool(boost::shared_ptr<MeasureTool> measureTool);
142 110
143 /** Removes a measure tool or throws if it cannot be found */ 111 /** Removes a measure tool or throws if it cannot be found */
144 void RemoveMeasureTool(boost::shared_ptr<MeasureTool> measureTool); 112 void RemoveMeasureTool(boost::shared_ptr<MeasureTool> measureTool);
167 Distance between the top of the angle measuring tool and the center of 135 Distance between the top of the angle measuring tool and the center of
168 the label showing the actual measure, in *scene* coordinates 136 the label showing the actual measure, in *scene* coordinates
169 */ 137 */
170 double GetAngleTopTextLabelDistanceS() const; 138 double GetAngleTopTextLabelDistanceS() const;
171 139
140
141 /** forwarded to the UndoStack */
142 void PushCommand(boost::shared_ptr<TrackerCommand> command);
143
144 /** forwarded to the UndoStack */
145 void Undo();
146
147 /** forwarded to the UndoStack */
148 void Redo();
149
150 /** forwarded to the UndoStack */
151 bool CanUndo() const;
152
153 /** forwarded to the UndoStack */
154 bool CanRedo() const;
155
156
172 private: 157 private:
173 double GetCanvasToSceneFactor() const; 158 double GetCanvasToSceneFactor() const;
174 159
175 std::vector<boost::shared_ptr<TrackerCommand> > commandStack_; 160 boost::weak_ptr<UndoStack> undoStackW_;
176 161
177 /** 162 boost::shared_ptr<UndoStack> GetUndoStack();
178 This is always between >= 0 and <= undoStack_.size() and gives the 163 boost::shared_ptr<const UndoStack> GetUndoStack() const;
179 position where the controller is in the undo stack. 164
180 - If numAppliedCommands_ > 0, one can undo
181 - If numAppliedCommands_ < numAppliedCommands_.size(), one can redo
182 */
183 size_t numAppliedCommands_;
184 std::vector<boost::shared_ptr<MeasureTool> > measureTools_; 165 std::vector<boost::shared_ptr<MeasureTool> > measureTools_;
185 boost::shared_ptr<Scene2D> scene_; 166 boost::shared_ptr<Scene2D> scene_;
186 boost::shared_ptr<IFlexiblePointerTracker> tracker_; 167 boost::shared_ptr<IFlexiblePointerTracker> tracker_;
187 168
188 // this is cached 169 // this is cached