Documentation de SFML 2.1

Attention: cette page se réfère à une ancienne version de SFML. Cliquez ici pour passer à la dernière version.
sf::ConvexShape Class Reference

Specialized shape representing a convex polygon. More...

#include <ConvexShape.hpp>

Inheritance diagram for sf::ConvexShape:
sf::Shape sf::Drawable sf::Transformable

Public Member Functions

 ConvexShape (unsigned int pointCount=0)
 Default constructor.
 
void setPointCount (unsigned int count)
 Set the number of points of the polygon.
 
virtual unsigned int getPointCount () const
 Get the number of points of the polygon.
 
void setPoint (unsigned int index, const Vector2f &point)
 Set the position of a point.
 
virtual Vector2f getPoint (unsigned int index) const
 Get the position of a point.
 
void setTexture (const Texture *texture, bool resetRect=false)
 Change the source texture of the shape.
 
void setTextureRect (const IntRect &rect)
 Set the sub-rectangle of the texture that the shape will display.
 
void setFillColor (const Color &color)
 Set the fill color of the shape.
 
void setOutlineColor (const Color &color)
 Set the outline color of the shape.
 
void setOutlineThickness (float thickness)
 Set the thickness of the shape's outline.
 
const TexturegetTexture () const
 Get the source texture of the shape.
 
const IntRectgetTextureRect () const
 Get the sub-rectangle of the texture displayed by the shape.
 
const ColorgetFillColor () const
 Get the fill color of the shape.
 
const ColorgetOutlineColor () const
 Get the outline color of the shape.
 
float getOutlineThickness () const
 Get the outline thickness of the shape.
 
FloatRect getLocalBounds () const
 Get the local bounding rectangle of the entity.
 
FloatRect getGlobalBounds () const
 Get the global bounding rectangle of the entity.
 
void setPosition (float x, float y)
 set the position of the object
 
void setPosition (const Vector2f &position)
 set the position of the object
 
void setRotation (float angle)
 set the orientation of the object
 
void setScale (float factorX, float factorY)
 set the scale factors of the object
 
void setScale (const Vector2f &factors)
 set the scale factors of the object
 
void setOrigin (float x, float y)
 set the local origin of the object
 
void setOrigin (const Vector2f &origin)
 set the local origin of the object
 
const Vector2fgetPosition () const
 get the position of the object
 
float getRotation () const
 get the orientation of the object
 
const Vector2fgetScale () const
 get the current scale of the object
 
const Vector2fgetOrigin () const
 get the local origin of the object
 
void move (float offsetX, float offsetY)
 Move the object by a given offset.
 
void move (const Vector2f &offset)
 Move the object by a given offset.
 
void rotate (float angle)
 Rotate the object.
 
void scale (float factorX, float factorY)
 Scale the object.
 
void scale (const Vector2f &factor)
 Scale the object.
 
const TransformgetTransform () const
 get the combined transform of the object
 
const TransformgetInverseTransform () const
 get the inverse of the combined transform of the object
 

Protected Member Functions

void update ()
 Recompute the internal geometry of the shape.
 

Detailed Description

Specialized shape representing a convex polygon.

This class inherits all the functions of sf::Transformable (position, rotation, scale, bounds, ...) as well as the functions of sf::Shape (outline, color, texture, ...).

It is important to keep in mind that a convex shape must always be... convex, otherwise it may not be drawn correctly. Moreover, the points must be defined in order; using a random order would result in an incorrect shape.

Usage example:

polygon.setPointCount(3);
polygon.setPoint(0, sf::Vector2f(0, 0));
polygon.setPoint(1, sf::Vector2f(0, 10));
polygon.setPoint(2, sf::Vector2f(25, 5));
polygon.setPosition(10, 20);
...
window.draw(polygon);
See Also
sf::Shape, sf::RectangleShape, sf::CircleShape

Definition at line 42 of file ConvexShape.hpp.

Constructor & Destructor Documentation

sf::ConvexShape::ConvexShape ( unsigned int  pointCount = 0)
explicit

Default constructor.

Parameters
pointCountNumber of points of the polygon

Member Function Documentation

const Color& sf::Shape::getFillColor ( ) const
inherited

Get the fill color of the shape.

Returns
Fill color of the shape
See Also
setFillColor
FloatRect sf::Shape::getGlobalBounds ( ) const
inherited

Get the global bounding rectangle of the entity.

The returned rectangle is in global coordinates, which means that it takes in account the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the sprite in the global 2D world's coordinate system.

Returns
Global bounding rectangle of the entity
const Transform& sf::Transformable::getInverseTransform ( ) const
inherited

get the inverse of the combined transform of the object

