P-E-R-R-Y
Utilitaires, contrats et vendors du moteur, en une seule doc
Loading...
Searching...
No Matches
SfmlTexture.hpp
Go to the documentation of this file.
1
10
11#ifndef SFMLTEXTURE_HPP_
12#define SFMLTEXTURE_HPP_
13
14//Sfml
15#include <SFML/Graphics.hpp>
16
17//Interface
18#include "ITexture.hpp"
19
20#include <iostream>
21#include <optional>
22
29
30 public:
31 SfmlTexture(std::string path) {
32 try {
33 _texture.emplace(path);
34 } catch (const sf::Exception &e) {
35 std::cerr << "Failed to load texture: " << e.what() << std::endl;
36 }
37 }
38
39 ~SfmlTexture() = default;
40
41 bool isReady() const override {
42 return _texture.has_value();
43 }
44
45 Vector2f getSize() const override {
46 if (!_texture.has_value())
47 return {};
48 sf::Vector2u size = _texture->getSize();
49 return {static_cast<double>(size.x), static_cast<double>(size.y)};
50 }
51
52 const sf::Texture &handle() const {
53 return _texture.value();
54 }
55
56 private:
57 std::optional<sf::Texture> _texture;
58};
59
61
62#endif /* !SFMLTEXTURE_HPP_ */
const sf::Texture & handle() const
Definition SfmlTexture.hpp:52
Vector2f getSize() const override
Get the Size object.
Definition SfmlTexture.hpp:45
bool isReady() const override
notice if the texture is ready
Definition SfmlTexture.hpp:41
SfmlTexture(std::string path)
Definition SfmlTexture.hpp:31
~SfmlTexture()=default
Loaded pixel data, independent of any ISprite that references it. Deleting every ISprite built from a...
Definition ITexture.hpp:23
Vector2< double > Vector2f
Definition Vector2.hpp:112