comparison OrthancStone/Sources/Viewport/SdlViewport.cpp @ 1576:92fca2b3ba3d

sanitizing the handling of canvas size
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Sep 2020 16:40:30 +0200
parents 85e117739eca
children
comparison
equal deleted inserted replaced
1575:e4a52cbbdd70 1576:92fca2b3ba3d
50 } 50 }
51 51
52 compositor_.reset(compositor); 52 compositor_.reset(compositor);
53 } 53 }
54 54
55
55 SdlViewport::SdlViewport() 56 SdlViewport::SdlViewport()
56 { 57 {
57 refreshEvent_ = SDL_RegisterEvents(1); 58 refreshEvent_ = SDL_RegisterEvents(1);
58 59
59 if (refreshEvent_ == static_cast<uint32_t>(-1)) 60 if (refreshEvent_ == static_cast<uint32_t>(-1))
74 event.type = refreshEvent_; 75 event.type = refreshEvent_;
75 SDL_PushEvent(&event); // This function is thread-safe, and can be called from other threads safely. 76 SDL_PushEvent(&event); // This function is thread-safe, and can be called from other threads safely.
76 } 77 }
77 78
78 79
80 void SdlViewport::UpdateSize(unsigned int width, unsigned int height)
81 {
82 SdlLock lock(*this);
83 lock.GetCompositor().SetCanvasSize(width, height);
84 lock.Invalidate();
85 }
86
87
79 SdlOpenGLViewport::SdlOpenGLViewport(const std::string& title, 88 SdlOpenGLViewport::SdlOpenGLViewport(const std::string& title,
80 unsigned int width, 89 unsigned int width,
81 unsigned int height, 90 unsigned int height,
82 bool allowDpiScaling) : 91 bool allowDpiScaling) :
83 context_(title.c_str(), width, height, allowDpiScaling) 92 context_(title.c_str(), width, height, allowDpiScaling)
84 { 93 {
85 AcquireCompositor(new OpenGLCompositor(context_)); // (*) 94 AcquireCompositor(new OpenGLCompositor(context_)); // (*)
86 } 95 }
87 96
97
98 void SdlOpenGLViewport::RefreshCanvasSize()
99 {
100 UpdateSize(context_.GetCanvasWidth(), context_.GetCanvasHeight());
101 }
102
103
88 boost::shared_ptr<SdlOpenGLViewport> SdlOpenGLViewport::Create( 104 boost::shared_ptr<SdlOpenGLViewport> SdlOpenGLViewport::Create(
89 const std::string& title, 105 const std::string& title,
90 unsigned int width, 106 unsigned int width,
91 unsigned int height, 107 unsigned int height,
92 bool allowDpiScaling) 108 bool allowDpiScaling)
118 SdlLock lock(*this); 134 SdlLock lock(*this);
119 lock.GetCompositor().Refresh(lock.GetController().GetScene()); 135 lock.GetCompositor().Refresh(lock.GetController().GetScene());
120 } 136 }
121 137
122 138
123 void SdlOpenGLViewport::UpdateSize(unsigned int width, unsigned int height)
124 {
125 // nothing to do in OpenGL, the OpenGLCompositor::UpdateSize will be called automatically
126 SdlLock lock(*this);
127 lock.Invalidate();
128 }
129
130
131 void SdlOpenGLViewport::ToggleMaximize() 139 void SdlOpenGLViewport::ToggleMaximize()
132 { 140 {
133 // No need to call "Invalidate()" here, as "UpdateSize()" will 141 // No need to call "Invalidate()" here, as "UpdateSize()" will
134 // be invoked after event "SDL_WINDOWEVENT_SIZE_CHANGED" 142 // be invoked after event "SDL_WINDOWEVENT_SIZE_CHANGED"
135 SdlLock lock(*this); 143 SdlLock lock(*this);
136 context_.ToggleMaximize(); 144 context_.ToggleMaximize();
137 } 145 }
138 146
139 147
148
149 void SdlCairoViewport::RefreshCanvasSize()
150 {
151 UpdateSize(window_.GetWidth(), window_.GetHeight());
152 }
140 153
141 SdlCairoViewport::SdlCairoViewport(const char* title, 154 SdlCairoViewport::SdlCairoViewport(const char* title,
142 unsigned int width, 155 unsigned int width,
143 unsigned int height, 156 unsigned int height,
144 bool allowDpiScaling) : 157 bool allowDpiScaling) :
174 { 187 {
175 window_.Render(sdlSurface_); 188 window_.Render(sdlSurface_);
176 } 189 }
177 } 190 }
178 191
179
180 void SdlCairoViewport::UpdateSize(unsigned int width,
181 unsigned int height)
182 {
183 SdlLock lock(*this);
184 dynamic_cast<CairoCompositor&>(lock.GetCompositor()).UpdateSize(width, height);
185 lock.Invalidate();
186 }
187
188 192
189 void SdlCairoViewport::ToggleMaximize() 193 void SdlCairoViewport::ToggleMaximize()
190 { 194 {
191 // No need to call "Invalidate()" here, as "UpdateSize()" will 195 // No need to call "Invalidate()" here, as "UpdateSize()" will
192 // be invoked after event "SDL_WINDOWEVENT_SIZE_CHANGED" 196 // be invoked after event "SDL_WINDOWEVENT_SIZE_CHANGED"