Shape.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2014 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 CPP3DS_SHAPE_HPP
26 #define CPP3DS_SHAPE_HPP
27 
29 // Headers
31 #include <cpp3ds/Graphics/Drawable.hpp>
32 #include <cpp3ds/Graphics/Transformable.hpp>
33 #include <cpp3ds/Graphics/VertexArray.hpp>
34 #include <cpp3ds/System/Vector2.hpp>
35 
36 
37 namespace cpp3ds
38 {
43 class Shape : public Drawable, public Transformable
44 {
45 public :
46 
51  virtual ~Shape();
52 
73  void setTexture(const Texture* texture, bool resetRect = false);
74 
87  void setTextureRect(const IntRect& rect);
88 
104  void setFillColor(const Color& color);
105 
116  void setOutlineColor(const Color& color);
117 
131  void setOutlineThickness(float thickness);
132 
145  const Texture* getTexture() const;
146 
155  const IntRect& getTextureRect() const;
156 
165  const Color& getFillColor() const;
166 
175  const Color& getOutlineColor() const;
176 
185  float getOutlineThickness() const;
186 
195  virtual unsigned int getPointCount() const = 0;
196 
212  virtual Vector2f getPoint(unsigned int index) const = 0;
213 
226  FloatRect getLocalBounds() const;
227 
240  FloatRect getGlobalBounds() const;
241 
242 protected :
243 
248  Shape();
249 
258  void update();
259 
260 private :
261 
269  virtual void draw(RenderTarget& target, RenderStates states) const;
270 
275  void updateFillColors();
276 
281  void updateTexCoords();
282 
287  void updateOutline();
288 
293  void updateOutlineColors();
294 
295 private :
296 
298  // Member data
300  const Texture* m_texture;
301  IntRect m_textureRect;
302  Color m_fillColor;
303  Color m_outlineColor;
304  float m_outlineThickness;
305  VertexArray m_vertices;
306  VertexArray m_outlineVertices;
307  FloatRect m_insideBounds;
308  FloatRect m_bounds;
309 };
310 
311 }
312 
313 
314 #endif
315 
316 
const Color & getOutlineColor() const
Get the outline color of the shape.
Decomposed transform defined by a position, a rotation and a scale.
FloatRect getLocalBounds() const
Get the local bounding rectangle of the entity.
const Color & getFillColor() const
Get the fill color of the shape.
void update()
Recompute the internal geometry of the shape.
Utility class for manpulating RGBA colors.
Definition: Color.hpp:36
Define a set of one or more 2D primitives.
Definition: VertexArray.hpp:47
virtual unsigned int getPointCount() const =0
Get the total number of points of the shape.
void setTexture(const Texture *texture, bool resetRect=false)
Change the source texture of the shape.
virtual ~Shape()
Virtual destructor.
void setOutlineColor(const Color &color)
Set the outline color of the shape.
const IntRect & getTextureRect() const
Get the sub-rectangle of the texture displayed by the shape.
void setOutlineThickness(float thickness)
Set the thickness of the shape's outline.
Abstract base class for objects that can be drawn to a render target.
Definition: Drawable.hpp:43
float getOutlineThickness() const
Get the outline thickness of the shape.
Shape()
Default constructor.
Base class for textured shapes with outline.
Definition: Shape.hpp:43
Base class for all render targets (window, texture, ...)
Define the states used for drawing to a RenderTarget.
void setTextureRect(const IntRect &rect)
Set the sub-rectangle of the texture that the shape will display.
virtual Vector2f getPoint(unsigned int index) const =0
Get a point of the shape.
void setFillColor(const Color &color)
Set the fill color of the shape.
some things could easily be broken///////
Definition: Texture.hpp:47
const Texture * getTexture() const
Get the source texture of the shape.
FloatRect getGlobalBounds() const
Get the global bounding rectangle of the entity.