CSFML - C binding of the Simple and Fast Multimedia Library

CSFML 3.0.0
Loading...
Searching...
No Matches
Typedefs | Functions
Shape.h File Reference
`#include <CSFML/Graphics/Export.h>`
`#include <CSFML/Graphics/Color.h>`
`#include <CSFML/Graphics/Rect.h>`
`#include <CSFML/Graphics/Transform.h>`
`#include <CSFML/Graphics/Types.h>`
`#include <CSFML/System/Vector2.h>`
`#include <stddef.h>`

Go to the source code of this file.

## Typedefs
typedef size_t(* | sfShapeGetPointCountCallback) (void *)
| Type of the callback used to get the number of points in a shape.
typedef sfVector2f(* | sfShapeGetPointCallback) (size_t, void *)
| Type of the callback used to get a point of a shape.

## Functions
sfShape * | sfShape_create (sfShapeGetPointCountCallback getPointCount, sfShapeGetPointCallback getPoint, void *userData)
| Create a new shape.
void | sfShape_destroy (const sfShape *shape)
| Destroy an existing shape.
void | sfShape_setPosition (sfShape *shape, sfVector2f position)
| Set the position of a shape.
void | sfShape_setRotation (sfShape *shape, float angle)
| Set the orientation of a shape.
void | sfShape_setScale (sfShape *shape, sfVector2f scale)
| Set the scale factors of a shape.
void | sfShape_setOrigin (sfShape *shape, sfVector2f origin)
| Set the local origin of a shape.
sfVector2f | sfShape_getPosition (const sfShape *shape)
| Get the position of a shape.
float | sfShape_getRotation (const sfShape *shape)
| Get the orientation of a shape.
sfVector2f | sfShape_getScale (const sfShape *shape)
| Get the current scale of a shape.
sfVector2f | sfShape_getOrigin (const sfShape *shape)
| Get the local origin of a shape.
void | sfShape_move (sfShape *shape, sfVector2f offset)
| Move a shape by a given offset.
void | sfShape_rotate (sfShape *shape, float angle)
| Rotate a shape.
void | sfShape_scale (sfShape *shape, sfVector2f factors)
| Scale a shape.
sfTransform | sfShape_getTransform (const sfShape *shape)
| Get the combined transform of a shape.
sfTransform | sfShape_getInverseTransform (const sfShape *shape)
| Get the inverse of the combined transform of a shape.
void | sfShape_setTexture (sfShape *shape, const sfTexture *texture, bool resetRect)
| Change the source texture of a shape.
void | sfShape_setTextureRect (sfShape *shape, sfIntRect rect)
| Set the sub-rectangle of the texture that a shape will display.
void | sfShape_setFillColor (sfShape *shape, sfColor color)
| Set the fill color of a shape.
void | sfShape_setOutlineColor (sfShape *shape, sfColor color)
| Set the outline color of a shape.
void | sfShape_setOutlineThickness (sfShape *shape, float thickness)
| Set the thickness of a shape's outline.
const sfTexture * | sfShape_getTexture (const sfShape *shape)
| Get the source texture of a shape.
sfIntRect | sfShape_getTextureRect (const sfShape *shape)
| Get the sub-rectangle of the texture displayed by a shape.
sfColor | sfShape_getFillColor (const sfShape *shape)
| Get the fill color of a shape.
sfColor | sfShape_getOutlineColor (const sfShape *shape)
| Get the outline color of a shape.
float | sfShape_getOutlineThickness (const sfShape *shape)
| Get the outline thickness of a shape.
size_t | sfShape_getPointCount (const sfShape *shape)
| Get the total number of points of a shape.
sfVector2f | sfShape_getPoint (const sfShape *shape, size_t index)
| Get a point of a shape.
sfVector2f | sfShape_getGeometricCenter (const sfShape *shape)
| Get the geometric center of the shape.
sfFloatRect | sfShape_getLocalBounds (const sfShape *shape)
| Get the local bounding rectangle of a shape.
sfFloatRect | sfShape_getGlobalBounds (const sfShape *shape)
| Get the global bounding rectangle of a shape.
void | sfShape_update (sfShape *shape)
| Recompute the internal geometry of a shape.

## Typedef Documentation

## ◆ sfShapeGetPointCallback

