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
This commit is contained in:
LaurentGom 2009-12-31 16:43:24 +00:00
parent 54e70a47f0
commit 6d717f3c87
3 changed files with 13 additions and 36 deletions

View File

@ -126,12 +126,12 @@ public :
const View& GetView() const; const View& GetView() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the default view of the window for read / write /// Get the default view of the window
/// ///
/// \return Default view /// \return Default view
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
View& GetDefaultView(); const View& GetDefaultView() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the viewport of a view applied to this target /// Get the viewport of a view applied to this target
@ -170,12 +170,6 @@ public :
protected : protected :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
RenderTarget();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Called by the derived class when it's ready to be initialized /// Called by the derived class when it's ready to be initialized
/// ///
@ -199,7 +193,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderQueue myRenderQueue; ///< Rendering queue storing render commands RenderQueue myRenderQueue; ///< Rendering queue storing render commands
View myDefaultView; ///< Default view View myDefaultView; ///< Default view
const View* myCurrentView; ///< Current active view View myCurrentView; ///< Current active view
}; };
} // namespace sf } // namespace sf

View File

@ -60,7 +60,7 @@ private :
// Adjust the size of the default view when the widget is resized // Adjust the size of the default view when the widget is resized
if (event.Type == sf::Event::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)));
} }
} }

View File

@ -33,16 +33,6 @@
namespace sf namespace sf
{ {
////////////////////////////////////////////////////////////
/// Default constructor
////////////////////////////////////////////////////////////
RenderTarget::RenderTarget() :
myCurrentView(&myDefaultView)
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Destructor /// Destructor
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -79,12 +69,6 @@ void RenderTarget::Draw(const Drawable& object)
// Save the current render states // Save the current render states
myRenderQueue.PushStates(); myRenderQueue.PushStates();
// Setup the viewport
myRenderQueue.SetViewport(GetViewport(*myCurrentView));
// Setup the projection matrix
myRenderQueue.SetProjection(myCurrentView->GetMatrix());
// Setup the shader // Setup the shader
myRenderQueue.SetShader(NULL); myRenderQueue.SetShader(NULL);
@ -104,12 +88,6 @@ void RenderTarget::Draw(const Drawable& object, const Shader& shader)
// Save the current render states // Save the current render states
myRenderQueue.PushStates(); myRenderQueue.PushStates();
// Setup the viewport
myRenderQueue.SetViewport(GetViewport(*myCurrentView));
// Setup the projection matrix
myRenderQueue.SetProjection(myCurrentView->GetMatrix());
// Setup the shader // Setup the shader
myRenderQueue.SetShader(&shader); myRenderQueue.SetShader(&shader);
@ -141,7 +119,12 @@ void RenderTarget::Flush()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void RenderTarget::SetView(const View& view) 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 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; return myDefaultView;
} }