Mercurial > hg > orthanc-stone
annotate Samples/Sdl/TrackerSampleApp.h @ 698:8b6adfb62a2f refactor-viewport-controller
Code is broken -- stashing ongoing work in a branch
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 15 May 2019 16:56:17 +0200 |
parents | cb3b76d16234 |
children | 059e1fd05fd6 |
rev | line source |
---|---|
644 | 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 | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
21 #include <Framework/Scene2DViewport/PointerTypes.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
22 |
654
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
644
diff
changeset
|
23 #include <Framework/Messages/IObserver.h> |
644 | 24 |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
25 #include <Framework/Scene2D/OpenGLCompositor.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
26 |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
27 #include <Framework/Scene2DViewport/ViewportController.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
28 #include <Framework/Scene2DViewport/IFlexiblePointerTracker.h> |
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
29 #include <Framework/Scene2DViewport/MeasureTools.h> |
644 | 30 |
31 #include <SDL.h> | |
32 | |
33 #include <boost/make_shared.hpp> | |
34 #include <boost/shared_ptr.hpp> | |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
35 #include <boost/enable_shared_from_this.hpp> |
644 | 36 |
37 namespace OrthancStone | |
38 { | |
39 enum GuiTool | |
40 { | |
41 GuiTool_Rotate = 0, | |
42 GuiTool_Pan, | |
43 GuiTool_Zoom, | |
44 GuiTool_LineMeasure, | |
45 GuiTool_CircleMeasure, | |
46 GuiTool_AngleMeasure, | |
47 GuiTool_EllipseMeasure, | |
48 GuiTool_LAST | |
49 }; | |
50 | |
51 const char* MeasureToolToString(size_t i); | |
52 | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
53 static const unsigned int FONT_SIZE_0 = 32; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
54 static const unsigned int FONT_SIZE_1 = 24; |
644 | 55 |
56 class Scene2D; | |
57 | |
654
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
644
diff
changeset
|
58 class TrackerSampleApp : public IObserver |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
59 , public boost::enable_shared_from_this<TrackerSampleApp> |
644 | 60 { |
61 public: | |
62 // 12 because. | |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
63 TrackerSampleApp(MessageBroker& broker); |
644 | 64 void PrepareScene(); |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
65 void Run(); |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
66 void SetInfoDisplayMessage(std::string key, std::string value); |
644 | 67 void DisableTracker(); |
68 | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
69 Scene2DPtr GetScene(); |
644 | 70 |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
71 void HandleApplicationEvent(const SDL_Event& event); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
72 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
73 /** |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
74 This method is called when the scene transform changes. It allows to |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
75 recompute the visual elements whose content depend upon the scene transform |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
76 */ |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
77 void OnSceneTransformChanged(const Scene2D::SceneTransformChanged& message); |
644 | 78 |
79 private: | |
80 void SelectNextTool(); | |
81 | |
82 | |
83 FlexiblePointerTrackerPtr TrackerHitTest(const PointerEvent& e); | |
84 | |
85 FlexiblePointerTrackerPtr CreateSuitableTracker( | |
86 const SDL_Event& event, | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
87 const PointerEvent& e); |
644 | 88 |
89 void TakeScreenshot( | |
90 const std::string& target, | |
91 unsigned int canvasWidth, | |
92 unsigned int canvasHeight); | |
93 | |
94 /** | |
95 This adds the command at the top of the undo stack | |
96 */ | |
97 void Commit(TrackerCommandPtr cmd); | |
98 void Undo(); | |
99 void Redo(); | |
100 | |
101 private: | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
102 void DisplayFloatingCtrlInfoText(const PointerEvent& e); |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
103 void DisplayInfoText(); |
644 | 104 void HideInfoText(); |
105 | |
106 private: | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
107 std::auto_ptr<OpenGLCompositor> compositor_; |
644 | 108 /** |
109 WARNING: the measuring tools do store a reference to the scene, and it | |
110 paramount that the scene gets destroyed AFTER the measurement tools. | |
111 */ | |
698
8b6adfb62a2f
Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents:
660
diff
changeset
|
112 ViewportControllerPtr controller_; |
644 | 113 |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
114 std::map<std::string, std::string> infoTextMap_; |
644 | 115 FlexiblePointerTrackerPtr activeTracker_; |
116 std::vector<TrackerCommandPtr> undoStack_; | |
117 | |
118 // we store the measure tools here so that they don't get deleted | |
119 std::vector<MeasureToolPtr> measureTools_; | |
120 | |
121 //static const int LAYER_POSITION = 150; | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
122 |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
123 |
644 | 124 int TEXTURE_2x2_1_ZINDEX; |
125 int TEXTURE_1x1_ZINDEX; | |
126 int TEXTURE_2x2_2_ZINDEX; | |
127 int LINESET_1_ZINDEX; | |
128 int LINESET_2_ZINDEX; | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
129 int FLOATING_INFOTEXT_LAYER_ZINDEX; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
130 int FIXED_INFOTEXT_LAYER_ZINDEX; |
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
131 |
644 | 132 GuiTool currentTool_; |
133 }; | |
134 | |
135 } |