From 6d717f3c8729ff19ec0e20d1e59b982d8c903e21 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Thu, 31 Dec 2009 16:43:24 +0000 Subject: [PATCH] Modified sf::RenderTarget so that it handles views by value rather than by reference git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1315 4e206d99-4929-0410-ac5d-dfc041789085 --- include/SFML/Graphics/RenderTarget.hpp | 12 +++------ samples/qt/Main.cpp | 2 +- src/SFML/Graphics/RenderTarget.cpp | 35 +++++++------------------- 3 files changed, 13 insertions(+), 36 deletions(-) diff --git a/include/SFML/Graphics/RenderTarget.hpp b/include/SFML/Graphics/RenderTarget.hpp index 52071bb85..68f1cbcc4 100644 --- a/include/SFML/Graphics/RenderTarget.hpp +++ b/include/SFML/Graphics/RenderTarget.hpp @@ -126,12 +126,12 @@ public : const View& GetView() const; //////////////////////////////////////////////////////////// - /// Get the default view of the window for read / write + /// Get the default view of the window /// /// \return Default view /// //////////////////////////////////////////////////////////// - View& GetDefaultView(); + const View& GetDefaultView() const; //////////////////////////////////////////////////////////// /// Get the viewport of a view applied to this target @@ -170,12 +170,6 @@ public : protected : - //////////////////////////////////////////////////////////// - /// Default constructor - /// - //////////////////////////////////////////////////////////// - RenderTarget(); - //////////////////////////////////////////////////////////// /// Called by the derived class when it's ready to be initialized /// @@ -199,7 +193,7 @@ private : //////////////////////////////////////////////////////////// RenderQueue myRenderQueue; ///< Rendering queue storing render commands View myDefaultView; ///< Default view - const View* myCurrentView; ///< Current active view + View myCurrentView; ///< Current active view }; } // namespace sf diff --git a/samples/qt/Main.cpp b/samples/qt/Main.cpp index c256f1ab5..8b44ad721 100644 --- a/samples/qt/Main.cpp +++ b/samples/qt/Main.cpp @@ -60,7 +60,7 @@ private : // Adjust the size of the default view when the widget is resized if (event.Type == sf::Event::Resized) { - GetDefaultView().Reset(sf::FloatRect(0, 0, event.Size.Width, event.Size.Height)); + SetView(sf::View(sf::FloatRect(0, 0, event.Size.Width, event.Size.Height))); } } diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index b0b8ab101..cf320eb19 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -33,16 +33,6 @@ namespace sf { -//////////////////////////////////////////////////////////// -/// Default constructor -//////////////////////////////////////////////////////////// -RenderTarget::RenderTarget() : -myCurrentView(&myDefaultView) -{ - -} - - //////////////////////////////////////////////////////////// /// Destructor //////////////////////////////////////////////////////////// @@ -79,12 +69,6 @@ void RenderTarget::Draw(const Drawable& object) // Save the current render states myRenderQueue.PushStates(); - // Setup the viewport - myRenderQueue.SetViewport(GetViewport(*myCurrentView)); - - // Setup the projection matrix - myRenderQueue.SetProjection(myCurrentView->GetMatrix()); - // Setup the shader myRenderQueue.SetShader(NULL); @@ -104,12 +88,6 @@ void RenderTarget::Draw(const Drawable& object, const Shader& shader) // Save the current render states myRenderQueue.PushStates(); - // Setup the viewport - myRenderQueue.SetViewport(GetViewport(*myCurrentView)); - - // Setup the projection matrix - myRenderQueue.SetProjection(myCurrentView->GetMatrix()); - // Setup the shader myRenderQueue.SetShader(&shader); @@ -141,7 +119,12 @@ void RenderTarget::Flush() //////////////////////////////////////////////////////////// void RenderTarget::SetView(const View& view) { - myCurrentView = &view; + // Save it + myCurrentView = view; + + // Send the view's viewport and projection matrix to the render queue + myRenderQueue.SetViewport(GetViewport(view)); + myRenderQueue.SetProjection(view.GetMatrix()); } @@ -150,14 +133,14 @@ void RenderTarget::SetView(const View& view) //////////////////////////////////////////////////////////// const View& RenderTarget::GetView() const { - return *myCurrentView; + return myCurrentView; } //////////////////////////////////////////////////////////// -/// Get the default view of the window for read / write +/// Get the default view of the window //////////////////////////////////////////////////////////// -View& RenderTarget::GetDefaultView() +const View& RenderTarget::GetDefaultView() const { return myDefaultView; }