Here is where I based my custom class off of:
https://github.com/SFML/SFML/wiki/Source:-Draw-Rounded-RectangleHere is my class:
namespace Graphics
{
class RoundedRectangle : public sf::Shape
{
private:
sf::Vector2f size;
float cornerradius;
unsigned int cornerpoints;
public:
RoundedRectangle(int, int, sf::Vector2f, int, unsigned int, float, sf::Color);
void setSize(const sf::Vector2f& Size);
const sf::Vector2f& getSize();
void setCornerRadius(float CornerRadius);
float getCornerRadius();
void setCornerPoints(unsigned int CornerPoints);
virtual unsigned int getPointCount();
virtual sf::Vector2f getPoint(unsigned int Index);
};
}
Implementation:
#pragma region Graphics
EZFile::Graphics::RoundedRectangle::RoundedRectangle(int Left, int Top, sf::Vector2f Size, int CornerRadius, unsigned int CornerPoints, float OutlineThickness, sf::Color OutlineColor)
{
setPosition(Left, Top);
size = Size;
cornerradius = CornerRadius;
cornerpoints = CornerPoints;
setOutlineThickness(OutlineThickness);
setOutlineColor(OutlineColor);
update();
}
void EZFile::Graphics::RoundedRectangle::setSize(const sf::Vector2f& Size)
{
size = Size;
update();
}
const sf::Vector2f& EZFile::Graphics::RoundedRectangle::getSize()
{
return size;
}
void EZFile::Graphics::RoundedRectangle::setCornerRadius(float CornerRadius)
{
cornerradius = CornerRadius;
update();
}
float EZFile::Graphics::RoundedRectangle::getCornerRadius()
{
return cornerradius;
}
void EZFile::Graphics::RoundedRectangle::setCornerPoints(unsigned int CornerPoints)
{
cornerpoints = CornerPoints;
}
unsigned int EZFile::Graphics::RoundedRectangle::getPointCount()
{
return cornerpoints * 4;
}
sf::Vector2f EZFile::Graphics::RoundedRectangle::getPoint(unsigned int Index)
{
if(Index >= cornerpoints*4)
return sf::Vector2f(0,0);
float deltaAngle = 90.0f/(cornerpoints-1);
sf::Vector2f center;
unsigned int centerIndex = Index/cornerpoints;
unsigned int offset = 0;
static const float pi = 3.141592654f;
switch(centerIndex)
{
case 0: center.x = size.x - cornerradius; center.y = cornerradius; break;
case 1: center.x = cornerradius; center.y = cornerradius; break;
case 2: center.x = cornerradius; center.y = size.y - cornerradius; break;
case 3: center.x = size.x - cornerradius; center.y = size.y - cornerradius; break;
}
return sf::Vector2f(cornerradius*cos(deltaAngle*(Index-centerIndex)*pi/180)+center.x,
cornerradius*sin(deltaAngle*(Index-centerIndex)*pi/180)-center.y);
}
#pragma endregion Graphics
And how I'm trying to use it (based on the first line of the example in the link:
/// Usage example:
/// \code
/// sf::RoundedRectangleShape roundedRectangle;
/// ....
EZFile::Graphics::RoundedRectangle shp;
Here is the other link I looked at:
http://en.sfml-dev.org/forums/index.php?topic=973.0This is just the beginning of a variety of controls I am making. My first control (button) will make a normal rectangle, but if it has a cornerradius of greater than 0, it uses that and makes a rounded rectangle instead. I'm planning on lots of controls (checkboxes, radio buttons, scrollable lists) with each one having options of different styles/etc.