]> git.localhorst.tv Git - l2e.git/blob - src/graphics/Frame.cpp
merged Point into Vector
[l2e.git] / src / graphics / Frame.cpp
1 /*
2  * Frame.cpp
3  *
4  *  Created on: Aug 7, 2012
5  *      Author: holy
6  */
7
8 #include "Frame.h"
9
10 using geometry::Vector;
11
12 namespace graphics {
13
14 // TODO: maybe create a cache for frames?
15 void Frame::Draw(SDL_Surface *dest, const Vector<int> &position, int width, int height) const {
16         // top-left corner
17         SDL_Rect srcRect;
18         srcRect.x = xOffset;
19         srcRect.y = yOffset;
20         srcRect.w = borderWidth;
21         srcRect.h = borderHeight;
22         SDL_Rect destRect;
23         destRect.x = position.X();
24         destRect.y = position.Y();
25         SDL_BlitSurface(surface, &srcRect, dest, &destRect);
26
27         // top border
28         srcRect.x += borderWidth;
29         srcRect.w = repeatWidth;
30         destRect.x += borderWidth;
31         int fullRepeatWidth(width - (2 * borderWidth));
32         int repeatCursor(0);
33         while (repeatCursor < fullRepeatWidth) {
34                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
35                 destRect.x += repeatWidth;
36                 repeatCursor += repeatWidth;
37         }
38
39         // top-right corner
40         srcRect.x += repeatWidth;
41         srcRect.w = borderWidth;
42         SDL_BlitSurface(surface, &srcRect, dest, &destRect);
43
44         // middle
45         destRect.y += borderHeight;
46         int fullRepeatHeight(height - (2 * borderHeight));
47         int hRepeatCursor(0);
48         while (hRepeatCursor < fullRepeatHeight) {
49
50                 // left border
51                 srcRect.x = xOffset;
52                 srcRect.y = yOffset + borderHeight;
53                 srcRect.w = borderWidth;
54                 srcRect.h = repeatHeight;
55                 destRect.x = position.X();
56                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
57
58                 // fill
59                 repeatCursor = 0;
60                 srcRect.x += borderWidth;
61                 srcRect.w = repeatWidth;
62                 destRect.x += borderWidth;
63                 while (repeatCursor < fullRepeatWidth) {
64                         SDL_BlitSurface(surface, &srcRect, dest, &destRect);
65                         destRect.x += repeatWidth;
66                         repeatCursor += repeatWidth;
67                 }
68
69                 // right border
70                 srcRect.x += repeatWidth;
71                 srcRect.w = borderWidth;
72                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
73
74                 destRect.y += repeatHeight;
75                 hRepeatCursor += repeatHeight;
76         }
77
78         // bottom-left corner
79         srcRect.x = xOffset;
80         srcRect.y = yOffset + borderHeight + repeatHeight;
81         srcRect.w = borderWidth;
82         srcRect.h = borderHeight;
83         destRect.x = position.X();
84         SDL_BlitSurface(surface, &srcRect, dest, &destRect);
85
86         // bottom border
87         srcRect.x += borderWidth;
88         srcRect.w = repeatWidth;
89         destRect.x += borderWidth;
90         repeatCursor = 0;
91         while (repeatCursor < fullRepeatWidth) {
92                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
93                 destRect.x += repeatWidth;
94                 repeatCursor += repeatWidth;
95         }
96         if (fullRepeatWidth < fullRepeatWidth) {
97                 srcRect.w = fullRepeatWidth - fullRepeatWidth;
98                 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
99                 destRect.x += fullRepeatWidth - fullRepeatWidth;
100         }
101
102         // bottom-right corner
103         srcRect.x += repeatWidth;
104         srcRect.w = borderWidth;
105         SDL_BlitSurface(surface, &srcRect, dest, &destRect);
106 }
107
108 }