Mercurial > hg > orthanc-stone
comparison Deprecated/Samples/Sdl/TrackerSampleApp.h @ 1402:65e1e4b08302
moved deprecated samples into Deprecated
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Wed, 29 Apr 2020 20:50:53 +0200 |
parents | Samples/Deprecated/Sdl/TrackerSampleApp.h@eac254fb6791 |
children | 828a9b4ee1b7 |
comparison
equal
deleted
inserted
replaced
1401:f6a2d46d2b76 | 1402:65e1e4b08302 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "../../Framework/Messages/IObserver.h" | |
23 #include "../../Framework/Scene2D/OpenGLCompositor.h" | |
24 #include "../../Framework/Scene2DViewport/IFlexiblePointerTracker.h" | |
25 #include "../../Framework/Scene2DViewport/MeasureTool.h" | |
26 #include "../../Framework/Scene2DViewport/PredeclaredTypes.h" | |
27 #include "../../Framework/Scene2DViewport/ViewportController.h" | |
28 #include "../../Framework/Viewport/SdlViewport.h" | |
29 | |
30 #include <SDL.h> | |
31 | |
32 #include <boost/make_shared.hpp> | |
33 #include <boost/shared_ptr.hpp> | |
34 #include <boost/enable_shared_from_this.hpp> | |
35 | |
36 namespace OrthancStone | |
37 { | |
38 enum GuiTool | |
39 { | |
40 GuiTool_Rotate = 0, | |
41 GuiTool_Pan, | |
42 GuiTool_Zoom, | |
43 GuiTool_LineMeasure, | |
44 GuiTool_CircleMeasure, | |
45 GuiTool_AngleMeasure, | |
46 GuiTool_EllipseMeasure, | |
47 GuiTool_LAST | |
48 }; | |
49 | |
50 const char* MeasureToolToString(size_t i); | |
51 | |
52 static const unsigned int FONT_SIZE_0 = 32; | |
53 static const unsigned int FONT_SIZE_1 = 24; | |
54 | |
55 class Scene2D; | |
56 class UndoStack; | |
57 | |
58 class TrackerSampleApp : public IObserver | |
59 , public boost::enable_shared_from_this<TrackerSampleApp> | |
60 { | |
61 public: | |
62 // 12 because. | |
63 TrackerSampleApp(MessageBroker& broker); | |
64 void PrepareScene(); | |
65 void Run(); | |
66 void SetInfoDisplayMessage(std::string key, std::string value); | |
67 void DisableTracker(); | |
68 | |
69 void HandleApplicationEvent(const SDL_Event& event); | |
70 | |
71 /** | |
72 This method is called when the scene transform changes. It allows to | |
73 recompute the visual elements whose content depend upon the scene transform | |
74 */ | |
75 void OnSceneTransformChanged( | |
76 const ViewportController::SceneTransformChanged& message); | |
77 | |
78 private: | |
79 void SelectNextTool(); | |
80 void CreateRandomMeasureTool(); | |
81 | |
82 | |
83 /** | |
84 In the case of this app, the viewport is an SDL viewport and it has | |
85 a OpenGLCompositor& GetCompositor() method | |
86 */ | |
87 ICompositor& GetCompositor(); | |
88 | |
89 /** | |
90 See the other overload | |
91 */ | |
92 const ICompositor& GetCompositor() const; | |
93 | |
94 /** | |
95 This returns a random point in the canvas part of the scene, but in | |
96 scene coordinates | |
97 */ | |
98 ScenePoint2D GetRandomPointInScene() const; | |
99 | |
100 boost::shared_ptr<IFlexiblePointerTracker> TrackerHitTest(const PointerEvent& e); | |
101 | |
102 boost::shared_ptr<IFlexiblePointerTracker> CreateSuitableTracker( | |
103 const SDL_Event& event, | |
104 const PointerEvent& e); | |
105 | |
106 void TakeScreenshot( | |
107 const std::string& target, | |
108 unsigned int canvasWidth, | |
109 unsigned int canvasHeight); | |
110 | |
111 /** | |
112 This adds the command at the top of the undo stack | |
113 */ | |
114 void Commit(boost::shared_ptr<TrackerCommand> cmd); | |
115 void Undo(); | |
116 void Redo(); | |
117 | |
118 private: | |
119 void DisplayFloatingCtrlInfoText(const PointerEvent& e); | |
120 void DisplayInfoText(); | |
121 void HideInfoText(); | |
122 | |
123 private: | |
124 /** | |
125 WARNING: the measuring tools do store a reference to the scene, and it | |
126 paramount that the scene gets destroyed AFTER the measurement tools. | |
127 */ | |
128 boost::shared_ptr<ViewportController> controller_; | |
129 | |
130 std::map<std::string, std::string> infoTextMap_; | |
131 boost::shared_ptr<IFlexiblePointerTracker> activeTracker_; | |
132 | |
133 //static const int LAYER_POSITION = 150; | |
134 | |
135 int TEXTURE_2x2_1_ZINDEX; | |
136 int TEXTURE_1x1_ZINDEX; | |
137 int TEXTURE_2x2_2_ZINDEX; | |
138 int LINESET_1_ZINDEX; | |
139 int LINESET_2_ZINDEX; | |
140 int FLOATING_INFOTEXT_LAYER_ZINDEX; | |
141 int FIXED_INFOTEXT_LAYER_ZINDEX; | |
142 | |
143 GuiTool currentTool_; | |
144 boost::shared_ptr<UndoStack> undoStack_; | |
145 SdlOpenGLViewport viewport_; | |
146 }; | |
147 | |
148 } |