-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAEBasic.h
299 lines (237 loc) · 7.43 KB
/
AEBasic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#ifndef AE_BASIC_CLASSES
#define AE_BASIC_CLASSES
#include <iostream>
#include <sstream>
#include <limits>
#include <vector>
#include <fstream>
#include "incLib.h"
#include "AETypes.h"
#include "AELogger.h"
#include "AELoggerFile.h"
#include "AEDll.h"
#include "Vector2D.h"
void lire_matrice(std::vector <std::vector<char> > matrice);
namespace AE
{
template<class T>
class Rect : public Vector2D<T>
{
public:
Rect() : x(0), y(0), w(0), h(0)
{
}
Rect(T _x, T _y, T _w=0, T _h=0) : x(_x), y(_y), w(_w), h(_h)
{
}
template<class S>
Rect(const Rect<S> &a_copier) : x( (T)a_copier.x ), y( (T)a_copier.y ), w( (T)a_copier.w ), h( (T)a_copier.h )
{
}
template<class S>
Rect(const Vector2D<S> &a_copier) : x( (T)a_copier.x ), y( (T)a_copier.y ), w(0), h(0)
{
}
Rect(const SDL_Rect &rect) : x(rect.x), y(rect.y), w(rect.w), h(rect.h)
{
}
template<class S>
void operator=(Rect<S> &a_copier)
{
x = (T)a_copier.x;
y = (T)a_copier.y;
w = (T)a_copier.w;
h = (T)a_copier.h;
}
void operator=(SDL_Rect &a_copier)
{
x = a_copier.x;
y = a_copier.y;
w = a_copier.w;
h = a_copier.h;
}
template<class S>
Rect operator+(Rect<S> &a_ajouter)
{
Rect to_return;
to_return = *this;
to_return.x += (T)a_ajouter.x;
to_return.y += (T)a_ajouter.y;
to_return.w += (T)a_ajouter.w;
to_return.h += (T)a_ajouter.h;
return to_return;
}
template<class S>
bool operator==(Rect<S> &compare)
{
if(x == compare.x && y == compare.y && w == compare.w && h == compare.h)
return true;
else
return false;
}
template<class S>
bool operator!=(Rect<S> &compare)
{
if(x == compare.x && y == compare.y && w == compare.w && h == compare.h)
return false;
else
return true;
}
Rect operator+(SDL_Rect &a_ajouter)
{
Rect to_return;
to_return = *this;
to_return.x += a_ajouter.x;
to_return.y += a_ajouter.y;
to_return.w += a_ajouter.w;
to_return.h += a_ajouter.h;
return to_return;
}
template<class S>
Rect operator-(Rect<S> &rect)
{
Rect to_return;
to_return = *this;
to_return.x -= rect.x;
to_return.y -= rect.y;
to_return.w -= rect.w;
to_return.h -= rect.h;
}
template<class S>
void operator-=(Rect<S> &rect)
{
x -= rect.x;
y -= rect.y;
w -= rect.w;
h -= rect.h;
}
void afficher()
{
Logger::Log() << "Rect - x : " << x << " ; y : " << y << " ; w : " << w << " ; h : " << h << Logger::endline;
}
bool zero()
{
if(x == 0 && y == 0 && w == 0 && h == 0)
return true;
return false;
}
T w, h;
T x, y;
};
class RGB
{
public:
RGB(int=0, int=0, int=0);
Uint32 toMapRGB(SDL_PixelFormat *format);
bool operator==(RGB color);
bool operator!=(RGB color);
int moyenne();
int r, g, b;
};
SDL_Surface * LoadImage(std::string chemin_image);
SDL_Surface * RGB_Surface(Rect<int> dimensions, int depth=32, Uint32 Gmask=0, Uint32 Rmask=0, Uint32 Bmask=0, Uint32 Amask=0);
SDL_Surface * copySurface(SDL_Surface *);
bool FreeSurface(SDL_Surface *to_free);
bool RotoZoomSurface(SDL_Surface *src, SDL_Surface *dest, double angle, double zoomx, double zoomy, bool anti_aliasing=false);
bool ApplySurface(SDL_Surface *source, SDL_Surface *dest, Rect<int> source_rect=Rect<int>(), Rect<int> dest_rect=Rect<int>() );
bool FillSurface(SDL_Surface *to_fill, RGB=RGB(255, 255, 255), Rect<int> to_fill_rect=Rect<int>() );
bool SetColorKey( SDL_Surface *, RGB transparent_color );
bool SaveBMP(SDL_Surface *, std::string chemin);
Uint32 getPixel(SDL_Surface *surface, Vector2D<int> position);
void setPixel(SDL_Surface *surface, Vector2D<int> position, Uint32 pixel);
class Pixel
{
public:
Pixel();
Pixel(const Pixel &to_copy);
Pixel(Uint32 pixel, SDL_PixelFormat &format);
Pixel(Uint8 r, Uint8 g, Uint8 b, Uint8 a, SDL_PixelFormat &format);
Uint32 getPixel();
void getPixelInfo(Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
void setPixelInfo(Uint8 r, Uint8 g, Uint8 b, Uint8 a, SDL_PixelFormat &format);
void setPixel(Uint32 pixel);
void setR(Uint8 R);
void setG(Uint8 G);
void setB(Uint8 B);
void setA(Uint8 A);
Uint8 getR();
Uint8 getG();
Uint8 getB();
Uint8 getA();
protected:
Uint32 m_pixel;
SDL_PixelFormat m_format;
};
class Surface
{
public:
Surface();
Surface(const Surface &);
Surface(const SDL_Surface *);
Surface(const std::string);
Surface(Rect<int> dimensions, int depth=32, Uint32 Gmask=0, Uint32 Rmask=0, Uint32 Bmask=0, Uint32 Amask=0);
~Surface();
SDL_Surface *getSurface(); // Il est fortement déconseillé d'utiliser cette fonction
bool rgb_surface(Rect<int> dimensions, int depth=32, Uint32 Gmask=0, Uint32 Rmask=0, Uint32 Bmask=0, Uint32 Amask=0);
bool load(std::string);
bool apply(Surface, Rect<int> = Rect<int>(), Rect<int> = Rect<int>() ) const;
bool fill(RGB=RGB(255, 255, 255), Rect<int> = Rect<int>() );
bool setColorKey(RGB transparent_color );
bool saveBMP(std::string chemin);
bool flip() const; // const (à la fin de la déclaration de la fonction) Veut dire que cette fonction ne change pas les variables de la classe
bool lock();
bool unlock();
void setPixel(Vector2D<int> position, Pixel &pixel);
Pixel getPixel(Vector2D<int> position);
void setPixelColor(Vector2D<int> position, RGB color);
RGB getPixelColor(Vector2D<int> position);
Uint8 getPixelOneComposant(Vector2D<int> position, char color_number);
bool free(); // Fait un free de la surface
void *pixels();
int pitch();
int width() const;
int height() const;
int BitsPerPixel() const;
SDL_PixelFormat PixelFormat() const;
SDL_PixelFormat *PixelFormatAddr() const;
void copySurface(Surface);
void copySurface(SDL_Surface *);
bool is_null() const;
bool operator=(Surface); // Ne copie pas la surface mais le pointeur de surface, attention aux confusions
bool operator=(SDL_Surface *); // IDEM :D
operator bool();
bool operator==(bool) const;
bool operator!=(bool) const;
protected:
SDL_Surface *m_surface; // Le pointeur de SDL_Surface
std::string m_path; // Si c'est une image loadée d'un fichier, le path n'est pas vide
};
struct SurfaceDeleter
{
void operator()(Surface *&surf);
};
typedef boost::shared_ptr<Surface> SurfacePtr;
//char **explode(char *str, char separator, int *number_exploded);
int string_to_int(std::string nombre_str);
void aller_a_ligne(std::ifstream &fichier, int num_ligne);
}
class MapPos
{
public:
MapPos( int L=0, int l=0, int rL=0, int rl=0, float plus_x=0, float plus_y=0);
MapPos(const MapPos &a_copier);
MapPos(int L, int l, const AE::Rect<float> a_copier);
void add(float, float);
void operator=(MapPos a_copier);
void operator=(AE::Rect<float> a_copier);
void operator+=(AE::Rect<float> a_ajouter);
MapPos operator+(AE::Rect<float> a_ajouter);
SDL_Rect* to_SDL_Rect();
AE::Rect<float> to_Rect();
int getPlusX();
int getPlusY();
int m_L, m_l;
int m_rL, m_rl;
float m_plus_percent_x, m_plus_percent_y;
};
#endif