Documentation of SFML 2.6.1

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
Loading...
Searching...
No Matches
Shape.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2023 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#ifndef SFML_SHAPE_HPP
26#define SFML_SHAPE_HPP
27
29// Headers
31#include <SFML/Graphics/Export.hpp>
32#include <SFML/Graphics/Drawable.hpp>
33#include <SFML/Graphics/Transformable.hpp>
34#include <SFML/Graphics/VertexArray.hpp>
35#include <SFML/System/Vector2.hpp>
36
37
38namespace sf
39{
44class SFML_GRAPHICS_API Shape : public Drawable, public Transformable
45{
46public:
47
52 virtual ~Shape();
53
74 void setTexture(const Texture* texture, bool resetRect = false);
75
88 void setTextureRect(const IntRect& rect);
89
105 void setFillColor(const Color& color);
106
117 void setOutlineColor(const Color& color);
118
132 void setOutlineThickness(float thickness);
133
146 const Texture* getTexture() const;
147
156 const IntRect& getTextureRect() const;
157
166 const Color& getFillColor() const;
167
176 const Color& getOutlineColor() const;
177
186 float getOutlineThickness() const;
187
196 virtual std::size_t getPointCount() const = 0;
197
213 virtual Vector2f getPoint(std::size_t index) const = 0;
214
228
249
250protected:
251
257
266 void update();
267
268private:
269
277 virtual void draw(RenderTarget& target, RenderStates states) const;
278
283 void updateFillColors();
284
289 void updateTexCoords();
290
295 void updateOutline();
296
301 void updateOutlineColors();
302
303private:
304
306 // Member data
308 const Texture* m_texture;
309 IntRect m_textureRect;
310 Color m_fillColor;
311 Color m_outlineColor;
312 float m_outlineThickness;
313 VertexArray m_vertices;
314 VertexArray m_outlineVertices;
315 FloatRect m_insideBounds;
316 FloatRect m_bounds;
317};
318
319} // namespace sf
320
321
322#endif // SFML_SHAPE_HPP
323
324
Utility class for manipulating RGBA colors.
Definition Color.hpp:41
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:45
Define the states used for drawing to a RenderTarget.
Base class for all render targets (window, texture, ...)
Base class for textured shapes with outline.
Definition Shape.hpp:45
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 ~Shape()
Virtual destructor.
void setFillColor(const Color &color)
Set the fill color of the shape.
virtual Vector2f getPoint(std::size_t index) const =0
Get a point of the shape.
Shape()
Default constructor.
const Color & getOutlineColor() const
Get the outline color of the shape.
void setOutlineColor(const Color &color)
Set the outline color of the shape.
void setOutlineThickness(float thickness)
Set the thickness of the shape's outline.
const Color & getFillColor() const
Get the fill 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:49
Decomposed transform defined by a position, a rotation and a scale.
Define a set of one or more 2D primitives.