Returns
Inverse of the combined transformations applied to the object
See Also
getTransform
FloatRect sf::Shape::getLocalBounds ( ) const
inherited

Get the local bounding rectangle of the entity.

The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the entity in the entity's coordinate system.

Returns
Local bounding rectangle of the entity
const Vector2f& sf::Transformable::getOrigin ( ) const
inherited

get the local origin of the object

Returns
Current origin
See Also
setOrigin
const Color& sf::Shape::getOutlineColor ( ) const
inherited

Get the outline color of the shape.

Returns
Outline color of the shape
See Also
setOutlineColor
float sf::Shape::getOutlineThickness ( ) const
inherited

Get the outline thickness of the shape.

Returns
Outline thickness of the shape
See Also
setOutlineThickness
virtual Vector2f sf::ConvexShape::getPoint ( unsigned int  index) const
virtual

Get the position of a point.

The result is undefined if index is out of the valid range.

Parameters
indexIndex of the point to get, in range [0 .. getPointCount() - 1]
Returns
Position of the index-th point of the polygon
See Also
setPoint

Implements sf::Shape.

virtual unsigned int sf::ConvexShape::getPointCount ( ) const
virtual

Get the number of points of the polygon.

Returns
Number of points of the polygon
See Also
setPointCount

Implements sf::Shape.

const Vector2f& sf::Transformable::getPosition ( ) const
inherited

get the position of the object

Returns
Current position
See Also
setPosition
float sf::Transformable::getRotation ( ) const
inherited

get the orientation of the object

The rotation is always in the range [0, 360].

Returns
Current rotation, in degrees
See Also
setRotation
const Vector2f& sf::Transformable::getScale ( ) const
inherited

get the current scale of the object

Returns
Current scale factors
See Also
setScale
const Texture* sf::Shape::getTexture ( ) const
inherited

Get the source texture of the shape.

If the shape has no source texture, a NULL pointer is returned. The returned pointer is const, which means that you can't modify the texture when you retrieve it with this function.

Returns
Pointer to the shape's texture
See Also
setTexture
const IntRect& sf::Shape::getTextureRect ( ) const
inherited

Get the sub-rectangle of the texture displayed by the shape.

Returns
Texture rectangle of the shape
See Also
setTextureRect
const Transform& sf::Transformable::getTransform ( ) const
inherited

get the combined transform of the object

Returns
Transform combining the position/rotation/scale/origin of the object
See Also
getInverseTransform
void sf::Transformable::move ( float  offsetX,
float  offsetY 
)
inherited

Move the object by a given offset.

This function adds to the current position of the object, unlike setPosition which overwrites it. Thus, it is equivalent to the following code:

sf::Vector2f pos = object.getPosition();
object.setPosition(pos.x + offsetX, pos.y + offsetY);
Parameters
offsetXX offset
offsetYY offset
See Also
setPosition
void sf::Transformable::move ( const Vector2f offset)
inherited

Move the object by a given offset.

This function adds to the current position of the object, unlike setPosition which overwrites it. Thus, it is equivalent to the following code:

object.setPosition(object.getPosition() + offset);
Parameters
offsetOffset
See Also
setPosition
void sf::Transformable::rotate ( float  angle)
inherited

Rotate the object.

This function adds to the current rotation of the object, unlike setRotation which overwrites it. Thus, it is equivalent to the following code:

object.setRotation(object.getRotation() + angle);
Parameters
angleAngle of rotation, in degrees
void sf::Transformable::scale ( float  factorX,
float  factorY 
)
inherited

Scale the object.

This function multiplies the current scale of the object, unlike setScale which overwrites it. Thus, it is equivalent to the following code:

sf::Vector2f scale = object.getScale();
object.setScale(scale.x * factorX, scale.y * factorY);
Parameters
factorXHorizontal scale factor
factorYVertical scale factor
See Also
setScale
void sf::Transformable::scale ( const Vector2f factor)
inherited

Scale the object.

This function multiplies the current scale of the object, unlike setScale which overwrites it. Thus, it is equivalent to the following code:

sf::Vector2f scale = object.getScale();
object.setScale(scale.x * factor.x, scale.y * factor.y);
Parameters
factorScale factors
See Also
setScale
void sf::Shape::setFillColor ( const Color color)
inherited

Set the fill color of the shape.

This color is modulated (multiplied) with the shape's texture if any. It can be used to colorize the shape, or change its global opacity. You can use sf::Color::Transparent to make the inside of the shape transparent, and have the outline alone. By default, the shape's fill color is opaque white.

Parameters
colorNew color of the shape
See Also
getFillColor, setOutlineColor
void sf::Transformable::setOrigin ( float  x,
float  y 
)
inherited

