sf::Shape Class Reference

Shape defines a drawable convex shape ; it also defines helper functions to draw simple shapes like lines, rectangles, circles, etc. More...

#include <Shape.hpp>

Inheritance diagram for sf::Shape:
sf::Drawable

List of all members.

Classes

struct  Point
 Defines a simple 2D point.

Public Member Functions

 Shape ()
 Default constructor.
void AddPoint (float x, float y, const Color &color=Color(255, 255, 255), const Color &outlineColor=Color(0, 0, 0))
 Add a point to the shape.
void AddPoint (const Vector2f &position, const Color &color=Color(255, 255, 255), const Color &outlineColor=Color(0, 0, 0))
 Add a point to the shape.
unsigned int GetPointsCount () const
 Get the number of points composing the shape.
void EnableFill (bool enable)
 Enable or disable filling the shape.
void EnableOutline (bool enable)
 Enable or disable drawing the shape outline.
void SetPointPosition (unsigned int index, const Vector2f &position)
 Set the position of a point.
void SetPointPosition (unsigned int index, float x, float y)
 Set the position of a point.
void SetPointColor (unsigned int index, const Color &color)
 Set the color of a point.
void SetPointOutlineColor (unsigned int index, const Color &outlineColor)
 Set the outline color of a point.
void SetOutlineWidth (float width)
 Change the width of the shape outline.
const Vector2fGetPointPosition (unsigned int index) const
 Get the position of a point.
const ColorGetPointColor (unsigned int index) const
 Get the color of a point.
const ColorGetPointOutlineColor (unsigned int index) const
 Get the outline color of a point.
float GetOutlineWidth () const
 Get the width of the shape outline.
void SetPosition (float x, float y)
 Set the position of the object (take 2 values).
void SetPosition (const Vector2f &position)
 Set the position of the object (take a 2D vector).
void SetX (float x)
 Set the X position of the object.
void SetY (float y)
 Set the Y position of the object.
void SetScale (float factorX, float factorY)
 Set the scale of the object (take 2 values).
void SetScale (const Vector2f &scale)
 Set the scale of the object (take a 2D vector).
void SetScaleX (float factor)
 Set the X scale factor of the object.
void SetScaleY (float factor)
 Set the Y scale factor of the object.
void SetOrigin (float x, float y)
 Set the local origin of the object, in coordinates relative to the top-left of the object (take 2 values).
void SetOrigin (const Vector2f &origin)
 Set the local origin of the object, in coordinates relative to the top-left of the object (take a 2D vector).
void SetRotation (float angle)
 Set the orientation of the object.
void SetColor (const Color &color)
 Set the color of the object.
void SetBlendMode (Blend::Mode mode)
 Set the blending mode for the object.
const Vector2fGetPosition () const
 Get the position of the object.
const Vector2fGetScale () const
 Get the current scale of the object.
const Vector2fGetOrigin () const
 Get the local origin of the object.
float GetRotation () const
 Get the orientation of the object.
const ColorGetColor () const
 Get the color of the object.
Blend::Mode GetBlendMode () const
 Get the current blending mode.
void Move (float offsetX, float offsetY)
 Move the object of a given offset (take 2 values).
void Move (const Vector2f &offset)
 Move the object of a given offset (take a 2D vector).
void Scale (float factorX, float factorY)
 Scale the object (take 2 values).
void Scale (const Vector2f &factor)
 Scale the object (take a 2D vector).
void Rotate (float Angle)
 Rotate the object.
Vector2f TransformToLocal (const Vector2f &point) const
 Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's origin, translation, rotation and scale to the point).
