Documentation de SFML 1.6

Attention: cette page se réfère à une ancienne version de SFML. Cliquez ici pour passer à la dernière version.
Shape.hpp
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
31 #include <SFML/Graphics/Drawable.hpp>
32 #include <SFML/System/Vector2.hpp>
33 #include <vector>
34 
35 
36 namespace sf
37 {
43 class SFML_API Shape : public sf::Drawable
44 {
45 public :
46 
51  Shape();
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 
256 protected :
257 
262  virtual void Render(RenderTarget& Target) const;
263 
264 private :
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