Mercurial > hg > orthanc-stone
annotate Samples/Sdl/TrackerSampleApp.h @ 872:733c6db3e5a3 am-dev
limiting the size of the cache
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 01 Jul 2019 13:36:51 +0200 |
parents | e3c56d4f863f |
children | 0aff28f15ea2 |
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 |
737 | 22 #include "../../Framework/Messages/IObserver.h" |
23 #include "../../Framework/Scene2D/OpenGLCompositor.h" | |
24 #include "../../Framework/Scene2DViewport/IFlexiblePointerTracker.h" | |
774
66ac7a2d1e3a
A few renames and cleanups + moved GUI constants to controller + start work on
Benjamin Golinvaux <bgo@osimis.io>
parents:
761
diff
changeset
|
25 #include "../../Framework/Scene2DViewport/MeasureTool.h" |
818
e42b491f1fb2
Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents:
774
diff
changeset
|
26 #include "../../Framework/Scene2DViewport/PredeclaredTypes.h" |
737 | 27 #include "../../Framework/Scene2DViewport/ViewportController.h" |
644 | 28 |
29 #include <SDL.h> | |
30 | |
31 #include <boost/make_shared.hpp> | |
32 #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
|
33 #include <boost/enable_shared_from_this.hpp> |
644 | 34 |
35 namespace OrthancStone | |
36 { | |
37 enum GuiTool | |
38 { | |
39 GuiTool_Rotate = 0, | |
40 GuiTool_Pan, | |
41 GuiTool_Zoom, | |
42 GuiTool_LineMeasure, | |
43 GuiTool_CircleMeasure, | |
44 GuiTool_AngleMeasure, | |
45 GuiTool_EllipseMeasure, | |
46 GuiTool_LAST | |
47 }; | |
48 | |
49 const char* MeasureToolToString(size_t i); | |
50 | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
51 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
|
52 static const unsigned int FONT_SIZE_1 = 24; |
644 | 53 |
54 class Scene2D; | |
858
e3c56d4f863f
GuiAdapter : mouse event routing in SDL + split the undo stack from the
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
55 class UndoStack; |
644 | 56 |
654
462a5074f914
Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents:
644
diff
changeset
|
57 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
|
58 , public boost::enable_shared_from_this<TrackerSampleApp> |
644 | 59 { |
60 public: | |
61 // 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
|
62 TrackerSampleApp(MessageBroker& broker); |
644 | 63 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
|
64 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
|
65 void SetInfoDisplayMessage(std::string key, std::string value); |
644 | 66 void DisableTracker(); |
67 | |
818
e42b491f1fb2
Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents:
774
diff
changeset
|
68 boost::shared_ptr<Scene2D> GetScene(); |
e42b491f1fb2
Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents:
774
diff
changeset
|
69 boost::shared_ptr<const Scene2D> GetScene() const; |
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 */ |
700
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
698
diff
changeset
|
77 void OnSceneTransformChanged( |
059e1fd05fd6
Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents:
698
diff
changeset
|
78 const ViewportController::SceneTransformChanged& message); |
644 | 79 |
80 private: | |
81 void SelectNextTool(); | |
761
07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents:
737
diff
changeset
|
82 void CreateRandomMeasureTool(); |
644 | 83 |
761
07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents:
737
diff
changeset
|
84 /** |
07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents:
737
diff
changeset
|
85 This returns a random point in the canvas part of the scene, but in |
07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents:
737
diff
changeset
|
86 scene coordinates |
07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents:
737
diff
changeset
|
87 */ |
07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents:
737
diff
changeset
|
88 ScenePoint2D GetRandomPointInScene() const; |
644 | 89 |
818
e42b491f1fb2
Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents:
774
diff
changeset
|
90 boost::shared_ptr<IFlexiblePointerTracker> TrackerHitTest(const PointerEvent& e); |
644 | 91 |
818
e42b491f1fb2
Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents:
774
diff
changeset
|
92 boost::shared_ptr<IFlexiblePointerTracker> CreateSuitableTracker( |
644 | 93 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
|
94 const PointerEvent& e); |
644 | 95 |
96 void TakeScreenshot( | |
97 const std::string& target, | |
98 unsigned int canvasWidth, | |
99 unsigned int canvasHeight); | |
100 | |
101 /** | |
102 This adds the command at the top of the undo stack | |
103 */ | |
818
e42b491f1fb2
Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents:
774
diff
changeset
|
104 void Commit(boost::shared_ptr<TrackerCommand> cmd); |
644 | 105 void Undo(); |
106 void Redo(); | |
107 | |
108 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
|
109 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
|
110 void DisplayInfoText(); |
644 | 111 void HideInfoText(); |
112 | |
113 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
|
114 std::auto_ptr<OpenGLCompositor> compositor_; |
644 | 115 /** |
116 WARNING: the measuring tools do store a reference to the scene, and it | |
117 paramount that the scene gets destroyed AFTER the measurement tools. | |
118 */ | |
818
e42b491f1fb2
Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents:
774
diff
changeset
|
119 boost::shared_ptr<ViewportController> controller_; |
644 | 120 |
660
cb3b76d16234
Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents:
656
diff
changeset
|
121 std::map<std::string, std::string> infoTextMap_; |
818
e42b491f1fb2
Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents:
774
diff
changeset
|
122 boost::shared_ptr<IFlexiblePointerTracker> activeTracker_; |
644 | 123 |
124 //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
|
125 |
644 | 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; | |
656
002d9562c8f5
Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents:
654
diff
changeset
|
131 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
|
132 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
|
133 |
644 | 134 GuiTool currentTool_; |
858
e3c56d4f863f
GuiAdapter : mouse event routing in SDL + split the undo stack from the
Benjamin Golinvaux <bgo@osimis.io>
parents:
818
diff
changeset
|
135 boost::shared_ptr<UndoStack> undoStack_; |
644 | 136 }; |
137 | |
138 } |