Mercurial > hg > orthanc-stone
comparison Applications/Platforms/Sdl/SdlViewport.cpp @ 1804:5a872e69c74f
reorganization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 May 2021 14:48:51 +0200 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
comparison
equal
deleted
inserted
replaced
1803:d1849468729b | 1804:5a872e69c74f |
---|---|
83 lock.GetCompositor().SetCanvasSize(width, height); | 83 lock.GetCompositor().SetCanvasSize(width, height); |
84 lock.Invalidate(); | 84 lock.Invalidate(); |
85 } | 85 } |
86 | 86 |
87 | 87 |
88 #if ORTHANC_ENABLE_OPENGL == 1 | |
88 SdlOpenGLViewport::SdlOpenGLViewport(const std::string& title, | 89 SdlOpenGLViewport::SdlOpenGLViewport(const std::string& title, |
89 unsigned int width, | 90 unsigned int width, |
90 unsigned int height, | 91 unsigned int height, |
91 bool allowDpiScaling) : | 92 bool allowDpiScaling) : |
92 context_(title.c_str(), width, height, allowDpiScaling) | 93 context_(title.c_str(), width, height, allowDpiScaling) |
93 { | 94 { |
94 AcquireCompositor(new OpenGLCompositor(context_)); // (*) | 95 AcquireCompositor(new OpenGLCompositor(context_)); // (*) |
95 } | 96 } |
96 | 97 #endif |
97 | 98 |
99 | |
100 #if ORTHANC_ENABLE_OPENGL == 1 | |
98 void SdlOpenGLViewport::RefreshCanvasSize() | 101 void SdlOpenGLViewport::RefreshCanvasSize() |
99 { | 102 { |
100 UpdateSize(context_.GetCanvasWidth(), context_.GetCanvasHeight()); | 103 UpdateSize(context_.GetCanvasWidth(), context_.GetCanvasHeight()); |
101 } | 104 } |
102 | 105 #endif |
103 | 106 |
104 boost::shared_ptr<SdlOpenGLViewport> SdlOpenGLViewport::Create( | 107 |
105 const std::string& title, | 108 #if ORTHANC_ENABLE_OPENGL == 1 |
106 unsigned int width, | 109 boost::shared_ptr<SdlOpenGLViewport> SdlOpenGLViewport::Create(const std::string& title, |
107 unsigned int height, | 110 unsigned int width, |
108 bool allowDpiScaling) | 111 unsigned int height, |
112 bool allowDpiScaling) | |
109 { | 113 { |
110 boost::shared_ptr<SdlOpenGLViewport> that = | 114 boost::shared_ptr<SdlOpenGLViewport> that = |
111 boost::shared_ptr<SdlOpenGLViewport>(new SdlOpenGLViewport(title, width, height, allowDpiScaling)); | 115 boost::shared_ptr<SdlOpenGLViewport>(new SdlOpenGLViewport(title, width, height, allowDpiScaling)); |
112 that->SdlViewport::PostConstructor(); | 116 that->SdlViewport::PostConstructor(); |
113 return that; | 117 return that; |
114 } | 118 } |
115 | 119 #endif |
120 | |
121 | |
122 #if ORTHANC_ENABLE_OPENGL == 1 | |
116 uint32_t SdlOpenGLViewport::GetSdlWindowId() | 123 uint32_t SdlOpenGLViewport::GetSdlWindowId() |
117 { | 124 { |
118 const SdlWindow& sdlWindowWrapper = context_.GetWindow(); | 125 const SdlWindow& sdlWindowWrapper = context_.GetWindow(); |
119 SDL_Window* sdlWindow = sdlWindowWrapper.GetObject(); | 126 SDL_Window* sdlWindow = sdlWindowWrapper.GetObject(); |
120 Uint32 sdlWindowId = SDL_GetWindowID(sdlWindow); | 127 Uint32 sdlWindowId = SDL_GetWindowID(sdlWindow); |
121 return sdlWindowId; | 128 return sdlWindowId; |
122 } | 129 } |
123 | 130 #endif |
131 | |
132 | |
133 #if ORTHANC_ENABLE_OPENGL == 1 | |
124 SdlOpenGLViewport::~SdlOpenGLViewport() | 134 SdlOpenGLViewport::~SdlOpenGLViewport() |
125 { | 135 { |
126 // Make sure that the "OpenGLCompositor" is destroyed BEFORE the | 136 // Make sure that the "OpenGLCompositor" is destroyed BEFORE the |
127 // "OpenGLContext" it references (*) | 137 // "OpenGLContext" it references (*) |
128 ClearCompositor(); | 138 ClearCompositor(); |
129 } | 139 } |
130 | 140 #endif |
131 | 141 |
142 | |
143 #if ORTHANC_ENABLE_OPENGL == 1 | |
132 void SdlOpenGLViewport::Paint() | 144 void SdlOpenGLViewport::Paint() |
133 { | 145 { |
134 SdlLock lock(*this); | 146 SdlLock lock(*this); |
135 lock.GetCompositor().Refresh(lock.GetController().GetScene()); | 147 lock.GetCompositor().Refresh(lock.GetController().GetScene()); |
136 } | 148 } |
137 | 149 #endif |
138 | 150 |
151 | |
152 #if ORTHANC_ENABLE_OPENGL == 1 | |
139 void SdlOpenGLViewport::ToggleMaximize() | 153 void SdlOpenGLViewport::ToggleMaximize() |
140 { | 154 { |
141 // No need to call "Invalidate()" here, as "UpdateSize()" will | 155 // No need to call "Invalidate()" here, as "UpdateSize()" will |
142 // be invoked after event "SDL_WINDOWEVENT_SIZE_CHANGED" | 156 // be invoked after event "SDL_WINDOWEVENT_SIZE_CHANGED" |
143 SdlLock lock(*this); | 157 SdlLock lock(*this); |
144 context_.ToggleMaximize(); | 158 context_.ToggleMaximize(); |
145 } | 159 } |
146 | 160 #endif |
147 | 161 |
148 | 162 |
149 void SdlCairoViewport::RefreshCanvasSize() | 163 void SdlCairoViewport::RefreshCanvasSize() |
150 { | 164 { |
151 UpdateSize(window_.GetWidth(), window_.GetHeight()); | 165 UpdateSize(window_.GetWidth(), window_.GetHeight()); |
152 } | 166 } |
153 | 167 |
154 SdlCairoViewport::SdlCairoViewport(const char* title, | 168 SdlCairoViewport::SdlCairoViewport(const std::string& title, |
155 unsigned int width, | 169 unsigned int width, |
156 unsigned int height, | 170 unsigned int height, |
157 bool allowDpiScaling) : | 171 bool allowDpiScaling) : |
158 window_(title, width, height, false /* enable OpenGL */, allowDpiScaling), | 172 window_(title, width, height, false /* enable OpenGL */, allowDpiScaling), |
159 sdlSurface_(NULL) | 173 sdlSurface_(NULL) |
231 { | 245 { |
232 LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface"; | 246 LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface"; |
233 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | 247 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
234 } | 248 } |
235 } | 249 } |
250 | |
251 | |
252 boost::shared_ptr<SdlCairoViewport> SdlCairoViewport::Create(const std::string& title, | |
253 unsigned int width, | |
254 unsigned int height, | |
255 bool allowDpiScaling) | |
256 { | |
257 boost::shared_ptr<SdlCairoViewport> that = | |
258 boost::shared_ptr<SdlCairoViewport>(new SdlCairoViewport(title, width, height, allowDpiScaling)); | |
259 that->SdlViewport::PostConstructor(); | |
260 return that; | |
261 } | |
236 } | 262 } |