Mercurial > hg > orthanc-stone
annotate Samples/Sdl/RadiographyEditor.cpp @ 1246:3fe803f65c47 broker
proper initialization of opengl canvas size
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jan 2020 12:56:40 +0100 |
parents | 80829436ce0c |
children | 2d8ab34c8c91 |
rev | line source |
---|---|
848
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
1 /** |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
2 * Stone of Orthanc |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
6 * |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
11 * |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
16 * |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
19 **/ |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
20 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
21 #include "../Shared/RadiographyEditorApp.h" |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
22 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
23 // From Stone |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
24 #include "../../Framework/Oracle/SleepOracleCommand.h" |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
25 #include "../../Framework/Oracle/ThreadedOracle.h" |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
26 #include "../../Applications/Sdl/SdlOpenGLWindow.h" |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
27 #include "../../Framework/Scene2D/OpenGLCompositor.h" |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
28 #include "../../Framework/Scene2D/CairoCompositor.h" |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
29 #include "../../Framework/Scene2D/ColorTextureSceneLayer.h" |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
30 #include "../../Framework/Scene2D/OpenGLCompositor.h" |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
31 #include "../../Framework/StoneInitialization.h" |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
32 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
33 #include <Core/Logging.h> |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
34 #include <Core/OrthancException.h> |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
35 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
36 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
37 #include <boost/shared_ptr.hpp> |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
38 #include <boost/weak_ptr.hpp> |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
39 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
40 #include <SDL.h> |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
41 #include <stdio.h> |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
42 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
43 using namespace OrthancStone; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
44 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
45 namespace OrthancStone |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
46 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
47 class NativeApplicationContext : public IMessageEmitter |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
48 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
49 private: |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
50 boost::shared_mutex mutex_; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
51 MessageBroker broker_; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
52 IObservable oracleObservable_; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
53 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
54 public: |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
55 NativeApplicationContext() : |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
56 oracleObservable_(broker_) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
57 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
58 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
59 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
60 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
61 virtual void EmitMessage(const IObserver& observer, |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
62 const IMessage& message) ORTHANC_OVERRIDE |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
63 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
64 try |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
65 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
66 boost::unique_lock<boost::shared_mutex> lock(mutex_); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
67 oracleObservable_.EmitMessage(observer, message); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
68 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
69 catch (Orthanc::OrthancException& e) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
70 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
71 LOG(ERROR) << "Exception while emitting a message: " << e.What(); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
72 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
73 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
74 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
75 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
76 class ReaderLock : public boost::noncopyable |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
77 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
78 private: |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
79 NativeApplicationContext& that_; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
80 boost::shared_lock<boost::shared_mutex> lock_; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
81 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
82 public: |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
83 ReaderLock(NativeApplicationContext& that) : |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
84 that_(that), |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
85 lock_(that.mutex_) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
86 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
87 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
88 }; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
89 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
90 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
91 class WriterLock : public boost::noncopyable |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
92 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
93 private: |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
94 NativeApplicationContext& that_; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
95 boost::unique_lock<boost::shared_mutex> lock_; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
96 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
97 public: |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
98 WriterLock(NativeApplicationContext& that) : |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
99 that_(that), |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
100 lock_(that.mutex_) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
101 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
102 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
103 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
104 MessageBroker& GetBroker() |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
105 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
106 return that_.broker_; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
107 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
108 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
109 IObservable& GetOracleObservable() |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
110 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
111 return that_.oracleObservable_; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
112 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
113 }; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
114 }; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
115 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
116 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
117 class OpenGlSdlCompositorFactory : public ICompositorFactory |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
118 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
119 OpenGL::IOpenGLContext& openGlContext_; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
120 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
121 public: |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
122 OpenGlSdlCompositorFactory(OpenGL::IOpenGLContext& openGlContext) : |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
123 openGlContext_(openGlContext) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
124 {} |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
125 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
126 ICompositor* GetCompositor(const Scene2D& scene) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
127 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
128 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
129 OpenGLCompositor* compositor = new OpenGLCompositor(openGlContext_, scene); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
130 compositor->SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
131 FONT_SIZE_0, Orthanc::Encoding_Latin1); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
132 compositor->SetFont(1, Orthanc::EmbeddedResources::UBUNTU_FONT, |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
133 FONT_SIZE_1, Orthanc::Encoding_Latin1); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
134 return compositor; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
135 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
136 }; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
137 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
138 static void GLAPIENTRY |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
139 OpenGLMessageCallback(GLenum source, |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
140 GLenum type, |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
141 GLuint id, |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
142 GLenum severity, |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
143 GLsizei length, |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
144 const GLchar* message, |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
145 const void* userParam) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
146 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
147 if (severity != GL_DEBUG_SEVERITY_NOTIFICATION) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
148 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
149 fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
150 (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
151 type, severity, message); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
152 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
153 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
154 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
155 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
156 /** |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
157 * IMPORTANT: The full arguments to "main()" are needed for SDL on |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
158 * Windows. Otherwise, one gets the linking error "undefined reference |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
159 * to `SDL_main'". https://wiki.libsdl.org/FAQWindows |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
160 **/ |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
161 int main(int argc, char* argv[]) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
162 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
163 using namespace OrthancStone; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
164 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
165 StoneInitialize(); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
166 Orthanc::Logging::EnableInfoLevel(true); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
167 // Orthanc::Logging::EnableTraceLevel(true); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
168 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
169 try |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
170 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
171 OrthancStone::NativeApplicationContext context; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
172 OrthancStone::NativeApplicationContext::WriterLock lock(context); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
173 OrthancStone::ThreadedOracle oracle(context); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
174 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
175 // False means we do NOT let Windows treat this as a legacy application |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
176 // that needs to be scaled |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
177 SdlOpenGLWindow window("Hello", 1024, 1024, false); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
178 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
179 glEnable(GL_DEBUG_OUTPUT); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
180 glDebugMessageCallback(OpenGLMessageCallback, 0); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
181 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
182 std::auto_ptr<OpenGlSdlCompositorFactory> compositorFactory(new OpenGlSdlCompositorFactory(window)); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
183 boost::shared_ptr<RadiographyEditorApp> app(new RadiographyEditorApp(oracle, lock.GetOracleObservable(), compositorFactory.release())); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
184 app->PrepareScene(); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
185 app->FitContent(window.GetCanvasWidth(), window.GetCanvasHeight()); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
186 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
187 bool stopApplication = false; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
188 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
189 while (!stopApplication) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
190 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
191 app->Refresh(); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
192 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
193 SDL_Event event; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
194 while (!stopApplication && SDL_PollEvent(&event)) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
195 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
196 OrthancStone::KeyboardModifiers modifiers = OrthancStone::KeyboardModifiers_None; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
197 if (event.key.keysym.mod & KMOD_CTRL) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
198 modifiers = static_cast<OrthancStone::KeyboardModifiers>(static_cast<int>(modifiers) | static_cast<int>(OrthancStone::KeyboardModifiers_Control)); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
199 if (event.key.keysym.mod & KMOD_ALT) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
200 modifiers = static_cast<OrthancStone::KeyboardModifiers>(static_cast<int>(modifiers) | static_cast<int>(OrthancStone::KeyboardModifiers_Alt)); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
201 if (event.key.keysym.mod & KMOD_SHIFT) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
202 modifiers = static_cast<OrthancStone::KeyboardModifiers>(static_cast<int>(modifiers) | static_cast<int>(OrthancStone::KeyboardModifiers_Shift)); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
203 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
204 OrthancStone::MouseButton button; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
205 if (event.button.button == SDL_BUTTON_LEFT) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
206 button = OrthancStone::MouseButton_Left; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
207 else if (event.button.button == SDL_BUTTON_MIDDLE) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
208 button = OrthancStone::MouseButton_Middle; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
209 else if (event.button.button == SDL_BUTTON_RIGHT) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
210 button = OrthancStone::MouseButton_Right; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
211 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
212 if (event.type == SDL_QUIT) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
213 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
214 stopApplication = true; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
215 break; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
216 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
217 else if (event.type == SDL_WINDOWEVENT && |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
218 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
219 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
220 app->DisableTracker(); // was: tracker.reset(NULL); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
221 app->UpdateSize(); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
222 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
223 else if (event.type == SDL_KEYDOWN && |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
224 event.key.repeat == 0 /* Ignore key bounce */) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
225 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
226 switch (event.key.keysym.sym) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
227 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
228 case SDLK_f: |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
229 window.GetWindow().ToggleMaximize(); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
230 break; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
231 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
232 case SDLK_q: |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
233 stopApplication = true; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
234 break; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
235 default: |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
236 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
237 app->OnKeyPressed(event.key.keysym.sym, modifiers); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
238 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
239 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
240 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
241 else if (event.type == SDL_MOUSEBUTTONDOWN) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
242 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
243 app->OnMouseDown(event.button.x, event.button.y, modifiers, button); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
244 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
245 else if (event.type == SDL_MOUSEMOTION) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
246 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
247 app->OnMouseMove(event.button.x, event.button.y, modifiers); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
248 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
249 else if (event.type == SDL_MOUSEBUTTONUP) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
250 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
251 app->OnMouseUp(event.button.x, event.button.y, modifiers, button); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
252 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
253 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
254 SDL_Delay(1); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
255 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
256 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
257 catch (Orthanc::OrthancException& e) |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
258 { |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
259 LOG(ERROR) << "EXCEPTION: " << e.What(); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
260 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
261 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
262 StoneFinalize(); |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
263 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
264 return 0; |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
265 } |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
266 |
80829436ce0c
starting to re-implement radiography editor with latest framework
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
267 |