comparison Applications/Samples/Sdl/RtViewer/RtViewerSdl.cpp @ 1573:32e0c007789d

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 21 Sep 2020 18:28:34 +0200
parents 6e0da8370270
children 92fca2b3ba3d
comparison
equal deleted inserted replaced
1572:1b3039384972 1573:32e0c007789d
206 unsigned int canvasWidth, 206 unsigned int canvasWidth,
207 unsigned int canvasHeight) 207 unsigned int canvasHeight)
208 { 208 {
209 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock()); 209 std::unique_ptr<IViewport::ILock> lock(viewport_->Lock());
210 ViewportController& controller = lock->GetController(); 210 ViewportController& controller = lock->GetController();
211 Scene2D& scene = controller.GetScene(); 211 const Scene2D& scene = controller.GetScene();
212 212
213 std::string ttf; 213 std::string ttf;
214 Orthanc::EmbeddedResources::GetFileResource(ttf, Orthanc::EmbeddedResources::UBUNTU_FONT); 214 Orthanc::EmbeddedResources::GetFileResource(ttf, Orthanc::EmbeddedResources::UBUNTU_FONT);
215 215
216 CairoCompositor compositor(canvasWidth, canvasHeight); 216 CairoCompositor compositor(canvasWidth, canvasHeight);
267 bool stop = false; 267 bool stop = false;
268 while (!stop) 268 while (!stop)
269 { 269 {
270 std::vector<SDL_Event> sdlEvents; 270 std::vector<SDL_Event> sdlEvents;
271 std::map<Uint32,SDL_Event> userEventsMap; 271 std::map<Uint32,SDL_Event> userEventsMap;
272 SDL_Event sdlEvent; 272
273
274 // FIRST: collect all pending events
275 while (SDL_PollEvent(&sdlEvent) != 0)
276 { 273 {
277 if ( (sdlEvent.type >= SDL_USEREVENT) && 274 SDL_Event sdlEvent;
278 (sdlEvent.type < SDL_LASTEVENT) ) 275
279 { 276 // FIRST: collect all pending events
280 // we don't want to have multiple refresh events , 277 while (SDL_PollEvent(&sdlEvent) != 0)
281 // and since every refresh event is a user event with a special type, 278 {
282 // we use a map 279 if ( (sdlEvent.type >= SDL_USEREVENT) &&
283 userEventsMap[sdlEvent.type] = sdlEvent; 280 (sdlEvent.type < SDL_LASTEVENT) )
284 } 281 {
285 else 282 // we don't want to have multiple refresh events ,
286 { 283 // and since every refresh event is a user event with a special type,
287 sdlEvents.push_back(sdlEvent); 284 // we use a map
285 userEventsMap[sdlEvent.type] = sdlEvent;
286 }
287 else
288 {
289 sdlEvents.push_back(sdlEvent);
290 }
288 } 291 }
289 } 292 }
290 293
291 // SECOND: add all user events to sdlEvents 294 // SECOND: add all user events to sdlEvents
292 for (std::map<Uint32,SDL_Event>::const_iterator it = userEventsMap.begin(); it != userEventsMap.end(); ++it) 295 for (std::map<Uint32,SDL_Event>::const_iterator it = userEventsMap.begin(); it != userEventsMap.end(); ++it)
296 {
293 sdlEvents.push_back(it->second); 297 sdlEvents.push_back(it->second);
298 }
294 299
295 // now process the events 300 // now process the events
296 for (std::vector<SDL_Event>::const_iterator it = sdlEvents.begin(); it != sdlEvents.end(); ++it) 301 for (std::vector<SDL_Event>::const_iterator it = sdlEvents.begin(); it != sdlEvents.end(); ++it)
297 { 302 {
298 const SDL_Event& sdlEvent = *it; 303 const SDL_Event& sdlEvent = *it;