SFML - Simple and Fast Multimedia Library

SFML 3.0.1

- Main Page
- Topics
- Namespaces
- Classes
- Files

- File List
- File Members

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-2025 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
45namespace sf
46{
47class Texture;
48class RenderTarget;
49
54 class SFML_GRAPHICS_API Shape : public Drawable, public Transformable
55{
56public:
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
149 [[nodiscard]] const Texture* getTexture() const;
150
159 [[nodiscard]] const IntRect& getTextureRect() const;
160
169 [[nodiscard]] Color getFillColor() const;
170
179 [[nodiscard]] Color getOutlineColor() const;
180
189 [[nodiscard]] float getOutlineThickness() const;
190
199 [[nodiscard]] virtual std::size_t getPointCount() const = 0;
200
216 [[nodiscard]] virtual Vector2f getPoint(std::size_t index) const = 0;
217
228 [[nodiscard]] virtual Vector2f getGeometricCenter() const;
229
242 [[nodiscard]] FloatRect getLocalBounds() const;
243
263 [[nodiscard]] FloatRect getGlobalBounds() const;
264
265protected:
274 void update();
275
276private:
284 void draw(RenderTarget& target, RenderStates states) const override;
285
290 void updateFillColors();
291
296 void updateTexCoords();
297
302 void updateOutline();
303
308 void updateOutlineColors();
309
311 // Member data
313 const Texture* m_texture{};
314 IntRect m_textureRect;
315 Color m_fillColor{Color::White};
316 Color m_outlineColor{Color::White};
317 float m_outlineThickness{};
318 VertexArray m_vertices{PrimitiveType::TriangleFan};
319 VertexArray m_outlineVertices{PrimitiveType::TriangleStrip};
320 FloatRect m_insideBounds;
321 FloatRect m_bounds;
322};
323
324} // namespace sf
325
326
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::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::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:210
sf::RenderStates
Define the states used for drawing to a RenderTarget
Definition RenderStates.hpp:48