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-2009 Laurent Gomila (laurent.gom@gmail.com)
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
33#include <vector>
34
35
36namespace sf
37{
44{
45public :
46
52
61 void AddPoint(float X, float Y, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0));
62
71 void AddPoint(const Vector2f& Position, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0));
72
79 unsigned int GetNbPoints() const;
80
88 void EnableFill(bool Enable);
89
97 void EnableOutline(bool Enable);
98
106 void SetPointPosition(unsigned int Index, const Vector2f& Position);
107
116 void SetPointPosition(unsigned int Index, float X, float Y);
117
125 void SetPointColor(unsigned int Index, const Color& Col);
126
134 void SetPointOutlineColor(unsigned int Index, const Color& OutlineCol);
135
142 void SetOutlineWidth(float Width);
143
152 const Vector2f& GetPointPosition(unsigned int Index) const;
153
162 const Color& GetPointColor(unsigned int Index) const;
163
172 const Color& GetPointOutlineColor(unsigned int Index) const;
173
180 float GetOutlineWidth() const;
181
193 static Shape Line(float P1X, float P1Y, float P2X, float P2Y, float Thickness, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
194
206 static Shape Line(const Vector2f& P1, const Vector2f& P2, float Thickness, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
207
218 static Shape Rectangle(float P1X, float P1Y, float P2X, float P2Y, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
219
230 static Shape Rectangle(const Vector2f& P1, const Vector2f& P2, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
231
242 static Shape Circle(float X, float Y, float Radius, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
243
254 static Shape Circle(const Vector2f& Center, float Radius, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
255
256protected :
257
262 virtual void Render(RenderTarget& Target) const;
263
264private :
265
270 void Compile();
271
282 static bool ComputeNormal(const Vector2f& P1, const Vector2f& P2, Vector2f& Normal);
283
287 struct Point
288 {
289 Point(const Vector2f& Pos = Vector2f(0, 0), const Color& C = Color(255, 255, 255), const Color& OutlineC = Color(255, 255, 255));
290
291 Vector2f Position;
292 Vector2f Normal;
293 Color Col;
294 Color OutlineCol;
295 };
296
298 // Member data
300 std::vector<Point> myPoints;
301 float myOutline;
302 bool myIsFillEnabled;
303 bool myIsOutlineEnabled;
304 bool myIsCompiled;
305};
306
307} // namespace sf
308
309
310#endif // SFML_SHAPE_HPP
#define SFML_API
Definition Config.hpp:114
Color is an utility class for manipulating 32-bits RGBA colors.
Definition Color.hpp:41
Abstract base class for every object that can be drawn into a render window.
Definition Drawable.hpp:59
friend class RenderTarget
Definition Drawable.hpp:325
void AddPoint(const Vector2f &Position, const Color &Col=Color(255, 255, 255), const Color &OutlineCol=Color(0, 0, 0))
Add a point to the shape.
static Shape Circle(const Vector2f &Center, float Radius, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0))
Create a shape made of a single circle (use vectors).
unsigned int GetNbPoints() const
Get the number of points composing the shape.
Shape()
Default constructor.
const Vector2f & GetPointPosition(unsigned int Index) const
Get the position of a point.
static Shape Line(const Vector2f &P1, const Vector2f &P2, float Thickness, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0))
Create a shape made of a single line (use vectors).
void EnableFill(bool Enable)
Enable or disable filling the shape.
float GetOutlineWidth() const
Get the width of the shape outline.
void SetOutlineWidth(float Width)
Change the width of the shape outline.
virtual void Render(RenderTarget &Target) const
/see Drawable::Render
static Shape Rectangle(float P1X, float P1Y, float P2X, float P2Y, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0))
Create a shape made of a single rectangle (use floats).
void AddPoint(float X, float Y, const Color &Col=Color(255, 255, 255), const Color &OutlineCol=Color(0, 0, 0))
Add a point to the shape.
static Shape Circle(float X, float Y, float Radius, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0))
Create a shape made of a single circle (use floats).
static Shape Line(float P1X, float P1Y, float P2X, float P2Y, float Thickness, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0))
Create a shape made of a single line (use floats).
void SetPointOutlineColor(unsigned int Index, const Color &OutlineCol)
Set the outline color of a point.
void SetPointColor(unsigned int Index, const Color &Col)
Set the color of a point.
static Shape Rectangle(const Vector2f &P1, const Vector2f &P2, const Color &Col, float Outline=0.f, const Color &OutlineCol=sf::Color(0, 0, 0))
Create a shape made of a single rectangle (use vectors).
const Color & GetPointColor(unsigned int Index) const
Get the color of a point.
void SetPointPosition(unsigned int Index, float X, float Y)
Set the position of a point.
void SetPointPosition(unsigned int Index, const Vector2f &Position)
Set the position of a point.
void EnableOutline(bool Enable)
Enable or disable drawing the shape outline.
const Color & GetPointOutlineColor(unsigned int Index) const
Get the outline color of a point.
Vector2< float > Vector2f
Definition Vector2.hpp:210