diff Framework/Viewport/SdlViewport.cpp @ 909:7a7e4e1f558f

SdlCairo resizable
author Alain Mazy <alain@mazy.be>
date Thu, 18 Jul 2019 09:41:10 +0200
parents 722ee73e6ba2
children 1091b2adeb5a
line wrap: on
line diff
--- a/Framework/Viewport/SdlViewport.cpp	Thu Jul 18 09:22:08 2019 +0200
+++ b/Framework/Viewport/SdlViewport.cpp	Thu Jul 18 09:41:10 2019 +0200
@@ -56,17 +56,7 @@
     window_(title, width, height, false /* enable OpenGL */, allowDpiScaling),
     compositor_(GetScene(), width, height)
   {
-    static const uint32_t rmask = 0x00ff0000;
-    static const uint32_t gmask = 0x0000ff00;
-    static const uint32_t bmask = 0x000000ff;
-
-    sdlSurface_ = SDL_CreateRGBSurfaceFrom((void*)(compositor_.GetCanvas().GetBuffer()), width, height, 32,
-                                           compositor_.GetCanvas().GetPitch(), rmask, gmask, bmask, 0);
-    if (!sdlSurface_)
-    {
-      LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface";
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
-    }
+    UpdateSdlSurfaceSize(width, height);
   }
 
 
@@ -85,4 +75,29 @@
     window_.Render(sdlSurface_);
   }
 
+  void SdlCairoViewport::UpdateSize(unsigned int width,
+                                    unsigned int height)
+  {
+    compositor_.UpdateSize(width, height);
+    UpdateSdlSurfaceSize(width, height);
+    Refresh();
+  }
+
+
+  void SdlCairoViewport::UpdateSdlSurfaceSize(unsigned int width,
+                                              unsigned int height)
+  {
+    static const uint32_t rmask = 0x00ff0000;
+    static const uint32_t gmask = 0x0000ff00;
+    static const uint32_t bmask = 0x000000ff;
+
+    sdlSurface_ = SDL_CreateRGBSurfaceFrom((void*)(compositor_.GetCanvas().GetBuffer()), width, height, 32,
+                                           compositor_.GetCanvas().GetPitch(), rmask, gmask, bmask, 0);
+    if (!sdlSurface_)
+    {
+      LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface";
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+    }
+  }
+
 }