Loading...
Searching...
No Matches
ml::RoundedRectangle Class Referenceabstract

An sf::Shape subclass that draws a rectangle with rounded corners. More...

#include <RoundedRectangle.h>

Inheritance diagram for ml::RoundedRectangle:

Public Member Functions

 RoundedRectangle (const sf::Vector2f &size=sf::Vector2f(0, 0), float radius=0.f, unsigned int cornerPointCount=8)
 Construct a rounded rectangle.
unsigned int getCornerPointCount () const
 Return the current per-corner vertex count.
Color getFillColor () const
virtual Vector2f getGeometricCenter () const
FloatRect getGlobalBounds () const
const Transform & getInverseTransform () const
FloatRect getLocalBounds () const
float getMiterLimit () const
Vector2f getOrigin () const
Color getOutlineColor () const
float getOutlineThickness () const
virtual sf::Vector2f getPoint (std::size_t index) const override
 Return the position of a single vertex.
virtual std::size_t getPointCount () const override
 Return the total number of shape vertices.
Vector2f getPosition () const
float getRadius () const
 Return the current corner arc radius.
Angle getRotation () const
Vector2f getScale () const
const sf::Vector2fgetSize () const
 Return the current size of the rectangle.
const Texture * getTexture () const
const IntRect & getTextureRect () const
const Transform & getTransform () const
void move (Vector2f offset)
void rotate (Angle angle)
void scale (Vector2f factor)
void setCornerPointCount (unsigned int count)
 Set the number of vertices per corner arc.
void setFillColor (Color color)
void setMiterLimit (float miterLimit)
void setOrigin (Vector2f origin)
void setOutlineColor (Color color)
void setOutlineThickness (float thickness)
void setPosition (Vector2f position)
void setRadius (float radius)
 Set the corner arc radius.
void setRotation (Angle angle)
void setScale (Vector2f factors)
void setSize (const sf::Vector2f &size)
 Set the width and height of the rectangle.
void setTexture (const Texture *texture, bool resetRect=false)
void setTextureRect (const IntRect &rect)

Protected Member Functions

virtual void draw (RenderTarget &target, RenderStates states) const=0
void update ()

Detailed Description

An sf::Shape subclass that draws a rectangle with rounded corners.

RoundedRectangle extends sf::Shape by generating vertex geometry for a rectangle whose corners are replaced by circular arcs. The number of vertices per arc is configurable, trading smoothness for polygon count.

It is the underlying shape type used by ml::Rectangle — most user code interacts with RoundedRectangle indirectly through that class. Direct use is appropriate when you need fine control over corner radius or point count without the additional framework layers.

Usage

ml::RoundedRectangle rr({200.f, 80.f}, 12.f, 10);
rr.setPosition({100.f, 100.f});
window.draw(rr);
An sf::Shape subclass that draws a rectangle with rounded corners.
static const Color Blue
void setFillColor(Color color)

Setting radius to 0 produces a standard sharp-cornered rectangle.

See also
Rectangle, Graphic

Definition at line 40 of file RoundedRectangle.h.

Constructor & Destructor Documentation

◆ RoundedRectangle()

ml::RoundedRectangle::RoundedRectangle ( const sf::Vector2f & size = sf::Vector2f(0, 0),
float radius = 0.f,
unsigned int cornerPointCount = 8 )
explicit

Construct a rounded rectangle.

Parameters
sizeWidth and height of the rectangle in pixels. Defaults to {0, 0}.
radiusCorner arc radius in pixels. Defaults to 0 (sharp corners). Clamped to half the shorter side so corners never overlap.
cornerPointCountNumber of vertices used to approximate each corner arc. Higher values produce smoother corners at the cost of more geometry. Defaults to 8.

Member Function Documentation

◆ getCornerPointCount()

unsigned int ml::RoundedRectangle::getCornerPointCount ( ) const

Return the current per-corner vertex count.

Returns
Number of vertices per corner arc.

◆ getPoint()

virtual sf::Vector2f ml::RoundedRectangle::getPoint ( std::size_t index) const
overridevirtual

Return the position of a single vertex.

Required by sf::Shape for geometry generation.

Parameters
indexVertex index in [0, getPointCount()).
Returns
Local-space position of the vertex.

Implements sf::Shape.

◆ getPointCount()

virtual std::size_t ml::RoundedRectangle::getPointCount ( ) const
overridevirtual

Return the total number of shape vertices.

Equal to cornerPointCount × 4 (one arc per corner). Required by sf::Shape.

Returns
Total vertex count.

Implements sf::Shape.

◆ getRadius()

float ml::RoundedRectangle::getRadius ( ) const

Return the current corner arc radius.

Returns
Corner radius in pixels.

◆ getSize()

const sf::Vector2f & ml::RoundedRectangle::getSize ( ) const

Return the current size of the rectangle.

Returns
Width and height in pixels.

◆ setCornerPointCount()

void ml::RoundedRectangle::setCornerPointCount ( unsigned int count)

Set the number of vertices per corner arc.

Triggers geometry regeneration.

Parameters
countVertex count per corner. Must be at least 1.

◆ setRadius()

void ml::RoundedRectangle::setRadius ( float radius)

Set the corner arc radius.

Triggers geometry regeneration. Values larger than half the shorter side are clamped automatically.

Parameters
radiusCorner radius in pixels.

◆ setSize()

void ml::RoundedRectangle::setSize ( const sf::Vector2f & size)

Set the width and height of the rectangle.

Triggers geometry regeneration.

Parameters
sizeNew size in pixels.

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