Gamedev Framework (gf)  0.11.0 A C++14 framework for 2D games
gf::Curve Class Referenceabstract

A curve is a one dimension object. More...

#include <gf/Curve.h>

Inheritance diagram for gf::Curve:
[legend]

## Public Types

enum  Type {
Simple,
Outlined
}
The type of the curve. More...

## Public Member Functions

Curve ()
Default constructor. More...

void setType (Type type)
Set the type of the curve. More...

Type getType () const noexcept
Return the type of the curve. More...

void setColor (const Color4f &color)
Set the fill color of the curve. More...

const Color4fgetColor () const
Get the fill color of the curve. More...

void setWidth (float width)
Set the width of the curve. More...

float getWidth () const
Get the width of the curve. More...

void setOutlineColor (const Color4f &color)
Set the outline color of the curve. More...

const Color4fgetOutlineColor () const
Get the outline color of the curve. More...

void setOutlineThickness (float thickness)
Set the thickness of the curve's outline. More...

float getOutlineThickness () const
Get the outline thickness of the curve. More...

virtual std::size_t getPointCount () const =0
Get the total number of points of the curve. More...

virtual Vector2f getPoint (std::size_t index) const =0
Get a point of the curve. More...

RectF getLocalBounds () const
Get the local bounding rectangle of the entity. More...

void setAnchor (Anchor anchor)
Set the anchor origin of the entity. More...

VertexBuffer commitGeometry () const
Create a buffer with the current geometry. More...

VertexBuffer commitOutlineGeometry () const
Create a buffer with the current outline geometry. More...

virtual void draw (RenderTarget &target, const RenderStates &states) override
Draw the object to a render target. More...

Public Member Functions inherited from gf::Transformable
Transformable ()
Default constructor. More...

void setOrigin (Vector2f origin)
Set the local origin of the object. More...

Vector2f getOrigin () const
Get the local origin of the object. More...

void setPosition (Vector2f position)
Set the position of the object. More...

Vector2f getPosition () const
Get the position of the object. More...

void move (Vector2f offset)
Move the object by a given offset. More...

void setRotation (float angle)
Set the orientation of the object. More...

float getRotation () const
Get the orientation of the object. More...

void rotate (float angle)
Rotate the object. More...

void setScale (Vector2f factors)
Set the scale factors of the object. More...

void setScale (float factor)
Set the scale factor of the object. More...

Vector2f getScale () const
Get the current scale of the object. More...

void scale (Vector2f factors)
Scale the object. More...

void scale (float factor)
Scale the object. More...

Matrix3f getTransform () const
Get the combined transform of the object. More...

Matrix3f getInverseTransform () const
Get the inverse of the combined transform of the object. More...

Public Member Functions inherited from gf::Drawable
virtual ~Drawable ()
Virtual desctructor. More...

## Protected Member Functions

void updateGeometry ()
Recompute the internal geometry of the curve. More...

void setClosed (bool closed=true)
Set the curve closed. More...

Protected Member Functions inherited from gf::Transformable
void setOriginFromAnchorAndBounds (Anchor anchor, const RectF &bounds)
Set the origin from an anchor and bounds. More...

## Detailed Description

A curve is a one dimension object.

A curve is similar to a shape but for one dimension objects like lines, Bézier curves, or compound curves.

A curve can be simple or outlined. A simple curve has no outline and is generally thin. An outline curve is more complex and can have an outline and has no limit on the width. By default, curves are outlined.

See also
gf::Line, gf::QuadraticBezierCurve, gf::CubicBezierCurve, gf::CompoundCurve

## ◆ Type

 enum gf::Curve::Type

The type of the curve.

Enumerator
Simple

A simple curve with no outline.

Outlined

An outlined curve.

## ◆ Curve()

 gf::Curve::Curve ( )

Default constructor.

## ◆ commitGeometry()

 VertexBuffer gf::Curve::commitGeometry ( ) const

Create a buffer with the current geometry.

The geometry is uploaded in the graphics memory so that it's faster to draw.

Returns
A buffer with the current geometry

## ◆ commitOutlineGeometry()

 VertexBuffer gf::Curve::commitOutlineGeometry ( ) const

