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-2024 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
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
#define SFML_GRAPHICS_API
Utility class for manipulating RGBA colors.
Definition Color.hpp:40
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:44
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.
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 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
Decomposed transform defined by a position, a rotation and a scale.
Rect< float > FloatRect
Definition Rect.hpp:147
Define the states used for drawing to a RenderTarget