tmxlite: D:/W/B/src/tmxlite-1.4.5/tmxlite/include/tmxlite/Types.hpp Source File

tmxlite 1.0.0 lightweight parse for Tiled maps

Types.hpp
1/*********************************************************************
2Matt Marchant 2016 - 2023
3http://trederia.blogspot.com
4
5tmxlite - Zlib license.
6
7This software is provided 'as-is', without any express or
8implied warranty. In no event will the authors be held
9liable for any damages arising from the use of this software.
10
11Permission is granted to anyone to use this software for any purpose,
12including commercial applications, and to alter it and redistribute
13it freely, subject to the following restrictions:
14
151. The origin of this software must not be misrepresented;
16you must not claim that you wrote the original software.
17If you use this software in a product, an acknowledgment
18in the product documentation would be appreciated but
19is not required.
20
212. Altered source versions must be plainly marked as such,
22and must not be misrepresented as being the original software.
23
243. This notice may not be removed or altered from any
25source distribution.
26*********************************************************************/
27
28#pragma once
29
30#include <tmxlite/Config.hpp>
31
32#include <cstdint>
33#include <ostream>
34
35
36namespace tmx
37{
41 template <class T>
42 struct Vector2 final
43 {
44 Vector2() : x(0), y(0) {}
45 Vector2(T x, T y) :x(x), y(y) {}
46 T x, y;
47 };
48
49 using Vector2f = Vector2<float>;
50 using Vector2i = Vector2<int>;
51 using Vector2u = Vector2<unsigned>;
52
53 template <typename T>
54 Vector2<T> operator + (const Vector2<T>& l, const Vector2<T>& r);
55
56 template <typename T>
57 Vector2<T>& operator += (Vector2<T>& l, const Vector2<T>& r);
58
59 template <typename T>
60 Vector2<T> operator - (const Vector2<T>& l, const Vector2<T>& r);
61
62 template <typename T>
63 Vector2<T>& operator -= (Vector2<T>& l, const Vector2<T>& r);
64
65 template <typename T>
66 Vector2<T> operator * (const Vector2<T>& l, const Vector2<T>& r);
67
68 template <typename T>
69 Vector2<T>& operator *= (Vector2<T>& l, const Vector2<T>& r);
70
71 template <typename T>
72 Vector2<T> operator * (const Vector2<T>& l, T r);
73
74 template <typename T>
75 Vector2<T>& operator *= (Vector2<T>& l, T r);
76
77 template <typename T>
78 Vector2<T> operator / (const Vector2<T>& l, const Vector2<T>& r);
79
80 template <typename T>
81 Vector2<T>& operator /= (Vector2<T>& l, const Vector2<T>& r);
82
83 template <typename T>
84 Vector2<T> operator / (const Vector2<T>& l, T r);
85
86 template <typename T>
87 Vector2<T>& operator /= (Vector2<T>& l, T r);
88
89#include "Types.inl"
90
94 template <class T>
95 struct Rectangle final
96 {
97 Rectangle() : left(0), top(0), width(0), height(0) {}
98 Rectangle(T l, T t, T w, T h) : left(l), top(t), width(w), height(h) {}
99 Rectangle(Vector2<T> position, Vector2<T> size) : left(position.x), top(position.y), width(size.x), height(size.y) {}
100 T left, top, width, height;
101 };
102
103 using FloatRect = Rectangle<float>;
104 using IntRect = Rectangle<int>;
105
110 struct TMXLITE_EXPORT_API Colour final
111 {
112 Colour(std::uint8_t red = 0, std::uint8_t green = 0, std::uint8_t blue = 0, std::uint8_t alpha = 255)
113 : r(red), g(green), b(blue), a(alpha) {}
114 std::uint8_t r, g, b, a;
115
116 bool operator == (const Colour& other) const
117 {
118 return other.r == r
119 && other.g == g
120 && other.b == b
121 && other.a == a;
122 }
123
124 bool operator != (const Colour& other) const
125 {
126 return !(*this == other);
127 }
128
129 explicit operator std::uint32_t() const
130 {
131 return (r << 24) | (g << 16) | (b << 8) | a;
132 }
133 };
134}
135
136template <typename T>
137std::ostream& operator << (std::ostream& os, const tmx::Vector2<T>& t)
138{
139 os << "{" << t.x << ", " << t.y << "}";
140 return os;
141}
142
143template <typename T>
144std::ostream& operator << (std::ostream& os, const tmx::Rectangle<T>& t)
145{
146 os << "{" << t.left << ", " << t.top << ", " << t.width << ", " << t.height << "}";
147 return os;
148}
149
150std::ostream& operator << (std::ostream& os, const tmx::Colour& c);
tmx::Colour
Contains the red, green, blue and alpha values of a colour in the range 0 - 255.
Definition Types.hpp:111
tmx::Rectangle
Describes a rectangular area, such as an AABB (axis aligned bounding box).
Definition Types.hpp:96
tmx::Vector2
Two dimensional vector used to store points and positions.
Definition Types.hpp:43