Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Viewport/SdlViewport.h @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Viewport/SdlViewport.h@32272ecfc6c2 |
children | b4ccd4963d37 |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 #pragma once | |
22 | |
23 #if !defined(ORTHANC_ENABLE_SDL) | |
24 # error Macro ORTHANC_ENABLE_SDL must be defined | |
25 #endif | |
26 | |
27 #if ORTHANC_ENABLE_SDL != 1 | |
28 # error SDL must be enabled to use this file | |
29 #endif | |
30 | |
31 #if !defined(ORTHANC_ENABLE_OPENGL) | |
32 # error The macro ORTHANC_ENABLE_OPENGL must be defined | |
33 #endif | |
34 | |
35 #if ORTHANC_ENABLE_OPENGL != 1 | |
36 # error Support for OpenGL is disabled | |
37 #endif | |
38 | |
39 #include "../OpenGL/SdlOpenGLContext.h" | |
40 #include "../Scene2D/OpenGLCompositor.h" | |
41 #include "../Scene2D/CairoCompositor.h" | |
42 #include "IViewport.h" | |
43 | |
44 #include <SDL_events.h> | |
45 | |
46 // TODO: required for UndoStack injection | |
47 // I don't like it either :) | |
48 #include <boost/weak_ptr.hpp> | |
49 | |
50 #include <boost/thread/recursive_mutex.hpp> | |
51 | |
52 namespace OrthancStone | |
53 { | |
54 class UndoStack; | |
55 | |
56 class SdlViewport : public IViewport, | |
57 public boost::enable_shared_from_this<SdlViewport> | |
58 { | |
59 private: | |
60 boost::recursive_mutex mutex_; | |
61 uint32_t refreshEvent_; | |
62 boost::shared_ptr<ViewportController> controller_; | |
63 std::unique_ptr<ICompositor> compositor_; | |
64 | |
65 void SendRefreshEvent(); | |
66 | |
67 protected: | |
68 class SdlLock : public ILock | |
69 { | |
70 private: | |
71 SdlViewport& that_; | |
72 boost::recursive_mutex::scoped_lock lock_; | |
73 | |
74 public: | |
75 SdlLock(SdlViewport& that) : | |
76 that_(that), | |
77 lock_(that.mutex_) | |
78 { | |
79 } | |
80 | |
81 virtual bool HasCompositor() const ORTHANC_OVERRIDE | |
82 { | |
83 return true; | |
84 } | |
85 | |
86 virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE; | |
87 | |
88 virtual ViewportController& GetController() ORTHANC_OVERRIDE | |
89 { | |
90 return *that_.controller_; | |
91 } | |
92 | |
93 virtual void Invalidate() ORTHANC_OVERRIDE | |
94 { | |
95 that_.SendRefreshEvent(); | |
96 } | |
97 }; | |
98 | |
99 void ClearCompositor() | |
100 { | |
101 compositor_.reset(); | |
102 } | |
103 | |
104 void AcquireCompositor(ICompositor* compositor /* takes ownership */); | |
105 | |
106 protected: | |
107 SdlViewport(); | |
108 void PostConstructor(); | |
109 | |
110 public: | |
111 | |
112 bool IsRefreshEvent(const SDL_Event& event) const | |
113 { | |
114 return (event.type == refreshEvent_); | |
115 } | |
116 | |
117 virtual ILock* Lock() ORTHANC_OVERRIDE | |
118 { | |
119 return new SdlLock(*this); | |
120 } | |
121 | |
122 virtual uint32_t GetSdlWindowId() = 0; | |
123 | |
124 virtual void UpdateSize(unsigned int width, | |
125 unsigned int height) = 0; | |
126 | |
127 virtual void ToggleMaximize() = 0; | |
128 | |
129 // Must be invoked from the main SDL thread | |
130 virtual void Paint() = 0; | |
131 }; | |
132 | |
133 | |
134 class SdlOpenGLViewport : public SdlViewport | |
135 { | |
136 private: | |
137 SdlOpenGLContext context_; | |
138 | |
139 private: | |
140 SdlOpenGLViewport(const std::string& title, | |
141 unsigned int width, | |
142 unsigned int height, | |
143 bool allowDpiScaling = true); | |
144 public: | |
145 static boost::shared_ptr<SdlOpenGLViewport> Create(const std::string&, | |
146 unsigned int width, | |
147 unsigned int height, | |
148 bool allowDpiScaling = true); | |
149 | |
150 | |
151 virtual ~SdlOpenGLViewport(); | |
152 | |
153 virtual uint32_t GetSdlWindowId() ORTHANC_OVERRIDE; | |
154 | |
155 virtual void Paint() ORTHANC_OVERRIDE; | |
156 | |
157 virtual void UpdateSize(unsigned int width, | |
158 unsigned int height) ORTHANC_OVERRIDE; | |
159 | |
160 virtual void ToggleMaximize() ORTHANC_OVERRIDE; | |
161 }; | |
162 | |
163 | |
164 class SdlCairoViewport : public SdlViewport | |
165 { | |
166 private: | |
167 SdlWindow window_; | |
168 SDL_Surface* sdlSurface_; | |
169 | |
170 void CreateSdlSurfaceFromCompositor(CairoCompositor& compositor); | |
171 | |
172 private: | |
173 SdlCairoViewport(const char* title, | |
174 unsigned int width, | |
175 unsigned int height, | |
176 bool allowDpiScaling = true); | |
177 public: | |
178 static boost::shared_ptr<SdlCairoViewport> Create(const char* title, | |
179 unsigned int width, | |
180 unsigned int height, | |
181 bool allowDpiScaling = true); | |
182 | |
183 | |
184 virtual ~SdlCairoViewport(); | |
185 | |
186 virtual uint32_t GetSdlWindowId() ORTHANC_OVERRIDE; | |
187 | |
188 virtual void Paint() ORTHANC_OVERRIDE; | |
189 | |
190 virtual void UpdateSize(unsigned int width, | |
191 unsigned int height) ORTHANC_OVERRIDE; | |
192 | |
193 virtual void ToggleMaximize() ORTHANC_OVERRIDE; | |
194 }; | |
195 } |