sfml_impl 0.1.0
Vendor SFML 3.0.2 : IGraphic2Module / IAudioModule
Loading...
Searching...
No Matches
SfmlTexture.hpp
Go to the documentation of this file.
1
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
28class SfmlTexture : public graphic::ITexture {
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
62#endif /* !SFMLTEXTURE_HPP_ */
Sfml Texture class - owns the loaded texture. SfmlSprite only references it (sf::Sprite itself alread...
Definition SfmlTexture.hpp:28
const sf::Texture & handle() const
Definition SfmlTexture.hpp:52
Vector2f getSize() const override
Definition SfmlTexture.hpp:45
bool isReady() const override
Definition SfmlTexture.hpp:41
SfmlTexture(std::string path)
Definition SfmlTexture.hpp:31
~SfmlTexture()=default