Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sf::View::reset in favor of assignment operations #2942

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 1 addition & 14 deletions include/SFML/Graphics/View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,6 @@ class SFML_GRAPHICS_API View
////////////////////////////////////////////////////////////
void setScissor(const FloatRect& scissor);

////////////////////////////////////////////////////////////
/// \brief Reset the view to the given rectangle
///
/// Note that this function resets the rotation angle to 0.
///
/// \param rectangle Rectangle defining the zone to display
///
/// \see setCenter, setSize, setRotation
///
////////////////////////////////////////////////////////////
void reset(const FloatRect& rectangle);

////////////////////////////////////////////////////////////
/// \brief Get the center of the view
///
Expand Down Expand Up @@ -339,10 +327,9 @@ class SFML_GRAPHICS_API View
/// Usage example:
/// \code
/// sf::RenderWindow window;
/// sf::View view;
///
/// // Initialize the view to a rectangle located at (100, 100) and with a size of 400x200
/// view.reset(sf::FloatRect({100, 100}, {400, 200}));
/// sf::View view(sf::FloatRect({100, 100}, {400, 200}));
///
/// // Rotate it by 45 degrees
/// view.rotate(sf::degrees(45));
Expand Down
4 changes: 2 additions & 2 deletions src/SFML/Graphics/RenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,8 @@ void RenderTarget::resetGLStates()
void RenderTarget::initialize()
{
// Setup the default and current views
m_defaultView.reset(FloatRect({0, 0}, Vector2f(getSize())));
m_view = m_defaultView;
m_defaultView = View(FloatRect({0, 0}, Vector2f(getSize())));
m_view = m_defaultView;

// Set GL states only on first draw, so that we don't pollute user's states
m_cache.glStatesSet = false;
Expand Down
16 changes: 2 additions & 14 deletions src/SFML/Graphics/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
namespace sf
{
////////////////////////////////////////////////////////////
View::View(const FloatRect& rectangle)
View::View(const FloatRect& rectangle) : m_center(rectangle.getCenter()), m_size(rectangle.getSize())
{
reset(rectangle);
}


Expand All @@ -54,6 +53,7 @@ void View::setCenter(const Vector2f& center)
m_invTransformUpdated = false;
}


////////////////////////////////////////////////////////////
void View::setSize(const Vector2f& size)
{
Expand Down Expand Up @@ -95,18 +95,6 @@ void View::setScissor(const FloatRect& scissor)
}


////////////////////////////////////////////////////////////
void View::reset(const FloatRect& rectangle)
{
m_center = rectangle.getCenter();
m_size = rectangle.getSize();
m_rotation = Angle::Zero;

m_transformUpdated = false;
m_invTransformUpdated = false;
}


////////////////////////////////////////////////////////////
const Vector2f& View::getCenter() const
{
Expand Down
18 changes: 0 additions & 18 deletions test/Graphics/View.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,6 @@ TEST_CASE("[Graphics] sf::View")
CHECK(view.getViewport() == sf::FloatRect({0, 0}, {1, 1}));
}

SECTION("reset()")
{
sf::View view;
view.setCenter({3.14f, 4.2f});
view.setSize({600, 900});
view.setRotation(sf::degrees(15));
view.setViewport({{150, 250}, {500, 750}});
view.setScissor({{0.2f, 0.3f}, {0.4f, 0.5f}});
view.reset({{1, 2}, {3, 4}});
CHECK(view.getCenter() == sf::Vector2f(2.5f, 4));
CHECK(view.getSize() == sf::Vector2f(3, 4));
CHECK(view.getRotation() == sf::Angle::Zero);
CHECK(view.getViewport() == sf::FloatRect({150, 250}, {500, 750}));
CHECK(view.getScissor() == sf::FloatRect({0.2f, 0.3f}, {0.4f, 0.5f}));
CHECK(view.getTransform() == Approx(sf::Transform(0.666667f, 0, -1.66667f, 0, -0.5f, 2, 0, 0, 1)));
CHECK(view.getInverseTransform() == Approx(sf::Transform(1.5f, 0, 2.5f, 0, -2, 4, 0, 0, 1)));
}

SECTION("move()")
{
sf::View view;
Expand Down