|
|
|
#ifndef COMPONENTS_TEXTURE_HPP
|
|
|
|
#define COMPONENTS_TEXTURE_HPP
|
|
|
|
|
|
|
|
#include "components/point.hpp"
|
|
|
|
#include "window.hpp"
|
|
|
|
|
|
|
|
class Texture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Texture(const char *path) {
|
|
|
|
tex = sdl2LoadTexture(path);
|
|
|
|
if (tex)
|
|
|
|
SDL_QueryTexture(tex, nullptr, nullptr, &w, &h);
|
|
|
|
}
|
|
|
|
|
|
|
|
~Texture() {
|
|
|
|
if (tex != nullptr)
|
|
|
|
SDL_DestroyTexture(tex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator()(SDL_Renderer *rend, Point p) const noexcept {
|
|
|
|
const int x = static_cast<int>(p.x);
|
|
|
|
const int y = static_cast<int>(p.y);
|
|
|
|
SDL_Rect rect {x, y, w, h};
|
|
|
|
|
|
|
|
SDL_RenderCopy(rend, tex, nullptr, &rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
Point dim() const noexcept {
|
|
|
|
return Point {static_cast<float>(w), static_cast<float>(h)};
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SDL_Texture *tex;
|
|
|
|
int w, h;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // COMPONENTS_TEXTURE_HPP
|
|
|
|
|