Mercurial > hg > orthanc-stone
changeset 909:7a7e4e1f558f
SdlCairo resizable
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Thu, 18 Jul 2019 09:41:10 +0200 |
parents | 2f16ad9d30ad |
children | a6c12fe88bcb |
files | Framework/Scene2D/CairoCompositor.cpp Framework/Scene2D/CairoCompositor.h Framework/Viewport/SdlViewport.cpp Framework/Viewport/SdlViewport.h Samples/Sdl/BasicScene.cpp |
diffstat | 5 files changed, 51 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Scene2D/CairoCompositor.cpp Thu Jul 18 09:22:08 2019 +0200 +++ b/Framework/Scene2D/CairoCompositor.cpp Thu Jul 18 09:41:10 2019 +0200 @@ -91,9 +91,14 @@ unsigned int canvasHeight) : helper_(scene, *this) { + UpdateSize(canvasWidth, canvasHeight); + } + + void CairoCompositor::UpdateSize(unsigned int canvasWidth, + unsigned int canvasHeight) + { canvas_.SetSize(canvasWidth, canvasHeight, false); } - CairoCompositor::~CairoCompositor() {
--- a/Framework/Scene2D/CairoCompositor.h Thu Jul 18 09:22:08 2019 +0200 +++ b/Framework/Scene2D/CairoCompositor.h Thu Jul 18 09:41:10 2019 +0200 @@ -82,6 +82,9 @@ virtual void Refresh(); + void UpdateSize(unsigned int canvasWidth, + unsigned int canvasHeight); + Orthanc::ImageAccessor* RenderText(size_t fontIndex, const std::string& utf8) const; };
--- 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); + } + } + }
--- a/Framework/Viewport/SdlViewport.h Thu Jul 18 09:22:08 2019 +0200 +++ b/Framework/Viewport/SdlViewport.h Thu Jul 18 09:41:10 2019 +0200 @@ -58,6 +58,9 @@ } virtual SdlWindow& GetWindow() = 0; + + virtual void UpdateSize(unsigned int width, + unsigned int height) = 0; }; class SdlOpenGLViewport : public SdlViewport @@ -88,6 +91,12 @@ { return context_.GetWindow(); } + + virtual void UpdateSize(unsigned int width, + unsigned int height) + { + // nothing to do in OpenGL, the OpenGLCompositor::UpdateSize will be called automatically + } }; @@ -124,5 +133,11 @@ virtual void Refresh(); + virtual void UpdateSize(unsigned int width, + unsigned int height); + + private: + void UpdateSdlSurfaceSize(unsigned int width, + unsigned int height); }; }