Initial integration, lots of broken stuff
[supertux.git] / src / unison / src / video / Blittable.cpp
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 #include <unison/video/Blittable.hpp>
7 #include <unison/video/DisplayList.hpp>
8
9 namespace Unison
10 {
11    namespace Video
12    {
13       Blittable::~Blittable()
14       {
15       }
16
17       void Blittable::blit_section(const SurfaceSection &section, const Point &dst_pos, const RenderOptions &options)
18       {
19          blit(section.image, dst_pos, section.clip_rect, options);
20       }
21
22       void Blittable::blit_section(const TextureSection &section, const Point &dst_pos, const RenderOptions &options)
23       {
24          blit(section.image, dst_pos, section.clip_rect, options);
25       }
26
27       void Blittable::draw(const DisplayList &list)
28       {
29          list.draw(this);
30       }
31
32       BlittableSection::BlittableSection(Blittable &image, const Rect &clip_rect) :
33          image(image),
34          clip_rect(clip_rect)
35       {
36       }
37
38       void BlittableSection::blit(const Surface &src, const Point &dst_pos, const Rect &src_rect, const RenderOptions &options)
39       {
40          Rect overlap = clip_rect.get_overlap(Rect(dst_pos, src_rect.size));
41          if(overlap == Rect())
42          {
43             return;
44          }
45          Rect clipped_src_rect(src_rect.pos, overlap.size);
46          clipped_src_rect.pos += overlap.pos;
47          clipped_src_rect.pos -= dst_pos;
48          image.blit(src, overlap.pos - clip_rect.pos, clipped_src_rect, options);
49       }
50
51       void BlittableSection::blit(const Texture &src, const Point &dst_pos, const Rect &src_rect, const RenderOptions &options)
52       {
53          Rect overlap = clip_rect.get_overlap(Rect(dst_pos, src_rect.size));
54          if(overlap == Rect())
55          {
56             return;
57          }
58          Rect clipped_src_rect(src_rect.pos, overlap.size);
59          clipped_src_rect.pos += overlap.pos;
60          clipped_src_rect.pos -= dst_pos;
61          image.blit(src, overlap.pos - clip_rect.pos, clipped_src_rect, options);
62       }
63
64       void BlittableSection::fill(const Color &color, const Rect &rect)
65       {
66          Rect overlap = clip_rect.get_overlap(rect);
67          overlap.pos -= clip_rect.pos;
68          image.fill(color, overlap);
69       }
70
71       void BlittableSection::fill_blend(const Color &color, const Rect &rect)
72       {
73          Rect overlap = clip_rect.get_overlap(rect);
74          overlap.pos -= clip_rect.pos;
75          image.fill_blend(color, overlap);
76       }
77    }
78 }