comparison Samples/Sdl/TrackerSampleApp.h @ 644:f939f449482c

Ongoing tracker work.
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 10 May 2019 16:15:55 +0200
parents
children 462a5074f914
comparison
equal deleted inserted replaced
634:6a144a45b2d8 644:f939f449482c
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-2019 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 #include <Framework/Scene2D/OpenGLCompositor.h>
22
23 #include "../Common/IFlexiblePointerTracker.h"
24 #include "../Common/MeasureTools.h"
25
26 #include <SDL.h>
27
28 #include <boost/make_shared.hpp>
29 #include <boost/shared_ptr.hpp>
30
31 namespace OrthancStone
32 {
33 class TrackerCommand;
34 typedef boost::shared_ptr<TrackerCommand> TrackerCommandPtr;
35
36 enum GuiTool
37 {
38 GuiTool_Rotate = 0,
39 GuiTool_Pan,
40 GuiTool_Zoom,
41 GuiTool_LineMeasure,
42 GuiTool_CircleMeasure,
43 GuiTool_AngleMeasure,
44 GuiTool_EllipseMeasure,
45 GuiTool_LAST
46 };
47
48 const char* MeasureToolToString(size_t i);
49
50 static const unsigned int FONT_SIZE = 32;
51
52 class Scene2D;
53
54 class TrackerSampleApp
55 {
56 public:
57 // 12 because.
58 TrackerSampleApp() : currentTool_(GuiTool_Rotate)
59 {
60 TEXTURE_2x2_1_ZINDEX = 1;
61 TEXTURE_1x1_ZINDEX = 2;
62 TEXTURE_2x2_2_ZINDEX = 3;
63 LINESET_1_ZINDEX = 4;
64 LINESET_2_ZINDEX = 5;
65 INFOTEXT_LAYER_ZINDEX = 6;
66 }
67 void PrepareScene();
68
69 void DisableTracker();
70
71 Scene2D& GetScene();
72
73 void HandleApplicationEvent(
74 const OpenGLCompositor& compositor,
75 const SDL_Event& event);
76
77 private:
78 void SelectNextTool();
79
80
81 FlexiblePointerTrackerPtr TrackerHitTest(const PointerEvent& e);
82
83 FlexiblePointerTrackerPtr CreateSuitableTracker(
84 const SDL_Event& event,
85 const PointerEvent& e,
86 const OpenGLCompositor& compositor);
87
88 void TakeScreenshot(
89 const std::string& target,
90 unsigned int canvasWidth,
91 unsigned int canvasHeight);
92
93 /**
94 This adds the command at the top of the undo stack
95 */
96 void Commit(TrackerCommandPtr cmd);
97 void Undo();
98 void Redo();
99
100 private:
101 void DisplayInfoText(const PointerEvent& e);
102 void HideInfoText();
103
104 private:
105 /**
106 WARNING: the measuring tools do store a reference to the scene, and it
107 paramount that the scene gets destroyed AFTER the measurement tools.
108 */
109 Scene2D scene_;
110
111 FlexiblePointerTrackerPtr activeTracker_;
112 std::vector<TrackerCommandPtr> undoStack_;
113
114 // we store the measure tools here so that they don't get deleted
115 std::vector<MeasureToolPtr> measureTools_;
116
117 //static const int LAYER_POSITION = 150;
118 #if 0
119 int TEXTURE_2x2_1_ZINDEX = 12;
120 int TEXTURE_1x1_ZINDEX = 13;
121 int TEXTURE_2x2_2_ZINDEX = 14;
122 int LINESET_1_ZINDEX = 50;
123 int LINESET_2_ZINDEX = 100;
124 int INFOTEXT_LAYER_ZINDEX = 150;
125 #else
126 int TEXTURE_2x2_1_ZINDEX;
127 int TEXTURE_1x1_ZINDEX;
128 int TEXTURE_2x2_2_ZINDEX;
129 int LINESET_1_ZINDEX;
130 int LINESET_2_ZINDEX;
131 int INFOTEXT_LAYER_ZINDEX;
132 #endif
133 GuiTool currentTool_;
134 };
135
136 }