]> git.localhorst.tv Git - l2e.git/blob - src/graphics/Texture.cpp
removed stupid file headers that eclipse put in
[l2e.git] / src / graphics / Texture.cpp
1 #include "Texture.h"
2
3 #include "../sdl/utility.h"
4
5 using geometry::Vector;
6
7 namespace graphics {
8
9 Texture::Texture(
10                 SDL_Surface *surface,
11                 const Vector<int> &size,
12                 const Vector<int> &offset)
13 : surface(surface)
14 , size(size)
15 , offset(offset) {
16
17 }
18
19 Texture::~Texture() {
20
21 }
22
23
24 void Texture::Render(SDL_Surface *dest, const Vector<int> &from, const Vector<int> &to) const {
25         SDL_Rect destRect;
26         destRect.x = from.X();
27         destRect.y = from.Y();
28         if (!surface || size == Vector<int>()) {
29                 destRect.w = to.X() - from.X();
30                 destRect.h = to.Y() - from.Y();
31                 SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00));
32                 return;
33         }
34
35         SDL_Rect srcRect;
36         srcRect.x = offset.X();
37         srcRect.y = offset.Y();
38
39         for (destRect.y = from.Y(); destRect.y < to.Y(); destRect.y += size.Y()) {
40                 srcRect.h = size.Y();
41                 destRect.h = size.Y();
42                 if (destRect.y + destRect.h > to.Y()) {
43                         srcRect.h = to.Y() - destRect.y;
44                         destRect.h = to.Y() - destRect.y;
45                 }
46                 for (destRect.x = from.X(); destRect.x < to.X(); destRect.x += size.X()) {
47                         srcRect.w = size.X();
48                         destRect.w = size.X();
49                         if (destRect.x + destRect.w > to.X()) {
50                                 srcRect.w = to.X() - destRect.x;
51                                 destRect.w = to.X() - destRect.x;
52                         }
53                         SDL_BlitSurface(surface, &srcRect, dest, &destRect);
54                 }
55         }
56 }
57
58 }