]> git.localhorst.tv Git - l2e.git/blob - src/graphics/Frame.cpp
deallocate most of the stuff Interpreter reservers
[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 = offset.X();
19         srcRect.y = offset.Y();
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 = offset.X();
52                 srcRect.y = offset.Y() + 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 = offset.X();
80         srcRect.y = offset.Y() + 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 }