-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.cpp
More file actions
40 lines (38 loc) · 1.2 KB
/
Image.cpp
File metadata and controls
40 lines (38 loc) · 1.2 KB
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
#include <allegro5/allegro.h>
#include <memory>
#include "IObject.hpp"
#include "Image.hpp"
#include "Point.hpp"
#include "Resources.hpp"
namespace Engine {
Image::Image(std::string img, float x, float y, float w, float h, float anchorX, float anchorY) :
IObject(x, y, w, h, anchorX, anchorY) {
if (Size.x == 0 && Size.y == 0) {
bmp = Resources::GetInstance().GetBitmap(img);
Size.x = GetBitmapWidth();
Size.y = GetBitmapHeight();
}
else if (Size.x == 0) {
bmp = Resources::GetInstance().GetBitmap(img);
Size.x = GetBitmapWidth() * Size.y / GetBitmapHeight();
}
else if (Size.y == 0) {
bmp = Resources::GetInstance().GetBitmap(img);
Size.y = GetBitmapHeight() * Size.x / GetBitmapWidth();
}
else /* Size.x != 0 && Size.y != 0 */ {
bmp = Resources::GetInstance().GetBitmap(img, Size.x, Size.y);
}
}
void Image::Draw() const {
al_draw_scaled_bitmap(bmp.get(), 0, 0, GetBitmapWidth(), GetBitmapHeight(),
Position.x - Anchor.x * GetBitmapWidth(), Position.y - Anchor.y * GetBitmapHeight(),
Size.x, Size.y, 0);
}
int Image::GetBitmapWidth() const {
return al_get_bitmap_width(bmp.get());
}
int Image::GetBitmapHeight() const {
return al_get_bitmap_height(bmp.get());
}
}