mp-sfml/include/imageService.h

20 lines
545 B
C++

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