supertux
surface.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_VIDEO_SURFACE_HPP
18 #define HEADER_SUPERTUX_VIDEO_SURFACE_HPP
19 
20 #include <string>
21 #include <optional>
22 
23 #include "math/rect.hpp"
24 #include "math/vector.hpp"
25 #include "video/flip.hpp"
26 #include "video/surface_ptr.hpp"
27 #include "video/texture_ptr.hpp"
28 
29 class ReaderMapping;
30 class SurfaceData;
31 
35 class Surface final
36 {
37 public:
38  static SurfacePtr from_texture(const TexturePtr& texture);
39  static SurfacePtr from_file(const std::string& filename, const std::optional<Rect>& rect = std::nullopt);
40  static SurfacePtr from_reader(const ReaderMapping& mapping, const std::optional<Rect>& rect = std::nullopt, const std::string& filename = "");
41 
42 private:
43  Surface(const TexturePtr& diffuse_texture, const TexturePtr& displacement_texture, Flip flip, const std::string& filename = "");
44  Surface(const TexturePtr& diffuse_texture, const TexturePtr& displacement_texture, const Rect& region, Flip flip, const std::string& filename = "");
45 
46 public:
47  ~Surface();
48 
49  SurfacePtr region(const Rect& rect) const;
50  SurfacePtr clone(Flip flip = NO_FLIP) const;
51 
52  TexturePtr get_texture() const;
53  TexturePtr get_displacement_texture() const;
54  Rect get_region() const { return m_region; }
55  int get_width() const;
56  int get_height() const;
57  Flip get_flip() const { return m_flip; }
58  const std::string& get_filename() const { return m_source_filename; }
59 
60 private:
61  const TexturePtr m_diffuse_texture;
62  const TexturePtr m_displacement_texture;
63  const Rect m_region;
64  const Flip m_flip;
65  const std::string m_source_filename;
66 
67 private:
68  Surface& operator=(const Surface&) = delete;
69 };
70 
71 #endif
72 
73 /* EOF */
A rectangular image.
Definition: surface.hpp:35
Definition: rect.hpp:30
Definition: reader_mapping.hpp:32