typedef sfVector2f(* sfShapeGetPointCallback) (size_t, void *)

Type of the callback used to get a point of a shape.

Definition at line 42 of file Shape.h.

## ◆ sfShapeGetPointCountCallback

typedef size_t(* sfShapeGetPointCountCallback) (void *)

Type of the callback used to get the number of points in a shape.

Definition at line 41 of file Shape.h.

## Function Documentation

## ◆ sfShape_create()

sfShape * sfShape_create | ( | sfShapeGetPointCountCallback | getPointCount,
|  | sfShapeGetPointCallback | getPoint,
|  | void * | userData )

Create a new shape.

Parameters

  getPointCount | Callback that provides the point count of the shape
  getPoint | Callback that provides the points of the shape
  userData | Data to pass to the callback functions

Returns
  A new sfShape object

## ◆ sfShape_destroy()

void sfShape_destroy | ( | const sfShape * | shape | ) |

Destroy an existing shape.

Parameters

  shape | Shape to delete

## ◆ sfShape_getFillColor()

sfColor sfShape_getFillColor | ( | const sfShape * | shape | ) |

Get the fill color of a shape.

Parameters

  shape | Shape object

Returns
  Fill color of the shape

## ◆ sfShape_getGeometricCenter()

sfVector2f sfShape_getGeometricCenter | ( | const sfShape * | shape | ) |

Get the geometric center of the shape.

The returned point is in local coordinates, that is, the shape's transforms (position, rotation, scale) are not taken into account.

Parameters

  shape | Shape object

Returns
  The geometric center of the shape

## ◆ sfShape_getGlobalBounds()

sfFloatRect sfShape_getGlobalBounds | ( | const sfShape * | shape | ) |

Get the global bounding rectangle of a shape.

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.

Parameters

  shape | Shape object

Returns
  Global bounding rectangle of the entity

## ◆ sfShape_getInverseTransform()

sfTransform sfShape_getInverseTransform | ( | const sfShape * | shape | ) |

Get the inverse of the combined transform of a shape.

Parameters

  shape | shape object

Returns
  Inverse of the combined transformations applied to the object

## ◆ sfShape_getLocalBounds()

sfFloatRect sfShape_getLocalBounds | ( | const sfShape * | shape | ) |

Get the local bounding rectangle of a shape.

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.

Parameters

  shape | Shape object

Returns
  Local bounding rectangle of the entity

## ◆ sfShape_getOrigin()

sfVector2f sfShape_getOrigin | ( | const sfShape * | shape | ) |

Get the local origin of a shape.

Parameters

  shape | Shape object

Returns
  Current origin

## ◆ sfShape_getOutlineColor()

sfColor sfShape_getOutlineColor | ( | const sfShape * | shape | ) |

Get the outline color of a shape.

Parameters

  shape | Shape object

Returns
  Outline color of the shape

## ◆ sfShape_getOutlineThickness()

float sfShape_getOutlineThickness | ( | const sfShape * | shape | ) |

Get the outline thickness of a shape.

Parameters

  shape | Shape object

Returns
  Outline thickness of the shape

## ◆ sfShape_getPoint()

sfVector2f sfShape_getPoint | ( | const sfShape * | shape,
|  | size_t | index )

Get a point of a shape.

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

Parameters

  shape | Shape object
  index | Index of the point to get, in range [0 .. getPointCount() - 1]

Returns
  Index-th point of the shape

## ◆ sfShape_getPointCount()

size_t sfShape_getPointCount | ( | const sfShape * | shape | ) |

Get the total number of points of a shape.

Parameters

  shape | Shape object

Returns
  Number of points of the shape

## ◆ sfShape_getPosition()

sfVector2f sfShape_getPosition | ( | const sfShape * | shape | ) |

Get the position of a shape.

Parameters

  shape | Shape object

Returns
  Current position

## ◆ sfShape_getRotation()

float sfShape_getRotation | ( | const sfShape * | shape | ) |

Get the orientation of a shape.

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

Parameters

  shape | Shape object

Returns
  Current rotation, in degrees

## ◆ sfShape_getScale()

sfVector2f sfShape_getScale | ( | const sfShape * | shape | ) |

Get the current scale of a shape.

Parameters

  shape | Shape object

Returns
  Current scale factors

## ◆ sfShape_getTexture()

