使用只能指针代替裸指针

This commit is contained in:
Jie
2024-09-30 13:34:05 +08:00
parent 7c049db4ac
commit 1237b164bf
12 changed files with 246 additions and 25 deletions

View File

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