comparison Resources/Graveyard/Deprecated/Samples/Sdl/TrackerSampleApp.h @ 1503:553084468225

moving /Deprecated/ to /Resources/Graveyard/Deprecated/
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Jun 2020 11:38:13 +0200
parents Deprecated/Samples/Sdl/TrackerSampleApp.h@828a9b4ee1b7
children
comparison
equal deleted inserted replaced
1502:e5729dab3f67 1503:553084468225
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 #pragma once
23
24 #include "../../Framework/Messages/IObserver.h"
25 #include "../../Framework/Scene2D/OpenGLCompositor.h"
26 #include "../../Framework/Scene2DViewport/IFlexiblePointerTracker.h"
27 #include "../../Framework/Scene2DViewport/MeasureTool.h"
28 #include "../../Framework/Scene2DViewport/PredeclaredTypes.h"
29 #include "../../Framework/Scene2DViewport/ViewportController.h"
30 #include "../../Framework/Viewport/SdlViewport.h"
31
32 #include <SDL.h>
33
34 #include <boost/make_shared.hpp>
35 #include <boost/shared_ptr.hpp>
36 #include <boost/enable_shared_from_this.hpp>
37
38 namespace OrthancStone
39 {
40 enum GuiTool
41 {
42 GuiTool_Rotate = 0,
43 GuiTool_Pan,
44 GuiTool_Zoom,
45 GuiTool_LineMeasure,
46 GuiTool_CircleMeasure,
47 GuiTool_AngleMeasure,
48 GuiTool_EllipseMeasure,
49 GuiTool_LAST
50 };
51
52 const char* MeasureToolToString(size_t i);
53
54 static const unsigned int FONT_SIZE_0 = 32;
55 static const unsigned int FONT_SIZE_1 = 24;
56
57 class Scene2D;
58 class UndoStack;
59
60 class TrackerSampleApp : public IObserver
61 , public boost::enable_shared_from_this<TrackerSampleApp>
62 {
63 public:
64 // 12 because.
65 TrackerSampleApp(MessageBroker& broker);
66 void PrepareScene();
67 void Run();
68 void SetInfoDisplayMessage(std::string key, std::string value);
69 void DisableTracker();
70
71 void HandleApplicationEvent(const SDL_Event& event);
72
73 /**
74 This method is called when the scene transform changes. It allows to
75 recompute the visual elements whose content depend upon the scene transform
76 */
77 void OnSceneTransformChanged(
78 const ViewportController::SceneTransformChanged& message);
79
80 private:
81 void SelectNextTool();
82 void CreateRandomMeasureTool();
83
84
85 /**
86 In the case of this app, the viewport is an SDL viewport and it has
87 a OpenGLCompositor& GetCompositor() method
88 */
89 ICompositor& GetCompositor();
90
91 /**
92 See the other overload
93 */
94 const ICompositor& GetCompositor() const;
95
96 /**
97 This returns a random point in the canvas part of the scene, but in
98 scene coordinates
99 */
100 ScenePoint2D GetRandomPointInScene() const;
101
102 boost::shared_ptr<IFlexiblePointerTracker> TrackerHitTest(const PointerEvent& e);
103
104 boost::shared_ptr<IFlexiblePointerTracker> CreateSuitableTracker(
105 const SDL_Event& event,
106 const PointerEvent& e);
107
108 void TakeScreenshot(
109 const std::string& target,
110 unsigned int canvasWidth,
111 unsigned int canvasHeight);
112
113 /**
114 This adds the command at the top of the undo stack
115 */
116 void Commit(boost::shared_ptr<TrackerCommand> cmd);
117 void Undo();
118 void Redo();
119
120 private:
121 void DisplayFloatingCtrlInfoText(const PointerEvent& e);
122 void DisplayInfoText();
123 void HideInfoText();
124
125 private:
126 /**
127 WARNING: the measuring tools do store a reference to the scene, and it
128 paramount that the scene gets destroyed AFTER the measurement tools.
129 */
130 boost::shared_ptr<ViewportController> controller_;
131
132 std::map<std::string, std::string> infoTextMap_;
133 boost::shared_ptr<IFlexiblePointerTracker> activeTracker_;
134
135 //static const int LAYER_POSITION = 150;
136
137 int TEXTURE_2x2_1_ZINDEX;
138 int TEXTURE_1x1_ZINDEX;
139 int TEXTURE_2x2_2_ZINDEX;
140 int LINESET_1_ZINDEX;
141 int LINESET_2_ZINDEX;
142 int FLOATING_INFOTEXT_LAYER_ZINDEX;
143 int FIXED_INFOTEXT_LAYER_ZINDEX;
144
145 GuiTool currentTool_;
146 boost::shared_ptr<UndoStack> undoStack_;
147 SdlOpenGLViewport viewport_;
148 };
149
150 }