mp-sfml/include/imageService.h

20 lines
545 B
C
Raw Permalink Normal View History

2024-09-09 13:20:59 +08:00
#include <SFML/Graphics.hpp>
#include <algorithm>
2024-09-30 13:34:05 +08:00
#include <memory>
2024-09-09 13:20:59 +08:00
class ImageService {
private:
2024-09-30 13:34:05 +08:00
std::shared_ptr<sf::Texture> texture = std::make_shared<sf::Texture>();
2024-09-09 13:20:59 +08:00
public:
ImageService(const std::string& name){
2024-09-30 13:34:05 +08:00
texture->loadFromFile(name);
2024-09-09 13:20:59 +08:00
}
2024-09-30 13:34:05 +08:00
std::shared_ptr<sf::Texture> GetTexture(){
2024-09-09 13:20:59 +08:00
return texture;
}
float GetScale(int width, int height){
2024-09-30 13:34:05 +08:00
auto imgSize = texture->getSize();
2024-09-09 13:20:59 +08:00
return std::min(static_cast<float>(width) / imgSize.x, static_cast<float>(height) / imgSize.y);
}
};