Base class for textured shapes with outline
SF::Shape is a drawable class that allows to define and
display a custom convex shape on a render target.
It's only an abstract base, it needs to be specialized for
concrete types of shapes (circle, rectangle, convex polygon,
In addition to the attributes provided by the specialized shape classes, a shape always has the following attributes:
- a texture
- a texture rectangle
- a fill color
- an outline color
- an outline thickness
Each feature is optional, and can be disabled easily:
- the texture can be null
- the fill/outline colors can be
- the outline thickness can be zero
You can write your own derived shape class, there are only two virtual functions to override:
point_countmust return the number of points of the shape
get_pointmust return the points of the shape
Direct known subclasses
Get the fill color of the shape
Returns: Fill color of the shape
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.
- color - New color of the shape
Get a point of the shape
The returned point is in local coordinates, that is, the shape's transforms (position, rotation, scale) are not taken into account. The result is undefined if index is out of the valid range.
- index - Index of the point to get, in range
0 ... point_count
Returns: index-th point of the shape
Get the global (non-minimal) bounding rectangle of the entity
The returned rectangle is in global coordinates, which means that it takes into account the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the shape in the global 2D world's coordinate system.
This function does not necessarily return the minimal bounding rectangle. It merely ensures that the returned rectangle covers all the vertices (but possibly more). This allows for a fast approximation of the bounds as a first check; you may want to use more precise checks on top of that.
Returns: Global bounding rectangle of the entity
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
Get the outline color of the shape
Returns: Outline color of the shape
Set the outline color of the shape
By default, the shape's outline color is opaque white.
- color - New outline color of the shape
Get the outline thickness of the shape
Returns: Outline thickness of the shape
(thickness : Number)
(thickness : Number)
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.
- thickness - New outline thickness
Get the total number of points of the shape
Returns: Number of points of the shape
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 behavior is undefined. texture can be NULL to disable texturing. If reset_rect 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.
- texture - New texture
- reset_rect - Should the texture rect be reset to the size of the new texture?
Get the sub-rectangle of the texture displayed by the shape
Returns: Texture rectangle of the shape
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.
- rect - Rectangle defining the region of the texture to display