Documentation of SFML 2.4.2

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
Shape.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2017 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 
38 namespace sf
39 {
44 class SFML_GRAPHICS_API Shape : public Drawable, public Transformable
45 {
46 public:
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 
227  FloatRect getLocalBounds() const;
228 
248  FloatRect getGlobalBounds() const;
249 
250 protected:
251 
256  Shape();
257 
266  void update();
267 
268 private:
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 
303 private:
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 
Decomposed transform defined by a position, a rotation and a scale.
Base class for textured shapes with outline.
Definition: Shape.hpp:44
Utility class for manipulating RGBA colors.
Definition: Color.hpp:40
Define the states used for drawing to a RenderTarget.
Abstract base class for objects that can be drawn to a render target.
Definition: Drawable.hpp:44
Define a set of one or more 2D primitives.
Definition: VertexArray.hpp:45
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:47
Base class for all render targets (window, texture, ...)