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
31
39
41
42#include <cstddef>
43
44
45namespace sf
46{
47class Texture;
48class RenderTarget;
49
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
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
306protected:
315 void update();
316
317private:
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
#define SFML_GRAPHICS_API
Utility class for manipulating RGBA colors.
Definition Color.hpp:40
static const Color White
White predefined color.
Definition Color.hpp:83
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:44
friend class RenderTarget
Definition Drawable.hpp:53
Base class for all render targets (window, texture, ...).
Base class for textured shapes with outline.
Definition Shape.hpp:55
float getOutlineThickness() const
Get the outline thickness of the shape.
void setTextureRect(const IntRect &rect)
Set the sub-rectangle of the texture that the shape will display.
virtual Vector2f getPoint(std::size_t index) const =0
Get a point of the shape.
void setFillColor(Color color)
Set the fill color of the shape.
float getMiterLimit() const
Get the limit on the ratio between miter length and outline thickness.
virtual Vector2f getGeometricCenter() const
Get the geometric center of the shape.
void setOutlineThickness(float thickness)
Set the thickness of the shape's outline.
Color getFillColor() const
Get the fill color of the shape.
void setMiterLimit(float miterLimit)
Set the limit on the ratio between miter length and outline thickness.
void setOutlineColor(Color color)
Set the outline color of the shape.
Color getOutlineColor() const
Get the outline color of the shape.
FloatRect getGlobalBounds() const
Get the global (non-minimal) bounding rectangle of the entity.
const IntRect & getTextureRect() const
Get the sub-rectangle of the texture displayed by the shape.
void update()
Recompute the internal geometry of the shape.
FloatRect getLocalBounds() const
Get the local bounding rectangle of the entity.
const Texture * getTexture() const
Get the source texture of the shape.
void setTexture(const Texture *texture, bool resetRect=false)
Change the source texture of the shape.
virtual std::size_t getPointCount() const =0
Get the total number of points of the shape.
Image living on the graphics card that can be used for drawing.
Definition Texture.hpp:56
Transformable()=default
Default constructor.
Rect< float > FloatRect
Definition Rect.hpp:147
Rect< int > IntRect
Definition Rect.hpp:146
Vector2< float > Vector2f
Definition Vector2.hpp:213
Define the states used for drawing to a RenderTarget.