set the local origin of the object

The origin of an object defines the center point for all transformations (position, scale, rotation). The coordinates of this point must be relative to the top-left corner of the object, and ignore all transformations (position, scale, rotation). The default origin of a transformable object is (0, 0).

Parameters
xX coordinate of the new origin
yY coordinate of the new origin
See Also
getOrigin
void sf::Transformable::setOrigin ( const Vector2f origin)
inherited

set the local origin of the object

The origin of an object defines the center point for all transformations (position, scale, rotation). The coordinates of this point must be relative to the top-left corner of the object, and ignore all transformations (position, scale, rotation). The default origin of a transformable object is (0, 0).

Parameters
originNew origin
See Also
getOrigin
void sf::Shape::setOutlineColor ( const Color color)
inherited

Set the outline color of the shape.

By default, the shape's outline color is opaque white.

Parameters
colorNew outline color of the shape
See Also
getOutlineColor, setFillColor
void sf::Shape::setOutlineThickness ( float  thickness)
inherited

Set the thickness of the shape's outline.

Note that negative values are allowed (so that the outline expands towards the center of the shape), and using zero disables the outline. By default, the outline thickness is 0.

Parameters
thicknessNew outline thickness
See Also
getOutlineThickness
void sf::ConvexShape::setPoint ( unsigned int  index,
const Vector2f point 
)

Set the position of a point.

Don't forget that the polygon must remain convex, and the points need to stay ordered! setPointCount must be called first in order to set the total number of points. The result is undefined if index is out of the valid range.

Parameters
indexIndex of the point to change, in range [0 .. getPointCount() - 1]
pointNew position of the point
See Also
getPoint
void sf::ConvexShape::setPointCount ( unsigned int  count)

Set the number of points of the polygon.

count must be greater than 2 to define a valid shape.

Parameters
countNew number of points of the polygon
See Also
getPointCount
void sf::Transformable::setPosition ( float  x,
float  y 
)
inherited

set the position of the object

This function completely overwrites the previous position. See the move function to apply an offset based on the previous position instead. The default position of a transformable object is (0, 0).

Parameters
xX coordinate of the new position
yY coordinate of the new position
See Also
move, getPosition
void sf::Transformable::setPosition ( const Vector2f position)
inherited

set the position of the object

This function completely overwrites the previous position. See the move function to apply an offset based on the previous position instead. The default position of a transformable object is (0, 0).

Parameters
positionNew position
See Also
move, getPosition
void sf::Transformable::setRotation ( float  angle)
inherited

set the orientation of the object

This function completely overwrites the previous rotation. See the rotate function to add an angle based on the previous rotation instead. The default rotation of a transformable object is 0.

Parameters
angleNew rotation, in degrees
See Also
rotate, getRotation
void sf::Transformable::setScale ( float  factorX,
float  factorY 
)
inherited

set the scale factors of the object

This function completely overwrites the previous scale. See the scale function to add a factor based on the previous scale instead. The default scale of a transformable object is (1, 1).

Parameters
factorXNew horizontal scale factor
factorYNew vertical scale factor
See Also
scale, getScale
void sf::Transformable::setScale ( const Vector2f factors)
inherited

set the scale factors of the object

This function completely overwrites the previous scale. See the scale function to add a factor based on the previous scale instead. The default scale of a transformable object is (1, 1).

Parameters
factorsNew scale factors
See Also
scale, getScale
void sf::Shape::setTexture ( const Texture texture,
bool  resetRect = false 
)
inherited

Change the source texture of the shape.

The texture argument refers to a texture that must exist as long as the shape uses it. Indeed, the shape doesn't store its own copy of the texture, but rather keeps a pointer to the one that you passed to this function. If the source texture is destroyed and the shape tries to use it, the behaviour is undefined. texture can be NULL to disable texturing. If resetRect is true, the TextureRect property of the shape is automatically adjusted to the size of the new texture. If it is false, the texture rect is left unchanged.

Parameters
textureNew texture
resetRectShould the texture rect be reset to the size of the new texture?
See Also
getTexture, setTextureRect
void sf::Shape::setTextureRect ( const IntRect rect)
inherited

Set the sub-rectangle of the texture that the shape will display.

The texture rect is useful when you don't want to display the whole texture, but rather a part of it. By default, the texture rect covers the entire texture.

Parameters
rectRectangle defining the region of the texture to display
See Also
getTextureRect, setTexture
void sf::Shape::update ( )
protectedinherited

Recompute the internal geometry of the shape.

This function must be called by the derived class everytime the shape's points change (ie. the result of either getPointCount or getPoint is different).


The documentation for this class was generated from the following file: