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)
7 #include <unison/video/Surface.hpp>
8 #include <unison/video/Window.hpp>
9 #include <unison/video/Renderers.hpp>
10 #include <unison/video/sdl/Blitters.hpp>
11 #include <unison/video/backend/Renderer.hpp>
21 Texture::Texture(const Surface &surface) :
22 Backend::Texture(surface),
30 /*Texture::Texture(const Surface &surface, const std::string &name) :
31 Backend::Texture(surface, name),
40 Texture::Texture(Backend::Texture *texture) :
41 Backend::Texture(texture),
54 const Surface Texture::get_surface()
68 void Texture::blit(const Surface &src, const Point &dst_pos, const Rect &src_rect, const RenderOptions &options)
71 Renderers::get().get_renderer().blit(src, src_rect, surface, dst_pos, options);
74 void Texture::blit(const Video::Texture &src, const Point &dst_pos, const Rect &src_rect, const RenderOptions &options)
77 Texture *texture = dynamic_cast<Texture *>(Backend::Texture::get_texture(src.get_id()));
78 Renderers::get().get_renderer().blit(texture, src_rect, surface, dst_pos, options);
81 void Texture::fill(const Color &color, const Rect &rect)
84 Renderers::get().get_renderer().fill(surface, color, rect);
87 void Texture::fill_blend(const Color &color, const Rect &rect)
90 Renderers::get().get_renderer().fill_blend(surface, color, rect);
93 SDL_Surface *Texture::get_transform(const RenderOptions &options, unsigned int numerator, unsigned int denominator)
95 if(scaled.get_size() == Area())
97 scaled = surface.scale(numerator, denominator);
99 assert(scaled.get_size() == surface.get_size() * numerator / denominator);
100 std::map<Color, AlphaMap> &cache = options.h_flip ? (options.v_flip ? d_cache : h_cache) : (options.v_flip ? v_cache : n_cache);
101 if(!cache[options.color][options.alpha])
103 Surface transformed = scaled.modulate(options.color).modulate(options.alpha);
106 transformed = transformed.h_flip();
110 transformed = transformed.v_flip();
112 cache[options.color][options.alpha] = Blitters::optimize(transformed);
114 return cache[options.color][options.alpha];