SFML 3.1.0
Loading...
Searching...
No Matches
Shape.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
30#include <SFML/Graphics/Export.hpp>
31
32#include <SFML/Graphics/Color.hpp>
33#include <SFML/Graphics/Drawable.hpp>
34#include <SFML/Graphics/PrimitiveType.hpp>
35#include <SFML/Graphics/Rect.hpp>
36#include <SFML/Graphics/RenderStates.hpp>
37#include <SFML/Graphics/Transformable.hpp>
38#include <SFML/Graphics/VertexArray.hpp>
39
40#include <SFML/System/Vector2.hpp>
41
42#include <cstddef>
43
44
45 namespace sf
46{
47 class Texture;
48 class RenderTarget;
49
54 class SFML_GRAPHICS_API Shape : public Drawable, public Transformable
55{
56 public:
77 void setTexture(const Texture* texture, bool resetRect = false);
78
91 void setTextureRect(const IntRect& rect);
92
108 void setFillColor(Color color);
109
120 void setOutlineColor(Color color);
121
135 void setOutlineThickness(float thickness);
136
166 void setMiterLimit(float miterLimit);
167
180 [[nodiscard]] const Texture* getTexture() const;
181
190 [[nodiscard]] const IntRect& getTextureRect() const;
191
200 [[nodiscard]] Color getFillColor() const;
201
210 [[nodiscard]] Color getOutlineColor() const;
211
220 [[nodiscard]] float getOutlineThickness() const;
221
230 [[nodiscard]] float getMiterLimit() const;
231
240 [[nodiscard]] virtual std::size_t getPointCount() const = 0;
241
257 [[nodiscard]] virtual Vector2f getPoint(std::size_t index) const = 0;
258
269 [[nodiscard]] virtual Vector2f getGeometricCenter() const;
270
283 [[nodiscard]] FloatRect getLocalBounds() const;
284
304 [[nodiscard]] FloatRect getGlobalBounds() const;
305
306 protected:
315 void update();
316
317 private:
325 void draw(RenderTarget& target, RenderStates states) const override;
326
331 void updateFillColors();
332
337 void updateTexCoords();
338
343 void updateOutline();
344
349 void updateOutlineColors();
350
352 // Member data
354 const Texture* m_texture{};
355 IntRect m_textureRect;
356 Color m_fillColor{Color::White};
357 Color m_outlineColor{Color::White};
358 float m_outlineThickness{};
359 float m_miterLimit{10.f};
360 VertexArray m_vertices{PrimitiveType::TriangleFan};
361 VertexArray m_outlineVertices{PrimitiveType::TriangleStrip};
362 FloatRect m_insideBounds;
363 FloatRect m_bounds;
364};
365
366} // namespace sf
367
368
Color.hpp
Drawable.hpp
Export.hpp
SFML_GRAPHICS_API
#define SFML_GRAPHICS_API
Definition Graphics/Export.hpp:42
PrimitiveType.hpp
Rect.hpp
RenderStates.hpp
Transformable.hpp
Vector2.hpp
VertexArray.hpp
sf::Color
Utility class for manipulating RGBA colors.
Definition Color.hpp:40
sf::Color::White
static const Color White
White predefined color.
Definition Color.hpp:83
sf::Drawable
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:44
sf::Drawable::RenderTarget
friend class RenderTarget
Definition Drawable.hpp:53
sf::RenderTarget
Base class for all render targets (window, texture, ...).
Definition RenderTarget.hpp:63
sf::Shape
Base class for textured shapes with outline.
Definition Shape.hpp:55
sf::Shape::getOutlineThickness
float getOutlineThickness() const
Get the outline thickness of the shape.
sf::Shape::setTextureRect
void setTextureRect(const IntRect &rect)
Set the sub-rectangle of the texture that the shape will display.
sf::Shape::getPoint
virtual Vector2f getPoint(std::size_t index) const =0
Get a point of the shape.
sf::Shape::setFillColor
void setFillColor(Color color)
Set the fill color of the shape.
sf::Shape::getMiterLimit
float getMiterLimit() const
Get the limit on the ratio between miter length and outline thickness.
sf::Shape::getGeometricCenter
virtual Vector2f getGeometricCenter() const
Get the geometric center of the shape.
sf::Shape::setOutlineThickness
void setOutlineThickness(float thickness)
Set the thickness of the shape's outline.
sf::Shape::getFillColor
Color getFillColor() const
Get the fill color of the shape.
sf::Shape::setMiterLimit
void setMiterLimit(float miterLimit)
Set the limit on the ratio between miter length and outline thickness.
sf::Shape::setOutlineColor
void setOutlineColor(Color color)
Set the outline color of the shape.
sf::Shape::getOutlineColor
Color getOutlineColor() const
Get the outline color of the shape.
sf::Shape::getGlobalBounds
FloatRect getGlobalBounds() const
Get the global (non-minimal) bounding rectangle of the entity.
sf::Shape::getTextureRect
const IntRect & getTextureRect() const
Get the sub-rectangle of the texture displayed by the shape.
sf::Shape::update
void update()
Recompute the internal geometry of the shape.
sf::Shape::getLocalBounds
FloatRect getLocalBounds() const
Get the local bounding rectangle of the entity.
sf::Shape::getTexture
const Texture * getTexture() const
Get the source texture of the shape.
sf::Shape::setTexture
void setTexture(const Texture *texture, bool resetRect=false)
Change the source texture of the shape.
sf::Shape::getPointCount
virtual std::size_t getPointCount() const =0
Get the total number of points of the shape.
sf::Texture
Image living on the graphics card that can be used for drawing.
Definition Texture.hpp:56
sf::Transformable::Transformable
Transformable()=default
Default constructor.
sf
Definition AudioResource.hpp:36
sf::FloatRect
Rect< float > FloatRect
Definition Rect.hpp:147
sf::IntRect
Rect< int > IntRect
Definition Rect.hpp:146
sf::Vector2f
Vector2< float > Vector2f
Definition Vector2.hpp:213
sf::RenderStates
Define the states used for drawing to a RenderTarget.
Definition RenderStates.hpp:48