mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
Remove sf::View::reset
in favor of assignment operations
It's rare that a type truly needs a .reset function. Copy/move assignment typically accomplishes the same thing with less code and is easier to maintain since it doesn't require updating your .reset() function as new data members are added. To reset a type is conceptually the same thing as simply assigning from a newly constructed instance of the same type.
This commit is contained in:
parent
4f28851ee6
commit
55f0918c62
@ -143,18 +143,6 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void setScissor(const FloatRect& scissor);
|
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
|
/// \brief Get the center of the view
|
||||||
///
|
///
|
||||||
@ -339,10 +327,9 @@ private:
|
|||||||
/// Usage example:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// sf::RenderWindow window;
|
/// sf::RenderWindow window;
|
||||||
/// sf::View view;
|
|
||||||
///
|
///
|
||||||
/// // Initialize the view to a rectangle located at (100, 100) and with a size of 400x200
|
/// // 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
|
/// // Rotate it by 45 degrees
|
||||||
/// view.rotate(sf::degrees(45));
|
/// view.rotate(sf::degrees(45));
|
||||||
|
@ -641,8 +641,8 @@ void RenderTarget::resetGLStates()
|
|||||||
void RenderTarget::initialize()
|
void RenderTarget::initialize()
|
||||||
{
|
{
|
||||||
// Setup the default and current views
|
// Setup the default and current views
|
||||||
m_defaultView.reset(FloatRect({0, 0}, Vector2f(getSize())));
|
m_defaultView = View(FloatRect({0, 0}, Vector2f(getSize())));
|
||||||
m_view = m_defaultView;
|
m_view = m_defaultView;
|
||||||
|
|
||||||
// Set GL states only on first draw, so that we don't pollute user's states
|
// Set GL states only on first draw, so that we don't pollute user's states
|
||||||
m_cache.glStatesSet = false;
|
m_cache.glStatesSet = false;
|
||||||
|
@ -34,9 +34,8 @@
|
|||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
View::View(const FloatRect& rectangle)
|
View::View(const FloatRect& rectangle) : m_center(rectangle.getCenter()), m_size(rectangle.getSize())
|
||||||
{
|
{
|
||||||
reset(rectangle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -54,6 +53,7 @@ void View::setCenter(const Vector2f& center)
|
|||||||
m_invTransformUpdated = false;
|
m_invTransformUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void View::setSize(const Vector2f& size)
|
void View::setSize(const Vector2f& size)
|
||||||
{
|
{
|
||||||
@ -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
|
const Vector2f& View::getCenter() const
|
||||||
{
|
{
|
||||||
|
@ -107,24 +107,6 @@ TEST_CASE("[Graphics] sf::View")
|
|||||||
CHECK(view.getViewport() == sf::FloatRect({0, 0}, {1, 1}));
|
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()")
|
SECTION("move()")
|
||||||
{
|
{
|
||||||
sf::View view;
|
sf::View view;
|
||||||
|
Loading…
Reference in New Issue
Block a user