tmxlite
lightweight Tiled tmx map parser for C++
Types.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_TYPES_HPP_
29 #define TMXLITE_TYPES_HPP_
30 
31 #include <tmxlite/Config.hpp>
32 
33 #include <cstdint>
34 
35 namespace tmx
36 {
40  template <class T>
41  struct Vector2 final
42  {
43  Vector2() : x(0), y(0) {}
44  Vector2(T x, T y) :x(x), y(y) {}
45  T x, y;
46  };
47 
48  using Vector2f = Vector2<float>;
49  using Vector2i = Vector2<int>;
51 
52  template <typename T>
53  Vector2<T> operator + (const Vector2<T>& l, const Vector2<T>& r);
54 
55  template <typename T>
56  Vector2<T>& operator += (Vector2<T>& l, const Vector2<T>& r);
57 
58  template <typename T>
59  Vector2<T> operator - (const Vector2<T>& l, const Vector2<T>& r);
60 
61  template <typename T>
62  Vector2<T>& operator -= (Vector2<T>& l, const Vector2<T>& r);
63 
64  template <typename T>
65  Vector2<T> operator * (const Vector2<T>& l, const Vector2<T>& r);
66 
67  template <typename T>
68  Vector2<T>& operator *= (Vector2<T>& l, const Vector2<T>& r);
69 
70  template <typename T>
71  Vector2<T> operator * (const Vector2<T>& l, T r);
72 
73  template <typename T>
74  Vector2<T>& operator *= (Vector2<T>& l, T r);
75 
76  template <typename T>
77  Vector2<T> operator / (const Vector2<T>& l, const Vector2<T>& r);
78 
79  template <typename T>
80  Vector2<T>& operator /= (Vector2<T>& l, const Vector2<T>& r);
81 
82  template <typename T>
83  Vector2<T> operator / (const Vector2<T>& l, T r);
84 
85  template <typename T>
86  Vector2<T>& operator /= (Vector2<T>& l, T r);
87 
88 #include "Types.inl"
89 
93  template <class T>
94  struct Rectangle final
95  {
96  Rectangle() : left(0), top(0), width(0), height(0) {}
97  Rectangle(T l, T t, T w, T h) : left(l), top(t), width(w), height(h) {}
98  Rectangle(Vector2<T> position, Vector2<T> size) : left(position.x), top(position.y), width(size.x), height(size.y) {}
99  T left, top, width, height;
100  };
101 
102  using FloatRect = Rectangle<float>;
103  using IntRect = Rectangle<int>;
104 
109  struct TMXLITE_EXPORT_API Colour final
110  {
111  Colour(std::uint8_t red = 0, std::uint8_t green = 0, std::uint8_t blue = 0, std::uint8_t alpha = 255)
112  : r(red), g(green), b(blue), a(alpha) {}
113  std::uint8_t r, g, b, a;
114  };
115 }
116 
117 #endif //TMXLITE_TYPES_HPP_
Definition: Log.hpp:58
Two dimensional vector used to store points and positions.
Definition: Types.hpp:41
Contains the red, green, blue and alpha values of a colour in the range 0 - 255.
Definition: Types.hpp:109
Describes a rectangular area, such as an AABB (axis aligned bounding box)
Definition: Types.hpp:94