const sfTexture * sfShape_getTexture | ( | const sfShape * | shape | ) |

Get the source texture of a 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.

Parameters

  shape | Shape object

Returns
  Pointer to the shape's texture

## ◆ sfShape_getTextureRect()

sfIntRect sfShape_getTextureRect | ( | const sfShape * | shape | ) |

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

Parameters

  shape | Shape object

Returns
  Texture rectangle of the shape

## ◆ sfShape_getTransform()

sfTransform sfShape_getTransform | ( | const sfShape * | shape | ) |

Get the combined transform of a shape.

Parameters

  shape | shape object

Returns
  Transform combining the position/rotation/scale/origin of the object

## ◆ sfShape_move()

void sfShape_move | ( | sfShape * | shape,
|  | sfVector2f | offset )

Move a shape by a given offset.

This function adds to the current position of the object, unlike sfShape_setPosition which overwrites it.

Parameters

  shape | Shape object
  offset | Offset

## ◆ sfShape_rotate()

void sfShape_rotate | ( | sfShape * | shape,
|  | float | angle )

Rotate a shape.

This function adds to the current rotation of the object, unlike sfShape_setRotation which overwrites it.

Parameters

  shape | Shape object
  angle | Angle of rotation, in degrees

## ◆ sfShape_scale()

void sfShape_scale | ( | sfShape * | shape,
|  | sfVector2f | factors )

Scale a shape.

This function multiplies the current scale of the object, unlike sfShape_setScale which overwrites it.

Parameters

  shape | Shape object
  factors | Scale factors

## ◆ sfShape_setFillColor()

void sfShape_setFillColor | ( | sfShape * | shape,
|  | sfColor | color )

Set the fill color of a 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 sfTransparent to make the inside of the shape transparent, and have the outline alone. By default, the shape's fill color is opaque white.

Parameters

  shape | Shape object
  color | New color of the shape

## ◆ sfShape_setOrigin()

void sfShape_setOrigin | ( | sfShape * | shape,
|  | sfVector2f | origin )

Set the local origin of a shape.

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 circle Shape object is (0, 0).

Parameters

  shape | Shape object
  origin | New origin

## ◆ sfShape_setOutlineColor()

void sfShape_setOutlineColor | ( | sfShape * | shape,
|  | sfColor | color )

Set the outline color of a shape.

You can use sfTransparent to disable the outline. By default, the shape's outline color is opaque white.

Parameters

  shape | Shape object
  color | New outline color of the shape

## ◆ sfShape_setOutlineThickness()

void sfShape_setOutlineThickness | ( | sfShape * | shape,
|  | float | thickness )

Set the thickness of a shape's outline.

This number cannot be negative. Using zero disables the outline. By default, the outline thickness is 0.

Parameters

  shape | Shape object
  thickness | New outline thickness

## ◆ sfShape_setPosition()

void sfShape_setPosition | ( | sfShape * | shape,
|  | sfVector2f | position )

Set the position of a shape.

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

Parameters

  shape | Shape object
  position | New position

## ◆ sfShape_setRotation()

void sfShape_setRotation | ( | sfShape * | shape,
|  | float | angle )

Set the orientation of a shape.

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

Parameters

  shape | Shape object
  angle | New rotation, in degrees

## ◆ sfShape_setScale()

void sfShape_setScale | ( | sfShape * | shape,
|  | sfVector2f | scale )

Set the scale factors of a shape.

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

Parameters

  shape | Shape object
  scale | New scale factors

## ◆ sfShape_setTexture()

void sfShape_setTexture | ( | sfShape * | shape,
|  | const sfTexture * | texture,
|  | bool | resetRect )

Change the source texture of a 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

  shape | Shape object
  texture | New texture
  resetRect | Should the texture rect be reset to the size of the new texture?

## ◆ sfShape_setTextureRect()

void sfShape_setTextureRect | ( | sfShape * | shape,
|  | sfIntRect | rect )

Set the sub-rectangle of the texture that a 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

  shape | Shape object
  rect | Rectangle defining the region of the texture to display

## ◆ sfShape_update()

void sfShape_update | ( | sfShape * | shape | ) |

Recompute the internal geometry of a shape.

This function must be called by specialized shape objects every time their points change (ie. the result of either the getPointCount or getPoint callbacks is different).