GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Sprite.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2016 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 
7 #ifndef SPRITE_H
8 #define SPRITE_H
9 #include <memory>
10 
11 #include "GDCore/Extensions/Builtin/SpriteExtension/Point.h"
12 #include "GDCore/Extensions/Builtin/SpriteExtension/Polygon2d.h"
13 #include "GDCore/String.h"
14 #undef LoadImage // prevent windows.h to be polluting everything
15 
16 namespace gd {
17 
25 class GD_CORE_API Sprite {
26  public:
27  Sprite();
28  virtual ~Sprite();
29 
33  inline void SetImageName(const gd::String& image_) { image = image_; }
34 
38  inline const gd::String& GetImageName() const { return image; }
39 
43  inline gd::String& GetImageName() { return image; }
44 
52  std::vector<Polygon2d> GetCollisionMask() const;
53 
57  std::vector<Polygon2d>& GetCustomCollisionMask() {
58  return customCollisionMask;
59  };
60 
64  const std::vector<Polygon2d>& GetCustomCollisionMask() const {
65  return customCollisionMask;
66  };
67 
72  void SetCustomCollisionMask(const std::vector<Polygon2d>& collisionMask);
73 
78  inline bool IsFullImageCollisionMask() const {
79  return fullImageCollisionMask;
80  }
81 
85  inline void SetFullImageCollisionMask(bool enabled) {
86  fullImageCollisionMask = enabled;
87  };
88 
92  inline std::vector<Point>& GetAllNonDefaultPoints() { return points; }
93 
97  inline const std::vector<Point>& GetAllNonDefaultPoints() const {
98  return points;
99  }
100 
104  void AddPoint(const Point& point);
105 
109  void DelPoint(const gd::String& name);
110 
114  const Point& GetPoint(const gd::String& name) const;
115 
119  Point& GetPoint(const gd::String& name);
120 
124  bool HasPoint(const gd::String& name) const;
125 
129  inline const Point& GetOrigin() const { return origine; }
130 
134  inline Point& GetOrigin() { return origine; }
135 
142  inline const Point& GetCenter() const { return centre; }
143 
150  inline Point& GetCenter() { return centre; }
151 
155  inline bool IsDefaultCenterPoint() const { return automaticCentre; }
156 
160  bool SetDefaultCenterPoint(bool enabled);
161 
162  private:
163  gd::String image;
164 
165  bool fullImageCollisionMask;
168  std::vector<Polygon2d> customCollisionMask;
169 
170  std::vector<Point> points;
171  Point origine;
172  Point centre;
173  bool automaticCentre;
174 
175  static Point
176  badPoint;
177 };
178 
179 } // namespace gd
180 #endif // SPRITE_H
Named point used by Sprite.
Definition: Point.h:16
Represents a sprite to be displayed on the screen.
Definition: Sprite.h:25
std::vector< Polygon2d > & GetCustomCollisionMask()
Get the custom collision mask.
Definition: Sprite.h:57
void SetImageName(const gd::String &image_)
Change the name of the sprite image.
Definition: Sprite.h:33
Point & GetOrigin()
Return Origin point.
Definition: Sprite.h:134
bool IsDefaultCenterPoint() const
Return true if the center point is automatically computed.
Definition: Sprite.h:155
const gd::String & GetImageName() const
Get the name of the sprite image.
Definition: Sprite.h:38
bool IsFullImageCollisionMask() const
Return true if the collision mask is a bounding box, false if a custom collision mask is used.
Definition: Sprite.h:78
Point & GetCenter()
Return Center point.
Definition: Sprite.h:150
gd::String & GetImageName()
Get the name of the sprite image.
Definition: Sprite.h:43
const std::vector< Polygon2d > & GetCustomCollisionMask() const
Get the custom collision mask.
Definition: Sprite.h:64
const Point & GetOrigin() const
Return Origin point.
Definition: Sprite.h:129
void SetFullImageCollisionMask(bool enabled)
Un/set use of the custom collision mask.
Definition: Sprite.h:85
const std::vector< Point > & GetAllNonDefaultPoints() const
Return all points, excluding origin and center.
Definition: Sprite.h:97
const Point & GetCenter() const
Return Center point.
Definition: Sprite.h:142
std::vector< Point > & GetAllNonDefaultPoints()
Return all points, excluding origin and center.
Definition: Sprite.h:92
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24