# HG changeset patch # User Sebastien Jodogne # Date 1570713888 -7200 # Node ID 32b403a47b19a6d631781ca1f7082e46dba3d9cc # Parent 0cc62db7e61b85fd8ea4ad729c88336d8c3a8366 simplifying IViewport diff -r 0cc62db7e61b -r 32b403a47b19 Framework/Scene2D/ICompositor.h --- a/Framework/Scene2D/ICompositor.h Thu Oct 10 14:37:23 2019 +0200 +++ b/Framework/Scene2D/ICompositor.h Thu Oct 10 15:24:48 2019 +0200 @@ -1,29 +1,29 @@ -#pragma once - -#include -#include -#include - -namespace OrthancStone -{ - class ICompositor : public boost::noncopyable - { - - public: - virtual ~ICompositor() {} - - virtual unsigned int GetCanvasWidth() const = 0; - - virtual unsigned int GetCanvasHeight() const = 0; - - virtual void Refresh() = 0; - -#if ORTHANC_ENABLE_LOCALE == 1 - virtual void SetFont(size_t index, - Orthanc::EmbeddedResources::FileResourceId resource, - unsigned int fontSize, - Orthanc::Encoding codepage) = 0; -#endif - - }; -} +#pragma once + +#include +#include +#include + +namespace OrthancStone +{ + class ICompositor : public boost::noncopyable + { + public: + virtual ~ICompositor() + { + } + + virtual unsigned int GetCanvasWidth() const = 0; + + virtual unsigned int GetCanvasHeight() const = 0; + + virtual void Refresh() = 0; + +#if ORTHANC_ENABLE_LOCALE == 1 + virtual void SetFont(size_t index, + Orthanc::EmbeddedResources::FileResourceId resource, + unsigned int fontSize, + Orthanc::Encoding codepage) = 0; +#endif + }; +} diff -r 0cc62db7e61b -r 32b403a47b19 Framework/Scene2DViewport/ViewportController.cpp --- a/Framework/Scene2DViewport/ViewportController.cpp Thu Oct 10 14:37:23 2019 +0200 +++ b/Framework/Scene2DViewport/ViewportController.cpp Thu Oct 10 15:24:48 2019 +0200 @@ -168,8 +168,12 @@ void ViewportController::FitContent() { - viewport_.GetScene().FitContent(viewport_.GetCanvasWidth(), viewport_.GetCanvasHeight()); - BroadcastMessage(SceneTransformChanged(*this)); + if (viewport_.HasCompositor()) + { + const ICompositor& compositor = viewport_.GetCompositor(); + viewport_.GetScene().FitContent(compositor.GetCanvasWidth(), compositor.GetCanvasHeight()); + BroadcastMessage(SceneTransformChanged(*this)); + } } void ViewportController::AddMeasureTool(boost::shared_ptr measureTool) @@ -219,4 +223,3 @@ return TEXT_CENTER_DISTANCE_CANVAS_COORD * GetCanvasToSceneFactor(); } } - diff -r 0cc62db7e61b -r 32b403a47b19 Framework/Viewport/IViewport.h --- a/Framework/Viewport/IViewport.h Thu Oct 10 14:37:23 2019 +0200 +++ b/Framework/Viewport/IViewport.h Thu Oct 10 15:24:48 2019 +0200 @@ -42,30 +42,13 @@ virtual void Refresh() = 0; - virtual unsigned int GetCanvasWidth() const = 0; - - virtual unsigned int GetCanvasHeight() const = 0; - // TODO - Is this needed at this level (e.g. for SDL)? virtual const std::string& GetCanvasIdentifier() const = 0; - virtual ScenePoint2D GetPixelCenterCoordinates(int x, int y) const = 0; - -#if ORTHANC_ENABLE_LOCALE == 1 - virtual void SetFont(size_t index, - Orthanc::EmbeddedResources::FileResourceId resource, - unsigned int fontSize, - Orthanc::Encoding codepage) = 0; -#endif + virtual ScenePoint2D GetPixelCenterCoordinates(int x, int y) = 0; - protected: - // TODO - Replace this by "ICompositor& GetCompositor()" - virtual ICompositor* GetCompositor() = 0; + virtual bool HasCompositor() const = 0; - virtual const ICompositor* GetCompositor() const - { - IViewport* self = const_cast(this); - return self->GetCompositor(); - } + virtual ICompositor& GetCompositor() = 0; }; } diff -r 0cc62db7e61b -r 32b403a47b19 Framework/Viewport/SdlViewport.cpp --- a/Framework/Viewport/SdlViewport.cpp Thu Oct 10 14:37:23 2019 +0200 +++ b/Framework/Viewport/SdlViewport.cpp Thu Oct 10 15:24:48 2019 +0200 @@ -49,10 +49,7 @@ void SdlOpenGLViewport::Refresh() { - if (GetCompositor()) - { - GetCompositor()->Refresh(); - } + compositor_->Refresh(); } @@ -77,7 +74,7 @@ void SdlCairoViewport::Refresh() { - GetCompositor()->Refresh(); + compositor_.Refresh(); window_.Render(sdlSurface_); } @@ -104,5 +101,4 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); } } - } diff -r 0cc62db7e61b -r 32b403a47b19 Framework/Viewport/SdlViewport.h --- a/Framework/Viewport/SdlViewport.h Thu Oct 10 14:37:23 2019 +0200 +++ b/Framework/Viewport/SdlViewport.h Thu Oct 10 15:24:48 2019 +0200 @@ -48,21 +48,21 @@ public: SdlViewport(const std::string& identifier) : ViewportBase(identifier) - {} + { + } SdlViewport(const std::string& identifier, boost::shared_ptr& scene) : ViewportBase(identifier, scene) { - } virtual SdlWindow& GetWindow() = 0; virtual void UpdateSize(unsigned int width, unsigned int height) = 0; + }; - }; class SdlOpenGLViewport : public SdlViewport { @@ -87,16 +87,21 @@ return context_.GetWindow(); } + virtual void Refresh() ORTHANC_OVERRIDE; + virtual void UpdateSize(unsigned int width, unsigned int height) ORTHANC_OVERRIDE { // nothing to do in OpenGL, the OpenGLCompositor::UpdateSize will be called automatically } - virtual void Refresh() ORTHANC_OVERRIDE; - protected: - virtual ICompositor* GetCompositor() ORTHANC_OVERRIDE + virtual bool HasCompositor() const ORTHANC_OVERRIDE { - return compositor_.get(); + return true; + } + + virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE + { + return *compositor_.get(); } }; @@ -108,6 +113,10 @@ CairoCompositor compositor_; SDL_Surface* sdlSurface_; + private: + void UpdateSdlSurfaceSize(unsigned int width, + unsigned int height); + public: SdlCairoViewport(const char* title, unsigned int width, @@ -126,19 +135,20 @@ { return window_; } - + virtual void Refresh() ORTHANC_OVERRIDE; virtual void UpdateSize(unsigned int width, unsigned int height) ORTHANC_OVERRIDE; - protected: - virtual ICompositor* GetCompositor() ORTHANC_OVERRIDE + + virtual bool HasCompositor() const ORTHANC_OVERRIDE { - return &compositor_; + return true; } - private: - void UpdateSdlSurfaceSize(unsigned int width, - unsigned int height); + virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE + { + return compositor_; + } }; } diff -r 0cc62db7e61b -r 32b403a47b19 Framework/Viewport/ViewportBase.cpp --- a/Framework/Viewport/ViewportBase.cpp Thu Oct 10 14:37:23 2019 +0200 +++ b/Framework/Viewport/ViewportBase.cpp Thu Oct 10 15:24:48 2019 +0200 @@ -45,10 +45,18 @@ } - ScenePoint2D ViewportBase::GetPixelCenterCoordinates(int x, int y) const + ScenePoint2D ViewportBase::GetPixelCenterCoordinates(int x, int y) { - return ScenePoint2D( - static_cast(x) + 0.5 - static_cast(GetCanvasWidth()) / 2.0, - static_cast(y) + 0.5 - static_cast(GetCanvasHeight()) / 2.0); + if (HasCompositor()) + { + const ICompositor& compositor = GetCompositor(); + return ScenePoint2D( + static_cast(x) + 0.5 - static_cast(compositor.GetCanvasWidth()) / 2.0, + static_cast(y) + 0.5 - static_cast(compositor.GetCanvasHeight()) / 2.0); + } + else + { + return ScenePoint2D(0, 0); + } } } diff -r 0cc62db7e61b -r 32b403a47b19 Framework/Viewport/ViewportBase.h --- a/Framework/Viewport/ViewportBase.h Thu Oct 10 14:37:23 2019 +0200 +++ b/Framework/Viewport/ViewportBase.h Thu Oct 10 15:24:48 2019 +0200 @@ -28,6 +28,10 @@ { class ViewportBase : public IViewport { + private: + std::string identifier_; + boost::shared_ptr scene_; + public: ViewportBase(const std::string& identifier); @@ -44,36 +48,6 @@ return identifier_; } - virtual ScenePoint2D GetPixelCenterCoordinates(int x, int y) const ORTHANC_OVERRIDE; - - virtual unsigned int GetCanvasWidth() const ORTHANC_OVERRIDE - { - if (GetCompositor()) - return GetCompositor()->GetCanvasWidth(); - else - return 0; - } - - virtual unsigned int GetCanvasHeight() const ORTHANC_OVERRIDE - { - if (GetCompositor()) - return GetCompositor()->GetCanvasHeight(); - else - return 0; - } - -#if ORTHANC_ENABLE_LOCALE == 1 - virtual void SetFont(size_t index, - Orthanc::EmbeddedResources::FileResourceId resource, - unsigned int fontSize, - Orthanc::Encoding codepage) ORTHANC_OVERRIDE - { - return GetCompositor()->SetFont(index, resource, fontSize, codepage); - } -#endif - - private: - std::string identifier_; - boost::shared_ptr scene_; + virtual ScenePoint2D GetPixelCenterCoordinates(int x, int y) ORTHANC_OVERRIDE; }; }