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)
6 #ifndef UNISON_VIDEO_TEXTURE_HPP
7 #define UNISON_VIDEO_TEXTURE_HPP
9 #include <unison/video/Blittable.hpp>
10 #include <unison/video/Surface.hpp>
11 #include <unison/video/Coord.hpp>
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
27 /// Default constructor
30 /// Opens image file indicated by filename
31 /// \param[in] filename The filename of the image file
32 Texture(const std::string &filename);
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);
39 /// Create a texture from the given surface
40 /// \param[in] surface The surface to optimize
41 Texture(const Surface &surface);
44 /// \param[in] rhs The source texture
45 Texture(const Texture &rhs);
50 /// Assignment operator
51 /// \param[in] rhs The source surface
52 Texture &operator =(const Texture &rhs);
54 /// Retrieves the texture's id
55 /// \return The id of the surface
56 TextureID get_id() const;
58 /// Retrieves the texture's size
59 /// \return The size of the surface
60 Area get_size() const;
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());
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());
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());
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());
86 static std::vector<Surface> save_textures();
87 static void load_textures(const std::vector<Surface> &surfaces);
89 /// Recover previously used but now unused texture IDs
90 static void recover_texture_ids();
98 /// All the textures in existence
99 static std::set<Texture *> textures;
102 /// A section of a texture
109 /// The clip rectangle
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()) :