Create a buffer with the current outline geometry.

The geometry is uploaded in the graphics memory so that it's faster to draw.

Returns
A buffer with the current outline geometry

## ◆ draw()

 virtual void gf::Curve::draw ( RenderTarget & target, const RenderStates & states )
overridevirtual

Draw the object to a render target.

This is a pure virtual function that has to be implemented by the derived class to define how the drawable should be drawn.

Parameters
 target Render target to draw to states Current render states

Implements gf::Drawable.

## ◆ getColor()

 const Color4f& gf::Curve::getColor ( ) const
inline

Get the fill color of the curve.

Returns
Fill color of the curve
See also
setColor()

## ◆ getLocalBounds()

 RectF gf::Curve::getLocalBounds ( ) const

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

## ◆ getOutlineColor()

 const Color4f& gf::Curve::getOutlineColor ( ) const
inline

Get the outline color of the curve.

Returns
Outline color of the curve
See also
setOutlineColor()

## ◆ getOutlineThickness()

 float gf::Curve::getOutlineThickness ( ) const
inline

Get the outline thickness of the curve.

Returns
Outline thickness of the curve
See also
setOutlineThickness()

## ◆ getPoint()

 virtual Vector2f gf::Curve::getPoint ( std::size_t index ) const
pure virtual

Get a point of the curve.

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

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

Parameters
 index Index of the point to get, in range $$[0, n-1]$$ where $$n$$ is the number of points of the curve.
Returns
index-th point of the curve
See also
getPointCount()

Implemented in gf::CompoundCurve, gf::CubicBezierCurve, gf::QuadraticBezierCurve, and gf::Line.

## ◆ getPointCount()

 virtual std::size_t gf::Curve::getPointCount ( ) const
pure virtual

Get the total number of points of the curve.

Returns
Number of points of the curve
See also
getPoint()

Implemented in gf::CompoundCurve, gf::CubicBezierCurve, gf::QuadraticBezierCurve, and gf::Line.

## ◆ getType()

 Type gf::Curve::getType ( ) const
inlinenoexcept

Return the type of the curve.

Returns
The current type of the curve

## ◆ getWidth()

 float gf::Curve::getWidth ( ) const
inline

Get the width of the curve.

Returns
The current width of the curve

## ◆ setAnchor()

 void gf::Curve::setAnchor ( Anchor anchor )

Set the anchor origin of the entity.

Compute the origin of the entity based on the local bounds and the specified anchor. Internally, this function calls Transformable::setOrigin().

Parameters
 anchor The anchor of the entity
See also
getLocalBounds(), Transformable::setOrigin()

## ◆ setClosed()

 void gf::Curve::setClosed ( bool closed = true )
protected

Set the curve closed.

This function must be called by derived class when the curve must be closed, i.e. the last point is connected to the first point with a line.

Parameters
 closed True if the curve is closed

## ◆ setColor()

 void gf::Curve::setColor ( const Color4f & color )

Set the fill color of the curve.

This color is modulated (multiplied) with the curve's texture if any. It can be used to colorize the curve, or change its global opacity.

By default, the curve's fill color is opaque white.

Parameters
 color New color of the curve
See also
getColor(), setOutlineColor()

## ◆ setOutlineColor()

 void gf::Curve::setOutlineColor ( const Color4f & color )

Set the outline color of the curve.

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

Parameters
 color New outline color of the curve
See also
getOutlineColor(), setColor()

## ◆ setOutlineThickness()

 void gf::Curve::setOutlineThickness ( float thickness )

Set the thickness of the curve's outline.

By default, the outline thickness is $$0$$.

Parameters
 thickness New outline thickness
See also
getOutlineThickness()

## ◆ setType()

 void gf::Curve::setType ( Type type )

Set the type of the curve.

By default, a curve is outlined.

Parameters
 type The type of the curve

## ◆ setWidth()

 void gf::Curve::setWidth ( float width )

Set the width of the curve.

Parameters
 width The width of the curve

## ◆ updateGeometry()

 void gf::Curve::updateGeometry ( )
protected

Recompute the internal geometry of the curve.

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