Mercurial > hg > orthanc-stone
annotate Samples/Sdl/RtViewer/RtViewerSdl.cpp @ 1431:1eaf19af15bf
OpenGL: OS X does not seem to support debug output functionality
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 15 May 2020 21:14:35 +0200 |
parents | 5128b448a6ee |
children | c6bfcc105414 |
rev | line source |
---|---|
1386
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
1 /** |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
2 * Stone of Orthanc |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
6 * |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
10 * the License, or (at your option) any later version. |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
11 * |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
15 * Affero General Public License for more details. |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
16 * |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
19 **/ |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
20 |
1404
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
21 #include "RtViewerApp.h" |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
22 #include "RtViewerView.h" |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
23 #include "../SdlHelpers.h" |
1386
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
24 |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
25 // Stone of Orthanc includes |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
26 #include <Framework/Loaders/GenericLoadersContext.h> |
1428
da411df009bd
trying to fix issue with GLAPIENTRY on OS X
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
27 #include <Framework/OpenGL/OpenGLIncludes.h> |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
28 #include <Framework/OpenGL/SdlOpenGLContext.h> |
1386
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
29 #include <Framework/StoneException.h> |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
30 #include <Framework/StoneInitialization.h> |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
31 |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
32 // Orthanc (a.o. for screenshot capture) |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
33 #include <Core/Images/Image.h> |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
34 #include <Core/Images/ImageProcessing.h> |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
35 #include <Core/Images/PngWriter.h> |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
36 |
1386
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
37 |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
38 #include <boost/program_options.hpp> |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
39 #include <boost/shared_ptr.hpp> |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
40 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
41 // #include <boost/pointer_cast.hpp> this include might be necessary in more recent boost versions |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
42 |
1386
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
43 #include <SDL.h> |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
44 |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
45 #include <string> |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
46 |
1430
5128b448a6ee
yet another try to fix OS X
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
47 |
1431
1eaf19af15bf
OpenGL: OS X does not seem to support debug output functionality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
48 #if !defined(__APPLE__) |
1eaf19af15bf
OpenGL: OS X does not seem to support debug output functionality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
49 /** |
1eaf19af15bf
OpenGL: OS X does not seem to support debug output functionality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
50 * OpenGL: "OS X does not seem to support debug output functionality |
1eaf19af15bf
OpenGL: OS X does not seem to support debug output functionality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
51 * (as gathered online)." |
1eaf19af15bf
OpenGL: OS X does not seem to support debug output functionality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
52 * https://learnopengl.com/In-Practice/Debugging |
1eaf19af15bf
OpenGL: OS X does not seem to support debug output functionality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
53 **/ |
1430
5128b448a6ee
yet another try to fix OS X
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
54 static void GLAPIENTRY |
1386
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
55 OpenGLMessageCallback(GLenum source, |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
56 GLenum type, |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
57 GLuint id, |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
58 GLenum severity, |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
59 GLsizei length, |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
60 const GLchar* message, |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
61 const void* userParam) |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
62 { |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
63 if (severity != GL_DEBUG_SEVERITY_NOTIFICATION) |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
64 { |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
65 fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
66 (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
67 type, severity, message); |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
68 } |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
69 } |
1431
1eaf19af15bf
OpenGL: OS X does not seem to support debug output functionality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
70 #endif |
1386
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
71 |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
72 namespace OrthancStone |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
73 { |
1404
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
74 void RtViewerView::EnableGLDebugOutput() |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
75 { |
1431
1eaf19af15bf
OpenGL: OS X does not seem to support debug output functionality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
76 #if !defined(__APPLE__) |
1404
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
77 glEnable(GL_DEBUG_OUTPUT); |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
78 glDebugMessageCallback(OpenGLMessageCallback, 0); |
1431
1eaf19af15bf
OpenGL: OS X does not seem to support debug output functionality
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
79 #endif |
1404
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
80 } |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
81 |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
82 boost::shared_ptr<IViewport> RtViewerView::CreateViewport(const std::string& canvasId) |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
83 { |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
84 // False means we do NOT let Windows treat this as a legacy application that needs to be scaled |
1404
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
85 return SdlOpenGLViewport::Create(canvasId, 1024, 1024, false); |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
86 } |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
87 |
1386
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
88 void RtViewerApp::ProcessOptions(int argc, char* argv[]) |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
89 { |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
90 namespace po = boost::program_options; |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
91 po::options_description desc("Usage:"); |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
92 |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
93 desc.add_options() |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
94 ("loglevel", po::value<std::string>()->default_value("WARNING"), |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
95 "You can choose WARNING, INFO or TRACE for the logging level: Errors and warnings will always be displayed. (default: WARNING)") |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
96 |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
97 ("orthanc", po::value<std::string>()->default_value("http://localhost:8042"), |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
98 "Base URL of the Orthanc instance") |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
99 |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
100 ("ctseries", po::value<std::string>()->default_value("a04ecf01-79b2fc33-58239f7e-ad9db983-28e81afa"), |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
101 "Orthanc ID of the CT series to load") |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
102 |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
103 ("rtdose", po::value<std::string>()->default_value("830a69ff-8e4b5ee3-b7f966c8-bccc20fb-d322dceb"), |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
104 "Orthanc ID of the RTDOSE instance to load") |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
105 |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
106 ("rtstruct", po::value<std::string>()->default_value("54460695-ba3885ee-ddf61ac0-f028e31d-a6e474d9"), |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
107 "Orthanc ID of the RTSTRUCT instance to load") |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
108 ; |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
109 |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
110 po::variables_map vm; |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
111 try |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
112 { |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
113 po::store(po::parse_command_line(argc, argv, desc), vm); |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
114 po::notify(vm); |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
115 } |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
116 catch (std::exception& e) |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
117 { |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
118 std::cerr << "Please check your command line options! (\"" << e.what() << "\")" << std::endl; |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
119 } |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
120 |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
121 for (po::variables_map::iterator it = vm.begin(); it != vm.end(); ++it) |
1386
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
122 { |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
123 std::string key = it->first; |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
124 const po::variable_value& value = it->second; |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
125 const std::string& strValue = value.as<std::string>(); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
126 SetArgument(key, strValue); |
1386
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
127 } |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
128 } |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
129 |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
130 void RtViewerApp::RunSdl(int argc, char* argv[]) |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
131 { |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
132 ProcessOptions(argc, argv); |
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
133 |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
134 /** |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
135 Create the shared loaders context |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
136 */ |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
137 loadersContext_.reset(new GenericLoadersContext(1, 4, 1)); |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
138 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
139 // we are in SDL --> downcast to concrete type |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
140 boost::shared_ptr<GenericLoadersContext> loadersContext = boost::dynamic_pointer_cast<GenericLoadersContext>(loadersContext_); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
141 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
142 /** |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
143 Url of the Orthanc instance |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
144 Typically, in a native application (Qt, SDL), it will be an absolute URL like "http://localhost:8042". In |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
145 wasm on the browser, it could be an absolute URL, provided you do not have cross-origin problems, or a relative |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
146 URL. In our wasm samples, it is set to "..", because we set up either a reverse proxy or an Orthanc ServeFolders |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
147 plugin that serves the main web application from an URL like "http://localhost:8042/rtviewer" (with ".." leading |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
148 to the main Orthanc root URL) |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
149 */ |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
150 std::string orthancUrl = arguments_["orthanc"]; |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
151 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
152 { |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
153 Orthanc::WebServiceParameters p; |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
154 if (HasArgument("orthanc")) |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
155 { |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
156 p.SetUrl(orthancUrl); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
157 } |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
158 if (HasArgument("user")) |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
159 { |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
160 ORTHANC_ASSERT(HasArgument("password")); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
161 p.SetCredentials(GetArgument("user"), GetArgument("password")); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
162 } |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
163 else |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
164 { |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
165 ORTHANC_ASSERT(!HasArgument("password")); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
166 } |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
167 loadersContext->SetOrthancParameters(p); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
168 } |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
169 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
170 loadersContext->StartOracle(); |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
171 |
1404
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
172 CreateLoaders(); |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
173 |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
174 /** |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
175 Create viewports |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
176 */ |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
177 CreateView("RtViewer Axial", VolumeProjection_Axial); |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
178 CreateView("RtViewer Coronal", VolumeProjection_Coronal); |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
179 CreateView("RtViewer Sagittal", VolumeProjection_Sagittal); |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
180 |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
181 for (size_t i = 0; i < views_.size(); ++i) |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
182 { |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
183 views_[i]->PrepareViewport(); |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
184 views_[i]->EnableGLDebugOutput(); |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
185 } |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
186 |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
187 DefaultViewportInteractor interactor; |
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
188 |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
189 /** |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
190 It is very important that the Oracle (responsible for network I/O) be started before creating and firing the |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
191 loaders, for any command scheduled by the loader before the oracle is started will be lost. |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
192 */ |
1404
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
193 StartLoaders(); |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
194 |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
195 |
1406
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
196 SdlRunLoop(views_, interactor); |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
197 loadersContext->StopOracle(); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
198 } |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
199 |
1404
3e644f6fadd4
Three-viewport is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1393
diff
changeset
|
200 void RtViewerView::TakeScreenshot(const std::string& target, |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
201 unsigned int canvasWidth, |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
202 unsigned int canvasHeight) |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
203 { |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
204 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
205 ViewportController& controller = lock->GetController(); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
206 Scene2D& scene = controller.GetScene(); |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
207 |
1393
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
208 CairoCompositor compositor(canvasWidth, canvasHeight); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
209 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, FONT_SIZE_0, Orthanc::Encoding_Latin1); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
210 compositor.Refresh(scene); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
211 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
212 Orthanc::ImageAccessor canvas; |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
213 compositor.GetCanvas().GetReadOnlyAccessor(canvas); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
214 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
215 Orthanc::Image png(Orthanc::PixelFormat_RGB24, canvas.GetWidth(), canvas.GetHeight(), false); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
216 Orthanc::ImageProcessing::Convert(png, canvas); |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
217 |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
218 Orthanc::PngWriter writer; |
27e0a00bd3e8
RtViewer SingleFrameViewer OK : wasm SDL single viewport
Benjamin Golinvaux <bgo@osimis.io>
parents:
1392
diff
changeset
|
219 writer.WriteToFile(target, png); |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
220 } |
1406
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
221 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
222 static boost::shared_ptr<OrthancStone::RtViewerView> GetViewFromWindowId( |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
223 const std::vector<boost::shared_ptr<OrthancStone::RtViewerView> >& views, |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
224 Uint32 windowID) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
225 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
226 using namespace OrthancStone; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
227 for (size_t i = 0; i < views.size(); ++i) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
228 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
229 boost::shared_ptr<OrthancStone::RtViewerView> view = views[i]; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
230 boost::shared_ptr<IViewport> viewport = view->GetViewport(); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
231 boost::shared_ptr<SdlViewport> sdlViewport = boost::dynamic_pointer_cast<SdlViewport>(viewport); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
232 Uint32 curWindowID = sdlViewport->GetSdlWindowId(); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
233 if (windowID == curWindowID) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
234 return view; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
235 } |
1427 | 236 return boost::shared_ptr<OrthancStone::RtViewerView>(); |
1406
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
237 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
238 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
239 void RtViewerApp::SdlRunLoop(const std::vector<boost::shared_ptr<OrthancStone::RtViewerView> >& views, |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
240 OrthancStone::IViewportInteractor& interactor) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
241 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
242 using namespace OrthancStone; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
243 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
244 // const std::vector<boost::shared_ptr<OrthancStone::RtViewerView> >& views |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
245 std::vector<boost::shared_ptr<OrthancStone::SdlViewport> > viewports; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
246 for (size_t i = 0; i < views.size(); ++i) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
247 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
248 boost::shared_ptr<RtViewerView> view = views[i]; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
249 boost::shared_ptr<IViewport> viewport = view->GetViewport(); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
250 boost::shared_ptr<SdlViewport> sdlViewport = |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
251 boost::dynamic_pointer_cast<SdlViewport>(viewport); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
252 viewports.push_back(sdlViewport); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
253 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
254 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
255 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
256 int scancodeCount = 0; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
257 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
258 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
259 bool stop = false; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
260 while (!stop) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
261 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
262 bool paint = false; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
263 SDL_Event event; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
264 while (SDL_PollEvent(&event)) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
265 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
266 if (event.type == SDL_QUIT) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
267 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
268 stop = true; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
269 break; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
270 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
271 else if (event.type == SDL_WINDOWEVENT && |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
272 (event.window.event == SDL_WINDOWEVENT_RESIZED || |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
273 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
274 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
275 boost::shared_ptr<RtViewerView> view = GetViewFromWindowId( |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
276 views, event.window.windowID); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
277 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
278 boost::shared_ptr<SdlViewport> sdlViewport = |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
279 boost::dynamic_pointer_cast<SdlViewport>(view->GetViewport()); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
280 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
281 sdlViewport->UpdateSize(event.window.data1, event.window.data2); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
282 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
283 else if (event.type == SDL_WINDOWEVENT && |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
284 (event.window.event == SDL_WINDOWEVENT_SHOWN || |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
285 event.window.event == SDL_WINDOWEVENT_EXPOSED)) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
286 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
287 boost::shared_ptr<RtViewerView> view = GetViewFromWindowId( |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
288 views, event.window.windowID); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
289 boost::shared_ptr<SdlViewport> sdlViewport = |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
290 boost::dynamic_pointer_cast<SdlViewport>(view->GetViewport()); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
291 sdlViewport->Paint(); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
292 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
293 else if (event.type == SDL_KEYDOWN && |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
294 event.key.repeat == 0 /* Ignore key bounce */) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
295 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
296 boost::shared_ptr<RtViewerView> view = GetViewFromWindowId( |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
297 views, event.window.windowID); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
298 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
299 switch (event.key.keysym.sym) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
300 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
301 case SDLK_f: |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
302 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
303 boost::shared_ptr<SdlViewport> sdlViewport = |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
304 boost::dynamic_pointer_cast<SdlViewport>(view->GetViewport()); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
305 sdlViewport->ToggleMaximize(); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
306 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
307 break; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
308 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
309 case SDLK_s: |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
310 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
311 std::unique_ptr<OrthancStone::IViewport::ILock> lock(view->GetViewport()->Lock()); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
312 lock->GetCompositor().FitContent(lock->GetController().GetScene()); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
313 lock->Invalidate(); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
314 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
315 break; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
316 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
317 case SDLK_q: |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
318 stop = true; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
319 break; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
320 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
321 default: |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
322 break; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
323 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
324 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
325 else if (event.type == SDL_MOUSEBUTTONDOWN || |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
326 event.type == SDL_MOUSEMOTION || |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
327 event.type == SDL_MOUSEBUTTONUP) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
328 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
329 boost::shared_ptr<RtViewerView> view = GetViewFromWindowId( |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
330 views, event.window.windowID); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
331 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
332 std::auto_ptr<OrthancStone::IViewport::ILock> lock(view->GetViewport()->Lock()); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
333 if (lock->HasCompositor()) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
334 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
335 OrthancStone::PointerEvent p; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
336 OrthancStoneHelpers::GetPointerEvent(p, lock->GetCompositor(), |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
337 event, keyboardState, scancodeCount); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
338 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
339 switch (event.type) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
340 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
341 case SDL_MOUSEBUTTONDOWN: |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
342 lock->GetController().HandleMousePress(interactor, p, |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
343 lock->GetCompositor().GetCanvasWidth(), |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
344 lock->GetCompositor().GetCanvasHeight()); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
345 lock->Invalidate(); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
346 break; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
347 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
348 case SDL_MOUSEMOTION: |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
349 if (lock->GetController().HandleMouseMove(p)) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
350 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
351 lock->Invalidate(); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
352 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
353 break; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
354 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
355 case SDL_MOUSEBUTTONUP: |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
356 lock->GetController().HandleMouseRelease(p); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
357 lock->Invalidate(); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
358 break; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
359 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
360 default: |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
361 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
362 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
363 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
364 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
365 else if (event.type == SDL_MOUSEWHEEL) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
366 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
367 boost::shared_ptr<RtViewerView> view = GetViewFromWindowId( |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
368 views, event.window.windowID); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
369 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
370 int delta = 0; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
371 if (event.wheel.y < 0) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
372 delta = -1; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
373 if (event.wheel.y > 0) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
374 delta = 1; |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
375 |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
376 view->Scroll(delta); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
377 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
378 else |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
379 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
380 for (size_t i = 0; i < views.size(); ++i) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
381 { |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
382 boost::shared_ptr<SdlViewport> sdlViewport = |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
383 boost::dynamic_pointer_cast<SdlViewport>(views[i]->GetViewport()); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
384 if (sdlViewport->IsRefreshEvent(event)) |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
385 sdlViewport->Paint(); |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
386 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
387 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
388 } |
1408
875c9a28236e
Fixed busy CPU in RtViewer
Benjamin Golinvaux <bgo@osimis.io>
parents:
1406
diff
changeset
|
389 // Small delay to avoid using 100% of CPU |
875c9a28236e
Fixed busy CPU in RtViewer
Benjamin Golinvaux <bgo@osimis.io>
parents:
1406
diff
changeset
|
390 SDL_Delay(1); |
1406
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
391 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
392 } |
5d7ee14dc1eb
Mouse wheel handler is now OK in SDL and Wasm
Benjamin Golinvaux <bgo@osimis.io>
parents:
1404
diff
changeset
|
393 } |
1386
dfb48f0794b1
Ongoing splitting SDL vs WASM (preparing RtViewer WASM)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1384
diff
changeset
|
394 } |
1392
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
395 |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
396 boost::weak_ptr<OrthancStone::RtViewerApp> g_app; |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
397 |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
398 /** |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
399 * IMPORTANT: The full arguments to "main()" are needed for SDL on |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
400 * Windows. Otherwise, one gets the linking error "undefined reference |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
401 * to `SDL_main'". https://wiki.libsdl.org/FAQWindows |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
402 **/ |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
403 int main(int argc, char* argv[]) |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
404 { |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
405 using namespace OrthancStone; |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
406 |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
407 StoneInitialize(); |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
408 |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
409 try |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
410 { |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
411 boost::shared_ptr<RtViewerApp> app = RtViewerApp::Create(); |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
412 g_app = app; |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
413 app->RunSdl(argc,argv); |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
414 } |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
415 catch (Orthanc::OrthancException& e) |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
416 { |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
417 LOG(ERROR) << "EXCEPTION: " << e.What(); |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
418 } |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
419 |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
420 StoneFinalize(); |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
421 |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
422 return 0; |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
423 } |
ffdb82850e98
Sdl run loop in /Common (might revert if need to customize)
Benjamin Golinvaux <bgo@osimis.io>
parents:
1389
diff
changeset
|
424 |