@@ -32,6 +32,7 @@ it freely, subject to the following restrictions:
32
32
#include < tmx/Helpers.hpp>
33
33
#include < tmx/DebugShape.hpp>
34
34
35
+ // TODO what's with all these includes???
35
36
#include < SFML/Graphics/Color.hpp>
36
37
#include < SFML/Graphics/Drawable.hpp>
37
38
#include < SFML/Graphics/Font.hpp>
@@ -43,6 +44,7 @@ it freely, subject to the following restrictions:
43
44
#include < SFML/Graphics/Sprite.hpp>
44
45
#include < SFML/Graphics/Text.hpp>
45
46
47
+ #include < SFML/Graphics/Transformable.hpp>
46
48
#include < SFML/System/NonCopyable.hpp>
47
49
48
50
#include < string>
@@ -65,8 +67,10 @@ namespace tmx
65
67
Tile
66
68
};
67
69
68
- // map object class.
69
- class TMX_EXPORT_API MapObject final
70
+ /* !
71
+ \brief Map Object class.
72
+ */
73
+ class TMX_EXPORT_API MapObject final : public sf::Transformable
70
74
{
71
75
private:
72
76
struct Segment
@@ -82,81 +86,146 @@ namespace tmx
82
86
public:
83
87
MapObject ();
84
88
85
- // **accessors**//
86
- // returns empty string if property not found
89
+ /* !
90
+ \brief Returns requested property or an empty string if property not found
91
+ */
87
92
std::string getPropertyString (const std::string& name);
88
- // returns top left corner of bounding rectangle
89
- sf::Vector2f getPosition () const {return m_position;}
90
- // returns precomputed centre of mass, or zero for polylines
91
- sf::Vector2f getCentre () const {return m_centrePoint;};
92
- // returns the type of shape of the object
93
- MapObjectShape getShapeType () const {return m_shape;};
94
- // returns and object's name
95
- std::string getName () const {return m_name;};
96
- // returns the object's type
97
- std::string getType () const {return m_type;};
98
- // returns the name of the object's parent layer
99
- std::string getParent () const {return m_parent;};
100
- // returns the objects AABB in world coordinates
101
- sf::FloatRect getAABB () const {return m_AABB;};
102
- // returns visibility
103
- bool visible () const {return m_visible;}
104
- // sets a property value, or adds it if property doesn't exist
93
+ /* !
94
+ \brief Returns precomputed centre of mass, or zero for polylines
95
+ */
96
+ sf::Vector2f getCentre () const { return m_centrePoint; }
97
+ /* !
98
+ \brief Returns the type of shape of the object
99
+ */
100
+ MapObjectShape getShapeType () const { return m_shape; }
101
+ /* !
102
+ \brief Returns the object's name
103
+ */
104
+ std::string getName () const { return m_name; }
105
+ /* !
106
+ \brief Returns the object's type
107
+ */
108
+ std::string getType () const { return m_type; }
109
+ /* !
110
+ \brief Returns the name of the object's parent layer
111
+ */
112
+ std::string getParent () const { return m_parent; }
113
+ /* !
114
+ \brief Returns the object's AABB in world coordinates
115
+ */
116
+ sf::FloatRect getAABB () const { return getTransform ().transformRect (m_AABB); }
117
+ /* !
118
+ \brief Returns visibility
119
+ */
120
+ bool visible () const { return m_visible; }
121
+ /* !
122
+ \brief Sets a property value, or adds it if property doesn't exist
123
+ */
105
124
void setProperty (const std::string& name, const std::string& value);
106
- // sets the object position in world coords
107
- void setPosition (float x, float y);
108
- void setPosition (const sf::Vector2f& position);
109
- // moves the object by given amount
110
- void move (float x, float y);
111
- void move (const sf::Vector2f& distance);
112
- // sets the width and height of the object
113
- void setSize (const sf::Vector2f& size){m_size = size;};
114
- // sets the object's name
115
- void setName (const std::string& name){m_name = name;}
116
- // sets the object's type
117
- void setType (const std::string& type){m_type = type;};
118
- // sets the name of the object's parent layer
119
- void setParent (const std::string& parent){m_parent = parent;};
120
- // sets the shape type
121
- void setShapeType (MapObjectShape shape){m_shape = shape;};
122
- // sets visibility
123
- void setVisible (bool visible){m_visible = visible;};
124
- // adds a point to the list of polygonal points. If calling this manually
125
- // call CreateDebugShape() afterwards to rebuild debug output
126
- void addPoint (const sf::Vector2f& point){m_polypoints.push_back (point);};
127
-
128
- // checks if an object contains given point in world coords.
129
- // Always returns false for polylines.
125
+ /* !
126
+ \brief Sets the width and height of the object
127
+ */
128
+ void setSize (const sf::Vector2f& size){ m_size = size; }
129
+ /* !
130
+ \brief Sets the object's name
131
+ */
132
+ void setName (const std::string& name){ m_name = name; }
133
+ /* !
134
+ \brief Ssets the object's type
135
+ */
136
+ void setType (const std::string& type){ m_type = type; }
137
+ /* !
138
+ \brief Sets the name of the object's parent layer
139
+ */
140
+ void setParent (const std::string& parent){ m_parent = parent; }
141
+ /* !
142
+ \brief Sets the shape type
143
+ */
144
+ void setShapeType (MapObjectShape shape){ m_shape = shape; }
145
+ /* !
146
+ \brief Sets visibility
147
+ */
148
+ void setVisible (bool visible);
149
+ /* !
150
+ \brief Adds a point to the list of polygonal points.
151
+ If calling this manually call createDebugShape() afterwards to
152
+ rebuild debug output and AABB
153
+ */
154
+ void addPoint (const sf::Vector2f& point){ m_polypoints.push_back (point); }
155
+
156
+ /* !
157
+ \brief Checks if an object contains given point in world coords.
158
+ Always returns false for polylines.
159
+ */
130
160
bool contains (sf::Vector2f point) const ;
131
- // checks if two objects intersect, including polylines
161
+ /* !
162
+ \brief Checks if two objects intersect, including polylines
163
+ */
132
164
bool intersects (const MapObject& object) const ;
133
- // creates a shape used for debug drawing - points are in world space
165
+ /* !
166
+ \brief Creates a shape used for debug drawing - points are in world space
167
+ */
134
168
void createDebugShape (const sf::Color& colour);
135
- // draws debug shape to given target
169
+ /* !
170
+ \brief Draws debug shape to given target
171
+ */
136
172
void drawDebugShape (sf::RenderTarget& rt) const ;
137
- // returns the first point of poly point member (if any)
173
+ /* !
174
+ \brief Returns the first point of poly point member (if any) in world coordinates
175
+ */
138
176
sf::Vector2f firstPoint () const ;
139
- // returns the last point of poly point member (if any)
177
+ /* !
178
+ \brief Returns the last point of poly point member (if any) in world coordinates
179
+ */
140
180
sf::Vector2f lastPoint () const ;
141
- // returns a unit vector normal to the polyline segment if intersected
142
- // takes the start and end point of a trajectory
181
+ /* !
182
+ \brief Returns a unit vector normal to the polyline segment if intersected.
183
+ \param start The start point of the segment to test in world coords
184
+ \param end The end point of the segment to test in world coords
185
+ */
143
186
sf::Vector2f collisionNormal (const sf::Vector2f& start, const sf::Vector2f& end) const ;
144
- // creates a vector of segments making up the poly shape
187
+ /* !
188
+ \brief Creates a vector of segments making up the poly shape
189
+ */
145
190
void createSegments ();
146
- // returns if an objects poly shape is convex or not
191
+ /* !
192
+ \brief Returns whether an object's poly shape is convex or not
193
+ */
147
194
bool convex () const ;
148
- // returns a reference to the array of points making up the object
195
+ /* !
196
+ \brief Returns a const reference to the array of points making up the object
197
+ */
149
198
const std::vector<sf::Vector2f>& polyPoints () const ;
150
- // reversing winding of object points
199
+ /* !
200
+ \brief Reverses the winding of object points
201
+ */
151
202
void reverseWinding ();
152
- // sets the quad used to draw the tile for tile objects
203
+ /* !
204
+ \brief Sets the quad used to draw the tile for tile objects
205
+ */
153
206
void setQuad (TileQuad* quad);
154
207
208
+ /* !
209
+ \brief Set the position of the object in world coordinates
210
+ */
211
+ void setPosition (float , float );
212
+ /* !
213
+ \brief Set the position of the object in world coordinates
214
+ */
215
+ void setPosition (const sf::Vector2f&);
216
+ /* !
217
+ \brief Move the objects position, in world coordinates
218
+ */
219
+ void move (float , float );
220
+ /* !
221
+ \brief Set the position of the object in world coordinates
222
+ */
223
+ void move (const sf::Vector2f&);
224
+
155
225
private:
156
226
// object properties, reflects those which are part of the tmx format
157
227
std::string m_name, m_type, m_parent; // parent is name of layer to which object belongs
158
- // sf::FloatRect m_rect; //width / height property of object plus position in world space
159
- sf::Vector2f m_position, m_size;
228
+ sf::Vector2f m_size;
160
229
std::map <std::string, std::string> m_properties;// map of custom name/value properties
161
230
bool m_visible;
162
231
std::vector<sf::Vector2f> m_polypoints; // list of points defining any polygonal shape
@@ -183,10 +252,14 @@ namespace tmx
183
252
};
184
253
using MapObjects = std::vector<MapObject>;
185
254
186
- // represents a single tile on a layer
255
+ /* !
256
+ \brief Represents a single tile on a layer
257
+ */
187
258
struct TMX_EXPORT_API MapTile final
188
259
{
189
- // returns the base centre point of sprite / tile
260
+ /* !
261
+ \brief Returns the base centre point of sprite / tile
262
+ */
190
263
sf::Vector2f getBase () const
191
264
{
192
265
return sf::Vector2f (sprite.getPosition ().x + (sprite.getLocalBounds ().width / 2 .f ),
0 commit comments