-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTexture.cpp
41 lines (34 loc) · 967 Bytes
/
Texture.cpp
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
#include "Texture.h"
Texture::Texture() : path("") {}
Texture::Texture(const std::string imgpath) : path(imgpath) {
if (!path.empty()) {
load(imgpath);
}
}
bool Texture::load(const std::string& imgpath) {
if (!imgpath.empty()) {
texture = driver->getTexture(imgpath.c_str());
path = imgpath;
return true;
}
return false;
}
std::string Texture::getPath() const {
return path;
}
void Texture::keyColor(const Vector2D& pos) {
if (texture)
driver->makeColorKeyTexture(texture, core::position2d<s32>(pos.x, pos.y));
}
void Texture::saveTexture(std::string path) {
irrHandler->doWriteTextureThreaded(texture, path);
}
void bindTexture() {
sol::usertype<Texture> bind_type = lua->new_usertype<Texture>("Texture",
sol::constructors<Texture(), Texture(std::string imgpath)>()
);
bind_type["load"] = &Texture::load;
bind_type["toStr"] = &Texture::getPath;
bind_type["keyColor"] = &Texture::keyColor;
bind_type["save"] = &Texture::saveTexture;
}