Vector2f TransformToGlobal (const Vector2f &point) const
 Transform a point from local coordinates into global coordinates (ie it applies the object's origin, translation, rotation and scale to the point).

Static Public Member Functions

static Shape Line (float p1x, float p1y, float p2x, float p2y, float thickness, const Color &color, float outline=0.f, const Color &outlineColor=Color(0, 0, 0))
 Create a shape made of a single line (use floats).
static Shape Line (const Vector2f &p1, const Vector2f &p2, float thickness, const Color &color, float outline=0.f, const Color &outlineColor=Color(0, 0, 0))
 Create a shape made of a single line (use vectors).
static Shape Rectangle (float p1x, float p1y, float p2x, float p2y, const Color &color, float outline=0.f, const Color &outlineColor=Color(0, 0, 0))
 Create a shape made of a single rectangle (use floats).
static Shape Rectangle (const Vector2f &p1, const Vector2f &p2, const Color &color, float outline=0.f, const Color &outlineColor=Color(0, 0, 0))
 Create a shape made of a single rectangle (use vectors).
static Shape Circle (float x, float y, float radius, const Color &color, float outline=0.f, const Color &outlineColor=Color(0, 0, 0))
 Create a shape made of a single circle (use floats).
static Shape Circle (const Vector2f &center, float radius, const Color &color, float outline=0.f, const Color &outlineColor=Color(0, 0, 0))
 Create a shape made of a single circle (use vectors).

Protected Member Functions

virtual void Render (RenderTarget &target, Renderer &renderer) const
 /see Drawable::Render
const Matrix3GetMatrix () const
 Get the transform matrix of the drawable.
const Matrix3GetInverseMatrix () const
 Get the inverse transform matrix of the drawable.

Detailed Description

Shape defines a drawable convex shape ; it also defines helper functions to draw simple shapes like lines, rectangles, circles, etc.

Definition at line 43 of file Shape.hpp.


Constructor & Destructor Documentation

sf::Shape::Shape (  ) 

Default constructor.

Definition at line 38 of file Shape.cpp.


Member Function Documentation

void sf::Shape::AddPoint ( const Vector2f position,
const Color color = Color(255, 255, 255),
const Color outlineColor = Color(0, 0, 0) 
)

Add a point to the shape.

Parameters:
position : Position of the point
color : Color of the point
outlineColor : Outline color of the point

Definition at line 61 of file Shape.cpp.

void sf::Shape::AddPoint ( float  x,
float  y,
const Color color = Color(255, 255, 255),
const Color outlineColor = Color(0, 0, 0) 
)

Add a point to the shape.

Parameters:
x,y : Position of the point
color : Color of the point
outlineColor : Outline color of the point

Definition at line 52 of file Shape.cpp.

Shape sf::Shape::Circle ( const Vector2f center,
float  radius,
const Color color,
float  outline = 0.f,
const Color outlineColor = Color(0, 0, 0) 
) [static]

Create a shape made of a single circle (use vectors).

Parameters:
center : Position of the center
radius : Radius
color : Color used to fill the circle
outline : Outline width
outlineColor : Color used to draw the outline

Definition at line 259 of file Shape.cpp.

Shape sf::Shape::Circle ( float  x,
float  y,
float  radius,
const Color color,
float  outline = 0.f,
const Color outlineColor = Color(0, 0, 0) 
) [static]

Create a shape made of a single circle (use floats).

Create a shape made of a single circle.

Parameters:
x,y : Position of the center
radius : Radius
color : Color used to fill the circle
outline : Outline width
outlineColor : Color used to draw the outline

Definition at line 250 of file Shape.cpp.

void sf::Shape::EnableFill ( bool  enable  ) 

Enable or disable filling the shape.

Fill is enabled by default

Parameters:
enable : True to enable, false to disable

Fill is enabled by default

Definition at line 81 of file Shape.cpp.

void sf::Shape::EnableOutline ( bool  enable  ) 

Enable or disable drawing the shape outline.

Outline is enabled by default

Parameters:
enable : True to enable, false to disable

Outline is enabled by default

Definition at line 91 of file Shape.cpp.

Blend::Mode sf::Drawable::GetBlendMode (  )  const [inherited]

Get the current blending mode.

Returns:
Current blending mode

Definition at line 263 of file Drawable.cpp.

const Color & sf::Drawable::GetColor (  )  const [inherited]

Get the color of the object.

Returns:
Current color

Definition at line 254 of file Drawable.cpp.

const Matrix3 & sf::Drawable::GetInverseMatrix (  )  const [protected, inherited]

Get the inverse transform matrix of the drawable.

Returns:
Inverse transform matrix

Definition at line 353 of file Drawable.cpp.

const Matrix3 & sf::Drawable::GetMatrix (  )  const [protected, inherited]

Get the transform matrix of the drawable.

Returns:
Transform matrix

Definition at line 337 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetOrigin (  )  const [inherited]

Get the local origin of the object.

Get the origin of the object.

Returns:
Current position of the origin

Definition at line 236 of file Drawable.cpp.

float sf::Shape::GetOutlineWidth (  )  const

Get the width of the shape outline.

Returns:
Current outline width

Definition at line 175 of file Shape.cpp.

const Color & sf::Shape::GetPointColor ( unsigned int  index  )  const

Get the color of a point.

Parameters:
Index : index of the point, in range [0, GetPointsCount() - 1]
Returns:
Color of the index-th point

Definition at line 157 of file Shape.cpp.

const Color & sf::Shape::GetPointOutlineColor ( unsigned int  index  )  const

Get the outline color of a point.

Parameters:
index : Index of the point, in range [0, GetPointsCount() - 1]
Returns:
Outline color of the index-th point

Definition at line 166 of file Shape.cpp.

const Vector2f & sf::Shape::GetPointPosition ( unsigned int  index  )  const

Get the position of a point.

Parameters:
index : Index of the point, in range [0, GetPointsCount() - 1]
Returns:
Position of the index-th point

Definition at line 148 of file Shape.cpp.

unsigned int sf::Shape::GetPointsCount (  )  const

Get the number of points composing the shape.

Parameters:
Total number of points

Definition at line 71 of file Shape.cpp.

const Vector2f & sf::Drawable::GetPosition (  )  const [inherited]

Get the position of the object.

Returns:
Current position

Definition at line 218 of file Drawable.cpp.

float sf::Drawable::GetRotation (  )  const [inherited]

Get the orientation of the object.

Rotation is always in the range [0, 360]

Returns:
Current rotation, in degrees

Definition at line 245 of file Drawable.cpp.

const Vector2f & sf::Drawable::GetScale (  )  const [inherited]

Get the current scale of the object.

Returns:
Current scale factor (always positive)

Definition at line 227 of file Drawable.cpp.

Shape sf::Shape::Line ( const Vector2f p1,
const Vector2f p2,
float  thickness,
const Color color,
float  outline = 0.f,
const Color outlineColor = Color(0, 0, 0) 
) [static]

Create a shape made of a single line (use vectors).

Parameters:
p1 : Position of the first point
p2 : Position second point
thickness : Line thickness
color : Color used to draw the line
outline : Outline width
outlineColor : Color used to draw the outline

Definition at line 196 of file Shape.cpp.

Shape sf::Shape::Line ( float  p1x,
float  p1y,
float  p2x,
float  p2y,
float  thickness,
const Color color,
float  outline = 0.f,
const Color outlineColor = Color(0, 0, 0) 
) [static]

Create a shape made of a single line (use floats).

Create a shape made of a single line.

Parameters:
p1x,p1y : Position of the first point
p2x,p2y : Position second point
thickness : Line thickness
color : Color used to draw the line
outline : Outline width
outlineColor : Color used to draw the outline

Definition at line 184 of file Shape.cpp.

void sf::Drawable::Move ( const Vector2f offset  )  [inherited]

Move the object of a given offset (take a 2D vector).

Parameters:
offset : Amount of units to move the object of

Definition at line 282 of file Drawable.cpp.

void sf::Drawable::Move ( float  offsetX,
float  offsetY 
) [inherited]

Move the object of a given offset (take 2 values).

Parameters:
offsetX : X offset
offsetY : Y offset

Definition at line 273 of file Drawable.cpp.

Shape sf::Shape::Rectangle ( const Vector2f p1,
const Vector2f p2,
const Color color,
float  outline = 0.f,
const Color outlineColor = Color(0, 0, 0) 
) [static]

Create a shape made of a single rectangle (use vectors).

Parameters:
p1 : Position of the first point
p2 : Position second point
color : Color used to fill the rectangle
outline : Outline width
outlineColor : Color used to draw the outline

Definition at line 241 of file Shape.cpp.

Shape sf::Shape::Rectangle ( float  p1x,
float  p1y,
float  p2x,
float  p2y,
const Color color,
float  outline = 0.f,
const Color outlineColor = Color(0, 0, 0) 
) [static]

Create a shape made of a single rectangle (use floats).

Create a shape made of a single rectangle.

Parameters:
p1x,p1y : Position of the first point
p2x,p2y : Position second point
color : Color used to fill the rectangle
outline : Outline width
outlineColor : Color used to draw the outline

Definition at line 221 of file Shape.cpp.

void sf::Shape::Render ( RenderTarget target,
Renderer renderer 
) const [protected, virtual]

/see Drawable::Render

Implements sf::Drawable.

Definition at line 284 of file Shape.cpp.

void sf::Drawable::Rotate ( float  Angle  )  [inherited]

Rotate the object.

Parameters:
Angle : Angle of rotation, in degrees

Definition at line 309 of file Drawable.cpp.

void sf::Drawable::Scale ( const Vector2f factor  )  [inherited]

Scale the object (take a 2D vector).

Parameters:
factor : Scaling factors (both values must be strictly positive)

Definition at line 300 of file Drawable.cpp.

void sf::Drawable::Scale ( float  factorX,
float  factorY 
) [inherited]

Scale the object (take 2 values).

Parameters:
factorX : Scaling factor on X (must be strictly positive)
factorY : Scaling factor on Y (must be strictly positive)

Definition at line 291 of file Drawable.cpp.

void sf::Drawable::SetBlendMode ( Blend::Mode  mode  )  [inherited]

Set the blending mode for the object.

The default blend mode is Blend::Alpha

Parameters:
mode : New blending mode

The default blend mode is Blend::Alpha

Definition at line 209 of file Drawable.cpp.

void sf::Drawable::SetColor ( const Color color  )  [inherited]

Set the color of the object.

The default color is white

Parameters:
color : New color

The default color is white

Definition at line 199 of file Drawable.cpp.

void sf::Drawable::SetOrigin ( const Vector2f origin  )  [inherited]

Set the local origin of the object, in coordinates relative to the top-left of the object (take a 2D vector).

The default origin is (0, 0)

Parameters:
origin : New origin

The default origin is (0, 0)

Definition at line 175 of file Drawable.cpp.

void sf::Drawable::SetOrigin ( float  x,
float  y 
) [inherited]

Set the local origin of the object, in coordinates relative to the top-left of the object (take 2 values).

The default origin is (0, 0)

Parameters:
x : X coordinate of the origin
y : Y coordinate of the origin

The default origin is (0, 0)

Definition at line 160 of file Drawable.cpp.

void sf::Shape::SetOutlineWidth ( float  width  ) 

Change the width of the shape outline.

Parameters:
width : New width

Definition at line 139 of file Shape.cpp.

void sf::Shape::SetPointColor ( unsigned int  index,
const Color color 
)

Set the color of a point.

Parameters:
index : Index of the point, in range [0, GetPointsCount() - 1]
color : New color of the index-th point

Definition at line 119 of file Shape.cpp.

void sf::Shape::SetPointOutlineColor ( unsigned int  index,
const Color outlineColor 
)

Set the outline color of a point.

Parameters:
index : Index of the point, in range [0, GetPointsCount() - 1]
outlineColor : New outline color of the index-th point

Definition at line 129 of file Shape.cpp.

void sf::Shape::SetPointPosition ( unsigned int  index,
float  x,
float  y 
)

Set the position of a point.

Parameters:
index : Index of the point, in range [0, GetPointsCount() - 1]
x : New X coordinate of the index-th point
y : New Y coordinate of the index-th point

Definition at line 110 of file Shape.cpp.

void sf::Shape::SetPointPosition ( unsigned int  index,
const Vector2f position 
)

Set the position of a point.

Parameters:
index : Index of the point, in range [0, GetPointsCount() - 1]
position : New position of the index-th point

Definition at line 100 of file Shape.cpp.

void sf::Drawable::SetPosition ( const Vector2f position  )  [inherited]

Set the position of the object (take a 2D vector).

Parameters:
position : New position

Definition at line 74 of file Drawable.cpp.

void sf::Drawable::SetPosition ( float  x,
float  y 
) [inherited]

Set the position of the object (take 2 values).

Parameters:
x : New X coordinate
y : New Y coordinate

Definition at line 64 of file Drawable.cpp.

void sf::Drawable::SetRotation ( float  angle  )  [inherited]

Set the orientation of the object.

Parameters:
angle : Angle of rotation, in degrees

Definition at line 184 of file Drawable.cpp.

void sf::Drawable::SetScale ( const Vector2f scale  )  [inherited]

Set the scale of the object (take a 2D vector).

Parameters:
Scale : New scale (both values must be strictly positive)

Definition at line 118 of file Drawable.cpp.

void sf::Drawable::SetScale ( float  factorX,
float  factorY 
) [inherited]

Set the scale of the object (take 2 values).

Parameters:
factorX : New horizontal scale (must be strictly positive)
factorY : New vertical scale (must be strictly positive)

Definition at line 108 of file Drawable.cpp.

void sf::Drawable::SetScaleX ( float  factor  )  [inherited]

Set the X scale factor of the object.

Parameters:
factor : New X scale factor

Definition at line 128 of file Drawable.cpp.

void sf::Drawable::SetScaleY ( float  factor  )  [inherited]

Set the Y scale factor of the object.

Parameters:
factor : New Y scale factor

Definition at line 143 of file Drawable.cpp.

void sf::Drawable::SetX ( float  x  )  [inherited]

Set the X position of the object.

Parameters:
x : New X coordinate

Definition at line 84 of file Drawable.cpp.

void sf::Drawable::SetY ( float  y  )  [inherited]

Set the Y position of the object.

Parameters:
y : New Y coordinate

Definition at line 96 of file Drawable.cpp.

Vector2f sf::Drawable::TransformToGlobal ( const Vector2f point  )  const [inherited]

Transform a point from local coordinates into global coordinates (ie it applies the object's origin, translation, rotation and scale to the point).

Parameters:
point : Point to transform
Returns:
Transformed point

Definition at line 328 of file Drawable.cpp.

Vector2f sf::Drawable::TransformToLocal ( const Vector2f point  )  const [inherited]

Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's origin, translation, rotation and scale to the point).

Parameters:
point : Point to transform
Returns:
Transformed point

Definition at line 319 of file Drawable.cpp.


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