Initial integration, lots of broken stuff
[supertux.git] / src / unison / include / unison / video / Texture.hpp
1 //          Copyright Timothy Goya 2007.
2 // Distributed under the Boost Software License, Version 1.0.
3 //    (See accompanying file LICENSE_1_0.txt or copy at
4 //          http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifndef UNISON_VIDEO_TEXTURE_HPP
7 #define UNISON_VIDEO_TEXTURE_HPP
8
9 #include <unison/video/Blittable.hpp>
10 #include <unison/video/Surface.hpp>
11 #include <unison/video/Coord.hpp>
12
13 #include <string>
14 #include <vector>
15 #include <set>
16
17 namespace Unison
18 {
19    namespace Video
20    {
21       typedef unsigned int TextureID;
22       static const TextureID INVALID_TEXTURE_ID = ~0;
23       /// An image that is optimized for fast drawing
24       class Texture : public Blittable
25       {
26          public:
27             /// Default constructor
28             Texture();
29
30             /// Opens image file indicated by filename
31             /// \param[in] filename The filename of the image file
32             Texture(const std::string &filename);
33
34             /// Opens image file indicated by filename and use the specified colorkey
35             /// \param[in] filename The filename of the image file
36             /// \param[in] colorkey The colorkey used by the file
37             Texture(const std::string &filename, const Color &colorkey);
38
39             /// Create a texture from the given surface
40             /// \param[in] surface The surface to optimize
41             Texture(const Surface &surface);
42
43             /// Copy constructor
44             /// \param[in] rhs The source texture
45             Texture(const Texture &rhs);
46
47             /// Destructor
48             ~Texture();
49
50             /// Assignment operator
51             /// \param[in] rhs The source surface
52             Texture &operator =(const Texture &rhs);
53
54             /// Retrieves the texture's id
55             /// \return The id of the surface
56             TextureID get_id() const;
57
58             /// Retrieves the texture's size
59             /// \return The size of the surface
60             Area get_size() const;
61
62             /// Does a surface-to-texture blit
63             /// \param[in] src The source surface
64             /// \param[in] dst_pos The position to blit to
65             /// \param[in] src_rect The part of the source surface to blit from
66             /// \param[in] options Extra blit options
67             void blit(const Surface &src, const Point &dst_pos = Point(), const Rect &src_rect = Rect(), const RenderOptions &options = RenderOptions());
68
69             /// Does a texture-to-texture blit
70             /// \param[in] src The source texture
71             /// \param[in] dst_pos The position to blit to
72             /// \param[in] src_rect The part of the source texture to blit from
73             /// \param[in] options Extra blit options
74             void blit(const Texture &src, const Point &dst_pos = Point(), const Rect &src_rect = Rect(), const RenderOptions &options = RenderOptions());
75
76             /// Fills a portion of the image with the given color
77             /// \param[in] color The color
78             /// \param[in] rect The portion to fill
79             void fill(const Color &color, const Rect &rect = Rect());
80
81             /// Fills and alpha blend a portion of the image with the given color
82             /// \param[in] color The color
83             /// \param[in] rect The portion to fill
84             void fill_blend(const Color &color, const Rect &rect = Rect());
85
86             static std::vector<Surface> save_textures();
87             static void load_textures(const std::vector<Surface> &surfaces);
88
89             /// Recover previously used but now unused texture IDs
90             static void recover_texture_ids();
91          private:
92             /// Copy on Write
93             void cow();
94
95             /// The texture ID
96             TextureID id;
97
98             /// All the textures in existence
99             static std::set<Texture *> textures;
100       };
101
102       /// A section of a texture
103       class TextureSection
104       {
105          public:
106             /// The image
107             Texture image;
108
109             /// The clip rectangle
110             Rect clip_rect;
111
112             /// Create a section from an image and a rectangle
113             /// \param[in] image The image
114             /// \param[in] rect The clip rectangle
115             TextureSection(const Texture &image = Texture(), const Rect &clip_rect = Rect()) :
116                image(image),
117                clip_rect(clip_rect)
118             {
119             }
120       };
121    }
122 }
123
124 #endif