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