Mercurial > hg > orthanc-stone
annotate Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewer.cpp @ 1688:c14dd6e11ddd
merge
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 25 Nov 2020 17:03:08 +0100 |
parents | 4fb8fdf03314 |
children | 9ac2a65d4172 |
rev | line source |
---|---|
1458
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
1 /** |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
2 * Stone of Orthanc |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
6 * |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
10 * the License, or (at your option) any later version. |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
11 * |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
15 * Affero General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1591
diff
changeset
|
16 * |
1458
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
19 **/ |
828a9b4ee1b7
added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1457
diff
changeset
|
20 |
1368 | 21 |
22 #include "SdlSimpleViewerApplication.h" | |
1387
4ebf246f3919
Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1383
diff
changeset
|
23 #include "../SdlHelpers.h" |
4ebf246f3919
Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1383
diff
changeset
|
24 #include "../../Common/SampleHelpers.h" |
1368 | 25 |
1542 | 26 #include "../../../../OrthancStone/Sources/Loaders/GenericLoadersContext.h" |
1560
b4ccd4963d37
fix sdl and wasm samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1542
diff
changeset
|
27 #include "../../../../OrthancStone/Sources/StoneEnumerations.h" |
1542 | 28 #include "../../../../OrthancStone/Sources/StoneException.h" |
29 #include "../../../../OrthancStone/Sources/StoneInitialization.h" | |
1560
b4ccd4963d37
fix sdl and wasm samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1542
diff
changeset
|
30 #include "../../../../OrthancStone/Sources/Viewport/DefaultViewportInteractor.h" |
1591
5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
31 #include "../../../Platforms/Sdl/SdlViewport.h" |
1368 | 32 |
1507
169adf9090a6
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1458
diff
changeset
|
33 #include <Compatibility.h> // For std::unique_ptr<> |
1457 | 34 #include <OrthancException.h> |
1387
4ebf246f3919
Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1383
diff
changeset
|
35 |
4ebf246f3919
Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1383
diff
changeset
|
36 #include <boost/program_options.hpp> |
4ebf246f3919
Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1383
diff
changeset
|
37 #include <SDL.h> |
4ebf246f3919
Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1383
diff
changeset
|
38 |
4ebf246f3919
Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1383
diff
changeset
|
39 #include <string> |
4ebf246f3919
Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1383
diff
changeset
|
40 |
1368 | 41 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
42 std::string orthancUrl; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
43 std::string instanceId; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
44 int frameIndex = 0; |
1368 | 45 |
1387
4ebf246f3919
Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1383
diff
changeset
|
46 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
47 static void ProcessOptions(int argc, char* argv[]) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
48 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
49 namespace po = boost::program_options; |
1532
c7a37c3a0b8e
print help in sdl samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
50 po::options_description desc("Usage"); |
1368 | 51 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
52 desc.add_options() |
1387
4ebf246f3919
Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1383
diff
changeset
|
53 ("loglevel", po::value<std::string>()->default_value("WARNING"), |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
54 "You can choose WARNING, INFO or TRACE for the logging level: Errors and warnings will always be displayed. (default: WARNING)") |
1368 | 55 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
56 ("orthanc", po::value<std::string>()->default_value("http://localhost:8042"), |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
57 "Base URL of the Orthanc instance") |
1368 | 58 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
59 ("instance", po::value<std::string>()->default_value("285dece8-e1956b38-cdc7d084-6ce3371e-536a9ffc"), |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
60 "Orthanc ID of the instance to display") |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
61 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
62 ("frame_index", po::value<int>()->default_value(0), |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
63 "The zero-based index of the frame (for multi-frame instances)") |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
64 ; |
1368 | 65 |
1532
c7a37c3a0b8e
print help in sdl samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
66 std::cout << desc << std::endl; |
c7a37c3a0b8e
print help in sdl samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
67 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
68 po::variables_map vm; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
69 try |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
70 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
71 po::store(po::parse_command_line(argc, argv, desc), vm); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
72 po::notify(vm); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
73 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
74 catch (std::exception& e) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
75 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
76 std::cerr << "Please check your command line options! (\"" << e.what() << "\")" << std::endl; |
1368 | 77 } |
78 | |
1387
4ebf246f3919
Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1383
diff
changeset
|
79 if (vm.count("loglevel") > 0) |
1368 | 80 { |
1387
4ebf246f3919
Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1383
diff
changeset
|
81 std::string logLevel = vm["loglevel"].as<std::string>(); |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
82 OrthancStoneHelpers::SetLogLevel(logLevel); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
83 } |
1368 | 84 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
85 if (vm.count("orthanc") > 0) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
86 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
87 // maybe check URL validity here |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
88 orthancUrl = vm["orthanc"].as<std::string>(); |
1368 | 89 } |
90 | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
91 if (vm.count("instance") > 0) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
92 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
93 instanceId = vm["instance"].as<std::string>(); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
94 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
95 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
96 if (vm.count("frame_index") > 0) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
97 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
98 frameIndex = vm["frame_index"].as<int>(); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
99 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
100 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
101 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
102 |
1368 | 103 /** |
104 * IMPORTANT: The full arguments to "main()" are needed for SDL on | |
105 * Windows. Otherwise, one gets the linking error "undefined reference | |
106 * to `SDL_main'". https://wiki.libsdl.org/FAQWindows | |
107 **/ | |
108 int main(int argc, char* argv[]) | |
109 { | |
110 try | |
111 { | |
112 OrthancStone::StoneInitialize(); | |
1591
5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
113 OrthancStone::SdlWindow::GlobalInitialize(); |
5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
114 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
115 ProcessOptions(argc, argv); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
116 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
117 //Orthanc::Logging::EnableInfoLevel(true); |
1368 | 118 //Orthanc::Logging::EnableTraceLevel(true); |
119 | |
120 { | |
121 | |
122 #if 1 | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
123 boost::shared_ptr<OrthancStone::SdlViewport> viewport = |
1368 | 124 OrthancStone::SdlOpenGLViewport::Create("Stone of Orthanc", 800, 600); |
125 #else | |
126 boost::shared_ptr<OrthancStone::SdlViewport> viewport = | |
127 OrthancStone::SdlCairoViewport::Create("Stone of Orthanc", 800, 600); | |
128 #endif | |
129 | |
130 OrthancStone::GenericLoadersContext context(1, 4, 1); | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
131 |
1395
62dc0d737e7b
build script for wasm sample + updated instructions + fixed Sdl sample for Orthanc listening on other ports that 8042
Alain Mazy <alain@mazy.be>
parents:
1392
diff
changeset
|
132 Orthanc::WebServiceParameters orthancWebService; |
62dc0d737e7b
build script for wasm sample + updated instructions + fixed Sdl sample for Orthanc listening on other ports that 8042
Alain Mazy <alain@mazy.be>
parents:
1392
diff
changeset
|
133 orthancWebService.SetUrl(orthancUrl); |
62dc0d737e7b
build script for wasm sample + updated instructions + fixed Sdl sample for Orthanc listening on other ports that 8042
Alain Mazy <alain@mazy.be>
parents:
1392
diff
changeset
|
134 context.SetOrthancParameters(orthancWebService); |
62dc0d737e7b
build script for wasm sample + updated instructions + fixed Sdl sample for Orthanc listening on other ports that 8042
Alain Mazy <alain@mazy.be>
parents:
1392
diff
changeset
|
135 |
1368 | 136 context.StartOracle(); |
137 | |
138 { | |
139 | |
140 boost::shared_ptr<SdlSimpleViewerApplication> application( | |
141 SdlSimpleViewerApplication::Create(context, viewport)); | |
142 | |
143 OrthancStone::DicomSource source; | |
144 | |
145 application->LoadOrthancFrame(source, instanceId, frameIndex); | |
146 | |
147 OrthancStone::DefaultViewportInteractor interactor; | |
1535
301571299212
DefaultViewportInteractor::SetWindowingLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1532
diff
changeset
|
148 interactor.SetWindowingLayer(0); |
1368 | 149 |
150 { | |
151 int scancodeCount = 0; | |
152 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount); | |
153 | |
154 bool stop = false; | |
155 while (!stop) | |
156 { | |
157 bool paint = false; | |
158 SDL_Event event; | |
159 while (SDL_PollEvent(&event)) | |
160 { | |
161 if (event.type == SDL_QUIT) | |
162 { | |
163 stop = true; | |
164 break; | |
165 } | |
166 else if (viewport->IsRefreshEvent(event)) | |
167 { | |
168 paint = true; | |
169 } | |
170 else if (event.type == SDL_WINDOWEVENT && | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
171 (event.window.event == SDL_WINDOWEVENT_RESIZED || |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
172 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) |
1368 | 173 { |
174 viewport->UpdateSize(event.window.data1, event.window.data2); | |
175 } | |
176 else if (event.type == SDL_WINDOWEVENT && | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
177 (event.window.event == SDL_WINDOWEVENT_SHOWN || |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
178 event.window.event == SDL_WINDOWEVENT_EXPOSED)) |
1368 | 179 { |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1560
diff
changeset
|
180 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock()); |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1560
diff
changeset
|
181 lock->RefreshCanvasSize(); |
1368 | 182 } |
183 else if (event.type == SDL_KEYDOWN && | |
184 event.key.repeat == 0 /* Ignore key bounce */) | |
185 { | |
186 switch (event.key.keysym.sym) | |
187 { | |
188 case SDLK_f: | |
189 viewport->ToggleMaximize(); | |
190 break; | |
191 | |
192 case SDLK_s: | |
193 application->FitContent(); | |
194 break; | |
195 | |
196 case SDLK_q: | |
197 stop = true; | |
198 break; | |
199 | |
200 default: | |
201 break; | |
202 } | |
203 } | |
204 else if (event.type == SDL_MOUSEBUTTONDOWN || | |
205 event.type == SDL_MOUSEMOTION || | |
206 event.type == SDL_MOUSEBUTTONUP) | |
207 { | |
1507
169adf9090a6
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1458
diff
changeset
|
208 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock()); |
1368 | 209 if (lock->HasCompositor()) |
210 { | |
211 OrthancStone::PointerEvent p; | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
212 OrthancStoneHelpers::GetPointerEvent(p, lock->GetCompositor(), |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
213 event, keyboardState, scancodeCount); |
1368 | 214 |
215 switch (event.type) | |
216 { | |
217 case SDL_MOUSEBUTTONDOWN: | |
218 lock->GetController().HandleMousePress(interactor, p, | |
219 lock->GetCompositor().GetCanvasWidth(), | |
220 lock->GetCompositor().GetCanvasHeight()); | |
221 lock->Invalidate(); | |
222 break; | |
223 | |
224 case SDL_MOUSEMOTION: | |
225 if (lock->GetController().HandleMouseMove(p)) | |
226 { | |
227 lock->Invalidate(); | |
228 } | |
229 break; | |
230 | |
231 case SDL_MOUSEBUTTONUP: | |
232 lock->GetController().HandleMouseRelease(p); | |
233 lock->Invalidate(); | |
234 break; | |
235 | |
236 default: | |
237 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
238 } | |
239 } | |
240 } | |
241 } | |
242 | |
243 if (paint) | |
244 { | |
245 viewport->Paint(); | |
246 } | |
247 | |
248 // Small delay to avoid using 100% of CPU | |
249 SDL_Delay(1); | |
250 } | |
251 } | |
252 context.StopOracle(); | |
253 } | |
254 } | |
255 | |
1591
5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
256 OrthancStone::SdlWindow::GlobalFinalize(); |
1368 | 257 OrthancStone::StoneFinalize(); |
258 return 0; | |
259 } | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
260 catch (Orthanc::OrthancException& e) |
1368 | 261 { |
262 LOG(ERROR) << "OrthancException: " << e.What(); | |
263 return -1; | |
264 } | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
265 catch (OrthancStone::StoneException& e) |
1368 | 266 { |
267 LOG(ERROR) << "StoneException: " << e.What(); | |
268 return -1; | |
269 } | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
270 catch (std::runtime_error& e) |
1368 | 271 { |
272 LOG(ERROR) << "Runtime error: " << e.what(); | |
273 return -1; | |
274 } | |
275 catch (...) | |
276 { | |
277 LOG(ERROR) << "Native exception"; | |
278 return -1; | |
279 } | |
280 } |