4 * Created on: Aug 7, 2012
10 using geometry::Vector;
14 // TODO: maybe create a cache for frames?
15 void Frame::Draw(SDL_Surface *dest, const Vector<int> &position, int width, int height) const {
18 srcRect.x = offset.X();
19 srcRect.y = offset.Y();
20 srcRect.w = BorderWidth();
21 srcRect.h = BorderHeight();
23 destRect.x = position.X();
24 destRect.y = position.Y();
25 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
28 srcRect.x += BorderWidth();
29 srcRect.w = RepeatWidth();
30 destRect.x += BorderWidth();
31 int fullRepeatWidth(width - (2 * BorderWidth()));
33 while (repeatCursor < fullRepeatWidth) {
34 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
35 destRect.x += RepeatWidth();
36 repeatCursor += RepeatWidth();
40 srcRect.x += RepeatWidth();
41 srcRect.w = BorderWidth();
42 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
45 destRect.y += BorderHeight();
46 int fullRepeatHeight(height - (2 * BorderHeight()));
48 while (hRepeatCursor < fullRepeatHeight) {
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);
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();
70 srcRect.x += RepeatWidth();
71 srcRect.w = BorderWidth();
72 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
74 destRect.y += RepeatHeight();
75 hRepeatCursor += RepeatHeight();
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);
87 srcRect.x += BorderWidth();
88 srcRect.w = RepeatWidth();
89 destRect.x += BorderWidth();
91 while (repeatCursor < fullRepeatWidth) {
92 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
93 destRect.x += RepeatWidth();
94 repeatCursor += RepeatWidth();
96 if (fullRepeatWidth < fullRepeatWidth) {
97 srcRect.w = fullRepeatWidth - fullRepeatWidth;
98 SDL_BlitSurface(surface, &srcRect, dest, &destRect);
99 destRect.x += fullRepeatWidth - fullRepeatWidth;
102 // bottom-right corner
103 srcRect.x += RepeatWidth();
104 srcRect.w = BorderWidth();
105 SDL_BlitSurface(surface, &srcRect, dest, &destRect);