tmxlite
lightweight Tiled tmx map parser for C++
Object.hpp
1 /*********************************************************************
2 Matt Marchant 2016
3 http://trederia.blogspot.com
4 
5 tmxlite - Zlib license.
6 
7 This software is provided 'as-is', without any express or
8 implied warranty. In no event will the authors be held
9 liable for any damages arising from the use of this software.
10 
11 Permission is granted to anyone to use this software for any purpose,
12 including commercial applications, and to alter it and redistribute
13 it freely, subject to the following restrictions:
14 
15 1. The origin of this software must not be misrepresented;
16 you must not claim that you wrote the original software.
17 If you use this software in a product, an acknowledgment
18 in the product documentation would be appreciated but
19 is not required.
20 
21 2. Altered source versions must be plainly marked as such,
22 and must not be misrepresented as being the original software.
23 
24 3. This notice may not be removed or altered from any
25 source distribution.
26 *********************************************************************/
27 
28 #ifndef TMXLITE_OBJECT_HPP_
29 #define TMXLITE_OBJECT_HPP_
30 
31 #include <tmxlite/Config.hpp>
32 #include <tmxlite/Property.hpp>
33 #include <tmxlite/Types.hpp>
34 
35 #include <string>
36 #include <vector>
37 
38 namespace pugi
39 {
40  class xml_node;
41 }
42 
43 namespace tmx
44 {
48  struct TMXLITE_EXPORT_API Text final
49  {
50  std::string fontFamily;
51  std::uint32_t pixelSize = 16;
52  bool wrap = false;
53  Colour colour;
54  bool bold = false;
55  bool italic = false;
56  bool underline = false;
57  bool strikethough = false;
58  bool kerning = true;
59 
60  enum class HAlign
61  {
62  Left, Centre, Right
63  }hAlign = HAlign::Left;
64 
65  enum class VAlign
66  {
67  Top, Centre, Bottom
68  }vAlign = VAlign::Top;
69 
70  std::string content;
71  };
72 
82  class TMXLITE_EXPORT_API Object final
83  {
84  public:
85  enum class Shape
86  {
87  Rectangle,
88  Ellipse,
89  Point,
90  Polygon,
91  Polyline,
92  Text
93  };
94 
95  Object();
96 
101  void parse(const pugi::xml_node&);
102 
106  std::uint32_t getUID() const { return m_UID; }
107 
111  const std::string& getName() const { return m_name; }
112 
116  const std::string& getType() const { return m_type; }
117 
121  const Vector2f& getPosition() const { return m_position; }
122 
129  const FloatRect& getAABB() const { return m_AABB; }
130 
134  float getRotation() const { return m_rotation; }
135 
141  uint32_t getTileID() const { return m_tileID; }
142 
146  bool visible() const { return m_visible; }
147 
151  Shape getShape() const { return m_shape; }
152 
159  const std::vector<Vector2f>& getPoints() const { return m_points; }
160 
165  const std::vector<Property>& getProperties() const { return m_properties; }
166 
174  const Text& getText() const { return m_textData; }
175  Text& getText() { return m_textData; }
176 
177  private:
178  std::uint32_t m_UID;
179  std::string m_name;
180  std::string m_type;
181  Vector2f m_position;
182  FloatRect m_AABB;
183  float m_rotation;
184  std::uint32_t m_tileID;
185  bool m_visible;
186 
187  Shape m_shape;
188  std::vector<Vector2f> m_points;
189  std::vector<Property> m_properties;
190 
191  Text m_textData;
192 
193  void parsePoints(const pugi::xml_node&);
194  void parseText(const pugi::xml_node&);
195  void parseTemplate(const std::string&);
196  };
197 }
198 
199 #endif //TMXLITE_OBJECT_HPP_
Definition: Log.hpp:58
Contains the red, green, blue and alpha values of a colour in the range 0 - 255.
Definition: Types.hpp:109
std::uint32_t getUID() const
Returns the unique ID of the Object.
Definition: Object.hpp:106
Shape getShape() const
Returns the Shape type of the Object.
Definition: Object.hpp:151
const std::string & getType() const
Returns the type of the Object, as defined in the editor.
Definition: Object.hpp:116
uint32_t getTileID() const
Returns the global tile ID associated with the Object if there is one. This is used to draw the Objec...
Definition: Object.hpp:141
float getRotation() const
Returns the rotation of the Object in degrees clockwise.
Definition: Object.hpp:134
std::string content
actual string content
Definition: Object.hpp:70
const std::string & getName() const
Returns the name of the Object.
Definition: Object.hpp:111
Objects are stored in ObjectGroup layers. Objects may be rectangular, elliptical, polygonal or a poly...
Definition: Object.hpp:82
const std::vector< Vector2f > & getPoints() const
Returns a reference to the vector of points which make up the Object. If the Object is rectangular or...
Definition: Object.hpp:159
const std::vector< Property > & getProperties() const
Returns a reference to the vector of properties belonging to the Object.
Definition: Object.hpp:165
bool visible() const
Returns whether or not the Object is visible.
Definition: Object.hpp:146
Definition: Layer.hpp:39
Describes a rectangular area, such as an AABB (axis aligned bounding box)
Definition: Types.hpp:94
const Vector2f & getPosition() const
Returns the position of the Object in pixels.
Definition: Object.hpp:121
const FloatRect & getAABB() const
Returns the global Axis Aligned Bounding Box. The AABB is positioned via the left and top properties...
Definition: Object.hpp:129
Contains the text information stored in a Text object.
Definition: Object.hpp:48
const Text & getText() const
Returns a Text struct containing information about any text this object may have, such as font data a...
Definition: Object.hpp:174