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 <boost/optional.hpp>
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
29class ReaderMapping;
30class SurfaceData;
31
32/** A rectangular image. The class basically holds a reference to a
33 texture with additional UV coordinates that specify a rectangular
34 area on this texture */
35class Surface final
36{
37public:
38 static SurfacePtr from_texture(const TexturePtr& texture);
39 static SurfacePtr from_file(const std::string& filename, const boost::optional<Rect>& rect = boost::none);
40 static SurfacePtr from_reader(const ReaderMapping& mapping, const boost::optional<Rect>& rect = boost::none);
41
42private:
43 Surface(const TexturePtr& diffuse_texture, const TexturePtr& displacement_texture, Flip flip);
44 Surface(const TexturePtr& diffuse_texture, const TexturePtr& displacement_texture, const Rect& region, Flip flip);
45
46public:
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
59private:
60 const TexturePtr m_diffuse_texture;
61 const TexturePtr m_displacement_texture;
62 const Rect m_region;
63 const Flip m_flip;
64
65private:
66 Surface& operator=(const Surface&) = delete;
67};
68
69#endif
70
71/* EOF */
72