Added constructors with parameters for shapes, and default-constructed shapes are now always empty

This commit is contained in:
Laurent Gomila 2011-12-04 10:53:14 +01:00
parent 6034b80ddf
commit 44cc9bad84
8 changed files with 35 additions and 34 deletions

View File

@ -44,16 +44,14 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
/// Creates a circle with a radius of 10. /// \param radius Radius of the circle
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CircleShape(); CircleShape(float radius = 0);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set the radius of the circle /// \brief Set the radius of the circle
/// ///
/// The default radius of a circle is 10.
///
/// \param radius New radius of the circle /// \param radius New radius of the circle
/// ///
/// \see GetRadius /// \see GetRadius

View File

@ -45,16 +45,12 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
/// Creates a default triangle, just so that it's not empty.
///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
ConvexShape(); ConvexShape();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set the number of points of the polygon /// \brief Set the number of points of the polygon
/// ///
/// The default number of points of a polygon is 6.
///
/// \param count New number of points of the polygon /// \param count New number of points of the polygon
/// ///
/// \see GetPointsCount /// \see GetPointsCount

View File

@ -44,16 +44,14 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
/// Creates a 10x10 rectangle. /// \param size Size of the rectangle
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RectangleShape(); RectangleShape(const Vector2f& size = Vector2f(0, 0));
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set the size of the rectangle /// \brief Set the size of the rectangle
/// ///
/// The default size of a rectangle is 10x10.
///
/// \param size New size of the rectangle /// \param size New size of the rectangle
/// ///
/// \see GetSize /// \see GetSize

View File

@ -44,16 +44,21 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Default constructor
/// ///
/// Creates a star with 5 points, an inner radius of 10 and
/// an outer radius of 20.
///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
StarShape(); StarShape();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set the inner radius of the star /// \brief Constructor
/// ///
/// The default inner radius of a star is 10. /// \param innerRadius Inner radius of the star
/// \param outerRadius Outer radius of the star
/// \param pointsCount Number of points of the star
///
////////////////////////////////////////////////////////////
StarShape(float innerRadius, float outerRadius, unsigned int pointsCount);
////////////////////////////////////////////////////////////
/// \brief Set the inner radius of the star
/// ///
/// \param radius New inner radius of the star /// \param radius New inner radius of the star
/// ///
@ -75,8 +80,6 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set the outer radius of the star /// \brief Set the outer radius of the star
/// ///
/// The default outer radius of a star is 20.
///
/// \param radius New outer radius of the star /// \param radius New outer radius of the star
/// ///
/// \see GetOuterRadius /// \see GetOuterRadius
@ -97,8 +100,6 @@ public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Set the number of points of the star /// \brief Set the number of points of the star
/// ///
/// The default number of points of a star is 5.
///
/// \param count New number of points of the star /// \param count New number of points of the star
/// ///
/// \see GetPointsCount /// \see GetPointsCount

View File

@ -32,9 +32,9 @@
namespace sf namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CircleShape::CircleShape() : CircleShape::CircleShape(float radius)
myRadius(10)
{ {
SetRadius(radius);
} }

View File

@ -31,13 +31,10 @@
namespace sf namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
ConvexShape::ConvexShape() ConvexShape::ConvexShape() :
myPoints()
{ {
// Let's define a triangle by default... just so that it's not empty Update();
SetPointsCount(3);
SetPoint(0, Vector2f(5, 0));
SetPoint(1, Vector2f(0, 10));
SetPoint(2, Vector2f(10, 10));
} }

View File

@ -32,9 +32,9 @@
namespace sf namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RectangleShape::RectangleShape() : RectangleShape::RectangleShape(const Vector2f& size) :
mySize(10, 10)
{ {
SetSize(size);
} }

View File

@ -33,10 +33,21 @@ namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
StarShape::StarShape() : StarShape::StarShape() :
myInnerRadius(10), myInnerRadius(0),
myOuterRadius(20), myOuterRadius(0),
myPointsCount(5) myPointsCount(0)
{ {
Update();
}
////////////////////////////////////////////////////////////
StarShape::StarShape(float innerRadius, float outerRadius, unsigned int pointsCount) :
myInnerRadius(innerRadius),
myOuterRadius(outerRadius),
myPointsCount(pointsCount)
{
Update();
} }